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 ISheetContext

Wenzhao Hua15837e6800d
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
index a1afcebf0d..2500e75cee 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
@@ -1,37 +1,18 @@
-import { IMouseEvent, IPointerEvent, Rect, Spreadsheet, SpreadsheetColumnTitle, SpreadsheetRowTitle, ScrollTimer } from '@univerjs/base-render';
+import { IMouseEvent, IPointerEvent, Rect, ScrollTimer, Spreadsheet, SpreadsheetColumnTitle, SpreadsheetRowTitle } from '@univerjs/base-render';
import {
- Nullable,
- Observer,
- Worksheet,
- ISelection,
- makeCellToSelection,
- IRangeData,
- RangeList,
- Range,
- IRangeCellData,
- ICellInfo,
- Command,
- Direction,
- ActionOperation,
- ISelectionData,
- DEFAULT_SELECTION,
- DEFAULT_CELL,
- IGridRange,
- ObserverManager,
- ICurrentUniverService,
+ ActionOperation, Command, DEFAULT_CELL, DEFAULT_SELECTION, Direction, ICellInfo, ICurrentUniverService, IGridRange, IRangeCellData, IRangeData, ISelection, ISelectionData, makeCellToSelection, Nullable,
+ Observer, ObserverManager, Range, RangeList, Worksheet
} from '@univerjs/core';
import { Inject, Injector } from '@wendellhu/redi';
-import { ACTION_NAMES, ISelectionsConfig } from '../../Basics';
+import { ACTION_NAMES, ISelectionsConfig, ISheetPluginConfig } from '../../Basics';
import { ISelectionModelValue, ISetSelectionValueActionData, SetSelectionValueAction } from '../../Model/Action/SetSelectionValueAction';
import { SelectionModel } from '../../Model/SelectionModel';
-import { SheetPlugin } from '../../SheetPlugin';
import { SheetView } from '../../View/Views/SheetView';
import { ColumnTitleController } from './ColumnTitleController';
import { DragLineController } from './DragLineController';
import { RowTitleController } from './RowTitleController';
import { SelectionController, SELECTION_TYPE } from './SelectionController';
-import { ISheetPlugin } from '../../Services/tokens';
/**
* TODO 注册selection拦截,可能在有公式ArrayObject时,fx公式栏显示不同
@@ -70,11 +51,11 @@ export class SelectionManager {
constructor(
/** @deprecated this should be divided into smaller pieces */
private readonly _sheetView: SheetView,
+ private readonly _config: ISheetPluginConfig,
@ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
@Inject(Injector) private readonly _injector: Injector,
@Inject(ObserverManager) private readonly _observerManager: ObserverManager,
/** @deprecated this should be divided into smaller pieces */
- @Inject(ISheetPlugin) private readonly _plugin: SheetPlugin,
@Inject(DragLineController) private readonly _dragLineController: DragLineController,
@Inject(ColumnTitleController) private readonly _columnTitleController: ColumnTitleController,
@Inject(RowTitleController) private readonly _rowTitleController: RowTitleController
@@ -228,10 +209,6 @@ export class SelectionManager {
}
}
- getPlugin() {
- return this._plugin;
- }
-
/**
* add a selection
* @param selectionRange
@@ -577,7 +554,7 @@ export class SelectionManager {
if (oldStartColumn !== finalStartColumn || oldStartRow !== finalStartRow || oldEndColumn !== finalEndColumn || oldEndRow !== finalEndRow) {
selectionControl && selectionControl.update(newSelectionRange);
- selectionControl && this._plugin.getObserver('onChangeSelectionObserver')?.notifyObservers(selectionControl);
+ selectionControl && this._observerManager.getObserver('onChangeSelectionObserver')?.notifyObservers(selectionControl);
}
if (setModel) {
@@ -892,7 +869,7 @@ export class SelectionManager {
}
// Notification toolbar updates button state and value
- this._plugin.getObserver('onChangeSelectionObserver')?.notifyObservers(selectionControl);
+ this._observerManager.getObserver('onChangeSelectionObserver')?.notifyObservers(selectionControl);
this._moveObserver = scene.onPointerMoveObserver.add((moveEvt: IPointerEvent | IMouseEvent) => {
this.moving(moveEvt, selectionControl);
@@ -949,7 +926,7 @@ export class SelectionManager {
* @param selections
*/
private _initModels() {
- const selections: ISelectionsConfig = this._plugin.getConfig().selections;
+ const selections: ISelectionsConfig = this._config.selections;
Object.keys(selections).forEach((worksheetId) => {
const selectionsList = selections[worksheetId];
@@ -1010,7 +987,7 @@ export class SelectionManager {
* @param selections
*/
private _initControls() {
- const selections: ISelectionsConfig = this._plugin.getConfig().selections;
+ const selections: ISelectionsConfig = this._config.selections;
Object.keys(selections).forEach((worksheetId) => {
const selectionsList = selections[worksheetId];
const currentControls: SelectionController[] = [];
diff --git a/packages/base-sheets/src/Services/tokens.ts b/packages/base-sheets/src/Services/tokens.ts
index c7a77cb446..7ac094a3d1 100644
--- a/packages/base-sheets/src/Services/tokens.ts
+++ b/packages/base-sheets/src/Services/tokens.ts
@@ -1,12 +1,8 @@
import { createIdentifier } from '@wendellhu/redi';
-import { SheetPlugin } from '../SheetPlugin';
import { SelectionManager } from '../Controller';
import { CanvasView } from '../View';
-/** @deprecated Temp solution. Remove this in august. */
-export const ISheetPlugin = createIdentifier<SheetPlugin>('deprecated.univer.sheet.plugin');
-
/** @deprecated temporary solution, we should inject SelectionManager directly */
export const ISelectionManager = createIdentifier<SelectionManager>('deprecated.univer.sheet.selection-manager');
diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/SheetPlugin.ts
index f0a239b55b..9ecaeeb898 100644
--- a/packages/base-sheets/src/SheetPlugin.ts
+++ b/packages/base-sheets/src/SheetPlugin.ts
@@ -20,7 +20,7 @@ import { DEFAULT_SPREADSHEET_PLUGIN_DATA, install, ISheetPluginConfig } from './
import { FormulaBarController } from './Controller/FormulaBarController';
import { NamedRangeActionExtensionFactory } from './Basics/Register/NamedRangeActionExtension';
import { en, zh } from './Locale';
-import { ISelectionManager, ISheetPlugin } from './Services/tokens';
+import { ISelectionManager } from './Services/tokens';
import { DragLineController } from './Controller/Selection/DragLineController';
import { ColumnTitleController } from './Controller/Selection/ColumnTitleController';
import { RowTitleController } from './Controller/Selection/RowTitleController';
@@ -261,15 +261,9 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
}
private initializeDependencies(sheetInjector: Injector) {
- const self = this;
-
const dependencies: Dependency[] = [
- [ISheetPlugin, { useValue: self }],
-
- // Rendering Module
[CanvasView],
- // #region Controllers
[CellEditorController],
[SheetContainerController],
[FormulaBarController],
@@ -283,7 +277,7 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
[
ISelectionManager,
{
- useFactory: (injector: Injector, canvasView: CanvasView) => injector.createInstance(SelectionManager, canvasView.getSheetView()),
+ useFactory: (injector: Injector, canvasView: CanvasView) => injector.createInstance(SelectionManager, canvasView.getSheetView(), this._config),
deps: [Injector, CanvasView],
},
],
@@ -292,13 +286,11 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {
[DragLineController],
[HideColumnController],
- // RulerManager
[ColumnRulerManager],
- // #endregion Controllers
];
dependencies.forEach((d) => {
sheetInjector.add(d);
});
}
-}
+}
\ No newline at end of file
diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.ts
index 803523344b..2d77bf2f08 100644
--- a/packages/base-sheets/src/index.ts
+++ b/packages/base-sheets/src/index.ts
@@ -3,4 +3,4 @@ export * from './Model';
export * from './Controller';
export * from './Basics';
export * from './View';
-export * from './Services/tokens';
+export { ICanvasView, ISelectionManager } from './Services/tokens';
\ No newline at end of file
diff --git a/packages/ui-plugin-sheets/src/Service/index.ts b/packages/ui-plugin-sheets/src/Service/index.ts
deleted file mode 100644
index e69de29bb2..0000000000