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
fix(sheet): dependency cycle (#557)
Gpound.liu828afdb40e38
diff --git a/packages/base-render/src/components/sheets/extensions/font.ts b/packages/base-render/src/components/sheets/extensions/font.tsindex f977b778c9..743df83f28 100644--- a/packages/base-render/src/components/sheets/extensions/font.ts+++ b/packages/base-render/src/components/sheets/extensions/font.ts@@ -1,7 +1,7 @@import { HorizontalAlign, IColorStyle, IScale, ObjectMatrix, WrapStrategy } from '@univerjs/core';import { fixLineWidthByScale } from '../../../basics/tools';-import { Documents } from '../..';+import type { Documents } from '../../docs/document';import { SpreadsheetExtensionRegistry } from '../../extension';import { IFontCacheItem } from '../interfaces';import { SheetComponent } from '../sheet-component';diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 89d0118172..526c2737c4 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -43,7 +43,7 @@ export {IFloatingObjectManagerService,} from './services/floating-object/floating-object-manager.service';export { DocumentType, IUniverInstanceService } from './services/instance/instance.service';-export { LifecycleStages, OnLifecycle } from './services/lifecycle/lifecycle';+export { LifecycleStages, OnLifecycle, runOnLifecycle } from './services/lifecycle/lifecycle';export { LifecycleService } from './services/lifecycle/lifecycle.service';export { ILocalStorageService } from './services/local-storage/local-storage.service';export { LocaleService } from './services/locale/locale.service';diff --git a/packages/sheets-plugin-numfmt/src/commands/commands/add.decimal.command.ts b/packages/sheets-plugin-numfmt/src/commands/commands/add.decimal.command.tsindex 1c00636222..cf883e11ce 100644--- a/packages/sheets-plugin-numfmt/src/commands/commands/add.decimal.command.ts+++ b/packages/sheets-plugin-numfmt/src/commands/commands/add.decimal.command.ts@@ -2,7 +2,7 @@ import { SelectionManagerService } from '@univerjs/base-sheets';import { CommandType, ICommand, ICommandService, IUniverInstanceService, Range } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { NumfmtService } from '../../service/numfmt.service';+import { INumfmtService } from '../../service/type';import { getDecimalFromPattern, isPatternEqualWithoutDecimal, setPatternDecimal } from '../../utils/decimal';import { SetNumfmtCommand, SetNumfmtCommandParams } from './set.numfmt.command';@@ -12,7 +12,7 @@ export const AddDecimalCommand: ICommand = {handler: async (accessor: IAccessor) => {const commandService = accessor.get(ICommandService);const selectionManagerService = accessor.get(SelectionManagerService);- const numfmtService = accessor.get(NumfmtService);+ const numfmtService = accessor.get(INumfmtService);const univerInstanceService = accessor.get(IUniverInstanceService);const selections = selectionManagerService.getSelections();diff --git a/packages/sheets-plugin-numfmt/src/commands/commands/subtract.decimal.command.ts b/packages/sheets-plugin-numfmt/src/commands/commands/subtract.decimal.command.tsindex 7ac2ff9f82..a18e19f761 100644--- a/packages/sheets-plugin-numfmt/src/commands/commands/subtract.decimal.command.ts+++ b/packages/sheets-plugin-numfmt/src/commands/commands/subtract.decimal.command.ts@@ -2,7 +2,7 @@ import { SelectionManagerService } from '@univerjs/base-sheets';import { CommandType, ICommand, ICommandService, IUniverInstanceService, Range } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { NumfmtService } from '../../service/numfmt.service';+import { INumfmtService } from '../../service/type';import { getDecimalFromPattern, isPatternEqualWithoutDecimal, setPatternDecimal } from '../../utils/decimal';import { SetNumfmtCommand, SetNumfmtCommandParams } from './set.numfmt.command';@@ -12,7 +12,7 @@ export const SubtractDecimalCommand: ICommand = {handler: async (accessor: IAccessor) => {const commandService = accessor.get(ICommandService);const selectionManagerService = accessor.get(SelectionManagerService);- const numfmtService = accessor.get(NumfmtService);+ const numfmtService = accessor.get(INumfmtService);const univerInstanceService = accessor.get(IUniverInstanceService);const selections = selectionManagerService.getSelections();diff --git a/packages/sheets-plugin-numfmt/src/commands/mutations/set.numfmt.mutation.ts b/packages/sheets-plugin-numfmt/src/commands/mutations/set.numfmt.mutation.tsindex 6c72545d71..e441164372 100644--- a/packages/sheets-plugin-numfmt/src/commands/mutations/set.numfmt.mutation.ts+++ b/packages/sheets-plugin-numfmt/src/commands/mutations/set.numfmt.mutation.ts@@ -2,13 +2,13 @@ import { CommandType, ICommand } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';import { FormatType } from '../../base/types';-import { NumfmtService } from '../../service/numfmt.service';+import { INumfmtService } from '../../service/type';export const factorySetNumfmtUndoMutation = (accessor: IAccessor,option: SetNumfmtMutationParams): SetNumfmtMutationParams => {- const numfmtService = accessor.get(NumfmtService);+ const numfmtService = accessor.get(INumfmtService);const undos: SetNumfmtMutationParams = {...option,values: option.values@@ -36,7 +36,7 @@ export const SetNumfmtMutation: ICommand<SetNumfmtMutationParams> = {return false;}const values = params.values;- const numfmtService = accessor.get(NumfmtService);+ const numfmtService = accessor.get(INumfmtService);const workbookId = params.workbookId;const sheetId = params.worksheetId;values.forEach((item) => {diff --git a/packages/sheets-plugin-numfmt/src/commands/operators/open.numfmt.panel.operator.ts b/packages/sheets-plugin-numfmt/src/commands/operators/open.numfmt.panel.operator.tsindex 25a032c9f9..e726fa2b92 100644--- a/packages/sheets-plugin-numfmt/src/commands/operators/open.numfmt.panel.operator.ts+++ b/packages/sheets-plugin-numfmt/src/commands/operators/open.numfmt.panel.operator.ts@@ -1,13 +1,13 @@import { CommandType, ICommand } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { NumfmtController } from '../../controllers/numfmt.controller';+import { INumfmtController } from '../../controllers/type';export const OpenNumfmtPanelOperator: ICommand = {id: 'sheet.operation.open.numfmt.panel',type: CommandType.OPERATION,handler: (accessor: IAccessor) => {- const numfmtController = accessor.get(NumfmtController);+ const numfmtController = accessor.get(INumfmtController);numfmtController.openPanel();return true;},diff --git a/packages/sheets-plugin-numfmt/src/controllers/numfmt.controller.ts b/packages/sheets-plugin-numfmt/src/controllers/numfmt.controller.tsindex 9b739e37bc..95299f0646 100644--- a/packages/sheets-plugin-numfmt/src/controllers/numfmt.controller.ts+++ b/packages/sheets-plugin-numfmt/src/controllers/numfmt.controller.ts@@ -26,11 +26,9 @@ import {INTERCEPTOR_POINT,IRange,IUniverInstanceService,- LifecycleStages,LocaleService,LocaleType,Nullable,- OnLifecycle,Range,SheetInterceptorService,ThemeService,@@ -57,8 +55,9 @@ import { OpenNumfmtPanelOperator } from '../commands/operators/open.numfmt.panelimport { SheetNumfmtPanel, SheetNumfmtPanelProps } from '../components/index';import { zhCn } from '../locale/zh-CN';import { AddDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem, SubtractDecimalMenuItem } from '../menu/menu';-import { NumfmtService } from '../service/numfmt.service';+import { INumfmtService } from '../service/type';import { getPatternPreview, getPatternType } from '../utils/pattern';+import type { INumfmtController } from './type';const createCollectEffectMutation = () => {type Config = { workbookId: string; worksheetId: string; row: number; col: number; value: Nullable<NumfmtItem> };@@ -75,8 +74,7 @@ const createCollectEffectMutation = () => {clean,};};-@OnLifecycle(LifecycleStages.Ready, NumfmtController)-export class NumfmtController extends Disposable {+export class NumfmtController extends Disposable implements INumfmtController {// collect effect mutations when edit end and push this to commands stack in next commands progressprivate _collectEffectMutation = createCollectEffectMutation();private _previewPattern = '';@@ -91,7 +89,7 @@ export class NumfmtController extends Disposable {@Inject(ICommandService) private _commandService: ICommandService,@Inject(SelectionManagerService) private _selectionManagerService: SelectionManagerService,@Inject(IRenderManagerService) private _renderManagerService: IRenderManagerService,- @Inject(NumfmtService) private _numfmtService: NumfmtService,+ @Inject(INumfmtService) private _numfmtService: INumfmtService,@Inject(ComponentManager) private _componentManager: ComponentManager,@Inject(IMenuService) private _menuService: IMenuService,@Inject(ISidebarService) private _sidebarService: ISidebarService,diff --git a/packages/sheets-plugin-numfmt/src/controllers/type.ts b/packages/sheets-plugin-numfmt/src/controllers/type.tsnew file mode 100644index 0000000000..2880cb6277--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/controllers/type.ts@@ -0,0 +1,8 @@+import { LifecycleStages, runOnLifecycle } from '@univerjs/core';+import { createIdentifier } from '@wendellhu/redi';++export interface INumfmtController {+ openPanel(): void;+}+export const INumfmtController = createIdentifier<INumfmtController>('INumfmtController');+runOnLifecycle(LifecycleStages.Rendered, INumfmtController);diff --git a/packages/sheets-plugin-numfmt/src/menu/menu.ts b/packages/sheets-plugin-numfmt/src/menu/menu.tsindex 31ce1b72a9..d63d6c801e 100644--- a/packages/sheets-plugin-numfmt/src/menu/menu.ts+++ b/packages/sheets-plugin-numfmt/src/menu/menu.ts@@ -14,7 +14,7 @@ import { isCurrencyPanel } from '../components/currency';import { isDatePanel } from '../components/date';import { MoreNumfmtType } from '../components/more-numfmt-type/MoreNumfmtType';import { isThousandthPercentilePanel } from '../components/thousandth-percentile';-import { NumfmtService } from '../service/numfmt.service';+import { INumfmtService } from '../service/type';export const CurrencyMenuItem = (componentManager: ComponentManager) => {const iconKey = 'icon-rmbSingle';@@ -61,7 +61,7 @@ export const SubtractDecimalMenuItem = (componentManager: ComponentManager) => {export const FactoryOtherMenuItem = (componentManager: ComponentManager) => {componentManager.register('sheet.numfmt.moreNumfmtType', MoreNumfmtType);return (_accessor: IAccessor) => {- const numfmtService = _accessor.get(NumfmtService);+ const numfmtService = _accessor.get(INumfmtService);const univerInstanceService = _accessor.get(IUniverInstanceService);const selectionManagerService = _accessor.get(SelectionManagerService);const value$ = new Observable((subscribe) =>diff --git a/packages/sheets-plugin-numfmt/src/numfmt-plugin.node.ts b/packages/sheets-plugin-numfmt/src/numfmt-plugin.node.tsindex 9a9b162732..a851028d82 100644--- a/packages/sheets-plugin-numfmt/src/numfmt-plugin.node.ts+++ b/packages/sheets-plugin-numfmt/src/numfmt-plugin.node.ts@@ -3,6 +3,7 @@ import { Inject, Injector } from '@wendellhu/redi';import { SHEET_NUMFMT_PLUGIN } from './base/const/PLUGIN_NAME';import { NumfmtService } from './service/numfmt.service';+import { INumfmtService } from './service/type';export class NumfmtPlugin extends Plugin {static override type = PluginType.Sheet;@@ -11,6 +12,6 @@ export class NumfmtPlugin extends Plugin {}override onStarting(): void {- this._injector.add([NumfmtService]);+ this._injector.add([INumfmtService, { useClass: NumfmtService }]);}}diff --git a/packages/sheets-plugin-numfmt/src/numfmt-plugin.ts b/packages/sheets-plugin-numfmt/src/numfmt-plugin.tsindex 643b6f5ac1..ad883dbacc 100644--- a/packages/sheets-plugin-numfmt/src/numfmt-plugin.ts+++ b/packages/sheets-plugin-numfmt/src/numfmt-plugin.ts@@ -3,7 +3,9 @@ import { Inject, Injector } from '@wendellhu/redi';import { SHEET_NUMFMT_PLUGIN } from './base/const/PLUGIN_NAME';import { NumfmtController } from './controllers/numfmt.controller';+import { INumfmtController } from './controllers/type';import { NumfmtService } from './service/numfmt.service';+import { INumfmtService } from './service/type';export class NumfmtPlugin extends Plugin {static override type = PluginType.Sheet;@@ -12,7 +14,7 @@ export class NumfmtPlugin extends Plugin {}override onStarting(): void {- this._injector.add([NumfmtService]);- this._injector.add([NumfmtController]);+ this._injector.add([INumfmtController, { useClass: NumfmtController, lazy: false }]);+ this._injector.add([INumfmtService, { useClass: NumfmtService, lazy: false }]);}}diff --git a/packages/sheets-plugin-numfmt/src/service/numfmt.service.ts b/packages/sheets-plugin-numfmt/src/service/numfmt.service.tsindex b4010c7636..777f733f47 100644--- a/packages/sheets-plugin-numfmt/src/service/numfmt.service.ts+++ b/packages/sheets-plugin-numfmt/src/service/numfmt.service.ts@@ -1,27 +1,11 @@-import {- Disposable,- ICellData,- ICommandService,- LifecycleStages,- Nullable,- ObjectMatrix,- OnLifecycle,-} from '@univerjs/core';+import { Disposable, ICommandService, Nullable, ObjectMatrix } from '@univerjs/core';import { Inject } from '@wendellhu/redi';import { NumfmtItem } from '../base/types';import { SetNumfmtMutation } from '../commands/mutations/set.numfmt.mutation';+import type { INumfmtService, NumfmtItemWithCache } from './type';-type NumfmtItemWithCache = NumfmtItem & {- // when change parameters or pattern, the cache is cleared follow mutation execute- _cache?: {- result: ICellData;- parameters: number; // The parameter that was last calculated- };-};--@OnLifecycle(LifecycleStages.Ready, NumfmtService)-export class NumfmtService extends Disposable {+export class NumfmtService extends Disposable implements INumfmtService {numfmtModel: Map<string, ObjectMatrix<NumfmtItemWithCache>> = new Map();// collect effect mutations when edit end and push this to commands stack in next commands progressdiff --git a/packages/sheets-plugin-numfmt/src/service/type.ts b/packages/sheets-plugin-numfmt/src/service/type.tsnew file mode 100644index 0000000000..6f98114aa2--- /dev/null+++ b/packages/sheets-plugin-numfmt/src/service/type.ts@@ -0,0 +1,21 @@+import type { ICellData, Nullable, ObjectMatrix } from '@univerjs/core';+import { LifecycleStages, runOnLifecycle } from '@univerjs/core';+import { createIdentifier } from '@wendellhu/redi';++import { NumfmtItem } from '../base/types/index';++export type NumfmtItemWithCache = NumfmtItem & {+ // when change parameters or pattern, the cache is cleared follow mutation execute+ _cache?: {+ result: ICellData;+ parameters: number; // The parameter that was last calculated+ };+};+export interface INumfmtService {+ getValue(workbookId: string, worksheetId: string, row: number, col: number): Nullable<NumfmtItemWithCache>;+ setValue(workbookId: string, worksheetId: string, row: number, col: number, value: Nullable<NumfmtItem>): void;+ getModel(workbookId: string, worksheetId: string): Nullable<ObjectMatrix<NumfmtItemWithCache>>;+}++export const INumfmtService = createIdentifier<INumfmtService>('INumfmtService');+runOnLifecycle(LifecycleStages.Rendered, INumfmtService);diff --git a/packages/ui-plugin-slides/src/controllers/info-bar-ui-controller.ts b/packages/ui-plugin-slides/src/controllers/info-bar-ui-controller.tsindex ec638282e4..492ff1fa28 100644--- a/packages/ui-plugin-slides/src/controllers/info-bar-ui-controller.ts+++ b/packages/ui-plugin-slides/src/controllers/info-bar-ui-controller.ts@@ -1,5 +1,5 @@import { InfoBarModel } from '../model/info-bar-model';-import { InfoBar } from '../views/info-bar';+import type { InfoBar } from '../views/info-bar';type IProps = {label?: string;diff --git a/packages/ui-plugin-slides/src/controllers/slide-container-ui-controller.ts b/packages/ui-plugin-slides/src/controllers/slide-container-ui-controller.tsindex e1c27d558e..bb7165c05b 100644--- a/packages/ui-plugin-slides/src/controllers/slide-container-ui-controller.ts+++ b/packages/ui-plugin-slides/src/controllers/slide-container-ui-controller.ts@@ -3,7 +3,7 @@ import { LocaleService, LocaleType } from '@univerjs/core';import { Inject, Injector } from '@wendellhu/redi';import { ISlideUIPluginConfig } from '../basics';-import { SlideContainer } from '../views/slide-container';+import type { SlideContainer } from '../views/slide-container';import { InfoBarUIController } from './info-bar-ui-controller';import { SlideBarUIController } from './slide-bar-ui-controller';import { ToolbarUIController } from './toolbar-ui-controller';diff --git a/packages/ui-plugin-slides/src/controllers/toolbar-ui-controller.ts b/packages/ui-plugin-slides/src/controllers/toolbar-ui-controller.tsindex 558406c8f1..e0928c325f 100644--- a/packages/ui-plugin-slides/src/controllers/toolbar-ui-controller.ts+++ b/packages/ui-plugin-slides/src/controllers/toolbar-ui-controller.ts@@ -13,7 +13,7 @@ import { ColorPicker } from '@univerjs/design';import { Inject } from '@wendellhu/redi';import { DefaultToolbarConfig, SLIDE_UI_PLUGIN_NAME, SlideToolbarConfig } from '../basics';-import { Toolbar } from '../views/toolbar';+import type { Toolbar } from '../views/toolbar';import styles from '../views/toolbar/index.module.less';export interface BaseToolbarSelectProps {