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(sheet-numfmt-plugin):numfmt plugin optimization

eiji-thb4bf4570ed97
diff --git a/.fleet/settings.json b/.fleet/settings.json
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtAction.ts b/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtAction.ts
new file mode 100644
index 0000000000..98faa7df97
--- /dev/null
+++ b/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtAction.ts
@@ -0,0 +1,32 @@
+import { ActionBase, ActionObservers, IActionData, Workbook } from '@univer/core';
+
+export interface ISetNumfmtActionData extends IActionData {
+ row: number;
+ column: number;
+ numfmt: string;
+}
+
+export class SetNumfmtAction extends ActionBase<ISetNumfmtActionData, ISetNumfmtActionData> {
+ constructor(actionData: ISetNumfmtActionData, workbook: Workbook, observers: ActionObservers) {
+ super(actionData, workbook, observers);
+ this._doActionData = {
+ ...actionData,
+ convertor: [],
+ };
+ this._oldActionData = {
+ ...actionData,
+ convertor: [],
+ };
+ this.do();
+ }
+
+ redo(): void {}
+
+ do(): void {}
+
+ undo(): void {}
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts b/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts
new file mode 100644
index 0000000000..2f52b4bac0
--- /dev/null
+++ b/packages/sheets-plugin-numfmt/src/Model/Apply/SetNumfmt.ts
@@ -0,0 +1 @@
+export function SetNumfmt() {}
diff --git a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts
index 12e73389d4..f72aac437f 100644
--- a/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts
+++ b/packages/sheets-plugin-numfmt/src/Model/NumfmtModel.ts
@@ -2,38 +2,38 @@ import { Nullable, ObjectMatrix } from '@univer/core';
import { numfmt } from '@univer/base-numfmt-engine';
export class NumfmtValue {
- numfmt: string;
+ _numfmt: string;
- color: string;
+ _color: string;
- value: string;
+ _value: string;
- status: boolean;
+ _status: boolean;
constructor(numfmt: string) {
- this.numfmt = numfmt;
- this.value = String();
- this.color = String();
- this.status = true;
+ this._numfmt = numfmt;
+ this._status = true;
+ this._value = String();
+ this._color = String();
}
- getValue() {
- this.calculate();
- return this.value;
+ calculate(): void {
+ if (this._status) {
+ const formatter = numfmt(this._numfmt);
+ this._value = formatter(this._value);
+ this._color = formatter.color(this._value);
+ this._status = false;
+ }
}
- getColor() {
+ getValue(): string {
this.calculate();
- return this.color;
+ return this._value;
}
- calculate(): void {
- if (this.status) {
- const formatter = numfmt(this.numfmt);
- this.value = formatter(this.value);
- this.color = formatter.color(this.value);
- this.status = false;
- }
+ getColor(): string {
+ this.calculate();
+ return this._color;
}
}