Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(formula): array formula border Rect

Dushusir7188452b7048
diff --git a/packages/base-sheets/src/Controller/AntLineController.ts b/packages/base-sheets/src/Controller/AntLineController.ts
index 0eb0160e4a..17a28cba07 100644
--- a/packages/base-sheets/src/Controller/AntLineController.ts
+++ b/packages/base-sheets/src/Controller/AntLineController.ts
@@ -99,6 +99,7 @@ export class AntLineControl {
height: totalHeight,
width: totalWidth,
strokeDashArray: [5],
+ evented: false,
});
}
diff --git a/packages/core/src/Sheets/Domain/Workbook.ts b/packages/core/src/Sheets/Domain/Workbook.ts
index dd149c7e9a..be0183a94d 100644
--- a/packages/core/src/Sheets/Domain/Workbook.ts
+++ b/packages/core/src/Sheets/Domain/Workbook.ts
@@ -67,7 +67,10 @@ export class Workbook {
this._context = context;
const { styles } = this._config;
- this._unitId = this._config.id ?? nanoid(6);
+ if (this._config.id === '') {
+ this._config.id = nanoid(6);
+ }
+ this._unitId = this._config.id;
this._styles = new Styles(styles);
this._worksheets = new Map<string, Worksheet>();
this._commandManager = context.getCommandManager();
diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
index a74cbd0c36..39060e3507 100644
--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
@@ -161,7 +161,7 @@ export class FormulaActionExtension extends BaseActionExtension<FormulaPlugin> {
checkArrayFormValue(row: number, column: number): Nullable<IRangeData> {
let formula;
- const arrayFormulaData = this._plugin.getFormulaController().getArrayFormulaData();
+ const arrayFormulaData = this._plugin.getFormulaController().getDataModel().getArrayFormulaData();
if (!arrayFormulaData) return null;
diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts
index f4b9638177..16b00feeca 100644
--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts
@@ -65,7 +65,7 @@ export class FormulaCellEditExtensionFactory extends BaseCellEditExtensionFactor
checkArrayFormValue(cell: ICell, unitId: string): Nullable<string> {
const { row, column } = cell;
let formula;
- const arrayFormulaData = this._plugin.getFormulaController().getArrayFormulaData();
+ const arrayFormulaData = this._plugin.getFormulaController().getDataModel().getArrayFormulaData();
if (!arrayFormulaData) return null;
diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts
index 4e298b1e76..72c2bf34a4 100644
--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts
@@ -65,7 +65,7 @@ export class FormulaCellInputExtensionFactory extends BaseCellInputExtensionFact
const { row, column } = cell;
let formula;
const formulaData = this._plugin.getFormulaController().getDataModel().getFormulaData();
- const arrayFormulaData = this._plugin.getFormulaController().getArrayFormulaData();
+ const arrayFormulaData = this._plugin.getFormulaController().getDataModel().getArrayFormulaData();
if (!arrayFormulaData) return null;
diff --git a/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts b/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts
deleted file mode 100644
index dc79037bf3..0000000000
--- a/packages/sheets-plugin-formula/src/Controller/ArrayFormLineController.ts
+++ /dev/null
@@ -1,286 +0,0 @@
-import { PLUGIN_NAMES, Tools, Workbook } from '@univer/core';
-import { Rect, Scene } from '@univer/base-render';
-import { SheetPlugin, SheetView } from '@univer/base-sheets';
-import { ArrayFormulaDataType } from '@univer/base-formula-engine';
-import { ArrayFormLine, ArrayFormLineModel, IArrayFormLineRange } from '../Model/ArrayFormLineModel';
-import { FormulaPlugin } from '../FormulaPlugin';
-
-enum ARRAY_FORM_LINE_MANAGER_KEY {
- top = '__ArrayFormLineTopControl__',
- bottom = '__ArrayFormLineBottomControl__',
- left = '__ArrayFormLineLeftControl__',
- right = '__ArrayFormLineRightControl__',
-}
-
-const LINE_COLOR = '#3969b9';
-/**
- * Ant Line Controller
- */
-export class ArrayFormLineControl {
- private _arrayFormLineModelList: ArrayFormLineModel[];
-
- private _sheetPlugin: SheetPlugin;
-
- private _activeSheetId: string;
-
- /**
- * Remove ArrayFormLineModel By SheetId
- * @param sheetId
- */
- private _removeArrayFormLineModelBySheetId(sheetId: string): void {
- const index = this._arrayFormLineModelList.findIndex((model) => model.getSheetId() !== sheetId);
- if (index > -1) {
- this._arrayFormLineModelList.splice(index, 1);
- }
- }
-
- /**
- * Find ArrayFormLineModel By SheetId
- * @param sheetId
- * @returns
- */
- private _findArrayFormLineModelBySheetId(sheetId: string, defaultValue: ArrayFormLineModel): ArrayFormLineModel {
- return this._arrayFormLineModelList.find((model) => model.getSheetId() === sheetId) ?? defaultValue;
- }
-
- /**
- * Save Or Update ArrayFormLineModel By SheetId
- * @param model
- * @returns
- */
- private _saveOrUpdateArrayFormLineModel(model: ArrayFormLineModel): void {
- for (let i = 0; i < this._arrayFormLineModelList.length; i++) {
- const itemModel = this._arrayFormLineModelList[i];
- if (itemModel.getSheetId() === model.getSheetId()) {
- this._arrayFormLineModelList[i] = model;
- return;
- }
- }
- this._arrayFormLineModelList.push(model);
- }
-
- /**
- * Create A Sheet ArrayFormLine Rect
- * @param sheetId
- * @param range
- */
- private _createArrayFormLinePathBySheetIdAndRange(sheetId: string, range: IArrayFormLineRange): Rect[] {
- let workbook = this.getWorkBook();
- let worksheet = workbook.getSheetBySheetId(sheetId);
-
- if (worksheet == null) {
- throw new Error(`not found sheet from id: ${sheetId}`);
- }
-
- let rowTitleWidth = worksheet.getConfig().rowTitle.width;
- let columnTitleHeight = worksheet.getConfig().columnTitle.height;
-
- let rowManager = worksheet.getRowManager();
- let columnManager = worksheet.getColumnManager();
-
- let totalHeight = 0;
- let totalWidth = 0;
- for (let i = range.startRow; i < range.endRow; i++) {
- totalHeight += rowManager.getRowHeight(i);
- }
- for (let i = range.startColumn; i < range.endColumn; i++) {
- totalWidth += columnManager.getColumnWidth(i);
- }
-
- let offsetLeft = 0;
- let offsetTop = 0;
- for (let i = 0; i <= range.startRow - 1; i++) {
- offsetTop += rowManager.getRowHeight(i);
- }
- for (let i = 0; i <= range.startColumn - 1; i++) {
- offsetLeft += columnManager.getColumnWidth(i);
- }
- const id = Tools.generateRandomId();
-
- // TODO: Gradient shadows
- // dark gray #ebebeb
- // light gray #fefefe
- return [
- new Rect(ARRAY_FORM_LINE_MANAGER_KEY.left + id, {
- stroke: LINE_COLOR,
- strokeWidth: 1,
- left: offsetLeft + rowTitleWidth,
- top: offsetTop + columnTitleHeight,
- height: totalHeight,
- width: 0.1,
- shadowOffsetX: 10,
- shadowOffsetY: 10,
- shadowColor: 'LightSkyBlue',
- shadowBlur: 5,
- }),
- new Rect(ARRAY_FORM_LINE_MANAGER_KEY.top + id, {
- stroke: LINE_COLOR,
- strokeWidth: 1,
- left: offsetLeft + rowTitleWidth,
- top: offsetTop + columnTitleHeight,
- height: 0.1,
- width: totalWidth,
- shadowOffsetX: 10,
- shadowOffsetY: 10,
- shadowColor: 'LightSkyBlue',
- shadowBlur: 5,
- }),
- new Rect(ARRAY_FORM_LINE_MANAGER_KEY.right + id, {
- stroke: LINE_COLOR,
- strokeWidth: 1,
- left: offsetLeft + rowTitleWidth + totalWidth,
- top: offsetTop + columnTitleHeight,
- height: totalHeight,
- width: 0.1,
- shadowOffsetX: 10,
- shadowOffsetY: 10,
- shadowColor: 'LightSkyBlue',
- shadowBlur: 5,
- }),
- new Rect(ARRAY_FORM_LINE_MANAGER_KEY.bottom + id, {
- stroke: LINE_COLOR,
- strokeWidth: 1,
- left: offsetLeft + rowTitleWidth,
- top: offsetTop + columnTitleHeight + totalHeight,
- height: 0.1,
- width: totalWidth,
- shadowOffsetX: 10,
- shadowOffsetY: 10,
- shadowColor: 'LightSkyBlue',
- shadowBlur: 5,
- }),
- ];
- }
-
- /**
- * Delete ArrayFormLine Canvas UI
- */
- private _deleteSceneAllArrayFormLinePath(): void {
- for (let i = 0; i < this._arrayFormLineModelList.length; i++) {
- let arrayFormLineModel = this._arrayFormLineModelList[i];
- let arrayFormLineList = arrayFormLineModel.getArrayFormLineList();
- for (let j = 0; j < arrayFormLineList.length; j++) {
- let arrayFormLine = arrayFormLineList[j];
- let antPath = arrayFormLine.getPath();
- if (antPath) {
- for (let index = 0; index < antPath.length; index++) {
- const element = antPath[index];
- element.hide();
- // element.dispose();
- }
- // this.getSheetViewScene().removeObjects(antPath);
- }
- }
- }
- }
-
- /**
- * Make Update ArrayFormLine Canvas UI
- */
- private _makeUpdateSceneArrayFormLinePath(): void {
- this._deleteSceneAllArrayFormLinePath();
- // this.getSheetViewScene().makeDirty(true);
- // this._sheetPlugin.getMainComponent().makeDirty(true);
- for (let i = 0; i < this._arrayFormLineModelList.length; i++) {
- let arrayFormLineModel = this._arrayFormLineModelList[i];
- let arrayFormLineList = arrayFormLineModel.getArrayFormLineList();
- if (arrayFormLineModel.getSheetId() !== this._activeSheetId) {
- continue;
- }
- for (let j = 0; j < arrayFormLineList.length; j++) {
- let arrayFormLine = arrayFormLineList[j];
- let antPath = this._createArrayFormLinePathBySheetIdAndRange(arrayFormLineModel.getSheetId(), arrayFormLine.getRange());
- arrayFormLine.setPath(antPath);
- this.getSheetViewScene().addObjects(antPath);
- }
- }
- }
-
- /**
- * Create ArrayFormLineController
- * @param plugin
- */
- constructor(private _plugin: FormulaPlugin) {
- this._sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
-
- this._arrayFormLineModelList = [];
- this._sheetPlugin
- .getContext()
- .getContextObserver('onAfterChangeActiveSheetObservable')
- .add(() => {
- this._activeSheetId = this._sheetPlugin.getWorkbook().getActiveSheet().getSheetId();
- this._makeUpdateSceneArrayFormLinePath();
- });
- this._sheetPlugin
- .getContext()
- .getContextObserver('onSheetRenderDidMountObservable')
- .add(() => {
- this._activeSheetId = this._sheetPlugin.getWorkbook().getActiveSheet().getSheetId();
- this._makeUpdateSceneArrayFormLinePath();
- });
- this._sheetPlugin.getObserver('onChangeSelectionObserver')?.add(() => {
- const currentCell = this._sheetPlugin.getSelectionManager().getCurrentCell();
- console.log('current cell', currentCell);
- });
- }
-
- /**
- * Remove ArrayFormLine By SheetId
- * @param sheetId
- */
- removeSheetArrayFormLine(sheetId: string = this._activeSheetId): void {
- this._removeArrayFormLineModelBySheetId(sheetId);
- this._makeUpdateSceneArrayFormLinePath();
- }
-
- /**
- * Add New ArrayFormLine By SheetId
- * @param sheetId
- * @param range
- */
- addArrayFormLineToSheet(range: IArrayFormLineRange, sheetId: string = this._activeSheetId): void {
- const arrayFormLineModel = this._findArrayFormLineModelBySheetId(sheetId, new ArrayFormLineModel(sheetId));
- arrayFormLineModel.addArrayFormLine(new ArrayFormLine(range));
- this._saveOrUpdateArrayFormLineModel(arrayFormLineModel);
- this._makeUpdateSceneArrayFormLinePath();
- }
-
- refreshArrayFormLine(value: ArrayFormulaDataType) {
- this._arrayFormLineModelList.length = 0;
-
- Object.keys(value).forEach((sheetId) => {
- const arrayFormula = value[sheetId];
- arrayFormula.forValue((r, c, v) => {
- const arrayFormLineModel = new ArrayFormLineModel(sheetId);
- arrayFormLineModel.addArrayFormLine(new ArrayFormLine(v));
- this._arrayFormLineModelList.push(arrayFormLineModel);
- });
- });
-
- this._makeUpdateSceneArrayFormLinePath();
- }
-
- /**
- * Return SheetView
- * @returns
- */
- getSheetView(): SheetView {
- return this._sheetPlugin.getCanvasView().getSheetView();
- }
-
- /**
- * Return WorkBook
- * @returns Workbook
- */
- getWorkBook(): Workbook {
- return this._sheetPlugin.getWorkbook();
- }
-
- /**
- * Return SheetView Scene
- * @returns
- */
- getSheetViewScene(): Scene {
- return this._sheetPlugin.getCanvasView().getSheetView().getScene();
- }
-}
diff --git a/packages/sheets-plugin-formula/src/Controller/ArrayFormulaLineController.ts b/packages/sheets-plugin-formula/src/Controller/ArrayFormulaLineController.ts
new file mode 100644
index 0000000000..c0a7beaf2f
--- /dev/null
+++ b/packages/sheets-plugin-formula/src/Controller/ArrayFormulaLineController.ts
@@ -0,0 +1,122 @@
+import { IRangeData, PLUGIN_NAMES, Workbook } from '@univer/core';
+import { Rect, Scene } from '@univer/base-render';
+import { SheetPlugin, SheetView } from '@univer/base-sheets';
+
+import { FormulaPlugin } from '../FormulaPlugin';
+
+enum ARRAY_FORMULA_LINE_MANAGER_KEY {
+ top = '__ArrayFormulaLineTopControl__',
+ bottom = '__ArrayFormulaLineBottomControl__',
+ left = '__ArrayFormulaLineLeftControl__',
+ right = '__ArrayFormulaLineRightControl__',
+ line = '__ArrayFormulaLineControl__',
+}
+
+const LINE_COLOR = '#3969b9';
+/**
+ * Ant Line Controller
+ */
+export class ArrayFormulaLineControl {
+ private _sheetPlugin: SheetPlugin;
+
+ private _leftControl: Rect;
+
+ private _rightControl: Rect;
+
+ private _topControl: Rect;
+
+ private _bottomControl: Rect;
+
+ private _arrayFormulaLine: Rect;
+
+ /**
+ * Create ArrayFormLineController
+ * @param plugin
+ */
+ constructor(private _plugin: FormulaPlugin, private _sheetId: string, private _range: IRangeData) {
+ this._sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
+
+ this._initialize();
+ }
+
+ private _initialize() {
+ const { startRow, startColumn, endRow, endColumn } = this._range;
+ const sheetId = this._sheetId;
+
+ let workbook = this.getWorkBook();
+ let worksheet = workbook.getSheetBySheetId(sheetId);
+
+ if (worksheet == null) {
+ throw new Error(`not found sheet from id: ${sheetId}`);
+ }
+
+ let rowTitleWidth = worksheet.getConfig().rowTitle.width;
+ let columnTitleHeight = worksheet.getConfig().columnTitle.height;
+
+ let rowManager = worksheet.getRowManager();
+ let columnManager = worksheet.getColumnManager();
+
+ let totalHeight = 0;
+ let totalWidth = 0;
+ for (let i = startRow; i < endRow; i++) {
+ totalHeight += rowManager.getRowHeight(i);
+ }
+ for (let i = startColumn; i < endColumn; i++) {
+ totalWidth += columnManager.getColumnWidth(i);
+ }
+
+ let offsetLeft = 0;
+ let offsetTop = 0;
+ for (let i = 0; i <= startRow - 1; i++) {
+ offsetTop += rowManager.getRowHeight(i);
+ }
+ for (let i = 0; i <= startColumn - 1; i++) {
+ offsetLeft += columnManager.getColumnWidth(i);
+ }
+
+ this._arrayFormulaLine = new Rect(ARRAY_FORMULA_LINE_MANAGER_KEY.line, {
+ stroke: LINE_COLOR,
+ strokeWidth: 1,
+ left: offsetLeft + rowTitleWidth,
+ top: offsetTop + columnTitleHeight,
+ height: totalHeight,
+ width: totalWidth,
+ evented: false,
+ });
+
+ this.getSheetViewScene().addObject(this._arrayFormulaLine);
+ // this._arrayFormulaLine.makeDirty(true);
+ }
+
+ /**
+ * Return SheetView
+ * @returns
+ */
+ getSheetView(): SheetView {
+ return this._sheetPlugin.getCanvasView().getSheetView();
+ }
+
+ /**
+ * Return WorkBook
+ * @returns Workbook
+ */
+ getWorkBook(): Workbook {
+ return this._sheetPlugin.getWorkbook();
+ }
+
+ /**
+ * Return SheetView Scene
+ * @returns
+ */
+ getSheetViewScene(): Scene {
+ return this._sheetPlugin.getCanvasView().getSheetView().getScene();
+ }
+
+ dispose() {
+ this._leftControl?.dispose();
+ this._rightControl?.dispose();
+ this._topControl?.dispose();
+ this._bottomControl?.dispose();
+ this._arrayFormulaLine?.dispose();
+ }
+}
diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
index 310b38f8d9..8f40a5255e 100644
--- a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
@@ -1,17 +1,16 @@
import { FormulaEnginePlugin, IInterpreterDatasetConfig, SheetDataType, UnitDataType, SheetNameMapType, ArrayFormulaDataType } from '@univer/base-formula-engine';
import { SheetPlugin } from '@univer/base-sheets';
-import { ObjectMatrix, PLUGIN_NAMES, SheetContext } from '@univer/core';
+import { PLUGIN_NAMES, SheetContext } from '@univer/core';
import { FORMULA_PLUGIN_NAME, CONFIG } from '../Basic';
import { IFormulaConfig } from '../Basic/Interfaces/IFormula';
import { FormulaPlugin } from '../FormulaPlugin';
import { FormulaDataModel } from '../Model/FormulaDataModel';
import { FormulaLabel } from '../View/UI/FormulaLabel';
+import { ArrayFormulaLineControl } from './ArrayFormulaLineController';
export class FormulaController {
private _formulaDataModel: FormulaDataModel;
- private _arrayFormulaData: ArrayFormulaDataType = {};
-
private _formulaEngine: FormulaEnginePlugin;
private _context: SheetContext;
@@ -20,6 +19,10 @@ export class FormulaController {
private _sheetPlugin: SheetPlugin;
+ private _activeSheetId: string;
+
+ private _arrayFormulaLineControls: ArrayFormulaLineControl[] = [];
+
constructor(private _plugin: FormulaPlugin, config?: IFormulaConfig) {
this._formulaDataModel = new FormulaDataModel(config);
@@ -27,6 +30,8 @@ export class FormulaController {
this._sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
+ this._activeSheetId = this._sheetPlugin.getWorkbook().getActiveSheet().getSheetId();
+
this._initRegisterComponent();
this._sheetPlugin.addToolButton({
@@ -70,6 +75,24 @@ export class FormulaController {
},
],
});
+
+ this._initialize();
+ }
+
+ private _initialize() {
+ this._sheetPlugin
+ .getContext()
+ .getContextObserver('onAfterChangeActiveSheetObservable')
+ .add(() => {
+ this._activeSheetId = this._sheetPlugin.getWorkbook().getActiveSheet().getSheetId();
+ this.clearArrayFormulaLineControl();
+ this.renderArrayFormulaLineControl();
+ });
+
+ this._sheetPlugin.getObserver('onChangeSelectionObserver')?.add(() => {
+ this.clearArrayFormulaLineControl();
+ this.renderArrayFormulaLineControl();
+ });
}
private _initRegisterComponent() {
@@ -144,21 +167,39 @@ export class FormulaController {
};
}
- getArrayFormulaData(): ArrayFormulaDataType {
- return this._arrayFormulaData;
+ addArrayFormulaData(value: ArrayFormulaDataType) {
+ this._formulaDataModel.setArrayFormulaData(value);
+
+ this.clearArrayFormulaLineControl();
+ this.renderArrayFormulaLineControl();
}
- addArrayFormulaData(value: ArrayFormulaDataType) {
- Object.keys(value).forEach((sheetId) => {
- const arrayFormula = value[sheetId];
- if (!this._arrayFormulaData[sheetId]) {
- this._arrayFormulaData[sheetId] = new ObjectMatrix();
+ clearArrayFormulaLineControl() {
+ const arrayFormulaLineControls = this._arrayFormulaLineControls;
+ if (arrayFormulaLineControls.length > 0) {
+ for (let control of arrayFormulaLineControls) {
+ control.dispose();
+ }
+ }
+
+ this._arrayFormulaLineControls = [];
+ }
+
+ renderArrayFormulaLineControl() {
+ const arrayFormulaData = this._formulaDataModel.getArrayFormulaData();
+ const arrayFormula = arrayFormulaData[this._activeSheetId];
+ if (!arrayFormula) return;
+
+ const currentCellData = this._sheetPlugin.getSelectionManager().getCurrentCellData();
+
+ arrayFormula.forValue((r, c, v) => {
+ const { startRow, startColumn, endRow, endColumn } = v;
+ if (currentCellData) {
+ const { startRow: row, startColumn: column } = currentCellData;
+ if (row >= startRow && row < endRow && column >= startColumn && column < endColumn) {
+ this._arrayFormulaLineControls.push(new ArrayFormulaLineControl(this._plugin, this._activeSheetId, v));
+ }
}
- arrayFormula.forValue((r, c, v) => {
- this._arrayFormulaData[sheetId].setValue(r, c, v);
- });
});
- const arrayFormLineControl = this._plugin.getArrayFormLineControl();
- arrayFormLineControl.refreshArrayFormLine(this._arrayFormulaData);
}
}
diff --git a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
index f115592b08..0805c94f87 100644
--- a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
+++ b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx
@@ -13,7 +13,6 @@ import { FormulaActionExtensionFactory } from './Basic/Register';
import { FormulaPluginObserve, install } from './Basic/Observer';
import { SearchFormulaController } from './Controller/SearchFormulaModalController';
import { FormulaPromptController } from './Controller/FormulaPromptController';
-import { ArrayFormLineControl } from './Controller/ArrayFormLineController';
export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
private _formulaController: FormulaController;
@@ -22,8 +21,6 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
private _formulaPromptController: FormulaPromptController;
- private _arrayFormLineControl: ArrayFormLineControl;
-
protected _formulaActionExtensionFactory: FormulaActionExtensionFactory;
constructor(private _config?: IFormulaConfig) {
@@ -66,8 +63,6 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
this.registerExtension();
- this._arrayFormLineControl = new ArrayFormLineControl(this);
-
// this._arrayFormLineControl.addArrayFormLineToSheet(
// {
// startRow: 1,
@@ -137,8 +132,4 @@ export class FormulaPlugin extends Plugin<FormulaPluginObserve, SheetContext> {
getFormulaPromptController() {
return this._formulaPromptController;
}
-
- getArrayFormLineControl() {
- return this._arrayFormLineControl;
- }
}
diff --git a/packages/sheets-plugin-formula/src/Model/ArrayFormLineModel.ts b/packages/sheets-plugin-formula/src/Model/ArrayFormLineModel.ts
deleted file mode 100644
index 0d6ec7a39c..0000000000
--- a/packages/sheets-plugin-formula/src/Model/ArrayFormLineModel.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-import { Rect } from '@univer/base-render';
-import { IRangeData, Nullable } from '@univer/core';
-
-export interface IArrayFormLineRange extends IRangeData {
- id?: string;
-}
-
-export class ArrayFormLine {
- private _range: IArrayFormLineRange;
-
- private _rect: Nullable<Rect[]>;
-
- constructor(range: IArrayFormLineRange) {
- this._range = range;
- }
-
- getRange(): IArrayFormLineRange {
- return this._range;
- }
-
- getPath(): Nullable<Rect[]> {
- return this._rect;
- }
-
- setPath(rect: Rect[]): void {
- this._rect = rect;
- }
-
- setRange(range: IArrayFormLineRange): void {
- this._range = range;
- }
-}
-
-export class ArrayFormLineModel {
- private _sheetId: string;
-
- private _arrayFormLineList: ArrayFormLine[];
-
- constructor(sheetId: string) {
- this._sheetId = sheetId;
- this._arrayFormLineList = [];
- }
-
- deleteArrayFormLineById(id: string): void {
- const index = this._arrayFormLineList.findIndex((arrayFormLine) => arrayFormLine.getRange().id === id);
- if (index > -1) {
- this._arrayFormLineList.splice(index, 1);
- }
- }
-
- addArrayFormLine(arrayFormLine: ArrayFormLine): void {
- this._arrayFormLineList.push(arrayFormLine);
- }
-
- getSheetId(): string {
- return this._sheetId;
- }
-
- getArrayFormLineList(): ArrayFormLine[] {
- return this._arrayFormLineList;
- }
-
- getArrayFormLineById(id: string): Nullable<ArrayFormLine> {
- const index = this._arrayFormLineList.findIndex((arrayFormLine) => arrayFormLine.getRange().id === id);
- if (index > -1) {
- return this._arrayFormLineList[index];
- }
- }
-}
diff --git a/packages/sheets-plugin-formula/src/Model/FormulaDataModel.ts b/packages/sheets-plugin-formula/src/Model/FormulaDataModel.ts
index 56802bc07d..ff6cfb9ab5 100644
--- a/packages/sheets-plugin-formula/src/Model/FormulaDataModel.ts
+++ b/packages/sheets-plugin-formula/src/Model/FormulaDataModel.ts
@@ -1,9 +1,12 @@
-import { FormulaDataType } from '@univer/base-formula-engine';
+import { ArrayFormulaDataType, FormulaDataType } from '@univer/base-formula-engine';
+import { ObjectMatrix } from '@univer/core';
import { IFormulaConfig, RecalculationModeType } from '../Basic/Interfaces/IFormula';
export class FormulaDataModel {
private _formulaData: FormulaDataType = {};
+ private _arrayFormulaData: ArrayFormulaDataType = {};
+
private _calculationChain: string[] = [];
private _recalculationMode = RecalculationModeType.AUTOMATIC;
@@ -29,4 +32,20 @@ export class FormulaDataModel {
setFormulaData(value: FormulaDataType) {
this._formulaData = value;
}
+
+ getArrayFormulaData(): ArrayFormulaDataType {
+ return this._arrayFormulaData;
+ }
+
+ setArrayFormulaData(value: ArrayFormulaDataType) {
+ Object.keys(value).forEach((sheetId) => {
+ const arrayFormula = value[sheetId];
+ if (!this._arrayFormulaData[sheetId]) {
+ this._arrayFormulaData[sheetId] = new ObjectMatrix();
+ }
+ arrayFormula.forValue((r, c, v) => {
+ this._arrayFormulaData[sheetId].setValue(r, c, v);
+ });
+ });
+ }
}