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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(sheet-numfmt-plugin):numfmt plugin optimization
eiji-th9ac164cf2010
diff --git a/packages/base-numfmt-engine/index.ts b/packages/base-numfmt-engine/index.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/packages/base-numfmt-engine/package.json b/packages/base-numfmt-engine/package.jsonindex 9d3d590400..daf1892064 100644--- a/packages/base-numfmt-engine/package.json+++ b/packages/base-numfmt-engine/package.json@@ -1,21 +1,17 @@{- "name": "@univer/sheets-plugin-format",+ "name": "@univer/base-numfmt-engine","version": "0.0.1","description": "UniverSheet normal plugin UI manager","keywords": [],"author": "DreamNum <[email protected]>","license": "MIT",- "main": "./src/index.ts",- "module": "./src/index.ts",- "types": "./src/index.d.ts",- "exports": {- ".": "./src/index.ts",- "./*": "./src/*"- },+ "main": "src/index.ts",+ "module": "src/index.ts",+ "types": "src/index.d.ts","publishConfig": {- "main": "./lib/index.umd.js",- "module": "./lib/index.es.js",- "types": "./lib/index.d.ts"+ "main": "lib/index.umd.js",+ "module": "lib/index.es.js",+ "types": "lib/index.d.ts"},"directories": {"lib": "lib"@@ -50,8 +46,6 @@"@univer/base-sheets": "workspace:^0.0.1","@univer/core": "workspace:^0.0.1","@univer/sheets-plugin-filter": "workspace:^0.0.1",- "@univer/style-universheet": "workspace:^0.0.1",- "preact": "^10.5.14",- "ssf": "0.11.2"+ "@univer/style-universheet": "workspace:^0.0.1"}}diff --git a/packages/base-numfmt-engine/src/index.ts b/packages/base-numfmt-engine/src/index.tsindex 213ad0b2c2..7696ed5aaf 100644--- a/packages/base-numfmt-engine/src/index.ts+++ b/packages/base-numfmt-engine/src/index.ts@@ -9,16 +9,14 @@ import { round } from './core/round';import { dateFromSerial, dateToSerial } from './core/serialDate';export interface FormatterType {- (value: number, opts?: OptionsData): void;+ (value: number | string, opts?: OptionsData): string;color(value, ops?): string;isDate(): boolean;isText(): boolean;isPercent(): boolean;}-const _cache: {- [key: string]: PatternType;-} = {};+const _cache: { [key: string]: PatternType } = {};function getFormatter(parseData: PatternType, initOpts: OptionsData = {}): FormatterType {const { pattern, partitions, locale } = parseData;diff --git a/packages/sheets-plugin-numfmt/package.json b/packages/sheets-plugin-numfmt/package.jsonindex 44ff29b09d..ed02bb58ec 100644--- a/packages/sheets-plugin-numfmt/package.json+++ b/packages/sheets-plugin-numfmt/package.json@@ -1,5 +1,5 @@{- "name": "@univer/sheets-plugin-format",+ "name": "@univer/sheets-plugin-numfmt","version": "0.0.1","description": "UniverSheet normal plugin UI manager","keywords": [],@@ -48,12 +48,8 @@"dependencies": {"@univer/base-component": "workspace:^0.0.1","@univer/base-render": "workspace:^0.0.1",- "@univer/base-sheets": "workspace:^0.0.1",+ "@univer/base-numfmt-engine": "workspace:^0.0.1","@univer/common-plugin-data": "workspace:^0.0.1",- "@univer/core": "workspace:^0.0.1",- "@univer/sheets-plugin-filter": "workspace:^0.0.1",- "@univer/style-universheet": "workspace:^0.0.1",- "preact": "^10.5.14",- "ssf": "0.11.2"+ "@univer/core": "workspace:^0.0.1"}}diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.tsnew file mode 100644index 0000000000..503c7e7b21--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts@@ -0,0 +1,21 @@+import { NumfmtModel, NumfmtValue } from '../Model/NumfmtModel';++export class NumfmtController {+ protected _model: NumfmtModel;++ constructor() {+ this._model = new NumfmtModel();+ }++ setNumfmt(row: number, column: number, numfmt: string): void {+ this._model.setNumfmtValue(row, column, new NumfmtValue(numfmt));+ }++ getValue(row: number, column: number): string {+ return '';+ }++ getColor(row: number, column: number): string {+ return '';+ }+}diff --git a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.tsnew file mode 100644index 0000000000..b458bd8069--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts@@ -0,0 +1,54 @@+import { Nullable, ObjectMatrix } from '@univer/core';+import { numfmt } from '@univer/base-numfmt-engine';++export class NumfmtValue {+ numfmt: string;++ color: string;++ value: string;++ status: boolean;++ constructor(numfmt: string) {+ this.numfmt = numfmt;+ this.value = '';+ this.color = '';+ this.status = true;+ }++ calculate(): void {+ if (this.status) {+ const formatter = numfmt(this.numfmt);+ this.value = formatter(this.value);+ this.color = formatter.color(this.value);+ this.status = false;+ }+ }++ getValue() {+ this.calculate();+ return this.value;+ }++ getColor() {+ this.calculate();+ return this.color;+ }+}++export class NumfmtModel {+ protected _matrix: ObjectMatrix<NumfmtValue>;++ constructor() {+ this._matrix = new ObjectMatrix<NumfmtValue>();+ }++ setNumfmtValue(row: number, column: number, numfmt: NumfmtValue): void {+ this._matrix.setValue(row, column, numfmt);+ }++ getNumfmtValue(row: number, column: number): Nullable<NumfmtValue> {+ return this._matrix.getValue(row, column);+ }+}diff --git a/packages/sheets-plugin-numfmt/src/NumfmtModel.ts b/packages/sheets-plugin-numfmt/src/NumfmtModel.tsdeleted file mode 100644index a0e8598c22..0000000000--- a/packages/sheets-plugin-numfmt/src/NumfmtModel.ts+++ /dev/null@@ -1,5 +0,0 @@-import { ObjectMatrix } from '@univer/core/src';--export class NumfmtModel {- protected _matrix: ObjectMatrix<any>;-}diff --git a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.tsindex 4a99b38d31..de4ff4ce6e 100644--- a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts+++ b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts@@ -1,5 +1,22 @@import { Context, Plugin } from '@univer/core';+import { NumfmtController } from './Controller/NumfmtController';export class NumfmtPlugin extends Plugin {- onMounted(ctx: Context): void {}+ protected _controller: NumfmtController;++ onMounted(ctx: Context): void {+ this._controller = new NumfmtController();+ }++ getValue(row: number, column: number): string {+ return this._controller.getValue(row, column);+ }++ getColor(row: number, column: number): string {+ return this._controller.getColor(row, column);+ }++ setNumfmt(row: number, column: number, numfmt: string): void {+ this._controller.setNumfmt(row, column, numfmt);+ }}