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
test(numfmt): add test case (#1170)
Gpound.liu2e6273755f4f
diff --git a/packages/sheets-numfmt/src/controllers/__tests__/cell-content.controller.spec.ts b/packages/sheets-numfmt/src/controllers/__tests__/cell-content.controller.spec.tsnew file mode 100644index 0000000000..84b7ef0bb0--- /dev/null+++ b/packages/sheets-numfmt/src/controllers/__tests__/cell-content.controller.spec.ts@@ -0,0 +1,72 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ICommandService, IUniverInstanceService } from '@univerjs/core';+import type { ISetNumfmtMutationParams } from '@univerjs/sheets';+import { SetNumfmtMutation } from '@univerjs/sheets';+import { beforeEach, describe, expect, it } from 'vitest';++import { NumfmtCellContent } from '../numfmt.cell-content.controller';+import { createTestBed } from './test.util';++describe('test cell-content', () => {+ let unitId: string = '';+ let subUnitId: string = '';+ let univerInstanceService: IUniverInstanceService;+ let testBed: any;+ let commandService: ICommandService;+ beforeEach(() => {+ testBed = createTestBed([[NumfmtCellContent]]);+ unitId = testBed.unitId;+ subUnitId = testBed.subUnitId;+ commandService = testBed.get(ICommandService);+ univerInstanceService = testBed.get(IUniverInstanceService);+ });++ it('Add a new data format to test whether the rendering layer is working correctly', () => {+ const params: ISetNumfmtMutationParams = {+ unitId,+ subUnitId,+ values: {+ 1: {+ ranges: [{ startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }],+ },+ },+ refMap: {+ 1: {+ pattern: '$#,##0;(#,##0)',+ type: '' as any,+ },+ },+ };+ const workbook = univerInstanceService.getCurrentUniverSheetInstance();+ const worksheet = workbook.getActiveSheet();+ testBed.get(NumfmtCellContent);+ const value = worksheet.getCell(0, 0);+ expect(value).toEqual({ v: 0, t: 2 });+ commandService.syncExecuteCommand(SetNumfmtMutation.id, params);+ const startTimeWithNumfmt = performance.now();+ const value1 = worksheet.getCell(0, 0);+ const timeWithNumfmt = performance.now() - startTimeWithNumfmt;+ expect(value1).toEqual({ v: '$0', t: 2 });+ const startTimeWithNumfmtCache = performance.now();+ const value2 = worksheet.getCell(0, 0);+ const timeWithNumfmtCache = performance.now() - startTimeWithNumfmtCache;+ // With caching, it takes less time than without caching+ // console.log(timeWithNumfmtCache, ' ', timeWithNumfmt);+ expect(timeWithNumfmt - timeWithNumfmtCache).toBeGreaterThanOrEqual(0);+ });+});diff --git a/packages/sheets-numfmt/src/controllers/__tests__/editor.controller.spec.ts b/packages/sheets-numfmt/src/controllers/__tests__/editor.controller.spec.tsnew file mode 100644index 0000000000..6f969754b8--- /dev/null+++ b/packages/sheets-numfmt/src/controllers/__tests__/editor.controller.spec.ts@@ -0,0 +1,160 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ICellDataForSheetInterceptor, Workbook, Worksheet } from '@univerjs/core';+import { createInterceptorKey, ICommandService, InterceptorManager, IUniverInstanceService } from '@univerjs/core';+import type { ISetNumfmtMutationParams, ISheetLocation } from '@univerjs/sheets';+import { SetNumfmtMutation } from '@univerjs/sheets';+import { IEditorBridgeService } from '@univerjs/sheets-ui';+import { beforeEach, describe, expect, it } from 'vitest';++import { NumfmtCellContent } from '../numfmt.cell-content.controller';+import { NumfmtEditorController } from '../numfmt.editor.controller';+import { createTestBed } from './test.util';++const BEFORE_CELL_EDIT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation>('BEFORE_CELL_EDIT');+const AFTER_CELL_EDIT = createInterceptorKey<ICellDataForSheetInterceptor, ISheetLocation>('AFTER_CELL_EDIT');+class MockEditorBridgeService {+ interceptor = new InterceptorManager({+ BEFORE_CELL_EDIT,+ AFTER_CELL_EDIT,+ });+}+describe('test editor', () => {+ let unitId: string = '';+ let subUnitId: string = '';+ let workbook: Workbook;+ let worksheet: Worksheet;+ let testBed: ReturnType<typeof createTestBed>;+ let commandService: ICommandService;++ beforeEach(() => {+ testBed = createTestBed([+ [NumfmtEditorController],+ [NumfmtCellContent],+ [IEditorBridgeService, { useClass: MockEditorBridgeService }],+ ]);+ unitId = testBed.unitId;+ subUnitId = testBed.subUnitId;+ commandService = testBed.get(ICommandService);+ const univerInstanceService = testBed.get(IUniverInstanceService);+ testBed.get(NumfmtEditorController);+ testBed.get(NumfmtCellContent);+ workbook = univerInstanceService.getCurrentUniverSheetInstance();+ worksheet = workbook.getActiveSheet();+ });++ it('before edit with currency', () => {+ const params: ISetNumfmtMutationParams = {+ unitId,+ subUnitId,+ values: {+ 1: {+ ranges: [{ startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }],+ },+ },+ refMap: {+ 1: {+ pattern: '$#,##0;(#,##0)',+ type: '' as any,+ },+ },+ };+ commandService.syncExecuteCommand(SetNumfmtMutation.id, params);+ const editorBridgeService = testBed.get(IEditorBridgeService);+ const location = {+ workbook,+ worksheet,+ unitId,+ subUnitId,+ row: 0,+ col: 0,+ };+ const cellData = worksheet.getCell(0, 0);+ expect(cellData).toEqual({ v: '$0', t: 2 });+ const result = editorBridgeService.interceptor.fetchThroughInterceptors(+ editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT+ )(cellData, location);+ // The currency format needs to be entered in the editor with real values, not with currency symbols+ expect(result).toEqual({ v: 0, t: 2 });+ });+ it('before edit with data', () => {+ const params: ISetNumfmtMutationParams = {+ unitId,+ subUnitId,+ values: {+ 1: {+ ranges: [{ startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }],+ },+ },+ refMap: {+ 1: {+ pattern: 'A/P h:mm:ss',+ type: '' as any,+ },+ },+ };+ commandService.syncExecuteCommand(SetNumfmtMutation.id, params);+ const editorBridgeService = testBed.get(IEditorBridgeService);+ const location = {+ workbook,+ worksheet,+ unitId,+ subUnitId,+ row: 0,+ col: 0,+ };+ const cellData = worksheet.getCell(0, 0);+ const result = editorBridgeService.interceptor.fetchThroughInterceptors(+ editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT+ )(cellData, location);+ // The data format needs to be entered in the editor with data string, not with real values+ expect(result!.v).toEqual(cellData!.v);+ });+ it('after edit with data', () => {+ const params: ISetNumfmtMutationParams = {+ unitId,+ subUnitId,+ values: {+ 1: {+ ranges: [{ startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }],+ },+ },+ refMap: {+ 1: {+ pattern: 'h:mm:ss',+ type: '' as any,+ },+ },+ };+ commandService.syncExecuteCommand(SetNumfmtMutation.id, params);+ const editorBridgeService = testBed.get(IEditorBridgeService);+ const location = {+ workbook,+ worksheet,+ unitId,+ subUnitId,+ row: 0,+ col: 0,+ };+ const cellData = { v: '12:33:22', t: 2 };+ const result = editorBridgeService.interceptor.fetchThroughInterceptors(+ editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT+ )(cellData, location);+ // The date-time drop is a numeric value, not a literal string+ expect(result?.v).toBe(0.5231712962962963);+ });+});diff --git a/packages/sheets-numfmt/src/controllers/__tests__/test.util.ts b/packages/sheets-numfmt/src/controllers/__tests__/test.util.tsnew file mode 100644index 0000000000..d3718848f2--- /dev/null+++ b/packages/sheets-numfmt/src/controllers/__tests__/test.util.ts@@ -0,0 +1,106 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { IWorkbookData } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, LocaleType, Plugin, PluginType, Univer } from '@univerjs/core';+import {+ INumfmtService,+ NumfmtService,+ RemoveNumfmtMutation,+ SetNumfmtMutation,+ SheetInterceptorService,+} from '@univerjs/sheets';+import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';+import type { Dependency } from '@wendellhu/redi';+import { Inject, Injector } from '@wendellhu/redi';++const TEST_WORKBOOK_DATA_DEMO: () => IWorkbookData = () => ({+ id: 'test',+ appVersion: '3.0.0-alpha',+ sheets: {+ sheet1: {+ id: 'sheet1',+ cellData: {+ 0: { 0: { v: 0, t: 2 }, 1: { v: 1, t: 2 }, 2: { v: 2, t: 2 }, 3: { v: 3, t: 2 }, 4: { v: 4, t: 2 } },+ 1: { 0: { v: 0, t: 2 }, 1: { v: 1, t: 2 }, 2: { v: 2, t: 2 }, 3: { v: 3, t: 2 }, 4: { v: 4, t: 2 } },+ 2: { 0: { v: 0, t: 2 }, 1: { v: 1, t: 2 }, 2: { v: 2, t: 2 }, 3: { v: 3, t: 2 }, 4: { v: 4, t: 2 } },+ 3: { 0: { v: 0, t: 2 }, 1: { v: 1, t: 2 }, 2: { v: 2, t: 2 }, 3: { v: 3, t: 2 }, 4: { v: 4, t: 2 } },+ },+ },+ },+ locale: LocaleType.ZH_CN,+ name: '',+ sheetOrder: [],+ styles: {},+});+export const createTestBed = (dependencies?: Dependency[]) => {+ const univer = new Univer();+ const injector = univer.__getInjector();++ let get: Injector['get'] | undefined;++ class TestSpyPlugin extends Plugin {+ static override type = PluginType.Sheet;++ constructor(+ _config: undefined,+ @Inject(Injector) override readonly _injector: Injector+ ) {+ super('test-plugin');++ this._injector = _injector;+ get = this._injector.get.bind(this._injector);+ }++ override onStarting(injector: Injector): void {+ injector.add([INumfmtService, { useClass: NumfmtService }]);+ injector.add([SheetInterceptorService]);+ injector.add([SheetSkeletonManagerService]);++ dependencies?.forEach((d) => injector.add(d));+ }++ override onDestroy(): void {+ get = undefined;+ }+ }++ univer.registerPlugin(TestSpyPlugin);++ const workbookJson = TEST_WORKBOOK_DATA_DEMO();+ const sheet = univer.createUniverSheet(workbookJson);++ if (get === undefined) {+ throw new Error('[TestPlugin]: not hooked on!');+ }++ const univerInstanceService = injector.get(IUniverInstanceService);+ const commandService = injector.get(ICommandService);+ commandService.registerCommand(RemoveNumfmtMutation);+ commandService.registerCommand(SetNumfmtMutation);+ univerInstanceService.focusUniverInstance('test');+ const unitId = workbookJson.id;+ const subUnitId = workbookJson.sheets.sheet1.id!;++ return {+ univer,+ get,+ sheet,+ unitId,+ subUnitId,+ // numfmtService,+ };+};diff --git a/packages/sheets-numfmt/src/controllers/numfmt.cell-content.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.cell-content.controller.tsnew file mode 100644index 0000000000..c2c5b0a96a--- /dev/null+++ b/packages/sheets-numfmt/src/controllers/numfmt.cell-content.controller.ts@@ -0,0 +1,132 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ICellData, ICellDataForSheetInterceptor } from '@univerjs/core';+import {+ CellValueType,+ Disposable,+ ICommandService,+ LifecycleStages,+ ObjectMatrix,+ OnLifecycle,+ Range,+ ThemeService,+ toDisposable,+} from '@univerjs/core';+import type { ISetNumfmtMutationParams } from '@univerjs/sheets';+import { INTERCEPTOR_POINT, INumfmtService, SetNumfmtMutation, SheetInterceptorService } from '@univerjs/sheets';+import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';+import { Inject } from '@wendellhu/redi';+import { distinctUntilChanged, map } from 'rxjs/operators';++import { getPatternPreview } from '../utils/pattern';++@OnLifecycle(LifecycleStages.Rendered, NumfmtCellContent)+export class NumfmtCellContent extends Disposable {+ constructor(+ @Inject(SheetInterceptorService) private _sheetInterceptorService: SheetInterceptorService,+ @Inject(ThemeService) private _themeService: ThemeService,+ @Inject(SheetSkeletonManagerService) private _sheetSkeletonManagerService: SheetSkeletonManagerService,+ @Inject(ICommandService) private _commandService: ICommandService,++ @Inject(INumfmtService) private _numfmtService: INumfmtService+ ) {+ super();+ this._initInterceptorCellContent();+ }++ private _initInterceptorCellContent() {+ const renderCache = new ObjectMatrix<{ result: ICellData; parameters: string | number }>();+ this.disposeWithMe(+ this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {+ handler: (cell, location, next) => {+ const unitId = location.unitId;+ const sheetId = location.subUnitId;+ const numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col);+ if (!numfmtValue) {+ return next(cell);+ }+ const originCellValue = cell;+ if (!originCellValue) {+ return next(cell);+ }+ // just handle number+ if (originCellValue.t !== CellValueType.NUMBER) {+ return next(cell);+ }++ let numfmtRes: string = '';+ const cache = renderCache.getValue(location.row, location.col);+ if (cache && cache.parameters === originCellValue.v) {+ return { ...cell, ...cache.result };+ }++ const info = getPatternPreview(numfmtValue.pattern, Number(originCellValue.v));++ numfmtRes = info.result;++ if (!numfmtRes) {+ return next(cell);+ }++ const res: ICellDataForSheetInterceptor = { v: numfmtRes };++ if (info.color) {+ const color = this._themeService.getCurrentTheme()[`${info.color}500`];++ if (color) {+ res.interceptorStyle = { cl: { rgb: color } };+ }+ }++ renderCache.setValue(location.row, location.col, {+ result: res,+ parameters: originCellValue.v as number,+ });++ return { ...cell, ...res };+ },+ })+ );+ this.disposeWithMe(+ this._commandService.onCommandExecuted((commandInfo) => {+ if (commandInfo.id === SetNumfmtMutation.id) {+ const params = commandInfo.params as ISetNumfmtMutationParams;+ Object.keys(params.values).forEach((key) => {+ const v = params.values[key];+ v.ranges.forEach((range) => {+ Range.foreach(range, (row, col) => {+ renderCache.realDeleteValue(row, col);+ });+ });+ });+ }+ })+ );+ this.disposeWithMe(+ toDisposable(+ this._sheetSkeletonManagerService.currentSkeleton$+ .pipe(+ map((skeleton) => skeleton?.sheetId),+ distinctUntilChanged()+ )+ .subscribe(() => {+ renderCache.reset();+ })+ )+ );+ }+}diff --git a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.controller.tsindex 811747129b..f5b4bb02e6 100644--- a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts+++ b/packages/sheets-numfmt/src/controllers/numfmt.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, ICellDataForSheetInterceptor, IRange } from '@univerjs/core';+import type { IRange } from '@univerjs/core';import {CellValueType,Disposable,@@ -23,7 +23,6 @@ import {IUniverInstanceService,LifecycleStages,LocaleService,- ObjectMatrix,OnLifecycle,Range,ThemeService,@@ -44,10 +43,10 @@ import {SheetInterceptorService,} from '@univerjs/sheets';import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';-import { ComponentManager, IMenuService, ISidebarService } from '@univerjs/ui';+import { ComponentManager, ISidebarService } from '@univerjs/ui';import { Inject, Injector } from '@wendellhu/redi';import { combineLatest, merge, Observable } from 'rxjs';-import { debounceTime, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators';+import { debounceTime, map, switchMap, tap } from 'rxjs/operators';import { SHEET_NUMFMT_PLUGIN } from '../base/const/PLUGIN_NAME';import { AddDecimalCommand } from '../commands/commands/add-decimal.command';@@ -59,8 +58,6 @@ import { CloseNumfmtPanelOperator } from '../commands/operations/close.numfmt.paimport { OpenNumfmtPanelOperator } from '../commands/operations/open.numfmt.panel.operation';import type { ISheetNumfmtPanelProps } from '../components/index';import { SheetNumfmtPanel } from '../components/index';-import { zhCN } from '../locale';-import { AddDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem, SubtractDecimalMenuItem } from '../menu/menu';import { getPatternPreview, getPatternType } from '../utils/pattern';import type { INumfmtController } from './type';@@ -84,7 +81,6 @@ export class NumfmtController extends Disposable implements INumfmtController {@Inject(IRenderManagerService) private _renderManagerService: IRenderManagerService,@Inject(INumfmtService) private _numfmtService: INumfmtService,@Inject(ComponentManager) private _componentManager: ComponentManager,- @Inject(IMenuService) private _menuService: IMenuService,@Inject(ISidebarService) private _sidebarService: ISidebarService,@Inject(LocaleService) private _localeService: LocaleService) {@@ -94,9 +90,6 @@ export class NumfmtController extends Disposable implements INumfmtController {this._initPanel();this._initCommands();this._commandExecutedListener();- this._initMenu();- this._initInterceptorCellContent();- this._initLocal();}openPanel = () => {@@ -190,17 +183,6 @@ export class NumfmtController extends Disposable implements INumfmtController {private _initPanel() {this._componentManager.register(SHEET_NUMFMT_PLUGIN, SheetNumfmtPanel);}- private _initLocal = () => {- this._localeService.load({ zhCN });- };-- private _initMenu() {- [AddDecimalMenuItem, SubtractDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem]- .map((factory) => factory(this._componentManager))- .forEach((configFactory) => {- this.disposeWithMe(this._menuService.addMenuItem(configFactory(this._injector)));- });- }private _initInterceptorCommands() {const self = this;@@ -254,88 +236,6 @@ export class NumfmtController extends Disposable implements INumfmtController {);}- private _initInterceptorCellContent() {- const renderCache = new ObjectMatrix<{ result: ICellData; parameters: string | number }>();- this.disposeWithMe(- this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {- handler: (cell, location, next) => {- const unitId = location.unitId;- const sheetId = location.subUnitId;- const numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col);- if (!numfmtValue) {- return next(cell);- }- const originCellValue = cell;- if (!originCellValue) {- return next(cell);- }- // just handle number- if (originCellValue.t !== CellValueType.NUMBER) {- return next(cell);- }-- let numfmtRes: string = '';- const cache = renderCache.getValue(location.row, location.col);- if (cache && cache.parameters === originCellValue.v) {- return { ...cell, ...cache.result };- }-- const info = getPatternPreview(numfmtValue.pattern, Number(originCellValue.v));-- numfmtRes = info.result;-- if (!numfmtRes) {- return next(cell);- }-- const res: ICellDataForSheetInterceptor = { v: numfmtRes };-- if (info.color) {- const color = this._themeService.getCurrentTheme()[`${info.color}500`];-- if (color) {- res.interceptorStyle = { cl: { rgb: color } };- }- }-- renderCache.setValue(location.row, location.col, {- result: res,- parameters: originCellValue.v as number,- });-- return { ...cell, ...res };- },- })- );- this.disposeWithMe(- this._commandService.onCommandExecuted((commandInfo) => {- if (commandInfo.id === SetNumfmtMutation.id) {- const params = commandInfo.params as ISetNumfmtMutationParams;- Object.keys(params.values).forEach((key) => {- const v = params.values[key];- v.ranges.forEach((range) => {- Range.foreach(range, (row, col) => {- renderCache.realDeleteValue(row, col);- });- });- });- }- })- );- this.disposeWithMe(- toDisposable(- this._sheetSkeletonManagerService.currentSkeleton$- .pipe(- map((skeleton) => skeleton?.sheetId),- distinctUntilChanged()- )- .subscribe(() => {- renderCache.reset();- })- )- );- }-private _initRealTimeRenderingInterceptor() {const isPanelOpenObserver = new Observable<boolean>((subscribe) => {this._commandService.onCommandExecuted((commandInfo) => {diff --git a/packages/sheets-numfmt/src/controllers/numfmt.i18n.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.i18n.controller.tsnew file mode 100644index 0000000000..f6b2690fe0--- /dev/null+++ b/packages/sheets-numfmt/src/controllers/numfmt.i18n.controller.ts@@ -0,0 +1,32 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { Disposable, LifecycleStages, LocaleService, OnLifecycle } from '@univerjs/core';+import { Inject } from '@wendellhu/redi';++import { zhCN } from '../locale';++@OnLifecycle(LifecycleStages.Rendered, NumfmtI18nController)+export class NumfmtI18nController extends Disposable {+ constructor(@Inject(LocaleService) private _localeService: LocaleService) {+ super();+ this._initLocal();+ }++ private _initLocal = () => {+ this._localeService.load({ zhCN });+ };+}diff --git a/packages/sheets-numfmt/src/controllers/numfmt.menu.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.menu.controller.tsnew file mode 100644index 0000000000..e905d63701--- /dev/null+++ b/packages/sheets-numfmt/src/controllers/numfmt.menu.controller.ts@@ -0,0 +1,41 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';+import { ComponentManager, IMenuService } from '@univerjs/ui';+import { Inject, Injector } from '@wendellhu/redi';++import { AddDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem, SubtractDecimalMenuItem } from '../menu/menu';++@OnLifecycle(LifecycleStages.Rendered, NumfmtMenuController)+export class NumfmtMenuController extends Disposable {+ constructor(+ @Inject(Injector) private _injector: Injector,+ @Inject(ComponentManager) private _componentManager: ComponentManager,+ @Inject(IMenuService) private _menuService: IMenuService+ ) {+ super();+ this._initMenu();+ }++ private _initMenu() {+ [AddDecimalMenuItem, SubtractDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem]+ .map((factory) => factory(this._componentManager))+ .forEach((configFactory) => {+ this.disposeWithMe(this._menuService.addMenuItem(configFactory(this._injector)));+ });+ }+}diff --git a/packages/sheets-numfmt/src/numfmt-plugin.ts b/packages/sheets-numfmt/src/numfmt-plugin.tsindex d7a46f3fef..fc660097d9 100644--- a/packages/sheets-numfmt/src/numfmt-plugin.ts+++ b/packages/sheets-numfmt/src/numfmt-plugin.ts@@ -19,9 +19,12 @@ import { Inject, Injector } from '@wendellhu/redi';import { SHEET_NUMFMT_PLUGIN } from './base/const/PLUGIN_NAME';import { NumfmtAutoFillController } from './controllers/numfmt.auto-fill.controller';+import { NumfmtCellContent } from './controllers/numfmt.cell-content.controller';import { NumfmtController } from './controllers/numfmt.controller';import { NumfmtCopyPasteController } from './controllers/numfmt.copy-paste.controller';import { NumfmtEditorController } from './controllers/numfmt.editor.controller';+import { NumfmtI18nController } from './controllers/numfmt.i18n.controller';+import { NumfmtMenuController } from './controllers/numfmt.menu.controller';import { NumfmtRefRangeController } from './controllers/numfmt.ref-range.controller';import { NumfmtSheetController } from './controllers/numfmt.sheet.controller';import { INumfmtController } from './controllers/type';@@ -45,5 +48,8 @@ export class UniverSheetsNumfmtPlugin extends Plugin {this._injector.add([NumfmtSheetController]);this._injector.add([NumfmtCopyPasteController]);this._injector.add([NumfmtAutoFillController]);+ this._injector.add([NumfmtCellContent]);+ this._injector.add([NumfmtI18nController]);+ this._injector.add([NumfmtMenuController]);}}diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.tsindex 36fcae0ac7..67ec353aaf 100644--- a/packages/sheets/src/index.ts+++ b/packages/sheets/src/index.ts@@ -252,6 +252,7 @@ export { type ISetWorksheetActiveOperationParams } from './commands/operations/sexport { type ISheetCommandSharedParams } from './commands/utils/interface';export { getAddMergeMutationRangeByType } from './controllers/merge-cell.controller';export { enUS, zhCN } from './locale';+export { NumfmtService } from './services/numfmt/numfmt.service';export type { FormatType, INumfmtItem, INumfmtItemWithCache } from './services/numfmt/type';export { INumfmtService } from './services/numfmt/type';export { RefRangeService } from './services/ref-range/ref-range.service';