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.

refactor: remove get functions from plugin interface

Wenzhao Hued46ccfcdf77
diff --git a/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts b/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts
index 6e0ba52cdb..7013c77ed4 100644
--- a/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts
+++ b/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts
@@ -1,5 +1,6 @@
import { SheetActionBase, ActionObservers, ActionType, ISheetActionData, ICellInfo, ISelection, Nullable, CommandUnit, CommandManager } from '@univerjs/core';
-import { ACTION_NAMES } from '../../Basics';
+
+import { ACTION_NAMES } from '../../Basics/Enum/ACTION_NAMES';
import { SetSelectionValue } from '../Apply/SetSelectionValue';
export interface ISelectionModelValue {
diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/SheetPlugin.ts
index 9ecaeeb898..9f9559ae5d 100644
--- a/packages/base-sheets/src/SheetPlugin.ts
+++ b/packages/base-sheets/src/SheetPlugin.ts
@@ -3,7 +3,6 @@ import { Plugin, PLUGIN_NAMES, DEFAULT_SELECTION, UniverSheet, PluginType, Comma
import { Dependency, Inject, Injector } from '@wendellhu/redi';
import { SheetPluginObserve, uninstall } from './Basics/Observer';
-import { CANVAS_VIEW_KEY } from './View/BaseView';
import { CanvasView } from './View/CanvasView';
import {
RightMenuController,
@@ -137,6 +136,7 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
override onDestroy(): void {
super.onDestroy();
+
uninstall(this);
const actionRegister = this._commandManager.getActionExtensionManager().getRegister();
@@ -149,7 +149,7 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
registerExtension() {
const actionRegister = this._commandManager.getActionExtensionManager().getRegister();
this._namedRangeActionExtensionFactory = new NamedRangeActionExtensionFactory(this);
- actionRegister.add(this._namedRangeActionExtensionFactory);
+ actionRegister.add(this._namedRangeActionExtensionFactory); // TODO: this should return a disposable function
this._columnRulerManager = this._sheetInjector.get(ColumnRulerManager);
const rulerRegister = this._columnRulerManager.getRegister();
@@ -158,108 +158,18 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
}
listenEventManager() {
- // TODO: move to toolbarcontroller
+ // TODO: move these init to controllers not here
this._countBarController.listenEventManager();
this._sheetBarController.listenEventManager();
this._toolbarController.listenEventManager();
this._rightMenuController.listenEventManager();
}
- /** @deprecated DI */
- getEditTooltipsController(): EditTooltipsController {
- return this._editTooltipsController;
- }
-
- /** @deprecated DI */
- getCanvasEngine() {
- return this._canvasEngine;
- }
-
- /** @deprecated DI */
- getCanvasView() {
- return this._sheetInjector.get(CanvasView);
- }
-
- /** @deprecated DI */
- getMainScene() {
- return this._canvasEngine.getScene(CANVAS_VIEW_KEY.MAIN_SCENE);
- }
-
- /** @deprecated DI */
- getSheetView() {
- return this.getCanvasView().getSheetView();
- }
-
- /** @deprecated DI */
+ /** @deprecated move to DI system */
getSelectionManager() {
return this._sheetInjector.get(ISelectionManager);
}
- /** @deprecated DI */
- getCurrentControls() {
- return this.getSelectionManager()?.getCurrentControls();
- }
-
- /** @deprecated DI */
- getSelectionShape() {
- return this._canvasEngine;
- }
-
- /** @deprecated DI */
- getMainComponent() {
- return this.getSheetView().getSpreadsheet();
- }
-
- /** @deprecated DI */
- getLeftTopComponent() {
- return this.getSheetView().getSpreadsheetLeftTopPlaceholder();
- }
-
- /** @deprecated DI */
- getRowComponent() {
- return this.getSheetView().getSpreadsheetRowTitle();
- }
-
- /** @deprecated DI */
- getColumnComponent() {
- return this.getSheetView().getSpreadsheetColumnTitle();
- }
-
- /** @deprecated DI */
- getSpreadsheetSkeleton() {
- return this.getSheetView().getSpreadsheetSkeleton();
- }
-
- /** @deprecated DI */
- getRightMenuControl() {
- return this._rightMenuController;
- }
-
- /** @deprecated DI */
- getToolbarControl() {
- return this._toolbarController;
- }
-
- /** @deprecated DI */
- getSheetBarControl() {
- return this._sheetBarController;
- }
-
- /** @deprecated DI */
- getCellEditorController() {
- return this._cellEditorController;
- }
-
- /** @deprecated DI */
- getCountBarController() {
- return this._countBarController;
- }
-
- /** @deprecated DI */
- getHideColumnController() {
- return this._hideColumnController;
- }
-
private initializeDependencies(sheetInjector: Injector) {
const dependencies: Dependency[] = [
[CanvasView],
@@ -293,4 +203,4 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
sheetInjector.add(d);
});
}
-}
\ No newline at end of file
+}
diff --git a/packages/core/src/Command/SheetActionBase.ts b/packages/core/src/Command/SheetActionBase.ts
index 4c57a257cc..01f4604212 100644
--- a/packages/core/src/Command/SheetActionBase.ts
+++ b/packages/core/src/Command/SheetActionBase.ts
@@ -15,20 +15,12 @@ export interface ISheetActionData extends IActionData {
* TODO: SlideAction/DocAction
* @beta
*/
-export abstract class SheetActionBase<
- D extends ISheetActionData,
- O extends ISheetActionData = D,
- R = void
-> extends ActionBase<D, O, R> {
+export abstract class SheetActionBase<D extends ISheetActionData, O extends ISheetActionData = D, R = void> extends ActionBase<D, O, R> {
protected _commandUnit: CommandUnit;
protected _workbook: Workbook;
- protected constructor(
- actionData: D,
- commandUnit: CommandUnit,
- observers: ActionObservers
- ) {
+ protected constructor(actionData: D, commandUnit: CommandUnit, observers: ActionObservers) {
super(actionData, observers);
if (commandUnit.WorkBookUnit == null) {
throw new Error('action workbook domain can not be null!');
diff --git a/packages/ui-plugin-docs/src/View/Toolbar/Toolbar.tsx b/packages/ui-plugin-docs/src/View/Toolbar/Toolbar.tsx
index c0e40caea6..65f40c6df8 100644
--- a/packages/ui-plugin-docs/src/View/Toolbar/Toolbar.tsx
+++ b/packages/ui-plugin-docs/src/View/Toolbar/Toolbar.tsx
@@ -37,7 +37,7 @@ export class Toolbar extends Component<IProps, IState> {
this.setToolbarListWidth();
}, 50);
- initialize() {
+ override initialize() {
this.state = {
// Button contains main button and drop down arrow, translation file contains main and right
showMore: false,
@@ -165,12 +165,12 @@ export class Toolbar extends Component<IProps, IState> {
}
};
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
window.addEventListener('resize', this.debounceSetToolbarListWidth);
}
- componentWillUnmount() {
+ override componentWillUnmount() {
window.removeEventListener('resize', this.debounceSetToolbarListWidth);
}
diff --git a/packages/ui-plugin-sheets/src/Controller/AppUIController.ts b/packages/ui-plugin-sheets/src/Controller/AppUIController.ts
index 889811081c..4a043da9ca 100644
--- a/packages/ui-plugin-sheets/src/Controller/AppUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/AppUIController.ts
@@ -49,4 +49,4 @@ export class AppUIController {
getSheetContainerController() {
return this._sheetContainerController;
}
-}
\ No newline at end of file
+}
diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
index e72abb2d10..e07e78a41b 100644
--- a/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
+++ b/packages/ui-plugin-sheets/src/View/Toolbar/Toolbar.tsx
@@ -1,8 +1,7 @@
import { AppContext, AppContextValues, BaseComponentProps, Button, Component, Container, createRef, debounce, PreactContext, Select, Tooltip } from '@univerjs/base-ui';
-import { SheetUIPlugin } from '../..';
-import { SHEET_UI_PLUGIN_NAME } from '../../Basics';
import { IToolbarItemProps } from '../../Controller';
import styles from './index.module.less';
+import { AppUIController } from '../../Controller/AppUIController';
interface IProps extends BaseComponentProps {
style?: JSX.CSSProperties;
@@ -156,12 +155,7 @@ export class Toolbar extends Component<IProps, IState> {
};
resetUl = () => {
- const wrapper = this.getContext()
- .getPluginManager()
- .getPluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)
- ?.getAppUIController()
- .getSheetContainerController()
- .getContentRef().current!;
+ const wrapper = this.context.injector.get(AppUIController).getSheetContainerController().getContentRef().current!;
const height = `${(wrapper as HTMLDivElement).offsetHeight}px`;
const ul = this.toolbarRef.current.querySelectorAll('ul');
for (let i = 0; i < ul.length; i++) {
@@ -169,12 +163,12 @@ export class Toolbar extends Component<IProps, IState> {
}
};
- componentDidMount() {
+ override componentDidMount() {
this.props.getComponent?.(this);
window.addEventListener('resize', this.debounceSetToolbarListWidth);
}
- componentWillUnmount() {
+ override componentWillUnmount() {
window.removeEventListener('resize', this.debounceSetToolbarListWidth);
}