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.

chore(ui-plugin-sheets): getGlobalContext

Dushusird1aa8eaec609
diff --git a/packages/base-sheets/src/Controller/ModalGroupController.ts b/packages/base-sheets/src/Controller/ModalGroupController.ts
deleted file mode 100644
index 5108f8c41e..0000000000
--- a/packages/base-sheets/src/Controller/ModalGroupController.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import { SheetPlugin } from '../SheetPlugin';
-import { ModalGroup } from '../View/UI/ModalGroup/ModalGroup';
-
-export type ModalGroupProps = string[];
-
-export class ModalGroupController {
- private _ModalGroup: ModalGroupProps;
-
- private _ModalGroupComponent: ModalGroup;
-
- private _plugin: SheetPlugin;
-
- constructor(plugin: SheetPlugin) {
- this._plugin = plugin;
-
- this._ModalGroup = [];
-
- this.init();
- }
-
- init() {
- this._plugin.getObserver('onModalGroupDidMountObservable')?.add((component) => {
- //初始化视图
- this._ModalGroupComponent = component;
- });
- }
-
- addModal(name: string, component: any) {
- const index = this._ModalGroup.findIndex((item) => item === name);
- if (index < 0) {
- this._plugin.registerComponent(name, component);
- this._ModalGroup.push(name);
-
- this._ModalGroupComponent?.setModalGroup(this._ModalGroup);
- }
- }
-
- getModal(name: string) {
- const ModalGroup = this._ModalGroupComponent.getModalGroup();
- return ModalGroup.find((item) => item.constructor.name === name);
- }
-}
diff --git a/packages/base-sheets/src/Controller/SideGroupController.ts b/packages/base-sheets/src/Controller/SideGroupController.ts
deleted file mode 100644
index 3dffea425e..0000000000
--- a/packages/base-sheets/src/Controller/SideGroupController.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-import { SheetPlugin } from '../SheetPlugin';
-import { SideGroup } from '../View/UI/SideGroup/SideGroup';
-
-export interface SideProps {
- name: string;
- zIndex: number;
- show?: boolean;
- onClick: (name: string) => void;
-}
-
-export type SideGroupProps = SideProps[];
-
-export class SideGroupController {
- private _SideGroup: SideGroupProps;
-
- private _SideGroupComponent: SideGroup;
-
- private _plugin: SheetPlugin;
-
- constructor(plugin: SheetPlugin) {
- this._plugin = plugin;
-
- this._SideGroup = [];
-
- this.init();
- }
-
- init() {
- this._plugin.getObserver('onSideGroupDidMountObservable')?.add((component) => {
- //初始化视图
- this._SideGroupComponent = component;
- });
- }
-
- addSide(name: string, component: any) {
- const index = this._SideGroup.findIndex((item) => item.name === name);
- if (index < 0) {
- this._plugin.registerComponent(name, component);
- this._SideGroup.push({
- name,
- zIndex: this._SideGroup.length + 1,
- show: false,
- onClick: this.activeSide,
- });
- }
- }
-
- removeSide(name: string) {
- const index = this._SideGroup.findIndex((item) => item.name === name);
- if (index > -1) {
- for (let i = index + 1; i < this._SideGroup.length; i++) {
- this._SideGroup[i].zIndex -= 1;
- }
- this._SideGroup.splice(index, 1);
- this._SideGroupComponent.setSideGroup(this._SideGroup);
- }
- }
-
- activeSide(name: string) {
- const index = this._SideGroup.findIndex((item) => item.name === name);
- if (index > -1) {
- for (let i = index + 1; i < this._SideGroup.length; i++) {
- this._SideGroup[i].zIndex -= 1;
- }
- this._SideGroup[index].zIndex = this._SideGroup.length;
- this._SideGroup[index].show = true;
- this._SideGroup.sort((a, b) => a.zIndex - b.zIndex);
-
- this._SideGroupComponent.setSideGroup(this._SideGroup);
- }
- }
-
- hideSide(name: string) {
- const index = this._SideGroup.findIndex((item) => item.name === name);
- if (index > -1) {
- this._SideGroup[index].show = false;
- this._SideGroupComponent.setSideGroup(this._SideGroup);
- }
- }
-}
diff --git a/packages/base-sheets/src/SheetPlugin111.tsx b/packages/base-sheets/src/SheetPlugin111.tsx
deleted file mode 100644
index 54152baf0d..0000000000
--- a/packages/base-sheets/src/SheetPlugin111.tsx
+++ /dev/null
@@ -1,378 +0,0 @@
-import { getRefElement, isElement, ISlotProps, RefObject, render } from '@univer/base-ui';
-import { Engine, RenderEngine } from '@univer/base-render';
-import {
- AsyncFunction,
- SheetContext,
- IWorkbookConfig,
- Plugin,
- PLUGIN_NAMES,
- Tools,
- CommandManager,
- IActionObserverProps,
- SheetActionBase,
- ACTION_NAMES,
- ISetNamedRangeActionData,
-} from '@univer/core';
-
-import { install, SheetPluginObserve, uninstall } from './Basics/Observer';
-import { RightMenuProps } from './Model/RightMenuModel';
-import { en, zh } from './Locale';
-import { CANVAS_VIEW_KEY } from './View/Render/BaseView';
-import { CanvasView } from './View/Render/CanvasView';
-import { SheetContainer } from './View/UI/SheetContainer';
-import {
- RightMenuController,
- InfoBarController,
- SheetBarControl,
- CellEditorController,
- AntLineControl,
- CountBarController,
- SheetContainerController,
- ToolbarController,
- BaseSheetContainerConfig,
-} from './Controller';
-import { IToolbarItemProps } from './Model/ToolbarModel';
-import { ModalGroupController } from './Controller/ModalGroupController';
-import { ISheetPluginConfig, DEFAULT_SPREADSHEET_PLUGIN_DATA } from './Basics';
-import { FormulaBarController } from './Controller/FormulaBarController';
-import { NamedRangeActionExtensionFactory } from './Basics/Register/NamedRangeActionExtension';
-
-/**
- * The main sheet base, construct the sheet container and layout, mount the rendering engine
- */
-
-export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {
- private _config: ISheetPluginConfig;
-
- private _toolbarRef: RefObject<HTMLElement>;
-
- private _splitLeftRef: RefObject<HTMLDivElement>;
-
- private _contentRef: RefObject<HTMLDivElement>;
-
- private _addButtonFunc: Function;
-
- private _addSiderFunc: AsyncFunction<ISlotProps>;
-
- private _addMainFunc: Function;
-
- private _showSiderByNameFunc: Function;
-
- private _showMainByNameFunc: Function;
-
- private _canvasEngine: Engine;
-
- private _canvasView: CanvasView;
-
- private _viewSheetMap: Map<string, string>;
-
- private _rightMenuControl: RightMenuController;
-
- private _toolbarControl: ToolbarController;
-
- private _infoBarControl: InfoBarController;
-
- private _formulaBarController: FormulaBarController;
-
- private _sheetBarControl: SheetBarControl;
-
- private _cellEditorController: CellEditorController;
-
- private _antLineController: AntLineControl;
-
- private _countBarController: CountBarController;
-
- private _sheetContainerController: SheetContainerController;
-
- private _modalGroupController: ModalGroupController;
-
- private _componentList: Map<string, any>;
-
- private _namedRangeActionExtensionFactory: NamedRangeActionExtensionFactory;
-
- constructor(config: Partial<ISheetPluginConfig> = {}) {
- super(PLUGIN_NAMES.SPREADSHEET);
-
- this._config = Tools.deepMerge({}, DEFAULT_SPREADSHEET_PLUGIN_DATA, config);
- }
-
- register(engineInstance: Engine) {
- // The preact ref component cannot determine whether ref.current or ref.current.base is DOM
- let container: HTMLElement = getRefElement(this._sheetContainerController.getContentRef());
-
- this._canvasEngine = engineInstance;
-
- engineInstance.setContainer(container);
- window.addEventListener('resize', () => {
- engineInstance.resize();
- });
-
- // should be clear
- setTimeout(() => {
- engineInstance.resize();
- }, 0);
-
- // window.onresize = () => {
- // engineInstance.resize();
- // };
- }
-
- initialize(context: SheetContext): void {
- this.context = context;
-
- /**
- * load more Locale object
- */
- context.getLocale().load({
- en,
- zh,
- });
-
- const configure: IWorkbookConfig = context.getWorkBook().getConfig();
-
- const sheetContainer = this._initContainer(this._config.container);
-
- const config: BaseSheetContainerConfig = {
- skin: configure.skin || 'default',
- layout: this._config.layout,
- container: sheetContainer,
- onDidMount: () => {},
- context,
- };
-
- this._componentList = new Map();
-
- const sheetContainerConfig = this._config.layout?.sheetContainerConfig;
- const rightMenuConfig = this._config.layout?.rightMenuConfig;
- const toolbarConfig = this._config.layout?.toolbarConfig;
-
- this._modalGroupController = new ModalGroupController(this);
- this._sheetContainerController = new SheetContainerController(this, config);
-
- // TODO rightMenu config
- if (sheetContainerConfig?.rightMenu) {
- this._rightMenuControl = new RightMenuController(this, rightMenuConfig);
- }
-
- if (sheetContainerConfig?.toolbar) {
- this._toolbarControl = new ToolbarController(this, toolbarConfig);
- }
- if (sheetContainerConfig?.infoBar) {
- this._infoBarControl = new InfoBarController(this);
- }
- if (sheetContainerConfig?.sheetBar) {
- this._sheetBarControl = new SheetBarControl(this);
- }
- this._cellEditorController = new CellEditorController(this);
- this._antLineController = new AntLineControl(this);
-
- if (sheetContainerConfig?.countBar) {
- this._countBarController = new CountBarController(this);
- }
- if (sheetContainerConfig?.formulaBar) {
- this._formulaBarController = new FormulaBarController(this);
- }
-
- this.getObserver('onSheetContainerDidMountObservable')?.add(() => {
- this._initializeRender(context);
- });
-
- // render sheet container
- render(
- <SheetContainer changeLocale={this._sheetContainerController.changeLocale} changeSkin={this._sheetContainerController.changeSkin} config={config} />,
- sheetContainer
- );
-
- // const formulaEngine = this.getPluginByName<FormulaPlugin>('formula')?.getFormulaEngine();
- // =(sum(max(B1:C10,10)*5-100,((1+1)*2+5)/2,10)+count(B1:C10,10*5-100))*5-100
- // =(sum(max(B1:C10,10)*5-100,((1+1)*2+5)/2,10, lambda(x,y, x*y*x)(sum(1,(1+2)*3),2))+lambda(x,y, x*y*x)(sum(1,(1+2)*3),2)+count(B1:C10,10*5-100))*5-100
- // =((1+2)-A1:B2 + 5)/2 + sum(indirect("A5"):B10 + A1:offset("C5", 1, 1), 100)
- // =1+(3*4=4)*5+1
- // =(-(1+2)--@A1:B2 + 5)/2 + -sum(indirect("A5"):B10# + B6# + A1:offset("C5", 1, 1) , 100) + {1,2,3;4,5,6;7,8,10} + lambda(x,y,z, x*y*z)(sum(1,(1+2)*3),2,lambda(x,y, @offset(A1:B0,x#*y#))(1,2):C20) & "美国人才" + sum((1+2%)*30%, 1+2)%
- // formulaEngine?.calculate(`=lambda(x,y, x*y*x)(sum(1,(1+2)*3),2)+1-max(100,200)`);
-
- this.registerExtension();
- }
-
- /**
- * Convert id to DOM
- * @param container
- * @returns
- */
- private _initContainer(container: HTMLElement | string) {
- let sheetContainer = null;
- if (typeof container === 'string') {
- const containerDOM = document.getElementById(container);
- if (containerDOM == null) {
- sheetContainer = document.createElement('div');
- sheetContainer.id = container;
- } else {
- sheetContainer = containerDOM;
- }
- } else if (isElement(container)) {
- sheetContainer = container;
- } else {
- sheetContainer = document.createElement('div');
- sheetContainer.id = 'universheet';
- }
-
- return sheetContainer;
- }
-
- onMounted(ctx: SheetContext): void {
- install(this);
-
- this.initialize(ctx);
-
- CommandManager.getActionObservers().add((actionObs: IActionObserverProps): void => {
- const currentUnitId = this.getContext().getWorkBook().getUnitId();
- const action = actionObs.action as SheetActionBase<ISetNamedRangeActionData, ISetNamedRangeActionData>;
- const actionData = action.getDoActionData();
- const actionUnitId = action.getWorkBook().getUnitId();
-
- if (currentUnitId !== actionUnitId) return;
-
- if (actionData.actionName === ACTION_NAMES.SET_NAMED_RANGE_ACTION) {
- const namedRange = actionData.namedRange;
- }
- });
- }
-
- get config() {
- return this._config;
- }
-
- private _initializeRender(context: SheetContext) {
- const engine = this.getPluginByName<RenderEngine>(PLUGIN_NAMES.BASE_RENDER)?.getEngine()!;
-
- this.register(engine);
-
- if (this._canvasView == null) {
- this._canvasView = new CanvasView(engine, this);
- }
-
- this.context.getContextObserver('onSheetRenderDidMountObservable')?.notifyObservers();
- }
-
- onDestroy(): void {
- super.onDestroy();
- uninstall(this);
-
- const actionRegister = this.context.getCommandManager().getActionExtensionManager().getRegister();
- actionRegister.delete(this._namedRangeActionExtensionFactory);
- }
-
- registerExtension() {
- const actionRegister = this.context.getCommandManager().getActionExtensionManager().getRegister();
- this._namedRangeActionExtensionFactory = new NamedRangeActionExtensionFactory(this);
- actionRegister.add(this._namedRangeActionExtensionFactory);
- }
-
- addButton(item: IToolbarItemProps): void {
- this._addButtonFunc(item);
- }
-
- getCanvasEngine() {
- return this._canvasEngine;
- }
-
- getCanvasView() {
- return this._canvasView;
- }
-
- getMainScene() {
- return this._canvasEngine.getScene(CANVAS_VIEW_KEY.MAIN_SCENE);
- }
-
- getSheetView() {
- return this.getCanvasView().getSheetView();
- }
-
- getSelectionManager() {
- return this.getSheetView()?.getSelectionManager();
- }
-
- getCurrentControls() {
- return this.getSelectionManager()?.getCurrentControls();
- }
-
- getSelectionShape() {
- return this._canvasEngine;
- }
-
- getMainComponent() {
- return this.getSheetView().getSpreadsheet();
- }
-
- getLeftTopComponent() {
- return this.getSheetView().getSpreadsheetLeftTopPlaceholder();
- }
-
- getRowComponent() {
- return this.getSheetView().getSpreadsheetRowTitle();
- }
-
- getColumnComponent() {
- return this.getSheetView().getSpreadsheetColumnTitle();
- }
-
- getSpreadsheetSkeleton() {
- return this.getSheetView().getSpreadsheetSkeleton();
- }
-
- getWorkbook() {
- return this.context.getWorkBook();
- }
-
- getRightMenuControl() {
- return this._rightMenuControl;
- }
-
- getToolbarControl() {
- return this._toolbarControl;
- }
-
- getInfoBarControl() {
- return this._infoBarControl;
- }
-
- getSheetBarControl() {
- return this._sheetBarControl;
- }
-
- getCellEditorController() {
- return this._cellEditorController;
- }
-
- getFormulaBarController() {
- return this._formulaBarController;
- }
-
- getModalGroupControl() {
- return this._modalGroupController;
- }
-
- getSheetContainerControl() {
- return this._sheetContainerController;
- }
-
- addRightMenu(item: RightMenuProps[] | RightMenuProps) {
- this._rightMenuControl && this._rightMenuControl.addItem(item);
- }
-
- addToolButton(config: IToolbarItemProps) {
- this._toolbarControl && this._toolbarControl.addToolButton(config);
- }
-
- registerComponent(name: string, component: any, props?: any) {
- this._componentList.set(name, component);
- }
-
- getRegisterComponent(name: string) {
- return this._componentList.get(name);
- }
-
- registerModal(name: string, component: any) {
- this._modalGroupController.addModal(name, component);
- }
-}
diff --git a/packages/core/src/Plugin/Plugin.ts b/packages/core/src/Plugin/Plugin.ts
index 76475c11c6..6115499acc 100644
--- a/packages/core/src/Plugin/Plugin.ts
+++ b/packages/core/src/Plugin/Plugin.ts
@@ -1,6 +1,8 @@
import { ContextBase } from '../Basics/ContextBase';
+import { Context } from '../Basics/Context';
import { Observable } from '../Observer';
import { Nullable, PropsFrom } from '../Shared';
+import { Univer } from '../Basics';
/**
* Basic function of plugin
@@ -8,6 +10,7 @@ import { Nullable, PropsFrom } from '../Shared';
export interface BasePlugin {
context: ContextBase;
getContext(): ContextBase;
+ getGlobalContext(): Context;
getPluginName(): string;
onCreate(context: ContextBase): void;
onMounted(context: ContextBase): void;
@@ -29,8 +32,7 @@ export interface BasePlugin {
* Plug-in base class, all plug-ins must inherit from this base class. provides the basic method
*/
export abstract class Plugin<Obs = any, O extends ContextBase = ContextBase>
- implements BasePlugin
-{
+ implements BasePlugin {
context: O;
private _name: string;
@@ -46,13 +48,13 @@ export abstract class Plugin<Obs = any, O extends ContextBase = ContextBase>
this.context = context;
}
- load<T>(data: T): void {}
+ load<T>(data: T): void { }
save(): object {
return Object();
}
- onMounted(context: O): void {}
+ onMounted(context: O): void { }
onDestroy(): void {
this.deleteObserve(...this._observeNames);
@@ -66,6 +68,14 @@ export abstract class Plugin<Obs = any, O extends ContextBase = ContextBase>
return this.context;
}
+ getGlobalContext(): Context {
+ return this.context.getUniver().getGlobalContext();
+ }
+
+ getUniver(): Univer {
+ return this.context.getUniver();
+ }
+
getObserver<K extends keyof Obs & string>(
name: K
): Nullable<Observable<PropsFrom<Obs[K]>>> {
diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaController.tsx b/packages/sheets-plugin-formula/src/Controller/FormulaController.tsx
index d5a2e33888..54228d70e8 100644
--- a/packages/sheets-plugin-formula/src/Controller/FormulaController.tsx
+++ b/packages/sheets-plugin-formula/src/Controller/FormulaController.tsx
@@ -33,7 +33,7 @@ export class FormulaController {
this._sheetPlugin = this._plugin.getContext().getPluginManager().getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET);
- this._sheetUIPlugin = this._plugin.getContext().getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);
+ this._sheetUIPlugin = this._plugin.getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);
this._activeSheetId = this._sheetPlugin.getWorkbook().getActiveSheet().getSheetId();
diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts
index 472e30b295..c47d7fc27f 100644
--- a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts
@@ -29,7 +29,7 @@ export class FormulaPromptController {
this._sheetPlugin = this._plugin.getContext().getPluginManager().getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET);
- this._sheetUIPlugin = this._plugin.getContext().getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);
+ this._sheetUIPlugin = this._plugin.getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);
this._initRegisterComponent();
this._initialize();
diff --git a/packages/ui-plugin-sheets/src/Controller/AppUIController.ts b/packages/ui-plugin-sheets/src/Controller/AppUIController.ts
index fb016a7b9b..e29e690c9c 100644
--- a/packages/ui-plugin-sheets/src/Controller/AppUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/AppUIController.ts
@@ -16,8 +16,8 @@ export class AppUIController {
const UIConfig = this._sheetContainerController.getUIConfig();
UI.create({
- context: this._plugin.getContext(),
- locale: this._plugin.getContext().getLocale().getCurrentLocale(),
+ context: this._plugin.getGlobalContext(),
+ locale: this._plugin.getGlobalContext().getLocale().getCurrentLocale(),
changeLocale: this.changeLocale,
UIConfig,
container: this._plugin.getConfig().container,
@@ -33,12 +33,12 @@ export class AppUIController {
*/
changeLocale = (locale: string) => {
this._plugin
- .getContext()
+ .getGlobalContext()
.getLocale()
.change(locale as LocaleType);
// publish
- this._plugin.getContext().getObserverManager().requiredObserver('onAfterChangeUILocaleObservable', 'core')!.notifyObservers();
+ this._plugin.getGlobalContext().getObserverManager().requiredObserver('onAfterChangeUILocaleObservable', 'core')!.notifyObservers();
};
getSheetContainerController() {
diff --git a/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts b/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts
index 3e910c085a..60b8b633db 100644
--- a/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts
@@ -25,7 +25,7 @@ export class CellEditorUIController {
constructor(plugin: SheetUIPlugin) {
this._plugin = plugin;
- this._sheetPlugin = plugin.getContext().getUniver().getCurrentUniverSheetInstance().context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
+ this._sheetPlugin = plugin.getUniver().getCurrentUniverSheetInstance().context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
this._initialize();
}
@@ -80,8 +80,8 @@ export class CellEditorUIController {
}
private _handleKeyboardObserver() {
- const onKeyDownObservable = this._plugin.getContext().getObserverManager().getObserver<KeyboardEvent>('onKeyDownObservable', 'core');
- const onKeyCompositionStartObservable = this._plugin.getContext().getObserverManager().getObserver<CompositionEvent>('onKeyCompositionStartObservable', 'core');
+ const onKeyDownObservable = this._plugin.getGlobalContext().getObserverManager().getObserver<KeyboardEvent>('onKeyDownObservable', 'core');
+ const onKeyCompositionStartObservable = this._plugin.getGlobalContext().getObserverManager().getObserver<CompositionEvent>('onKeyCompositionStartObservable', 'core');
if (onKeyDownObservable && !onKeyDownObservable.hasObservers()) {
onKeyDownObservable.add((evt: KeyboardEvent) => {
diff --git a/packages/ui-plugin-sheets/src/Controller/CountBarUIController.ts b/packages/ui-plugin-sheets/src/Controller/CountBarUIController.ts
index 15d5ae0183..d7fe61a1fe 100644
--- a/packages/ui-plugin-sheets/src/Controller/CountBarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/CountBarUIController.ts
@@ -10,7 +10,7 @@ export class CountBarUIController {
let rectList = rangeList.getRangeList();
let recList: string[] = [];
let plugin = this._plugin;
- let workbook = plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();
+ let workbook = plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook();
let worksheet = workbook.getActiveSheet();
let cellMatrix = worksheet.getCellMatrix();
let avg = 0;
@@ -59,7 +59,7 @@ export class CountBarUIController {
const data = event.data;
const workbook = action.getWorkBook();
const unitId = workbook.getUnitId();
- const currentWorkbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();
+ const currentWorkbook = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook();
const currentUnitId = currentWorkbook.getUnitId();
if (unitId === currentUnitId) {
switch (data.actionName) {
@@ -70,7 +70,7 @@ export class CountBarUIController {
}
}
});
- const manager = plugin.getContext()
+ const manager = plugin
.getUniver()
.getCurrentUniverSheetInstance()
.context
@@ -88,7 +88,7 @@ export class CountBarUIController {
// changeRatio
onChange = (v: string) => {
console.log(v);
- this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().setZoomRatio(Tools.numberFixed(v / 100, 2));
+ this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().setZoomRatio(Tools.numberFixed(v / 100, 2));
}
// 刷新组件
diff --git a/packages/ui-plugin-sheets/src/Controller/FormulaBarUIController.ts b/packages/ui-plugin-sheets/src/Controller/FormulaBarUIController.ts
index 35ee34ed68..5d156f4fd1 100644
--- a/packages/ui-plugin-sheets/src/Controller/FormulaBarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/FormulaBarUIController.ts
@@ -17,7 +17,7 @@ export class FormulaBarUIController {
constructor(plugin: SheetUIPlugin) {
this._plugin = plugin;
- this._sheetPlugin = plugin.getContext().getUniver().getCurrentUniverSheetInstance().context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
+ this._sheetPlugin = plugin.getUniver().getCurrentUniverSheetInstance().context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
this._initialize();
}
diff --git a/packages/ui-plugin-sheets/src/Controller/InfoBarUIController.ts b/packages/ui-plugin-sheets/src/Controller/InfoBarUIController.ts
index c5c617ba97..d4880fad0d 100644
--- a/packages/ui-plugin-sheets/src/Controller/InfoBarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/InfoBarUIController.ts
@@ -26,7 +26,7 @@ export class InfoBarUIController {
private _infoList: BaseInfoBarProps;
private _refreshComponent(): void {
- const name = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook().getConfig().name;
+ const name = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook().getConfig().name;
this._infoBarModel = new InfoBarModel(name);
this._infoList = {
back: {
diff --git a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
index b45ad491d9..4cb970d753 100644
--- a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
@@ -47,7 +47,7 @@ export class RightMenuUIController {
constructor(plugin: SheetUIPlugin, config?: SheetRightMenuConfig) {
this._plugin = plugin;
- this._sheetPlugin = plugin.getContext().getUniver().getCurrentUniverSheetInstance().context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
+ this._sheetPlugin = plugin.getUniver().getCurrentUniverSheetInstance().context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
this._config = Tools.deepMerge({}, DefaultRightMenuConfig, config);
diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
index a7e79b0c4a..6c76e34898 100644
--- a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
+++ b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
@@ -43,7 +43,7 @@ export class SheetBarUIController {
menuList: this._menuList,
selectSheet: (event: Event, data: { item: SheetUlProps }) => {
this._dataId = data.item.sheetId;
- const sheet = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(this._dataId);
+ const sheet = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(this._dataId);
if (sheet) {
sheet.activate();
}
@@ -63,7 +63,7 @@ export class SheetBarUIController {
}
protected _refreshSheetData(): void {
- const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook();
const sheets = workbook.getSheets();
this._menuList = sheets.map((sheet, index) => ({
label: sheet.getName(),
@@ -171,7 +171,7 @@ export class SheetBarUIController {
const data = event.data;
const workbook = action.getWorkBook();
const unitId = workbook.getUnitId();
- const currentWorkbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();
+ const currentWorkbook = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook();
const currentUnitId = currentWorkbook.getUnitId();
if (unitId === currentUnitId) {
switch (data.actionName) {
@@ -336,7 +336,7 @@ export class SheetBarUIController {
});
list.forEach((ele, index) => {
if (ele.sheetId === sheetId) {
- this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook().setSheetOrder(ele.sheetId, index);
+ this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook().setSheetOrder(ele.sheetId, index);
}
});
}
diff --git a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts
index 400da6901e..017910213d 100644
--- a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts
@@ -171,7 +171,7 @@ export class SheetContainerUIController {
.change(locale as LocaleType);
// publish
- this._plugin.getContext().getObserverManager().requiredObserver('onAfterChangeUILocaleObservable', 'core')!.notifyObservers();
+ this._plugin.getGlobalContext().getObserverManager().requiredObserver('onAfterChangeUILocaleObservable', 'core')!.notifyObservers();
};
getContentRef() {
@@ -179,7 +179,7 @@ export class SheetContainerUIController {
}
setEventManager() {
- const universheets = this._plugin.getContext().getUniver().getAllUniverSheetsInstance();
+ const universheets = this._plugin.getUniver().getAllUniverSheetsInstance();
universheets.forEach((universheet: UniverSheet) => {
universheet.getWorkBook().getContext().getPluginManager().getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET).listenEventManager();
});