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): 1. array form action inject 2. remove unused plugin folder

Dushusir47c42b3067b9
diff --git a/packages/base-formula-engine/src/index.ts b/packages/base-formula-engine/src/index.ts
index d33b3a1a4e..f576a15332 100644
--- a/packages/base-formula-engine/src/index.ts
+++ b/packages/base-formula-engine/src/index.ts
@@ -1,4 +1,4 @@
import { IFormatData } from './../../core/src/Interfaces/ICellData';
export { FormulaEnginePlugin } from './FormulaEnginePlugin';
-export { type FormulaDataType, type IInterpreterDatasetConfig, type SheetDataType, type UnitDataType, type SheetNameMapType, type IFormulaData } from './Basics/Common';
+export { type FormulaDataType, type IInterpreterDatasetConfig, type SheetDataType, type UnitDataType, type SheetNameMapType, type IFormulaData, type ArrayFormulaDataType } from './Basics/Common';
diff --git a/packages/base-sheets/src/Controller/FormulaBarController.ts b/packages/base-sheets/src/Controller/FormulaBarController.ts
index bab0d62b1e..9bd69840bb 100644
--- a/packages/base-sheets/src/Controller/FormulaBarController.ts
+++ b/packages/base-sheets/src/Controller/FormulaBarController.ts
@@ -80,6 +80,10 @@ export class FormulaBarController {
}
this._formulaBar.setFormulaContent(cellValue);
}
+ // empty cell
+ else {
+ this._formulaBar.setFormulaContent('');
+ }
}
});
@@ -87,4 +91,8 @@ export class FormulaBarController {
// set NamedRange data
}
+
+ getFormulaBar() {
+ return this._formulaBar;
+ }
}
diff --git a/packages/base-sheets/src/SheetPlugin.tsx b/packages/base-sheets/src/SheetPlugin.tsx
index 3d5c62cf29..aaad776955 100644
--- a/packages/base-sheets/src/SheetPlugin.tsx
+++ b/packages/base-sheets/src/SheetPlugin.tsx
@@ -338,6 +338,10 @@ export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {
return this._cellEditorController;
}
+ getFormulaBarController() {
+ return this._formulaBarController;
+ }
+
getModalGroupControl() {
return this._modalGroupController;
}
diff --git a/packages/docs-plugin-import-doc/.eslintrc.js b/packages/docs-plugin-import-doc/.eslintrc.js
deleted file mode 100644
index 7f4cf3e7ba..0000000000
--- a/packages/docs-plugin-import-doc/.eslintrc.js
+++ /dev/null
@@ -1,51 +0,0 @@
-module.exports = {
- env: {
- browser: true,
- es2021: true,
- node: true,
- },
- parser: '@typescript-eslint/parser',
- extends: [
- 'airbnb-typescript',
- 'prettier',
- 'eslint:recommended',
- 'plugin:import/recommended',
- 'plugin:import/typescript',
- ],
- parserOptions: {
- ecmaVersion: 12,
- sourceType: 'module',
- project: './tsconfig.json',
- },
- plugins: ['@typescript-eslint', 'prettier', 'import'],
- rules: {
- 'prettier/prettier': [
- 'error',
- {
- endOfLine: 'auto',
- },
- ],
- 'import/prefer-default-export': 'off',
- 'import/no-extraneous-dependencies': [
- 'error',
- { devDependencies: true },
- ],
- // turn on errors for missing imports
- 'import/no-unresolved': 'error',
- },
- settings: {
- 'import/parsers': {
- '@typescript-eslint/parser': ['.ts', '.tsx'],
- },
- 'import/resolver': {
- typescript: {
- alwaysTryTypes: true, // always try to resolve config under `<root>@config` directory even it doesn't contain any source code, like `@config/unist`
-
- // Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default
-
- // use <root>/path/to/folder/tsconfig.json
- project: './tsconfig.json',
- },
- },
- },
-};
diff --git a/packages/docs-plugin-import-doc/.gitignore b/packages/docs-plugin-import-doc/.gitignore
deleted file mode 100644
index 12e1bd6bec..0000000000
--- a/packages/docs-plugin-import-doc/.gitignore
+++ /dev/null
@@ -1,101 +0,0 @@
-#ide
-*.DS_Store
-.idea
-.vscode
-
-#npm
-package-lock.json
-
-dist
-lib
-docs/.vuepress/dist
-
-# Logs
-logs
-*.log
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-lerna-debug.log*
-
-# Runtime config
-pids
-*.pid
-*.seed
-*.pid.lock
-
-# Directory for instrumented libs generated by jscoverage/JSCover
-lib-cov
-
-# Coverage directory used by tools like istanbul
-coverage
-
-# nyc test coverage
-.nyc_output
-
-# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
-.grunt
-
-# Bower dependency directory (https://bower.io/)
-bower_components
-
-# node-waf configuration
-.lock-wscript
-
-# Compiled binary addons (https://nodejs.org/api/addons.html)
-build/Release
-
-# Dependency directories
-node_modules
-jspm_packages/
-
-# TypeScript v1 declaration files
-typings/
-
-# Optional npm cache directory
-.npm
-
-# Optional eslint cache
-.eslintcache
-
-# Optional REPL History
-.node_repl_history
-
-# Output of 'npm pack'
-*.tgz
-
-# Yarn Integrity file
-.yarn-integrity
-
-# dotenv environment variables file
-.env
-
-# next.js build output
-.next
-
-#lerna-changelog
-.changelog
-
-
-#editor workspace file
-.idea/
-
-
-.DS_Store
-
-.history
-# examples
-
-
-# Production
-/build
-
-# Generated files
-.docusaurus
-.cache-loader
-
-# Misc
-.env.local
-.env.development.local
-.env.test.local
-.env.production.local
diff --git a/packages/docs-plugin-import-doc/.prettierrc.cjs b/packages/docs-plugin-import-doc/.prettierrc.cjs
deleted file mode 100644
index 6604107223..0000000000
--- a/packages/docs-plugin-import-doc/.prettierrc.cjs
+++ /dev/null
@@ -1,7 +0,0 @@
-module.exports = {
- singleQuote: true,
- trailingComma: 'es5',
- tabWidth: 4,
- semi: true,
- printWidth: 180,
-};
diff --git a/packages/docs-plugin-import-doc/README-zh.md b/packages/docs-plugin-import-doc/README-zh.md
deleted file mode 100644
index 1ffc058d8b..0000000000
--- a/packages/docs-plugin-import-doc/README-zh.md
+++ /dev/null
@@ -1,55 +0,0 @@
-# style-universheet
-
-简体中文 | [English](./README.md)
-
-## 介绍
-
-UniverSheet ImportDoc插件
-
-### 安装
-
-```bash
-npm i @univer/docs-plugin-import-doc
-```
-
-### 使用
-
-```js
-impport {ImportDoc} from '@univer/docs-plugin-import-doc'
-
-const univerSheet = new UniverSheet();
-univerSheet.installPlugin(new ImportDoc());
-```
-
-## 本地开发
-
-### 环境
-
-- [Node.js](https://nodejs.org/en/) Version >= 10
-- [npm](https://www.npmjs.com/) Version >= 6
-
-### 安装
-
-```
-pnpm install
-```
-
-### 开发
-
-```
-# 当前目录 ./packages/docs-plugin-import-doc/
-npm run dev
-
-# 或者项目根目录 ./
-pnpm run --filter @univer/docs-plugin-import-doc dev
-```
-
-### 打包
-
-```
-# 当前目录 ./packages/docs-plugin-import-doc/
-npm run build
-
-# 或者根目录 ./
-pnpm run --filter @univer/docs-plugin-import-doc build
-```
diff --git a/packages/docs-plugin-import-doc/README.md b/packages/docs-plugin-import-doc/README.md
deleted file mode 100644
index 1c0c97646d..0000000000
--- a/packages/docs-plugin-import-doc/README.md
+++ /dev/null
@@ -1,55 +0,0 @@
-# style-universheet
-
-English| [简体中文](./README-zh.md)
-
-## Introduction
-
-UniverSheet Plugin ImportDoc
-
-### Installation
-
-```bash
-npm i @univer/docs-plugin-import-doc
-```
-
-### Usage
-
-```js
-impport {ImportDoc} from '@univer/docs-plugin-import-doc'
-
-const univerSheet = new UniverSheet();
-univerSheet.installPlugin(new ImportDoc());
-```
-
-## Local development
-
-### Requirements
-
-- [Node.js](https://nodejs.org/en/) Version >= 10
-- [npm](https://www.npmjs.com/) Version >= 6
-
-### Installation
-
-```
-pnpm install
-```
-
-### Development
-
-```
-# Current directory ./packages/docs-plugin-import-doc/
-npm run dev
-
-# Or project root directory ./
-pnpm run --filter @univer/docs-plugin-import-doc dev
-```
-
-### Package
-
-```
-# Current directory ./packages/docs-plugin-import-doc/
-npm run build
-
-# Or root directory ./
-pnpm run --filter @univer/docs-plugin-import-doc build
-```
diff --git a/packages/docs-plugin-import-doc/index.html b/packages/docs-plugin-import-doc/index.html
deleted file mode 100644
index 2cd6b29ddc..0000000000
--- a/packages/docs-plugin-import-doc/index.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="UTF-8" />
- <link rel="icon" type="image/svg+xml" href="favicon.svg" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>UniverDoc</title>
- <style>
- html,
- body {
- height: 100%;
- margin: 0;
- }
- </style>
-</head>
-
-<body>
- <input type="file" id="file"/>
-</body>
-<script type="module">
- import { Document } from './src/main.ts';
-
- const input = document.getElementById('file');
- input.addEventListener('change', (ev) => {
- const file = input.files[0];
- const docx = Document.parse(file);
- console.log(docx)
- })
-</script>
-</html>
diff --git a/packages/docs-plugin-import-doc/jest.config.js b/packages/docs-plugin-import-doc/jest.config.js
deleted file mode 100644
index 73ef4bae42..0000000000
--- a/packages/docs-plugin-import-doc/jest.config.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
-module.exports = {
- preset: 'ts-jest',
- testEnvironment: 'jsdom',
- moduleFileExtensions: ['js', 'ts', 'tsx'],
-
- roots: ['<rootDir>/src'],
- testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
- transform: {
- '^.+\\.(ts|tsx)$': 'ts-jest',
- '^.+\\.tsx?$': 'babel-jest', // https://github.com/kulshekhar/ts-jest/issues/937#issuecomment-455431207
- },
- globals: {
- 'ts-jest': {
- tsConfig: 'tsconfig.test.json',
- },
- },
-};
diff --git a/packages/docs-plugin-import-doc/package.json b/packages/docs-plugin-import-doc/package.json
deleted file mode 100644
index 27f47f5380..0000000000
--- a/packages/docs-plugin-import-doc/package.json
+++ /dev/null
@@ -1,60 +0,0 @@
-{
- "name": "@univer/docs-plugin-import-doc",
- "version": "0.0.1",
- "description": "UniverSheet normal docs-plugin-import-doc",
- "keywords": [],
- "author": "DreamNum <[email protected]>",
- "license": "MIT",
- "main": "./lib/univer-docs-plugin-import-doc.cjs.js",
- "module": "./lib/univer-docs-plugin-import-doc.es.js",
- "browser": {
- "./lib/univer-docs-plugin-import-doc.cjs.js": "./src/index.ts",
- "./lib/univer-docs-plugin-import-doc.es.js": "./src/index.ts"
- },
- "types": "./src/Types/index.d.ts",
- "exports": {
- ".": {
- "import": {
- "node": "./lib/univer-docs-plugin-import-doc.cjs.js",
- "default": "./lib/univer-docs-plugin-import-doc.es.js"
- },
- "require": "./lib/univer-docs-plugin-import-doc.cjs.js",
- "types": "./lib/univer-docs-plugin-import-doc.d.ts"
- },
- "./*": "./src/*"
- },
- "directories": {
- "lib": "lib"
- },
- "scripts": {
- "test": "jest",
- "dev": "vite",
- "build": "tsc && vite build",
- "watch": "vite build",
- "link": "pnpm link ./",
- "serve": "vite preview"
- },
- "devDependencies": {
- "@preact/preset-vite": "2.0.0",
- "@testing-library/preact": "^2.0.1",
- "@types/jest": "^27.0.1",
- "@types/node": "^16.4.6",
- "eslint": "^8.22.0",
- "eslint-config-airbnb-typescript": "^17.0.0",
- "eslint-config-prettier": "^8.3.0",
- "eslint-plugin-import": "^2.23.4",
- "eslint-plugin-jsx-a11y": "^6.5.1",
- "eslint-plugin-prettier": "^3.4.0",
- "eslint-plugin-react": "^7.28.0",
- "eslint-plugin-react-hooks": "^4.3.0",
- "less": "^4.1.1",
- "prettier": "^2.3.2",
- "ts-jest": "29.0.1",
- "ts-node": "^10.2.1",
- "typescript": "^4.4.1-rc",
- "vite": "^2.4.4"
- },
- "dependencies": {
- "jszip": "^3.5.0"
- }
-}
diff --git a/packages/docs-plugin-import-doc/src/core/Document.ts b/packages/docs-plugin-import-doc/src/core/Document.ts
deleted file mode 100644
index 6aeda8a40a..0000000000
--- a/packages/docs-plugin-import-doc/src/core/Document.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import {Docx} from "./Docx";
-
-const docx = new Docx();
-
-export class Document {
- public static async parse(file: Buffer): Promise<Document> {
- return docx.load(file);
- }
-
- public constructor() {
-
- }
-}
diff --git a/packages/docs-plugin-import-doc/src/core/Docx.ts b/packages/docs-plugin-import-doc/src/core/Docx.ts
deleted file mode 100644
index 50059a6f2e..0000000000
--- a/packages/docs-plugin-import-doc/src/core/Docx.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import {Document} from './Document'
-import JSZip from "jszip";
-
-export class Docx {
- async load(buffer: Buffer): Promise<Document> {
- debugger
- const zip = await JSZip.loadAsync(buffer);
- for (const entry of Object.values(zip.files)) {
- console.log(entry)
- }
- return new Document();
- }
-}
diff --git a/packages/docs-plugin-import-doc/src/io/DocxExport.ts b/packages/docs-plugin-import-doc/src/io/DocxExport.ts
deleted file mode 100644
index 64bc7e8593..0000000000
--- a/packages/docs-plugin-import-doc/src/io/DocxExport.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export class DocxExport {
-
-}
diff --git a/packages/docs-plugin-import-doc/src/io/DocxImport.ts b/packages/docs-plugin-import-doc/src/io/DocxImport.ts
deleted file mode 100644
index cd9522b766..0000000000
--- a/packages/docs-plugin-import-doc/src/io/DocxImport.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export class DocxImport {
-
-}
diff --git a/packages/docs-plugin-import-doc/src/main.ts b/packages/docs-plugin-import-doc/src/main.ts
deleted file mode 100644
index f5f80db6b2..0000000000
--- a/packages/docs-plugin-import-doc/src/main.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './core/Document'
diff --git a/packages/docs-plugin-import-doc/src/utils/DocxUtils.ts b/packages/docs-plugin-import-doc/src/utils/DocxUtils.ts
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/packages/docs-plugin-import-doc/tsconfig.json b/packages/docs-plugin-import-doc/tsconfig.json
deleted file mode 100644
index fc81cbd47e..0000000000
--- a/packages/docs-plugin-import-doc/tsconfig.json
+++ /dev/null
@@ -1,31 +0,0 @@
-{
- "compilerOptions": {
- "rootDir": "./",
- "outDir": "lib",
- "target": "ESNext",
-
- "lib": ["ESNext", "DOM", "WebWorker"],
- "module": "ESNext",
- "moduleResolution": "Node", //This value is needed for Node.js.
-
- "declaration": true,
- "declarationDir": "./lib",
- "declarationMap": true,
- "sourceMap": true,
- "resolveJsonModule": true,
- "strict": true,
- "allowJs": true,
-
- "baseUrl": "./",
- "skipLibCheck": true,
- "esModuleInterop": true, // auto allowSyntheticDefaultImports tru
- "suppressImplicitAnyIndexErrors": true,
- "experimentalDecorators": true,
- "jsx": "preserve",
- "jsxFactory": "h",
- "jsxFragmentFactory": "Fragment",
- "strictPropertyInitialization": false,
- "types": ["jest", "node", "@types/jest"]
- },
- "include": ["src/**/*", "test/**/*.test.(ts|tsx|js)"]
-}
diff --git a/packages/docs-plugin-import-doc/tsconfig.ref.json b/packages/docs-plugin-import-doc/tsconfig.ref.json
deleted file mode 100644
index 0c86b2c554..0000000000
--- a/packages/docs-plugin-import-doc/tsconfig.ref.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "extends": "./tsconfig.json",
- "include": ["src/**/*"],
- "compilerOptions": {
- "composite": true
- }
-}
diff --git a/packages/docs-plugin-import-doc/tsconfig.test.json b/packages/docs-plugin-import-doc/tsconfig.test.json
deleted file mode 100644
index a2ac02c4ae..0000000000
--- a/packages/docs-plugin-import-doc/tsconfig.test.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "extends": "./tsconfig.json",
- "compilerOptions": {
- "jsx": "react-jsx",
- "jsxImportSource": "preact"
- }
-}
diff --git a/packages/docs-plugin-import-doc/vite.config.ts b/packages/docs-plugin-import-doc/vite.config.ts
deleted file mode 100644
index d5006f79b6..0000000000
--- a/packages/docs-plugin-import-doc/vite.config.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-import { defineConfig } from 'vite';
-import path from 'path';
-import preact from '@preact/preset-vite';
-import { name, version } from './package.json';
-
-const resolve = (url: string) => path.resolve(__dirname, url);
-
-export default defineConfig({
- build: {
- // lib: {
- // entry: resolve('src/index.ts'),
- // name: 'BaseStyleUniver',
- // formats: ['es', 'umd'],
- // fileName: 'index',
- // },
- // outDir: './lib',
- },
- define: {
- pkgJson: { name, version },
- },
- css: {
- modules: {
- localsConvention: 'camelCaseOnly', // dash to camelCase conversion// .apply-color -> applyColor
- generateScopedName: 'univer-[local]', // custom prefix class name
- },
- preprocessorOptions: {
- less: {
- javascriptEnabled: true,
- },
- },
- },
- server: {
- port: 3103,
- open: true, // Automatically open the app in the browser on server start.
- },
- plugins: [preact()],
-});
diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
index 6e8aa80cd6..b7c0b5c8b0 100644
--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaActionExtension.ts
@@ -4,10 +4,12 @@ import {
BaseActionExtension,
BaseActionExtensionFactory,
Command,
+ IRangeData,
ISetRangeDataActionData,
isFormulaString,
ISheetActionData,
IUnitRange,
+ Nullable,
ObjectMatrix,
Tools,
} from '@univer/core';
@@ -33,43 +35,61 @@ export class FormulaActionExtension extends BaseActionExtension<FormulaPlugin> {
return false;
}
+ if (actionData.actionName !== ACTION_NAMES.SET_RANGE_DATA_ACTION) {
+ return false;
+ }
+
// Filter out Actions that contain formulas, inject setRangeDataAction
- if (actionData.actionName === ACTION_NAMES.SET_RANGE_DATA_ACTION) {
- // TODO FALSE PASS
- const { sheetId, cellValue } = actionData;
+ const { sheetId, cellValue } = actionData;
- if (Tools.isEmptyObject(formulaData)) return;
+ if (Tools.isEmptyObject(formulaData)) return;
- const cellData = new ObjectMatrix(formulaData[unitId][sheetId]);
+ if (!formulaData[unitId][sheetId]) {
+ formulaData[unitId][sheetId] = {};
+ }
+ const cellData = new ObjectMatrix(formulaData[unitId][sheetId]);
- if (cellValue == null) {
- return;
- }
+ if (cellValue == null) {
+ return;
+ }
- const rangeMatrix = new ObjectMatrix(cellValue);
-
- // update formula string,Any modification to cellData will be linked to formulaData
- rangeMatrix.forValue((r, c, cell) => {
- const formulaString = cell.m;
- if (Tools.isStringNumber(formulaString)) {
- isCalculate = true;
-
- // if change formula to number, remove formula
- const formulaCell = cellData.getRow(r)?.get(c);
- if (formulaCell) {
- cellData.deleteValue(r, c);
- }
- } else if (isFormulaString(formulaString)) {
- isCalculate = true;
- cellData.setValue(r, c, {
- formula: formulaString,
- row: r,
- column: c,
- sheetId,
- });
+ const rangeMatrix = new ObjectMatrix(cellValue);
+
+ let isArrayForm = false;
+
+ // update formula string,Any modification to cellData will be linked to formulaData
+ rangeMatrix.forValue((r, c, cell) => {
+ const arrayFormCellRangeData = this.checkArrayFormValue(r, c);
+ const formulaString = cell.m;
+ if (arrayFormCellRangeData && formulaString === '') {
+ isArrayForm = true;
+ isCalculate = true;
+
+ unitRange.push({
+ unitId,
+ sheetId,
+ rangeData: arrayFormCellRangeData,
+ });
+ } else if (Tools.isStringNumber(formulaString)) {
+ isCalculate = true;
+
+ // if change formula to number, remove formula
+ const formulaCell = cellData.getRow(r)?.get(c);
+ if (formulaCell) {
+ cellData.deleteValue(r, c);
}
- });
+ } else if (isFormulaString(formulaString)) {
+ isCalculate = true;
+ cellData.setValue(r, c, {
+ formula: formulaString,
+ row: r,
+ column: c,
+ sheetId,
+ });
+ }
+ });
+ if (!isArrayForm) {
unitRange.push({
unitId,
sheetId,
@@ -82,13 +102,17 @@ export class FormulaActionExtension extends BaseActionExtension<FormulaPlugin> {
// Add command after calculating the formula
engine.execute(unitId, formulaData, formulaController.toInterpreterCalculateProps(), false, unitRange).then((data) => {
- // TODO arrayFormulaData
const { sheetData, arrayFormulaData } = data;
if (!sheetData) {
console.error('No sheetData from Formula Engine!');
return;
}
+
+ if (arrayFormulaData) {
+ this._plugin.getFormulaController().setArrayFormulaData(arrayFormulaData);
+ }
+
const sheetIds = Object.keys(sheetData);
// Update each calculated value, possibly involving all cells
@@ -134,6 +158,32 @@ export class FormulaActionExtension extends BaseActionExtension<FormulaPlugin> {
commandManager.invoke(command);
});
}
+
+ checkArrayFormValue(row: number, column: number): Nullable<IRangeData> {
+ let formula;
+ const arrayFormulaData = this._plugin.getFormulaController().getArrayFormulaData();
+
+ if (!arrayFormulaData) return null;
+
+ Object.keys(arrayFormulaData).forEach((sheetId) => {
+ const sheetData = arrayFormulaData[sheetId];
+
+ sheetData.forValue((rowIndex: number, columnIndex: number, value: IRangeData) => {
+ const { startRow, startColumn, endRow, endColumn } = value;
+ if (row >= startRow && row < endRow && column >= startColumn && column < endColumn) {
+ formula = {
+ startRow,
+ endRow: startRow,
+ startColumn,
+ endColumn: startColumn,
+ };
+ return false;
+ }
+ });
+ });
+
+ return formula;
+ }
}
export class FormulaActionExtensionFactory extends BaseActionExtensionFactory<FormulaPlugin> {
diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts
index 8171f08af7..f4b9638177 100644
--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts
@@ -1,5 +1,6 @@
-import { BaseCellEditExtension, BaseCellEditExtensionFactory, ICell } from '@univer/base-sheets';
+import { BaseCellEditExtension, BaseCellEditExtensionFactory, ICell, SheetPlugin } from '@univer/base-sheets';
import { IFormulaData } from '@univer/base-formula-engine';
+import { IRangeData, Nullable, PLUGIN_NAMES } from '@univer/core';
import { FormulaPlugin } from '../../FormulaPlugin';
export class FormulaCellEditExtension extends BaseCellEditExtension {
@@ -22,11 +23,20 @@ export class FormulaCellEditExtensionFactory extends BaseCellEditExtensionFactor
}
check(cell: ICell) {
- const { row, column } = cell;
+ const unitId = this._plugin.getContext().getWorkBook().getUnitId();
+ let formula = this.checkFormulaValue(cell) || this.checkArrayFormValue(cell, unitId);
- const formulaData = this._plugin.getFormulaController().getDataModel().getFormulaData();
+ if (formula !== '' && !formula) {
+ return false;
+ }
+
+ return this.create(cell, formula);
+ }
+ checkFormulaValue(cell: ICell): Nullable<string> {
+ const { row, column } = cell;
let formula;
+ const formulaData = this._plugin.getFormulaController().getDataModel().getFormulaData();
Object.keys(formulaData).forEach((unitId) => {
const sheetData = formulaData[unitId];
@@ -49,10 +59,35 @@ export class FormulaCellEditExtensionFactory extends BaseCellEditExtensionFactor
}
});
- if (!formula) {
- return false;
- }
+ return formula;
+ }
- return this.create(cell, formula);
+ checkArrayFormValue(cell: ICell, unitId: string): Nullable<string> {
+ const { row, column } = cell;
+ let formula;
+ const arrayFormulaData = this._plugin.getFormulaController().getArrayFormulaData();
+
+ if (!arrayFormulaData) return null;
+
+ Object.keys(arrayFormulaData).forEach((sheetId) => {
+ const sheetData = arrayFormulaData[sheetId];
+
+ sheetData.forValue((rowIndex: number, columnIndex: number, value: IRangeData) => {
+ const { startRow, startColumn, endRow, endColumn } = value;
+ if (row >= startRow && row < endRow && column >= startColumn && column < endColumn) {
+ formula = '';
+ this._plugin
+ .getContext()
+ .getPluginManager()
+ .getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)
+ .getFormulaBarController()
+ .getFormulaBar()
+ .setFormulaContent('');
+ return false;
+ }
+ });
+ });
+
+ return formula;
}
}
diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts
index 02ee77e71b..4e298b1e76 100644
--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts
+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts
@@ -1,5 +1,6 @@
import { BaseCellInputExtension, BaseCellInputExtensionFactory, ICell } from '@univer/base-sheets';
import { IFormulaData } from '@univer/base-formula-engine';
+import { IRangeData, Nullable } from '@univer/core';
import { FormulaPlugin } from '../../FormulaPlugin';
export class FormulaCellInputExtension extends BaseCellInputExtension {
@@ -22,11 +23,20 @@ export class FormulaCellInputExtensionFactory extends BaseCellInputExtensionFact
}
check(cell: ICell) {
- const { row, column } = cell;
+ const unitId = this._plugin.getContext().getWorkBook().getUnitId();
+ let formula = this.checkFormulaValue(cell) || this.checkArrayFormValue(cell, unitId);
- const formulaData = this._plugin.getFormulaController().getDataModel().getFormulaData();
+ if (!formula) {
+ return false;
+ }
+
+ return this.create(cell, formula);
+ }
+ checkFormulaValue(cell: ICell): Nullable<string> {
+ const { row, column } = cell;
let formula;
+ const formulaData = this._plugin.getFormulaController().getDataModel().getFormulaData();
Object.keys(formulaData).forEach((unitId) => {
const sheetData = formulaData[unitId];
@@ -48,10 +58,31 @@ export class FormulaCellInputExtensionFactory extends BaseCellInputExtensionFact
}
});
- if (!formula) {
- return false;
- }
+ return formula;
+ }
- return this.create(cell, formula);
+ checkArrayFormValue(cell: ICell, unitId: string): Nullable<string> {
+ const { row, column } = cell;
+ let formula;
+ const formulaData = this._plugin.getFormulaController().getDataModel().getFormulaData();
+ const arrayFormulaData = this._plugin.getFormulaController().getArrayFormulaData();
+
+ if (!arrayFormulaData) return null;
+
+ Object.keys(arrayFormulaData).forEach((sheetId) => {
+ const sheetData = arrayFormulaData[sheetId];
+
+ sheetData.forValue((rowIndex: number, columnIndex: number, value: IRangeData) => {
+ const { startRow, startColumn, endRow, endColumn } = value;
+ if (row >= startRow && row < endRow && column >= startColumn && column < endColumn) {
+ const cellData = formulaData[unitId][sheetId];
+ // TODO: cellData[startRow] is ObjectArray?
+ formula = cellData[startRow].get(startColumn).formula;
+ return false;
+ }
+ });
+ });
+
+ return formula;
}
}
diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
index 7f98225162..1d070ff942 100644
--- a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
@@ -1,4 +1,4 @@
-import { FormulaEnginePlugin, IInterpreterDatasetConfig, SheetDataType, UnitDataType, SheetNameMapType } from '@univer/base-formula-engine';
+import { FormulaEnginePlugin, IInterpreterDatasetConfig, SheetDataType, UnitDataType, SheetNameMapType, ArrayFormulaDataType } from '@univer/base-formula-engine';
import { SheetPlugin } from '@univer/base-sheets';
import { PLUGIN_NAMES, SheetContext } from '@univer/core';
import { FORMULA_PLUGIN_NAME, CONFIG } from '../Basic';
@@ -10,6 +10,8 @@ import { FormulaLabel } from '../View/UI/FormulaLabel';
export class FormulaController {
private _formulaDataModel: FormulaDataModel;
+ private _arrayFormulaData: ArrayFormulaDataType;
+
private _formulaEngine: FormulaEnginePlugin;
private _context: SheetContext;
@@ -141,4 +143,12 @@ export class FormulaController {
columnCount,
};
}
+
+ getArrayFormulaData(): ArrayFormulaDataType {
+ return this._arrayFormulaData;
+ }
+
+ setArrayFormulaData(value: ArrayFormulaDataType) {
+ this._arrayFormulaData = value;
+ }
}
diff --git a/packages/sheets-plugin-numfmt/src/Basic/Register/NumfmtActionExtension.ts b/packages/sheets-plugin-numfmt/src/Basic/Register/NumfmtActionExtension.ts
index d17fac39ea..cbe228ec8f 100644
--- a/packages/sheets-plugin-numfmt/src/Basic/Register/NumfmtActionExtension.ts
+++ b/packages/sheets-plugin-numfmt/src/Basic/Register/NumfmtActionExtension.ts
@@ -7,31 +7,44 @@ export class NumfmtActionExtension extends BaseActionExtension<NumfmtPlugin> {
execute() {
const numfmtMatrix = new ObjectMatrix<string>();
const actionDataList = this.actionDataList as ISetRangeDataActionData[];
+
actionDataList.forEach((actionData) => {
if (actionData.operation != null && !ActionOperation.hasExtension(actionData)) {
return false;
}
- if (actionData.actionName === ACTION_NAMES.SET_RANGE_DATA_ACTION) {
- let { cellValue, sheetId } = actionData;
- const rangeMatrix = new ObjectMatrix(cellValue);
-
- rangeMatrix.forValue((r, c, cell) => {
- const typed = numfmt.parseValue(cell.v) as unknown as { z: string; v: string };
- if (typed) {
- const format = numfmt(typed.z);
- cell.m = format(typed.v);
- cell.v = typed.v || String();
- numfmtMatrix.setValue(r, c, typed.z);
- }
- });
-
- const setNumfmtRangeDataAction = {
- actionName: PLUGIN_ACTION_NAMES.SET_NUMFMT_RANGE_DATA_ACTION,
- sheetId,
- cellValue: numfmtMatrix.toJSON(),
- };
- this.push(setNumfmtRangeDataAction);
+
+ if (actionData.actionName !== ACTION_NAMES.SET_RANGE_DATA_ACTION) {
+ return false;
}
+
+ let { cellValue, sheetId } = actionData;
+ const numfmtConfig = this._plugin.getNumfmtBySheetIdConfig(sheetId);
+ const currSheetNumfmtMatrix = new ObjectMatrix(numfmtConfig);
+ const rangeMatrix = new ObjectMatrix(cellValue);
+
+ rangeMatrix.forValue((r, c, cell) => {
+ const typed = numfmt.parseValue(cell.v) as unknown as { z: string; v: string };
+
+ if (typed) {
+ // format already set,get format, e.g. 100% => =sum(2), we will set 200%
+ const currNumfmtValue = currSheetNumfmtMatrix.getValue(r, c);
+ // if (currNumfmtValue) {
+ // typed.z = ;
+ // }
+
+ const format = numfmt(typed.z);
+ cell.m = format(typed.v);
+ cell.v = typed.v || String();
+ numfmtMatrix.setValue(r, c, typed.z);
+ }
+ });
+
+ const setNumfmtRangeDataAction = {
+ actionName: PLUGIN_ACTION_NAMES.SET_NUMFMT_RANGE_DATA_ACTION,
+ sheetId,
+ cellValue: numfmtMatrix.toJSON(),
+ };
+ this.push(setNumfmtRangeDataAction);
});
}
}
diff --git a/packages/style-google/index.ts b/packages/style-google/index.ts
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/packages/style-mobile/index.ts b/packages/style-mobile/index.ts
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/packages/style-office365/index.ts b/packages/style-office365/index.ts
deleted file mode 100644
index e69de29bb2..0000000000