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-th2e90d7b43d90
diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.tsindex 63a3368e59..23338dfdcd 100644--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts@@ -1,4 +1,4 @@-import { Plugin } from '@univer/core';+import { ObjectMatrixPrimitiveType, Plugin } from '@univer/core';import { NumfmtModel, NumfmtValue } from '../Model/NumfmtModel';export class NumfmtController {@@ -11,17 +11,19 @@ export class NumfmtController {this._plugin = plugin;}+ getConfig(): ObjectMatrixPrimitiveType<NumfmtValue> {+ return this._model.getNumfmtConfig();+ }+getColor(row: number, column: number): string {- const numfmt = this._model.getNumfmtValue(row, column);- return numfmt ? numfmt.getColor() : String();+ return this._model.getNumfmtColor(row, column);}getValue(row: number, column: number): string {- const numfmt = this._model.getNumfmtValue(row, column);- return numfmt ? numfmt.getValue() : String();+ return this._model.getNumfmtValue(row, column);}setNumfmt(row: number, column: number, numfmt: string): void {- this._model.setNumfmtValue(row, column, new NumfmtValue(numfmt));+ this._model.setNumfmtValue(row, column, numfmt);}}diff --git a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.tsindex f72aac437f..e02b27ce62 100644--- a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts+++ b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts@@ -1,54 +1,60 @@-import { Nullable, ObjectMatrix } from '@univer/core';+import { ObjectMatrix, ObjectMatrixPrimitiveType } from '@univer/core';import { numfmt } from '@univer/base-numfmt-engine';-export class NumfmtValue {- _numfmt: string;+export interface NumfmtValue {+ numfmt: string;- _color: string;+ color: string;- _value: string;+ value: string;- _status: boolean;+ change: boolean;+}- constructor(numfmt: string) {- this._numfmt = numfmt;- this._status = true;- this._value = String();- this._color = String();- }+export class NumfmtModel {+ protected _matrix: ObjectMatrix<NumfmtValue>;- calculate(): void {- if (this._status) {- const formatter = numfmt(this._numfmt);- this._value = formatter(this._value);- this._color = formatter.color(this._value);- this._status = false;+ protected _calculate(primeval: NumfmtValue): void {+ if (primeval.change) {+ const formatter = numfmt(primeval.numfmt);+ primeval.value = formatter(primeval.value);+ primeval.color = formatter.color(primeval.value);+ primeval.change = false;}}- getValue(): string {- this.calculate();- return this._value;+ constructor() {+ this._matrix = new ObjectMatrix<NumfmtValue>();}- getColor(): string {- this.calculate();- return this._color;+ getNumfmtConfig(): ObjectMatrixPrimitiveType<NumfmtValue> {+ return this._matrix.toJSON();}-}-export class NumfmtModel {- protected _matrix: ObjectMatrix<NumfmtValue>;-- constructor() {- this._matrix = new ObjectMatrix<NumfmtValue>();+ setNumfmtValue(row: number, column: number, value: string): void {+ this._matrix.setValue(row, column, {+ numfmt: value,+ change: true,+ value: String(),+ color: String(),+ });}- setNumfmtValue(row: number, column: number, numfmt: NumfmtValue): void {- this._matrix.setValue(row, column, numfmt);+ getNumfmtValue(row: number, column: number): string {+ const primeval = this._matrix.getValue(row, column);+ if (primeval) {+ this._calculate(primeval);+ return primeval.value;+ }+ return String();}- getNumfmtValue(row: number, column: number): Nullable<NumfmtValue> {- return this._matrix.getValue(row, column);+ getNumfmtColor(row: number, column: number): string {+ const primeval = this._matrix.getValue(row, column);+ if (primeval) {+ this._calculate(primeval);+ return primeval.color;+ }+ return String();}}diff --git a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.tsindex 1a838a5129..1f24f31a26 100644--- a/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts+++ b/packages/sheets-plugin-numfmt/src/NumfmtPlugin.ts@@ -13,6 +13,10 @@ export class NumfmtPlugin extends Plugin {this._controller = new NumfmtController(this);}+ getConfig() {+ this._controller.getConfig();+ }+getValue(row: number, column: number): string {return this._controller.getValue(row, column);}