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: support create multi instances for a business (#234)

Wenzhao Hu9ad259707878
diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index 2600788565..11d6ef83a9 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -95,6 +95,7 @@ module.exports = {
// eslint-plugin-unused-imports
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/default-param-last': 'off',
+ '@typescript-eslint/lines-between-class-members': 'off',
// '@typescript-eslint/member-ordering': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-redeclare': 'off', // dependency interface and dependency token share the same name
diff --git a/.github/contributing-zh.md b/.github/contributing-zh.md
index b22abd5270..f3985a4943 100644
--- a/.github/contributing-zh.md
+++ b/.github/contributing-zh.md
@@ -592,7 +592,7 @@ git rebase --continue
比如,获取 workbook
```js
-context.getWorkBook();
+context;
```
### 挂载 meta data
@@ -602,9 +602,9 @@ context.getWorkBook();
是否需要挂载 meta data,每个插件的情况不一样。插件的临时数据只需要插件自己存储,无需挂载到核心,只有需要存储的插件才需要挂载到核心上。如果一个插件的数据在每一个 sheet 页上都不一样,就要放在 worksheet 上,反之就挂载在 workbook 上
```js
-const activeSheetId = context.getWorkBook().getActiveSheet().getSheetId();
+const activeSheetId = context.getActiveSheet().getSheetId();
// add new AlternatingColors meta data
-context.getWorkBook().setPluginMeta <
+context.setPluginMeta <
IKeyType <
IBandedRange >> (ALTERNATING_COLORS_PLUGIN_NAME, { [activeSheetId]: [] });
```
@@ -972,7 +972,7 @@ export class AlternatingColorsPlugin extends Plugin {
actionName: ACTION_NAMES.SET_TAB_COLOR_ACTION,
color: color,
};
- let command = new Command(_context.getWorkBook(), setTabColor);
+ let command = new Command(_context, setTabColor);
_commandManager.invoke(command);
return this;
}
diff --git a/packages/base-docs/src/Controller/InputController.ts b/packages/base-docs/src/Controller/InputController.ts
index 4ab6b1f751..ef585098ba 100644
--- a/packages/base-docs/src/Controller/InputController.ts
+++ b/packages/base-docs/src/Controller/InputController.ts
@@ -175,7 +175,7 @@ export class InputController extends Disposable {
}
const skeleton = document.getSkeleton();
- const docsModel = this._currentUniverService.getCurrentUniverDocInstance().getDocument();
+ const docsModel = this._currentUniverService.getCurrentUniverDocInstance();
const startNodePosition = activeSelection.getStart();
const preSpan = document.findSpanByPosition(startNodePosition);
@@ -297,7 +297,7 @@ export class InputController extends Disposable {
}
const skeleton = document.getSkeleton();
- const docsModel = this._currentUniverService.getCurrentUniverDocInstance().getDocument();
+ const docsModel = this._currentUniverService.getCurrentUniverDocInstance();
const startNodePosition = activeSelection.getStart();
const activeRange = activeSelection.getRange();
@@ -745,7 +745,7 @@ export class InputController extends Disposable {
private _initialize(docsView: DocsView): DisposableCollection {
docsView.getDocs().enableEditor();
const events = docsView.getDocs().getEditorInputEvent();
- const docsModel = this._currentUniverService.getCurrentUniverDocInstance().getDocument();
+ const docsModel = this._currentUniverService.getCurrentUniverDocInstance();
const disposableCollection = new DisposableCollection();
if (!events) {
diff --git a/packages/base-docs/src/View/Render/Views/DocsView.ts b/packages/base-docs/src/View/Render/Views/DocsView.ts
index 23442b8132..380c8a56f3 100644
--- a/packages/base-docs/src/View/Render/Views/DocsView.ts
+++ b/packages/base-docs/src/View/Render/Views/DocsView.ts
@@ -39,7 +39,7 @@ export class DocsView extends BaseView {
const docsModel = this._useExternalModel
? externalModel
- : this._currentUniverService.getCurrentUniverDocInstance()?.getDocument();
+ : this._currentUniverService.getCurrentUniverDocInstance();
if (docsModel) {
this._docsViewManagerService.registerCanvasViewForUniverInstance(docsModel!.getUnitId(), this);
}
@@ -85,7 +85,7 @@ export class DocsView extends BaseView {
const scene = this.getScene();
const docsModel = this._useExternalModel
? this._model!
- : this._currentUniverService.getCurrentUniverDocInstance()?.getDocument();
+ : this._currentUniverService.getCurrentUniverDocInstance();
if (!docsModel) {
return;
diff --git a/packages/base-docs/src/commands/commands/core-editing.command.ts b/packages/base-docs/src/commands/commands/core-editing.command.ts
index 32d634dc63..dc712369f9 100644
--- a/packages/base-docs/src/commands/commands/core-editing.command.ts
+++ b/packages/base-docs/src/commands/commands/core-editing.command.ts
@@ -322,7 +322,7 @@ export const CoverCommand: ICommand<ICoverCommandParams> = {
return false;
}
- doc.getDocument().reset(snapshot || createEmptyDocSnapshot());
+ doc.reset(snapshot || createEmptyDocSnapshot());
if (clearUndoRedoStack) {
const undoRedoService = accessor.get(IUndoRedoService);
diff --git a/packages/base-docs/src/commands/mutations/core-editing.mutation.ts b/packages/base-docs/src/commands/mutations/core-editing.mutation.ts
index e840c48f8b..2d92b8938c 100644
--- a/packages/base-docs/src/commands/mutations/core-editing.mutation.ts
+++ b/packages/base-docs/src/commands/mutations/core-editing.mutation.ts
@@ -52,7 +52,7 @@ export const RichTextEditingMutation: IMutation<IRichTextEditingMutationParams,
const { unitId, mutations } = params;
const currentUniverService = accessor.get(ICurrentUniverService);
- const document = currentUniverService.getUniverDocInstance(unitId)?.getDocument();
+ const document = currentUniverService.getUniverDocInstance(unitId);
if (!document) {
throw new Error(`Document not found for unitId: ${unitId}`);
}
diff --git a/packages/base-docs/src/commands/operations/cursor.operation.ts b/packages/base-docs/src/commands/operations/cursor.operation.ts
index 76fe957f1e..105d5ef0e2 100644
--- a/packages/base-docs/src/commands/operations/cursor.operation.ts
+++ b/packages/base-docs/src/commands/operations/cursor.operation.ts
@@ -22,7 +22,7 @@ export const MoveCursorOperation: IOperation<IMoveCursorOperationParams> = {
const currentUniverService = accessor.get(ICurrentUniverService);
const inputController = accessor.get(InputController);
- inputController.moveCursor(currentUniverService.getCurrentUniverDocInstance().getDocument(), params.direction);
+ inputController.moveCursor(currentUniverService.getCurrentUniverDocInstance(), params.direction);
return true;
},
diff --git a/packages/base-sheets/src/Basics/component-tools.ts b/packages/base-sheets/src/Basics/component-tools.ts
index ca90166478..29983af256 100644
--- a/packages/base-sheets/src/Basics/component-tools.ts
+++ b/packages/base-sheets/src/Basics/component-tools.ts
@@ -26,7 +26,7 @@ export function getSheetObject(
currentUniverService: ICurrentUniverService,
renderManagerService: IRenderManagerService
): Nullable<ISheetObjectParam> {
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const unitId = workbook.getUnitId();
diff --git a/packages/base-sheets/src/Controller/FormulaBarController.ts b/packages/base-sheets/src/Controller/FormulaBarController.ts
index 7c87cfb7cd..7dfd4c73fc 100644
--- a/packages/base-sheets/src/Controller/FormulaBarController.ts
+++ b/packages/base-sheets/src/Controller/FormulaBarController.ts
@@ -21,7 +21,7 @@ export class FormulaBarController {
// endColumn: column,
// };
// }
- // const cellData = this._plugin.getWorkbook().getActiveSheet().getRange(currentRangeData).getObjectValue({ isIncludeStyle: true });
+ // const cellData = this._plugin.getActiveSheet().getRange(currentRangeData).getObjectValue({ isIncludeStyle: true });
// if (cellData) {
// let cellValue = String(cellData.m || cellData.v || '');
// // If the cell has a formula, it needs to be intercepted
diff --git a/packages/base-sheets/src/Controller/Selection.controller.ts b/packages/base-sheets/src/Controller/Selection.controller.ts
index 13ad7b5082..1e9c80e9a5 100644
--- a/packages/base-sheets/src/Controller/Selection.controller.ts
+++ b/packages/base-sheets/src/Controller/Selection.controller.ts
@@ -40,7 +40,7 @@ export class SelectionController extends Disposable {
}
private _initialize() {
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const sheetObject = this._getSheetObject();
@@ -147,7 +147,7 @@ export class SelectionController extends Disposable {
private _userActionSyncListener() {
this._selectionTransformerShapeManager.selectionRangeWithStyle$.subscribe((selectionDataWithStyleList) => {
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const unitId = workbook.getUnitId();
const sheetId = workbook.getActiveSheet().getSheetId();
@@ -172,7 +172,7 @@ export class SelectionController extends Disposable {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (updateCommandList.includes(command.id)) {
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const params = command.params as ISetZoomRatioMutationParams;
diff --git a/packages/base-sheets/src/Controller/freeze.controller.ts b/packages/base-sheets/src/Controller/freeze.controller.ts
index 91c4d4dcd9..19f64b4f0b 100644
--- a/packages/base-sheets/src/Controller/freeze.controller.ts
+++ b/packages/base-sheets/src/Controller/freeze.controller.ts
@@ -449,7 +449,7 @@ export class FreezeController extends Disposable {
xSplit = xSplit < 0 ? 0 : xSplit;
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
this._commandService.executeCommand(SetFrozenCommand.id, {
@@ -874,7 +874,7 @@ export class FreezeController extends Disposable {
private _scrollListener() {
this._scrollManagerService.scrollInfo$.subscribe((param) => {
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const freeze = worksheet.getConfig().freeze;
@@ -891,7 +891,7 @@ export class FreezeController extends Disposable {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (updateCommandList.includes(command.id)) {
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const params = command.params as ISetFrozenMutationParams;
diff --git a/packages/base-sheets/src/Controller/sheet-render.controller.ts b/packages/base-sheets/src/Controller/sheet-render.controller.ts
index 61d3cdf83d..f1ee83d319 100644
--- a/packages/base-sheets/src/Controller/sheet-render.controller.ts
+++ b/packages/base-sheets/src/Controller/sheet-render.controller.ts
@@ -58,7 +58,7 @@ export class SheetRenderController extends Disposable {
const { skeleton: spreadsheetSkeleton, unitId, sheetId } = param;
- const workbook = this._currentUniverService.getUniverSheetInstance(unitId)?.getWorkBook();
+ const workbook = this._currentUniverService.getUniverSheetInstance(unitId);
const worksheet = workbook?.getSheetBySheetId(sheetId);
@@ -138,7 +138,7 @@ export class SheetRenderController extends Disposable {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (updateCommandList.includes(command.id)) {
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const unitId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const sheetId = worksheet.getSheetId();
diff --git a/packages/base-sheets/src/Controller/zoom.controller.ts b/packages/base-sheets/src/Controller/zoom.controller.ts
index 35441efb33..1d7300351c 100644
--- a/packages/base-sheets/src/Controller/zoom.controller.ts
+++ b/packages/base-sheets/src/Controller/zoom.controller.ts
@@ -65,7 +65,7 @@ export class ZoomController extends Disposable {
ratioDelta /= 2;
}
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const sheet = workbook.getActiveSheet();
const currentRatio = sheet.getZoomRatio();
let nextRatio = +parseFloat(`${currentRatio + ratioDelta}`).toFixed(1);
@@ -87,7 +87,7 @@ export class ZoomController extends Disposable {
return;
}
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
@@ -103,7 +103,7 @@ export class ZoomController extends Disposable {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (updateCommandList.includes(command.id)) {
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const params = command.params;
diff --git a/packages/base-sheets/src/View/sheet-canvas-view.ts b/packages/base-sheets/src/View/sheet-canvas-view.ts
index aba8d783dd..70beae6e0a 100644
--- a/packages/base-sheets/src/View/sheet-canvas-view.ts
+++ b/packages/base-sheets/src/View/sheet-canvas-view.ts
@@ -38,7 +38,7 @@ export class SheetCanvasView {
}
private _initialize() {
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const unitId = workbook.getUnitId();
@@ -72,7 +72,7 @@ export class SheetCanvasView {
private _initialComponent(currentRender: IRender) {
const scene = this._scene;
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const unitId = workbook.getUnitId();
diff --git a/packages/base-sheets/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts
index 70955c037c..284cb5aa98 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts
@@ -67,8 +67,7 @@ describe('Test style commands', () => {
function getMerge(): IRange[] | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getConfig().mergeData;
}
@@ -110,8 +109,7 @@ describe('Test style commands', () => {
function getMerge(): IRange[] | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getConfig().mergeData;
}
@@ -150,8 +148,7 @@ describe('Test style commands', () => {
function getMerge(): IRange[] | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getConfig().mergeData;
}
@@ -190,8 +187,7 @@ describe('Test style commands', () => {
function getMerge(): IRange[] | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getConfig().mergeData;
}
diff --git a/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts
index 61074f0611..48f3152a3d 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts
@@ -62,8 +62,7 @@ describe('Test clear selection content commands', () => {
function getValue(): Nullable<ICellData> {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getValue();
}
@@ -108,15 +107,14 @@ describe('Test clear selection content commands', () => {
function getValue(): Nullable<ICellData> {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getValue();
}
function getStyle(): Nullable<IStyleData> {
const value = getValue();
- const styles = get(ICurrentUniverService).getUniverSheetInstance('test')?.getWorkBook().getStyles();
+ const styles = get(ICurrentUniverService).getUniverSheetInstance('test')?.getStyles();
if (value && styles) {
return styles.getStyleByCell(value);
}
@@ -178,15 +176,14 @@ describe('Test clear selection content commands', () => {
function getValue(): Nullable<ICellData> {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getValue();
}
function getStyle(): Nullable<IStyleData> {
const value = getValue();
- const styles = get(ICurrentUniverService).getUniverSheetInstance('test')?.getWorkBook().getStyles();
+ const styles = get(ICurrentUniverService).getUniverSheetInstance('test')?.getStyles();
if (value && styles) {
return styles.getStyleByCell(value);
}
diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-border-command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-border-command.spec.ts
index 3ae796e9c2..5a243fa9f3 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/set-border-command.spec.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/set-border-command.spec.ts
@@ -72,8 +72,7 @@ describe('Test style commands', () => {
function getBorder({ startRow, startColumn }: IRange): IBorderData | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(startRow, startColumn)
.getBorder();
}
diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts
index 4673f06db9..3f05f452c4 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/set-col-width.command.spec.ts
@@ -19,7 +19,7 @@ describe('Test set col width commands', () => {
let commandService: ICommandService;
function getColumnWidth(col: number): number {
- const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getActiveSheet();
return worksheet.getColumnWidth(col);
}
@@ -33,7 +33,7 @@ describe('Test set col width commands', () => {
commandService.registerCommand(SetColWidthCommand);
commandService.registerCommand(SetWorksheetColWidthMutation);
- const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getActiveSheet();
const maxRow = worksheet.getMaxRows() - 1;
const selectionManager = get(SelectionManagerService);
selectionManager.setCurrentSelection({
diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts
index 69ac4be13f..0534c36edb 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts
@@ -54,14 +54,13 @@ describe('Test set range values commands', () => {
getValue = (): Nullable<ICellData> =>
get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getValue();
getStyle = (): Nullable<IStyleData> => {
const value = getValue();
- const styles = get(ICurrentUniverService).getUniverSheetInstance('test')?.getWorkBook().getStyles();
+ const styles = get(ICurrentUniverService).getUniverSheetInstance('test')?.getStyles();
if (value && styles) {
return styles.getStyleByCell(value);
}
diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts
index 5126cfdd9f..76c3be6465 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/set-row-height.command.spec.ts
@@ -21,7 +21,7 @@ describe('Test set row height commands', () => {
let commandService: ICommandService;
function getRowHeight(row: number): number {
- const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getActiveSheet();
return worksheet.getRowHeight(row);
}
@@ -35,7 +35,7 @@ describe('Test set row height commands', () => {
commandService.registerCommand(SetRowHeightCommand);
commandService.registerCommand(SetWorksheetRowHeightMutation);
- const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = get(ICurrentUniverService).getCurrentUniverSheetInstance().getActiveSheet();
const maxColumn = worksheet.getMaxColumns() - 1;
const selectionManager = get(SelectionManagerService);
selectionManager.setCurrentSelection({
diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-style.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-style.command.spec.ts
index 54c308e1ab..fd54d2bd50 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/set-style.command.spec.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/set-style.command.spec.ts
@@ -108,8 +108,7 @@ describe("Test commands used for updating cells' styles", () => {
function getFontBold(): FontWeight | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getFontWeight();
}
@@ -181,8 +180,7 @@ describe("Test commands used for updating cells' styles", () => {
return (
get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(startRow, startColumn, endRow, endColumn)
.getFontStyle() === FontItalic.ITALIC
);
@@ -224,8 +222,7 @@ describe("Test commands used for updating cells' styles", () => {
function getFontUnderline(): ITextDecoration | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getUnderline();
}
@@ -274,8 +271,7 @@ describe("Test commands used for updating cells' styles", () => {
function getFontThroughLine(): ITextDecoration | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getStrikeThrough();
}
@@ -315,8 +311,7 @@ describe("Test commands used for updating cells' styles", () => {
function getFontSize(): number | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getFontSize();
}
@@ -354,8 +349,7 @@ describe("Test commands used for updating cells' styles", () => {
function getFontFamily(): string | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getFontFamily();
}
@@ -393,8 +387,7 @@ describe("Test commands used for updating cells' styles", () => {
function getFontColor(): Nullable<string> | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getTextStyle()?.cl?.rgb;
}
@@ -432,8 +425,7 @@ describe("Test commands used for updating cells' styles", () => {
function getBackgroundColor(): string | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getBackground();
}
@@ -473,8 +465,7 @@ describe("Test commands used for updating cells' styles", () => {
function getVerticalAlignment(): VerticalAlign | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getVerticalAlignment();
}
@@ -514,8 +505,7 @@ describe("Test commands used for updating cells' styles", () => {
function getHorizontalAlignment(): HorizontalAlign | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getHorizontalAlignment();
}
@@ -557,8 +547,7 @@ describe("Test commands used for updating cells' styles", () => {
function getTextWrap(): BooleanNumber | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getWrap();
}
@@ -600,8 +589,7 @@ describe("Test commands used for updating cells' styles", () => {
function getTextRotation(): ITextRotation | undefined {
return get(ICurrentUniverService)
.getUniverSheetInstance('test')
- ?.getWorkBook()
- .getSheetBySheetId('sheet1')
+ ?.getSheetBySheetId('sheet1')
?.getRange(0, 0, 0, 0)
.getTextRotation();
}
diff --git a/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts b/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts
index 2018b1a33e..bb4d6db1d6 100644
--- a/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts
+++ b/packages/base-sheets/src/commands/commands/add-worksheet-merge.command.ts
@@ -36,12 +36,8 @@ export const AddWorksheetMergeCommand: ICommand = {
const selections = selectionManagerService.getRangeDatas();
if (!selections?.length) return false;
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
- const worksheetId = currentUniverService
- .getCurrentUniverSheetInstance()
- .getWorkBook()
- .getActiveSheet()
- .getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const worksheetId = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts
index cd274355fd..d9f5f1509c 100644
--- a/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts
+++ b/packages/base-sheets/src/commands/commands/clear-selection-all.command.ts
@@ -30,7 +30,7 @@ export const ClearSelectionAllCommand: ICommand = {
const selectionManagerService = accessor.get(SelectionManagerService);
const undoRedoService = accessor.get(IUndoRedoService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const workbookId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const worksheetId = worksheet.getSheetId();
diff --git a/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts
index dd93e4b6f5..968a21cf66 100644
--- a/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts
+++ b/packages/base-sheets/src/commands/commands/clear-selection-content.command.ts
@@ -30,7 +30,7 @@ export const ClearSelectionContentCommand: ICommand = {
const selectionManagerService = accessor.get(SelectionManagerService);
const undoRedoService = accessor.get(IUndoRedoService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const workbookId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const worksheetId = worksheet.getSheetId();
diff --git a/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts b/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts
index 702bf5025c..3be89ff05b 100644
--- a/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts
+++ b/packages/base-sheets/src/commands/commands/clear-selection-format.command.ts
@@ -30,7 +30,7 @@ export const ClearSelectionFormatCommand: ICommand = {
const selectionManagerService = accessor.get(SelectionManagerService);
const undoRedoService = accessor.get(IUndoRedoService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const workbookId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const worksheetId = worksheet.getSheetId();
diff --git a/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts b/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts
index fced8679d3..ed29493096 100644
--- a/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-format-to-range.command.ts
@@ -40,10 +40,10 @@ export const CopyFormatToRangeCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const handleResult = handleCopyRange(accessor, workbookId, worksheetId, originRange, params.destinationRange);
if (!handleResult) return false;
@@ -97,8 +97,7 @@ function handleCopyRange(
const worksheet = accessor
.get(ICurrentUniverService)
.getUniverSheetInstance(workbookId)
- ?.getWorkBook()
- .getSheetBySheetId(worksheetId);
+ ?.getSheetBySheetId(worksheetId);
if (!worksheet) return;
const sheetMatrix = worksheet.getCellMatrix();
diff --git a/packages/base-sheets/src/commands/commands/copy-range-to.command.ts b/packages/base-sheets/src/commands/commands/copy-range-to.command.ts
index dedf24decd..ef39b3ad6b 100644
--- a/packages/base-sheets/src/commands/commands/copy-range-to.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-range-to.command.ts
@@ -40,10 +40,10 @@ export const CopyRangeToCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const handleResult = handleCopyRange(accessor, workbookId, worksheetId, originRange, params.destinationRange);
if (!handleResult) return false;
@@ -139,8 +139,7 @@ function handleCopyRange(
const worksheet = accessor
.get(ICurrentUniverService)
.getUniverSheetInstance(workbookId)
- ?.getWorkBook()
- .getSheetBySheetId(worksheetId);
+ ?.getSheetBySheetId(worksheetId);
if (!worksheet) return;
const sheetMatrix = worksheet.getCellMatrix();
diff --git a/packages/base-sheets/src/commands/commands/copy-to-worksheet.command.ts b/packages/base-sheets/src/commands/commands/copy-to-worksheet.command.ts
index c9122288f4..8f4259b8c5 100644
--- a/packages/base-sheets/src/commands/commands/copy-to-worksheet.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-to-worksheet.command.ts
@@ -24,15 +24,13 @@ export const CopySheetToCommand: ICommand = {
const workbookId = params.workbookId || currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId =
- params.worksheetId ||
- currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();
+ params.worksheetId || currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
const copyToWorkbookId = params.workbookId || currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const copyToSheetId =
- params.copyToSheetId ||
- currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ params.copyToSheetId || currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
- const copyToWorkbook = currentUniverService.getUniverSheetInstance(copyToWorkbookId)?.getWorkBook();
+ const copyToWorkbook = currentUniverService.getUniverSheetInstance(copyToWorkbookId);
if (!copyToWorkbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts b/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts
index ba588b5d63..a576b16d35 100644
--- a/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-values-to-range.command.ts
@@ -39,10 +39,10 @@ export const CopyValuesToRangeCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const handleResult = handleCopyRange(accessor, workbookId, worksheetId, originRange, params.destinationRange);
if (!handleResult) return false;
@@ -100,8 +100,7 @@ function handleCopyRange(
const worksheet = accessor
.get(ICurrentUniverService)
.getUniverSheetInstance(workbookId)
- ?.getWorkBook()
- .getSheetBySheetId(worksheetId);
+ ?.getSheetBySheetId(worksheetId);
if (!worksheet) return;
const sheetMatrix = worksheet.getCellMatrix();
diff --git a/packages/base-sheets/src/commands/commands/copy-worksheet.command.ts b/packages/base-sheets/src/commands/commands/copy-worksheet.command.ts
index 02940c5b1f..89d4c72888 100644
--- a/packages/base-sheets/src/commands/commands/copy-worksheet.command.ts
+++ b/packages/base-sheets/src/commands/commands/copy-worksheet.command.ts
@@ -26,14 +26,14 @@ export const CopySheetCommand: ICommand = {
let workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
let worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
if (params) {
workbookId = params.workbookId ?? workbookId;
worksheetId = params.worksheetId ?? worksheetId;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/delete-range-move-left.command.ts b/packages/base-sheets/src/commands/commands/delete-range-move-left.command.ts
index b5e32f8f08..7401f1c06c 100644
--- a/packages/base-sheets/src/commands/commands/delete-range-move-left.command.ts
+++ b/packages/base-sheets/src/commands/commands/delete-range-move-left.command.ts
@@ -30,13 +30,13 @@ export const DeleteRangeMoveLeftCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
const range = selectionManagerService.getRangeDatas();
if (!range?.length) return false;
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/delete-range-move-up.command.ts b/packages/base-sheets/src/commands/commands/delete-range-move-up.command.ts
index c49c495d20..d8f90ad777 100644
--- a/packages/base-sheets/src/commands/commands/delete-range-move-up.command.ts
+++ b/packages/base-sheets/src/commands/commands/delete-range-move-up.command.ts
@@ -30,13 +30,13 @@ export const DeleteRangeMoveUpCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
const range = selectionManagerService.getRangeDatas();
if (!range?.length) return false;
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/insert-range-move-down.command.ts b/packages/base-sheets/src/commands/commands/insert-range-move-down.command.ts
index d0064b7e85..07b11f5ff6 100644
--- a/packages/base-sheets/src/commands/commands/insert-range-move-down.command.ts
+++ b/packages/base-sheets/src/commands/commands/insert-range-move-down.command.ts
@@ -31,13 +31,13 @@ export const InsertRangeMoveDownCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
const range = selectionManagerService.getRangeDatas();
if (!range?.length) return false;
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/insert-range-move-right.command.ts b/packages/base-sheets/src/commands/commands/insert-range-move-right.command.ts
index 00d359eb0e..fbac80b815 100644
--- a/packages/base-sheets/src/commands/commands/insert-range-move-right.command.ts
+++ b/packages/base-sheets/src/commands/commands/insert-range-move-right.command.ts
@@ -31,13 +31,13 @@ export const InsertRangeMoveRightCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
const range = selectionManagerService.getRangeDatas();
if (!range?.length) return false;
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/insert-row-col.command.ts b/packages/base-sheets/src/commands/commands/insert-row-col.command.ts
index a587f7c116..f892bc21e6 100644
--- a/packages/base-sheets/src/commands/commands/insert-row-col.command.ts
+++ b/packages/base-sheets/src/commands/commands/insert-row-col.command.ts
@@ -63,7 +63,7 @@ export const InsertRowCommand: ICommand = {
const undoRedoService = accessor.get(IUndoRedoService);
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getUniverSheetInstance(params.workbookId)!.getWorkBook()!;
+ const workbook = currentUniverService.getUniverSheetInstance(params.workbookId)!!;
const worksheet = workbook.getSheetBySheetId(params.worksheetId)!;
// insert rows & undos
@@ -196,7 +196,7 @@ export const InsertRowBeforeCommand: ICommand<IInsertRowBeforeOrAfterCommandPara
}
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
if (!workbook) {
return false;
}
@@ -243,7 +243,7 @@ export const InsertRowAfterCommand: ICommand<IInsertRowBeforeOrAfterCommandParam
}
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
if (!workbook) {
return false;
}
@@ -292,7 +292,7 @@ export const InsertColCommand: ICommand<InsertColCommandBaseParams> = {
const undoRedoService = accessor.get(IUndoRedoService);
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
@@ -438,7 +438,7 @@ export const InsertColBeforeCommand: ICommand<InsertColCommandParams> = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
let range: IRange;
@@ -449,7 +449,7 @@ export const InsertColBeforeCommand: ICommand<InsertColCommandParams> = {
return false;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
@@ -485,7 +485,7 @@ export const InsertColAfterCommand: ICommand<InsertColCommandParams> = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
let range: IRange;
@@ -496,7 +496,7 @@ export const InsertColAfterCommand: ICommand<InsertColCommandParams> = {
return false;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/insert-sheet.command.ts b/packages/base-sheets/src/commands/commands/insert-sheet.command.ts
index 42ff4eb9f5..5dc9657a47 100644
--- a/packages/base-sheets/src/commands/commands/insert-sheet.command.ts
+++ b/packages/base-sheets/src/commands/commands/insert-sheet.command.ts
@@ -42,7 +42,7 @@ export const InsertSheetCommand: ICommand = {
workbookId = params.workbookId ?? workbookId;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
let index = workbook.getSheets().length;
diff --git a/packages/base-sheets/src/commands/commands/move-columns-to.command.ts b/packages/base-sheets/src/commands/commands/move-columns-to.command.ts
index a1e91eaa45..3653d3727f 100644
--- a/packages/base-sheets/src/commands/commands/move-columns-to.command.ts
+++ b/packages/base-sheets/src/commands/commands/move-columns-to.command.ts
@@ -28,10 +28,10 @@ export const MoveColumnsCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/move-range-to.command.ts b/packages/base-sheets/src/commands/commands/move-range-to.command.ts
index feb3bd9f68..3a522907e3 100644
--- a/packages/base-sheets/src/commands/commands/move-range-to.command.ts
+++ b/packages/base-sheets/src/commands/commands/move-range-to.command.ts
@@ -38,10 +38,10 @@ export const MoveRangeToCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/move-rows.command.ts b/packages/base-sheets/src/commands/commands/move-rows.command.ts
index bec73b7b17..de0da602ea 100644
--- a/packages/base-sheets/src/commands/commands/move-rows.command.ts
+++ b/packages/base-sheets/src/commands/commands/move-rows.command.ts
@@ -44,7 +44,7 @@ export const MoveRowsCommand: ICommand = {
const movedRanges = findMoveRanges[0];
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
if (!workbook) return false;
const workbookId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
diff --git a/packages/base-sheets/src/commands/commands/remove-row-col.command.ts b/packages/base-sheets/src/commands/commands/remove-row-col.command.ts
index 398bd278df..f88aa2c34b 100644
--- a/packages/base-sheets/src/commands/commands/remove-row-col.command.ts
+++ b/packages/base-sheets/src/commands/commands/remove-row-col.command.ts
@@ -51,11 +51,11 @@ export const RemoveRowCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
if (!selections?.length) return false;
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
@@ -211,11 +211,11 @@ export const RemoveColCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
if (!selections?.length) return false;
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/remove-sheet.command.ts b/packages/base-sheets/src/commands/commands/remove-sheet.command.ts
index f94f93a409..c738bb0197 100644
--- a/packages/base-sheets/src/commands/commands/remove-sheet.command.ts
+++ b/packages/base-sheets/src/commands/commands/remove-sheet.command.ts
@@ -28,7 +28,7 @@ export const RemoveSheetCommand: ICommand = {
let workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
let worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
@@ -37,7 +37,7 @@ export const RemoveSheetCommand: ICommand = {
worksheetId = params.worksheetId ?? worksheetId;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/remove-worksheet-merge.command.ts b/packages/base-sheets/src/commands/commands/remove-worksheet-merge.command.ts
index e69d313694..537d5520a7 100644
--- a/packages/base-sheets/src/commands/commands/remove-worksheet-merge.command.ts
+++ b/packages/base-sheets/src/commands/commands/remove-worksheet-merge.command.ts
@@ -33,11 +33,11 @@ export const RemoveWorksheetMergeCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-border-command.ts b/packages/base-sheets/src/commands/commands/set-border-command.ts
index cd8745fc6f..e707be85d3 100644
--- a/packages/base-sheets/src/commands/commands/set-border-command.ts
+++ b/packages/base-sheets/src/commands/commands/set-border-command.ts
@@ -94,7 +94,7 @@ export const SetBorderCommand: ICommand = {
const borderStyleManagerService = accessor.get(BorderStyleManagerService);
const selections = selectionManagerService.getRangeDatas();
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const workbookId = workbook.getUnitId();
const worksheet = workbook.getActiveSheet();
const worksheetId = worksheet.getSheetId();
diff --git a/packages/base-sheets/src/commands/commands/set-border-styles-command.ts b/packages/base-sheets/src/commands/commands/set-border-styles-command.ts
index 7866d3563e..ef73b4879c 100644
--- a/packages/base-sheets/src/commands/commands/set-border-styles-command.ts
+++ b/packages/base-sheets/src/commands/commands/set-border-styles-command.ts
@@ -77,10 +77,9 @@ export const SetBorderCommand: ICommand = {
const workbookId = params.workbookId || currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId =
- params.worksheetId ||
- currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();
+ params.worksheetId || currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-frozen-cancel.command.ts b/packages/base-sheets/src/commands/commands/set-frozen-cancel.command.ts
index 339affa25d..08eb5ea9c7 100644
--- a/packages/base-sheets/src/commands/commands/set-frozen-cancel.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-frozen-cancel.command.ts
@@ -18,11 +18,11 @@ export const SetFrozenCancelCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-frozen.command.ts b/packages/base-sheets/src/commands/commands/set-frozen.command.ts
index 59f58bbbb8..c05a69492f 100644
--- a/packages/base-sheets/src/commands/commands/set-frozen.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-frozen.command.ts
@@ -25,11 +25,11 @@ export const SetFrozenCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-hide-gridlines.command.ts b/packages/base-sheets/src/commands/commands/set-hide-gridlines.command.ts
index 83215a309b..c9909c9fb4 100644
--- a/packages/base-sheets/src/commands/commands/set-hide-gridlines.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-hide-gridlines.command.ts
@@ -32,7 +32,7 @@ export const SetHideGridlinesCommand: ICommand = {
let workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
let worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
let hideGridlines = BooleanNumber.FALSE;
@@ -43,7 +43,7 @@ export const SetHideGridlinesCommand: ICommand = {
hideGridlines = params.hideGridlines ?? BooleanNumber.FALSE;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-range-formatted-value.command.ts b/packages/base-sheets/src/commands/commands/set-range-formatted-value.command.ts
index 9e4d5cdc69..1c2efc3b9d 100644
--- a/packages/base-sheets/src/commands/commands/set-range-formatted-value.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-range-formatted-value.command.ts
@@ -42,11 +42,11 @@ export const SetRangeFormattedValueCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-range-values.command.ts b/packages/base-sheets/src/commands/commands/set-range-values.command.ts
index 8d8cfe2e24..70c58e170b 100644
--- a/packages/base-sheets/src/commands/commands/set-range-values.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-range-values.command.ts
@@ -51,7 +51,7 @@ export const SetRangeValuesCommand: ICommand = {
workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId(),
worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId(),
} = params;
diff --git a/packages/base-sheets/src/commands/commands/set-scroll.command.ts b/packages/base-sheets/src/commands/commands/set-scroll.command.ts
index a83e70bbb8..7bfb7fe640 100644
--- a/packages/base-sheets/src/commands/commands/set-scroll.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-scroll.command.ts
@@ -16,7 +16,7 @@ export const ScrollCommand: ICommand<IScrollCommandParams> = {
handler: async (accessor, params = { sheetViewStartRow: 0, sheetViewStartColumn: 0 }) => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const currentWorkbook = currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook();
+ const currentWorkbook = currentUniverService.getCurrentUniverSheetInstance();
const currentWorksheet = currentWorkbook.getActiveSheet();
if (!currentWorksheet) {
@@ -45,7 +45,7 @@ export const RestScrollCommand: ICommand<{}> = {
handler: async (accessor) => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const currentWorkbook = currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook();
+ const currentWorkbook = currentUniverService.getCurrentUniverSheetInstance();
const currentWorksheet = currentWorkbook.getActiveSheet();
if (!currentWorksheet) {
diff --git a/packages/base-sheets/src/commands/commands/set-selections.command.ts b/packages/base-sheets/src/commands/commands/set-selections.command.ts
index 1a375c9277..2197c85c06 100644
--- a/packages/base-sheets/src/commands/commands/set-selections.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-selections.command.ts
@@ -43,7 +43,7 @@ export const MoveSelectionCommand: ICommand<IMoveSelectionCommandParams> = {
return false;
}
- const workbook = accessor.get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const selection = accessor.get(SelectionManagerService).getLast();
if (!selection) {
@@ -104,7 +104,7 @@ export const ExpandSelectionCommand: ICommand<IExpandSelectionCommandParams> = {
return false;
}
- const currentWorkbook = accessor.get(ICurrentUniverService).getCurrentUniverSheetInstance().getWorkBook();
+ const currentWorkbook = accessor.get(ICurrentUniverService).getCurrentUniverSheetInstance();
const currentWorksheet = currentWorkbook.getActiveSheet();
const selection = accessor.get(SelectionManagerService).getLast();
@@ -170,7 +170,7 @@ export const SelectAllCommand: ICommand<ISelectAllCommandParams> = {
},
handler: async (accessor, params = { expandToGapFirst: true, loop: false }) => {
const selection = accessor.get(SelectionManagerService).getLast();
- const workbook = accessor.get(ICurrentUniverService).getCurrentUniverSheetInstance()?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
if (!selection || !worksheet) {
diff --git a/packages/base-sheets/src/commands/commands/set-style.command.ts b/packages/base-sheets/src/commands/commands/set-style.command.ts
index bd81c49bcc..44bcce6941 100644
--- a/packages/base-sheets/src/commands/commands/set-style.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-style.command.ts
@@ -57,12 +57,12 @@ export const SetStyleCommand: ICommand<ISetStyleParams<unknown>> = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
const style = params.style;
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
@@ -134,7 +134,7 @@ export const SetBoldCommand: ICommand = {
const worksheet = accessor
.get(ICurrentUniverService)
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet();
const currentlyBold =
worksheet.getRange(selection.primary.actualRow, selection.primary.actualColumn).getFontWeight() ===
@@ -166,7 +166,7 @@ export const SetItalicCommand: ICommand = {
const worksheet = accessor
.get(ICurrentUniverService)
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet();
let currentlyItalic = true;
if (selection.primary) {
@@ -201,7 +201,7 @@ export const SetUnderlineCommand: ICommand = {
const worksheet = accessor
.get(ICurrentUniverService)
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet();
let currentlyUnderline = true;
if (selection.primary) {
@@ -238,7 +238,7 @@ export const SetStrikeThroughCommand: ICommand = {
const worksheet = accessor
.get(ICurrentUniverService)
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet();
let currentlyStrokeThrough = true;
if (selection.primary) {
diff --git a/packages/base-sheets/src/commands/commands/set-tab-color.command.ts b/packages/base-sheets/src/commands/commands/set-tab-color.command.ts
index 1a84e34770..9e883aab1d 100644
--- a/packages/base-sheets/src/commands/commands/set-tab-color.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-tab-color.command.ts
@@ -23,11 +23,11 @@ export const SetTabColorCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-activate.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-activate.command.ts
index e321d5e333..d9ad6a2880 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-activate.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-activate.command.ts
@@ -24,7 +24,7 @@ export const SetWorksheetActivateCommand: ICommand = {
let workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
let worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts
index bdd5f57deb..e539ef11aa 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-col-width.command.ts
@@ -32,7 +32,7 @@ export const DeltaColumnWidthCommand: ICommand<IDeltaColumnWidthCommandParams> =
}
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const workbookId = workbook.getUnitId();
const worksheetId = worksheet.getSheetId();
@@ -123,7 +123,7 @@ export const SetColWidthCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-column-hide.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-column-hide.command.ts
index f2de7e2268..84086f3a9d 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-column-hide.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-column-hide.command.ts
@@ -26,10 +26,10 @@ export const SetWorksheetColumnHideCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-column-show.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-column-show.command.ts
index e7db140019..177aa10e5f 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-column-show.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-column-show.command.ts
@@ -26,10 +26,10 @@ export const SetWorksheetColumnShowCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-hide.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-hide.command.ts
index 95e3a45571..1a5a2262f8 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-hide.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-hide.command.ts
@@ -35,7 +35,7 @@ export const SetWorksheetHideCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
let worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
@@ -43,7 +43,7 @@ export const SetWorksheetHideCommand: ICommand = {
worksheetId = params.worksheetId ?? worksheetId;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-name.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-name.command.ts
index 8265c478b3..7bf836691d 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-name.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-name.command.ts
@@ -27,8 +27,7 @@ export const SetWorksheetNameCommand: ICommand = {
const workbookId = params.workbookId || currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId =
- params.worksheetId ||
- currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();
+ params.worksheetId || currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
const redoMutationParams: ISetWorksheetNameMutationParams = {
worksheetId,
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-order.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-order.command.ts
index a540982ea1..0d66535c53 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-order.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-order.command.ts
@@ -24,10 +24,9 @@ export const SetWorksheetOrderCommand: ICommand = {
const workbookId = params.workbookId || currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId =
- params.worksheetId ||
- currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();
+ params.worksheetId || currentUniverService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-right-to-left.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-right-to-left.command.ts
index 5ba4f24dac..b7ec7f78b6 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-right-to-left.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-right-to-left.command.ts
@@ -32,7 +32,7 @@ export const SetWorksheetRightToLeftCommand: ICommand = {
let workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
let worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
let rightToLeft = BooleanNumber.FALSE;
@@ -43,7 +43,7 @@ export const SetWorksheetRightToLeftCommand: ICommand = {
rightToLeft = params.rightToLeft ?? BooleanNumber.FALSE;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts
index 5944114d9f..75c8ddf7a3 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-row-height.command.ts
@@ -32,7 +32,7 @@ export const DeltaRowHeightCommand: ICommand = {
}
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const workbookId = workbook.getUnitId();
const worksheetId = worksheet.getSheetId();
@@ -117,7 +117,7 @@ export const SetRowHeightCommand: ICommand = {
const selections = selectionManagerService.getRangeDatas();
if (!selections?.length) return false;
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const workbookId = workbook.getUnitId();
const worksheetId = workbook.getActiveSheet().getSheetId();
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-row-hide.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-row-hide.command.ts
index 759913f32c..cb6bdf485e 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-row-hide.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-row-hide.command.ts
@@ -26,10 +26,10 @@ export const SetWorksheetRowHideCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-row-show.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-row-show.command.ts
index 89d2657872..0965db5d35 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-row-show.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-row-show.command.ts
@@ -26,10 +26,10 @@ export const SetWorksheetRowShowCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-worksheet-show.command.ts b/packages/base-sheets/src/commands/commands/set-worksheet-show.command.ts
index c445ee9384..a5f7b69779 100644
--- a/packages/base-sheets/src/commands/commands/set-worksheet-show.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-worksheet-show.command.ts
@@ -35,7 +35,7 @@ export const SetWorksheetShowCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
let worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
@@ -43,7 +43,7 @@ export const SetWorksheetShowCommand: ICommand = {
worksheetId = params.worksheetId ?? worksheetId;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/set-zoom-ratio.command.ts b/packages/base-sheets/src/commands/commands/set-zoom-ratio.command.ts
index ed09856658..c868d6df22 100644
--- a/packages/base-sheets/src/commands/commands/set-zoom-ratio.command.ts
+++ b/packages/base-sheets/src/commands/commands/set-zoom-ratio.command.ts
@@ -25,7 +25,7 @@ export const SetZoomRatioCommand: ICommand = {
let workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
let worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
let zoomRatio = 1;
@@ -36,7 +36,7 @@ export const SetZoomRatioCommand: ICommand = {
zoomRatio = params.zoomRatio ?? zoomRatio;
}
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/commands/trim-whitespace.command.ts b/packages/base-sheets/src/commands/commands/trim-whitespace.command.ts
index 406d00d95f..f8d795ea62 100644
--- a/packages/base-sheets/src/commands/commands/trim-whitespace.command.ts
+++ b/packages/base-sheets/src/commands/commands/trim-whitespace.command.ts
@@ -35,14 +35,11 @@ export const TrimWhitespaceCommand: ICommand = {
const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();
const worksheetId = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
- const worksheet = currentUniverService
- .getUniverSheetInstance(workbookId)
- ?.getWorkBook()
- .getSheetBySheetId(worksheetId);
+ const worksheet = currentUniverService.getUniverSheetInstance(workbookId)?.getSheetBySheetId(worksheetId);
if (!worksheet) return false;
const sheetMatrix = worksheet.getCellMatrix();
const cellValue = new ObjectMatrix<ICellV>();
diff --git a/packages/base-sheets/src/commands/mutations/add-worksheet-merge.mutation.ts b/packages/base-sheets/src/commands/mutations/add-worksheet-merge.mutation.ts
index 14f6629779..aa293012ff 100644
--- a/packages/base-sheets/src/commands/mutations/add-worksheet-merge.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/add-worksheet-merge.mutation.ts
@@ -35,7 +35,7 @@ export const AddWorksheetMergeMutation: IMutation<IAddWorksheetMergeMutationPara
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
const config = worksheet.getConfig()!;
const mergeConfigData = config.mergeData;
diff --git a/packages/base-sheets/src/commands/mutations/delete-range.mutation.ts b/packages/base-sheets/src/commands/mutations/delete-range.mutation.ts
index cd7df7b5e8..41ac696b18 100644
--- a/packages/base-sheets/src/commands/mutations/delete-range.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/delete-range.mutation.ts
@@ -26,7 +26,7 @@ export const DeleteRangeUndoMutationFactory = (
const currentUniverService = accessor.get(ICurrentUniverService);
const worksheet = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getSheetBySheetId(params.worksheetId);
if (!worksheet) return null;
const cellMatrix = worksheet.getCellMatrix();
@@ -79,7 +79,7 @@ export const DeleteRangeMutation: IMutation<IDeleteRangeMutationParams, boolean>
type: CommandType.MUTATION,
handler: async (accessor, params) => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/mutations/insert-range.mutation.ts b/packages/base-sheets/src/commands/mutations/insert-range.mutation.ts
index 91190d3a63..18d3cb5011 100644
--- a/packages/base-sheets/src/commands/mutations/insert-range.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/insert-range.mutation.ts
@@ -25,7 +25,7 @@ export const InsertRangeMutation: IMutation<IInsertRangeMutationParams, boolean>
type: CommandType.MUTATION,
handler: async (accessor, params) => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/mutations/insert-row-col.mutation.ts b/packages/base-sheets/src/commands/mutations/insert-row-col.mutation.ts
index eef10d553d..62b692d179 100644
--- a/packages/base-sheets/src/commands/mutations/insert-row-col.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/insert-row-col.mutation.ts
@@ -38,7 +38,7 @@ export const InsertRowMutation: IMutation<IInsertRowMutationParams> = {
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(worksheetId);
+ const worksheet = universheet.getSheetBySheetId(worksheetId);
if (worksheet == null) {
throw new Error('worksheet is null error!');
}
@@ -100,7 +100,7 @@ export const InsertColMutation: IMutation<IInsertColMutationParams> = {
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
const manager = worksheet.getColumnManager();
const columnPrimitive = manager.getColumnData().toJSON();
diff --git a/packages/base-sheets/src/commands/mutations/insert-sheet.mutation.ts b/packages/base-sheets/src/commands/mutations/insert-sheet.mutation.ts
index 1d7c3615ce..31a96af988 100644
--- a/packages/base-sheets/src/commands/mutations/insert-sheet.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/insert-sheet.mutation.ts
@@ -24,7 +24,7 @@ export const InsertSheetMutation: IMutation<IInsertSheetMutationParams, boolean>
handler: async (accessor, params) => {
const currentUniverService = accessor.get(ICurrentUniverService);
const { sheet, index, workbookId } = params;
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) {
return false;
diff --git a/packages/base-sheets/src/commands/mutations/remove-row-col.mutation.ts b/packages/base-sheets/src/commands/mutations/remove-row-col.mutation.ts
index d3cf271595..289601e3fa 100644
--- a/packages/base-sheets/src/commands/mutations/remove-row-col.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/remove-row-col.mutation.ts
@@ -50,7 +50,7 @@ export const RemoveRowMutation: IMutation<IRemoveRowsMutationParams> = {
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
const manager = worksheet.getRowManager();
@@ -82,7 +82,7 @@ export const IRemoveColMutationFactory = (
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (worksheet == null) {
throw new Error('worksheet is null error!');
@@ -119,7 +119,7 @@ export const RemoveColMutation: IMutation<IRemoveColMutationParams> = {
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
const manager = worksheet.getColumnManager();
diff --git a/packages/base-sheets/src/commands/mutations/remove-sheet.mutation.ts b/packages/base-sheets/src/commands/mutations/remove-sheet.mutation.ts
index 95fd592d48..a45ca5fae2 100644
--- a/packages/base-sheets/src/commands/mutations/remove-sheet.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/remove-sheet.mutation.ts
@@ -15,7 +15,7 @@ export const RemoveSheetUndoMutationFactory = (
params: IRemoveSheetMutationParams
): IInsertSheetMutationParams => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const { worksheetId, workbookId } = params;
const sheet = workbook.getSheetBySheetId(worksheetId)!.getConfig();
const config = workbook!.getConfig();
@@ -34,7 +34,7 @@ export const RemoveSheetMutation: IMutation<IRemoveSheetMutationParams, boolean>
handler: async (accessor, params) => {
const currentUniverService = accessor.get(ICurrentUniverService);
const { worksheetId, workbookId } = params;
- const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(workbookId);
if (!workbook) {
return false;
diff --git a/packages/base-sheets/src/commands/mutations/remove-worksheet-merge.mutation.ts b/packages/base-sheets/src/commands/mutations/remove-worksheet-merge.mutation.ts
index 9f894ccf00..dcedfdddf8 100644
--- a/packages/base-sheets/src/commands/mutations/remove-worksheet-merge.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/remove-worksheet-merge.mutation.ts
@@ -17,7 +17,7 @@ export const RemoveWorksheetMergeMutationFactory = (
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (worksheet == null) {
throw new Error('worksheet is null error!');
}
@@ -53,7 +53,7 @@ export const RemoveWorksheetMergeMutation: IMutation<IRemoveWorksheetMergeMutati
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
const config = worksheet.getConfig();
const mergeConfigData = config.mergeData;
diff --git a/packages/base-sheets/src/commands/mutations/set-border-styles.mutation.ts b/packages/base-sheets/src/commands/mutations/set-border-styles.mutation.ts
index a0f30e36f2..517928d661 100644
--- a/packages/base-sheets/src/commands/mutations/set-border-styles.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-border-styles.mutation.ts
@@ -32,10 +32,10 @@ export const SetBorderStylesUndoMutationFactory = (
params: ISetBorderStylesMutationParams
): ISetBorderStylesMutationParams => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const worksheet = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getSheetBySheetId(params.worksheetId);
const cellMatrix = worksheet?.getCellMatrix();
const styles = workbook.getStyles();
@@ -59,7 +59,7 @@ export const SetBorderStylesMutation: IMutation<ISetBorderStylesMutationParams,
type: CommandType.MUTATION,
handler: async (accessor, params) => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-frozen.mutation.ts b/packages/base-sheets/src/commands/mutations/set-frozen.mutation.ts
index 378f38b119..637e7bdb80 100644
--- a/packages/base-sheets/src/commands/mutations/set-frozen.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-frozen.mutation.ts
@@ -20,7 +20,7 @@ export const SetFrozenMutationFactory = (
if (universheet == null) {
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (worksheet == null) {
throw new Error('worksheet is null error!');
@@ -46,7 +46,7 @@ export const SetFrozenMutation: IMutation<ISetFrozenMutationParams> = {
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
const config = worksheet.getConfig();
const { startRow, startColumn, ySplit, xSplit } = params;
diff --git a/packages/base-sheets/src/commands/mutations/set-hide-gridlines.mutatiom.ts b/packages/base-sheets/src/commands/mutations/set-hide-gridlines.mutatiom.ts
index 09bc318860..7ae99bdcc3 100644
--- a/packages/base-sheets/src/commands/mutations/set-hide-gridlines.mutatiom.ts
+++ b/packages/base-sheets/src/commands/mutations/set-hide-gridlines.mutatiom.ts
@@ -11,7 +11,7 @@ export const SetHideGridlinesUndoMutationFactory = (
accessor: IAccessor,
params: ISetHideGridlinesMutationParams
): ISetHideGridlinesMutationParams => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
const worksheet = workbook!.getSheetBySheetId(params.worksheetId);
const config = worksheet!.getConfig();
@@ -27,7 +27,7 @@ export const SetHideGridlinesMutation: IMutation<ISetHideGridlinesMutationParams
id: 'sheet.mutation.set-hide-gridlines',
type: CommandType.MUTATION,
handler: async (accessor, params) => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-range-formatted-value.mutation.ts b/packages/base-sheets/src/commands/mutations/set-range-formatted-value.mutation.ts
index c995c3a3f5..528f75c2cb 100644
--- a/packages/base-sheets/src/commands/mutations/set-range-formatted-value.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-range-formatted-value.mutation.ts
@@ -33,7 +33,7 @@ export const SetRangeFormattedValueUndoMutationFactory = (
const currentUniverService = accessor.get(ICurrentUniverService);
const worksheet = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getSheetBySheetId(params.worksheetId);
const cellMatrix = worksheet?.getCellMatrix();
@@ -59,7 +59,7 @@ export const SetRangeFormattedValueMutation: IMutation<ISetRangeFormattedValueMu
type: CommandType.MUTATION,
handler: async (accessor, params) => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-range-styles.mutation.ts b/packages/base-sheets/src/commands/mutations/set-range-styles.mutation.ts
index 2b2bb34720..4bdade4341 100644
--- a/packages/base-sheets/src/commands/mutations/set-range-styles.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-range-styles.mutation.ts
@@ -35,10 +35,10 @@ export const SetRangeStyleUndoMutationFactory = (
params: ISetRangeStyleMutationParams
): ISetRangeStyleMutationParams => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const worksheet = currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getSheetBySheetId(params.worksheetId);
if (worksheet == null) {
throw new Error('error');
@@ -78,7 +78,7 @@ export const SetRangeStyleMutation: IMutation<ISetRangeStyleMutationParams, bool
type: CommandType.MUTATION,
handler: async (accessor, params) => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = currentUniverService.getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts
index ebfe1273d5..be971e9516 100644
--- a/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts
@@ -50,7 +50,7 @@ export const SetRangeValuesUndoMutationFactory = (
throw new Error('universheet is null error!');
}
- const workbook = universheet.getWorkBook();
+ const workbook = universheet;
const worksheet = workbook.getSheetBySheetId(worksheetId);
if (worksheet == null) {
@@ -126,7 +126,7 @@ export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, bo
type: CommandType.MUTATION,
handler: async (accessor, params) => {
const currentUniverService = accessor.get(ICurrentUniverService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) {
return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-tab-color.mutation.ts b/packages/base-sheets/src/commands/mutations/set-tab-color.mutation.ts
index 656dc0a791..c4f6e1e0a4 100644
--- a/packages/base-sheets/src/commands/mutations/set-tab-color.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-tab-color.mutation.ts
@@ -11,7 +11,7 @@ export const SetTabColorUndoMutationFactory = (
accessor: IAccessor,
params: ISetTabColorMutationParams
): ISetTabColorMutationParams => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
const worksheet = workbook!.getSheetBySheetId(params.worksheetId);
const config = worksheet!.getConfig();
@@ -27,7 +27,7 @@ export const SetTabColorMutation: IMutation<ISetTabColorMutationParams> = {
id: 'sheet.mutation.set-tab-color',
type: CommandType.MUTATION,
handler: async (accessor, params) => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-activate.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-activate.mutation.ts
index b0f07ac3b2..d72e9da142 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-activate.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-activate.mutation.ts
@@ -16,7 +16,7 @@ export const SetWorksheetUnActivateMutationFactory = (
throw new Error('universheet is null error!');
}
- const worksheets = universheet.getWorkBook().getWorksheets();
+ const worksheets = universheet.getWorksheets();
let activate: Nullable<Worksheet> = null;
for (const [, worksheet] of worksheets) {
@@ -44,7 +44,7 @@ export const SetWorksheetActivateMutation: IMutation<ISetWorksheetActivateMutati
if (!universheet) return false;
- const worksheets = universheet.getWorkBook().getWorksheets();
+ const worksheets = universheet.getWorksheets();
for (const [, worksheet] of worksheets) {
if (worksheet.getSheetId() === params.worksheetId) {
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-col-width.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-col-width.mutation.ts
index fa0b275528..4e8c8c12c6 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-col-width.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-col-width.mutation.ts
@@ -19,7 +19,7 @@ export const SetWorksheetColWidthMutationFactory = (
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (worksheet == null) {
throw new Error('universheet is null error!');
}
@@ -53,7 +53,7 @@ export const SetWorksheetColWidthMutation: IMutation<ISetWorksheetColWidthMutati
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
const defaultColumnWidth = worksheet.getConfig().defaultColumnWidth;
const manager = worksheet.getColumnManager();
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-column-hide.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-column-hide.mutation.ts
index 9768a215ee..24e9152a33 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-column-hide.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-column-hide.mutation.ts
@@ -36,7 +36,7 @@ export const SetWorksheetColumnHideMutation: IMutation<ISetWorksheetColumnHideMu
return false;
}
- const manager = universheet.getWorkBook().getSheetBySheetId(params.worksheetId)!.getColumnManager();
+ const manager = universheet.getSheetBySheetId(params.worksheetId)!.getColumnManager();
for (let i = 0; i < params.ranges.length; i++) {
const range = params.ranges[i];
for (let j = range.startColumn; j < range.startColumn + range.endColumn; j++) {
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-column-show.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-column-show.mutation.ts
index 970d68a9c5..b61855c1a9 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-column-show.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-column-show.mutation.ts
@@ -36,7 +36,7 @@ export const SetWorksheetColumnShowMutation: IMutation<ISetWorksheetColumnShowMu
return false;
}
- const manager = universheet.getWorkBook().getSheetBySheetId(params.worksheetId)!.getColumnManager();
+ const manager = universheet.getSheetBySheetId(params.worksheetId)!.getColumnManager();
for (let i = 0; i < params.ranges.length; i++) {
const range = params.ranges[i];
for (let j = range.startColumn; j < range.startColumn + range.endColumn; j++) {
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-config.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-config.mutation.ts
index 57340ff5c2..f6ae9022aa 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-config.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-config.mutation.ts
@@ -13,7 +13,7 @@ export const SetWorksheetConfigUndoMutationFactory = (
accessor: IAccessor,
params: ISetWorksheetConfigMutationParams
): ISetWorksheetConfigMutationParams => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
const worksheet = workbook!.getSheetBySheetId(params.worksheetId)!;
const config = Tools.deepClone(worksheet.getConfig());
@@ -29,7 +29,7 @@ export const SetWorksheetConfigMutation: IMutation<ISetWorksheetConfigMutationPa
id: 'sheet.mutation.set-worksheet-config',
type: CommandType.MUTATION,
handler: async (accessor, params) => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-hide.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-hide.mutation.ts
index b956ab4873..48c560e698 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-hide.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-hide.mutation.ts
@@ -12,7 +12,7 @@ export const SetWorksheetHideMutationFactory = (
params: ISetWorksheetHideMutationParams
): ISetWorksheetHideMutationParams => {
const universheet = accessor.get(ICurrentUniverService).getCurrentUniverSheetInstance();
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (worksheet == null) {
throw new Error('worksheet is null error!');
}
@@ -33,7 +33,7 @@ export const SetWorksheetHideMutation: IMutation<ISetWorksheetHideMutationParams
return false;
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) {
return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-name.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-name.mutation.ts
index c436f5a00d..41d4df0d19 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-name.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-name.mutation.ts
@@ -12,7 +12,7 @@ export const SetWorksheetNameMutationFactory = (
params: ISetWorksheetNameMutationParams
): ISetWorksheetNameMutationParams => {
const universheet = accessor.get(ICurrentUniverService).getCurrentUniverSheetInstance();
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (worksheet == null) {
throw new Error('worksheet is null error!');
}
@@ -33,7 +33,7 @@ export const SetWorksheetNameMutation: IMutation<ISetWorksheetNameMutationParams
return false;
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) {
return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-order.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-order.mutation.ts
index 32d566e8a4..7a2c6c746e 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-order.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-order.mutation.ts
@@ -11,7 +11,7 @@ export const SetWorksheetOrderUndoMutationFactory = (
accessor: IAccessor,
params: ISetWorksheetOrderMutationParams
): ISetWorksheetOrderMutationParams => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
const config = workbook!.getConfig();
const oldIndex = config.sheetOrder.findIndex((current: string) => current === params.worksheetId);
return {
@@ -24,7 +24,7 @@ export const SetWorksheetOrderMutation: IMutation<ISetWorksheetOrderMutationPara
id: 'sheet.mutation.set-worksheet-order',
type: CommandType.MUTATION,
handler: async (accessor, params) => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const config = workbook.getConfig();
const exclude = config.sheetOrder.filter((currentId: string) => currentId !== params.worksheetId);
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-right-to-left.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-right-to-left.mutation.ts
index 7b3f3cadf8..f2364739d7 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-right-to-left.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-right-to-left.mutation.ts
@@ -11,7 +11,7 @@ export const SetWorksheetRightToLeftUndoMutationFactory = (
accessor: IAccessor,
params: ISetWorksheetRightToLeftMutationParams
): ISetWorksheetRightToLeftMutationParams => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
const worksheet = workbook!.getSheetBySheetId(params.worksheetId);
const config = worksheet!.getConfig();
@@ -27,7 +27,7 @@ export const SetWorksheetRightToLeftMutation: IMutation<ISetWorksheetRightToLeft
id: 'sheet.mutation.set-worksheet-right-to-left',
type: CommandType.MUTATION,
handler: async (accessor, params) => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts
index b55ddbfb04..a5cc991fc6 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts
@@ -19,7 +19,7 @@ export const SetWorksheetRowHeightMutationFactory = (
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (worksheet == null) {
throw new Error('universheet is null error!');
}
@@ -53,7 +53,7 @@ export const SetWorksheetRowHeightMutation: IMutation<ISetWorksheetRowHeightMuta
throw new Error('universheet is null error!');
}
- const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);
+ const worksheet = universheet.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
const defaultRowHeight = worksheet.getConfig().defaultRowHeight;
const manager = worksheet.getRowManager();
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-row-hide.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-row-hide.mutation.ts
index 32819b13b8..ec74c9ece5 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-row-hide.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-row-hide.mutation.ts
@@ -33,7 +33,7 @@ export const SetWorksheetRowHideMutation: IMutation<ISetWorksheetRowHideMutation
throw new Error('universheet is null error!');
}
- const manager = universheet.getWorkBook().getSheetBySheetId(params.worksheetId)!.getRowManager();
+ const manager = universheet.getSheetBySheetId(params.worksheetId)!.getRowManager();
for (let i = 0; i < params.ranges.length; i++) {
const range = params.ranges[i];
diff --git a/packages/base-sheets/src/commands/mutations/set-worksheet-row-show.mutation.ts b/packages/base-sheets/src/commands/mutations/set-worksheet-row-show.mutation.ts
index 5dded80e3d..d408270dde 100644
--- a/packages/base-sheets/src/commands/mutations/set-worksheet-row-show.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-worksheet-row-show.mutation.ts
@@ -33,7 +33,7 @@ export const SetWorksheetRowShowMutation: IMutation<ISetWorksheetRowShowMutation
throw new Error('universheet is null error!');
}
- const manager = universheet.getWorkBook().getSheetBySheetId(params.worksheetId)!.getRowManager();
+ const manager = universheet.getSheetBySheetId(params.worksheetId)!.getRowManager();
for (let i = 0; i < params.ranges.length; i++) {
const range = params.ranges[i];
for (let j = range.startRow; j < range.endRow + 1; j++) {
diff --git a/packages/base-sheets/src/commands/mutations/set-zoom-ratio.mutation.ts b/packages/base-sheets/src/commands/mutations/set-zoom-ratio.mutation.ts
index c0911f2a9a..5945d2d343 100644
--- a/packages/base-sheets/src/commands/mutations/set-zoom-ratio.mutation.ts
+++ b/packages/base-sheets/src/commands/mutations/set-zoom-ratio.mutation.ts
@@ -11,7 +11,7 @@ export const SetZoomRatioUndoMutationFactory = (
accessor: IAccessor,
params: ISetZoomRatioMutationParams
): ISetZoomRatioMutationParams => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
const worksheet = workbook!.getSheetBySheetId(params.worksheetId);
const old = worksheet!.getConfig().zoomRatio;
return {
@@ -24,7 +24,7 @@ export const SetZoomRatioMutation: IMutation<ISetZoomRatioMutationParams> = {
id: 'sheet.mutation.set-zoom-ratio',
type: CommandType.MUTATION,
handler: async (accessor, params) => {
- const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId)?.getWorkBook();
+ const workbook = accessor.get(ICurrentUniverService).getUniverSheetInstance(params.workbookId);
if (!workbook) return false;
const worksheet = workbook.getSheetBySheetId(params.worksheetId);
if (!worksheet) return false;
diff --git a/packages/base-sheets/src/services/sheet-skeleton-manager.service.ts b/packages/base-sheets/src/services/sheet-skeleton-manager.service.ts
index e09a96462b..2d1e6c3121 100644
--- a/packages/base-sheets/src/services/sheet-skeleton-manager.service.ts
+++ b/packages/base-sheets/src/services/sheet-skeleton-manager.service.ts
@@ -63,7 +63,7 @@ export class SheetSkeletonManagerService implements IDisposable {
} else {
const { unitId, sheetId } = searchParm;
- const workbook = this._currentUniverService.getUniverSheetInstance(searchParm.unitId)?.getWorkBook();
+ const workbook = this._currentUniverService.getUniverSheetInstance(searchParm.unitId);
const worksheet = workbook?.getSheetBySheetId(searchParm.sheetId);
diff --git a/packages/base-slides/src/View/Render/CanvasView.ts b/packages/base-slides/src/View/Render/CanvasView.ts
index be446aacdf..99dd88ffbc 100644
--- a/packages/base-slides/src/View/Render/CanvasView.ts
+++ b/packages/base-slides/src/View/Render/CanvasView.ts
@@ -86,7 +86,7 @@ export class CanvasView {
}
activePage(pageId?: string) {
- const model = this._currentUniverService.getCurrentUniverSlideInstance().getSlideModel();
+ const model = this._currentUniverService.getCurrentUniverSlideInstance();
let page: Nullable<ISlidePage>;
if (pageId) {
page = model.getPage(pageId);
@@ -199,7 +199,7 @@ export class CanvasView {
}
private _createSlide() {
- const model = this._currentUniverService.getCurrentUniverSlideInstance().getSlideModel();
+ const model = this._currentUniverService.getCurrentUniverSlideInstance();
const mainScene = this._scene;
if (!mainScene) return;
@@ -227,7 +227,7 @@ export class CanvasView {
}
private _addBackgroundRect(scene: Scene, fill: IColorStyle) {
- const model = this._currentUniverService.getCurrentUniverSlideInstance().getSlideModel();
+ const model = this._currentUniverService.getCurrentUniverSlideInstance();
const pageSize = model.getPageSize();
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index 2738d819b8..1c4cc9cfca 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -1,5 +1,7 @@
+/* eslint-disable @typescript-eslint/no-explicit-any */
import { Ctor, Injector } from '@wendellhu/redi';
+import { DocumentModel } from '../Docs/Domain/DocumentModel';
import { Plugin, PluginCtor, PluginRegistry, PluginStore, PluginType } from '../plugin/plugin';
import { CommandService, ICommandService } from '../services/command/command.service';
import { ConfigService, IConfigService } from '../services/config/config.service';
@@ -12,7 +14,8 @@ import { DesktopLogService, ILogService } from '../services/log/log.service';
import { DesktopPermissionService, IPermissionService } from '../services/permission/permission.service';
import { ThemeService } from '../services/theme/theme.service';
import { IUndoRedoService, LocalUndoRedoService } from '../services/undoredo/undoredo.service';
-import { Nullable } from '../Shared';
+import { Workbook } from '../Sheets/Domain/Workbook';
+import { SlideModel } from '../Slides/Domain/SlideModel';
import { LocaleType } from '../Types/Enum/LocaleType';
import { IDocumentData, ISlideData, IUniverData, IWorkbookConfig } from '../Types/Interfaces';
import { UniverDoc } from './UniverDoc';
@@ -23,27 +26,34 @@ import { UniverSlide } from './UniverSlide';
* Univer.
*/
export class Univer {
- private readonly _univerInjector: Injector;
+ private readonly _rootInjector: Injector;
private readonly _univerPluginStore = new PluginStore();
private readonly _univerPluginRegistry = new PluginRegistry();
+ private _univerSheet: UniverSheet | null = null;
+
+ private _univerDoc: UniverDoc | null = null;
+
+ private _univerSlide: UniverSlide | null = null;
+
constructor(univerData: Partial<IUniverData> = {}) {
- this._univerInjector = this._initDependencies();
+ this._rootInjector = this._initDependencies();
const { theme, locale, locales } = univerData;
- theme && this._univerInjector.get(ThemeService).setTheme(theme);
- locales && this._univerInjector.get(LocaleService).load(locales);
- locale && this._univerInjector.get(LocaleService).setLocale(locale);
+ theme && this._rootInjector.get(ThemeService).setTheme(theme);
+ locales && this._rootInjector.get(LocaleService).load(locales);
+ locale && this._rootInjector.get(LocaleService).setLocale(locale);
}
dispose(): void {
// left empty for purpose
+ // TODO@wzhudev: dispose all the businesses
}
private get _currentUniverService(): ICurrentUniverService {
- return this._univerInjector.get(ICurrentUniverService);
+ return this._rootInjector.get(ICurrentUniverService);
}
/** Register a plugin into univer. */
@@ -51,88 +61,95 @@ export class Univer {
// TODO: type of `configs` could be optimized here using typescript infer
if (plugin.type === PluginType.Univer) {
- this.registerUniverPlugin(plugin, configs);
+ this._registerUniverPlugin(plugin, configs);
} else if (plugin.type === PluginType.Sheet) {
- this.registerSheetPlugin(plugin, configs);
+ this._registerSheetPlugin(plugin, configs);
} else if (plugin.type === PluginType.Doc) {
- this.registerDocPlugin(plugin, configs);
+ this._registerDocPlugin(plugin, configs);
} else if (plugin.type === PluginType.Slide) {
- this.registerSlidePlugin(plugin, configs);
+ this._registerSlidePlugin(plugin, configs);
} else {
throw new Error(`Unimplemented plugin system for business: "${plugin.type}".`);
}
}
setLocale(locale: LocaleType) {
- this._univerInjector.get(LocaleService).setLocale(locale);
+ this._rootInjector.get(LocaleService).setLocale(locale);
}
- /** Create a univer sheet instance with internal dependency injection. */
- createUniverSheet(config: Partial<IWorkbookConfig>): UniverSheet {
- const sheet = this._univerInjector.createInstance(UniverSheet, config);
- this._currentUniverService.addSheet(sheet);
- this.initializePluginsForSheet(sheet);
- this._tryProgressToReady();
- sheet.onReady();
- return sheet;
- }
+ /**
+ * Create a univer sheet instance with internal dependency injection.
+ */
+ createUniverSheet(config: Partial<IWorkbookConfig>): Workbook {
+ let workbook: Workbook;
+ const addSheet = () => {
+ workbook = this._univerSheet!.createSheet(config);
+ this._currentUniverService.addSheet(workbook);
+ };
+
+ if (!this._univerSheet) {
+ this._univerSheet = this._rootInjector.createInstance(UniverSheet);
+ addSheet();
+
+ this._univerPluginRegistry
+ .getRegisterPlugins(PluginType.Sheet)
+ .forEach((p) => this._univerSheet!.addPlugin(p.plugin as unknown as PluginCtor<any>, p.options));
+ this._univerSheet.init();
+
+ this._tryProgressToReady();
+ } else {
+ addSheet();
+ }
- createUniverDoc(config: Partial<IDocumentData>): UniverDoc {
- const doc = this._univerInjector.createInstance(UniverDoc, config);
- this._currentUniverService.addDoc(doc);
- this.initializePluginsForDoc(doc);
- this._tryProgressToReady();
- doc.onReady();
- return doc;
+ return workbook!;
}
- createUniverSlide(config: Partial<ISlideData>): UniverSlide {
- const slide = this._univerInjector.createInstance(UniverSlide, config);
- this._currentUniverService.addSlide(slide);
- this.initializePluginsForSlide(slide);
- this._tryProgressToReady();
- slide.onReady();
- return slide;
- }
+ createUniverDoc(config: Partial<IDocumentData>): DocumentModel {
+ let doc: DocumentModel;
+ const addDoc = () => {
+ doc = this._univerDoc!.createDoc(config);
+ this._currentUniverService.addDoc(doc);
+ };
- getUniverSheetInstance(id: string): Nullable<UniverSheet> {
- return this._currentUniverService.getUniverSheetInstance(id);
- }
+ if (!this._univerDoc) {
+ this._univerDoc = this._rootInjector.createInstance(UniverDoc);
+ addDoc();
- getUniverDocInstance(id: string): Nullable<UniverDoc> {
- return this._currentUniverService.getUniverDocInstance(id);
- }
+ this._univerPluginRegistry
+ .getRegisterPlugins(PluginType.Doc)
+ .forEach((p) => this._univerDoc!.addPlugin(p.plugin as unknown as PluginCtor<any>, p.options));
+ this._univerDoc.init();
- getUniverSlideInstance(id: string): Nullable<UniverSheet> {
- return null;
- }
+ this._tryProgressToReady();
+ } else {
+ addDoc();
+ }
- getAllUniverSheetsInstance() {
- return this._currentUniverService.getAllUniverSheetsInstance();
+ return doc!;
}
- getAllUniverDocsInstance() {
- return this._currentUniverService.getAllUniverDocsInstance();
- }
+ createUniverSlide(config: Partial<ISlideData>): SlideModel {
+ let slide: SlideModel;
+ const addSlide = () => {
+ slide = this._univerSlide!.createSlide(config);
+ this._currentUniverService.addSlide(slide);
+ };
- getAllUniverSlidesInstance() {
- return this._currentUniverService.getAllUniverSlidesInstance();
- }
+ if (!this._univerSlide) {
+ this._univerSlide = this._rootInjector.createInstance(UniverSlide);
+ addSlide();
- /**
- * get active universheet
- * @returns
- */
- getCurrentUniverSheetInstance() {
- return this._currentUniverService.getCurrentUniverSheetInstance();
- }
+ this._univerPluginRegistry
+ .getRegisterPlugins(PluginType.Slide)
+ .forEach((p) => this._univerSlide!.addPlugin(p.plugin as unknown as PluginCtor<any>, p.options));
+ this._univerSlide.init();
- getCurrentUniverDocInstance() {
- return this._currentUniverService.getCurrentUniverDocInstance();
- }
+ this._tryProgressToReady();
+ } else {
+ addSlide();
+ }
- getCurrentUniverSlideInstance() {
- return this._currentUniverService.getCurrentUniverSlideInstance();
+ return slide!;
}
private _initDependencies(): Injector {
@@ -163,67 +180,60 @@ export class Univer {
}
private _tryProgressToReady(): void {
- const lifecycleService = this._univerInjector.get(LifecycleService);
+ const lifecycleService = this._rootInjector.get(LifecycleService);
if (lifecycleService.stage < LifecycleStages.Ready) {
this._univerPluginStore.forEachPlugin((p) => p.onReady());
- // TODO: call UniverSheet etc on ready.
- this._univerInjector.get(LifecycleService).stage = LifecycleStages.Ready;
+ this._rootInjector.get(LifecycleService).stage = LifecycleStages.Ready;
}
}
- private registerUniverPlugin<T extends Plugin>(plugin: PluginCtor<T>, options?: any): void {
+ private _registerUniverPlugin<T extends Plugin>(plugin: PluginCtor<T>, options?: any): void {
// For plugins at Univer level. Plugins would be initialized immediately so they can register dependencies.
- const pluginInstance: Plugin = this._univerInjector.createInstance(plugin as unknown as Ctor<any>, options);
- pluginInstance.onStarting(this._univerInjector);
+ const pluginInstance: Plugin = this._rootInjector.createInstance(plugin as unknown as Ctor<any>, options);
+ pluginInstance.onStarting(this._rootInjector);
this._univerPluginStore.addPlugin(pluginInstance);
}
- private registerSheetPlugin<T extends Plugin>(pluginCtor: PluginCtor<T>, options?: any) {
+ private _registerSheetPlugin<T extends Plugin>(pluginCtor: PluginCtor<T>, options?: any) {
this._univerPluginRegistry.registerPlugin(pluginCtor, options);
+ // TODO: implement add plugin when Univer business object is created
// Add plugins to the plugin registration. And for each initialized UniverSheet, instantiate these dependencies immediately.
- const sheets = this._currentUniverService.getAllUniverSheetsInstance();
- if (sheets.length) {
- sheets.forEach((sheet) => {
- sheet.addPlugin(pluginCtor, options);
- });
- }
+ // const sheets = this._currentUniverService.getAllUniverSheetsInstance();
+ // if (sheets.length) {
+ // sheets.forEach((sheet) => {
+ // sheet.addPlugin(pluginCtor, options);
+ // });
+ // }
}
- private registerDocPlugin<T extends Plugin>(pluginCtor: PluginCtor<T>, options?: any) {
+ private _registerDocPlugin<T extends Plugin>(pluginCtor: PluginCtor<T>, options?: any) {
this._univerPluginRegistry.registerPlugin(pluginCtor, options);
- const docs = this._currentUniverService.getAllUniverDocsInstance();
- if (docs.length) {
- docs.forEach((doc) => {
- doc.addPlugin(pluginCtor, options);
- });
- }
+ // const docs = this._currentUniverService.getAllUniverDocsInstance();
+ // if (docs.length) {
+ // docs.forEach((doc) => {
+ // doc.addPlugin(pluginCtor, options);
+ // });
+ // }
}
- private registerSlidePlugin<T extends Plugin>(pluginCtor: PluginCtor<T>, options?: any) {
+ private _registerSlidePlugin<T extends Plugin>(pluginCtor: PluginCtor<T>, options?: any) {
this._univerPluginRegistry.registerPlugin(pluginCtor, options);
- const slides = this._currentUniverService.getAllUniverSlidesInstance();
- if (slides.length) {
- slides.forEach((slide) => {
- slide.addPlugin(pluginCtor, options);
- });
- }
- }
-
- private initializePluginsForSheet(sheet: UniverSheet): void {
- const plugins = this._univerPluginRegistry.getRegisterPlugins(PluginType.Sheet);
- plugins.forEach((p) => {
- sheet.addPlugin(p.plugin as unknown as PluginCtor<any>, p.options);
- });
+ // const slides = this._currentUniverService.getAllUniverSlidesInstance();
+ // if (slides.length) {
+ // slides.forEach((slide) => {
+ // slide.addPlugin(pluginCtor, options);
+ // });
+ // }
}
- private initializePluginsForDoc(doc: UniverDoc): void {
+ private _initializePluginsForDoc(doc: UniverDoc): void {
const plugins = this._univerPluginRegistry.getRegisterPlugins(PluginType.Doc);
plugins.forEach((p) => {
doc.addPlugin(p.plugin as unknown as PluginCtor<any>, p.options);
});
}
- private initializePluginsForSlide(slide: UniverSlide): void {
+ private _initializePluginsForSlide(slide: UniverSlide): void {
const plugins = this._univerPluginRegistry.getRegisterPlugins(PluginType.Slide);
plugins.forEach((p) => {
slide.addPlugin(p.plugin as unknown as PluginCtor<any>, p.options);
diff --git a/packages/core/src/Basics/UniverDoc.ts b/packages/core/src/Basics/UniverDoc.ts
index d1bd293571..afee3151a4 100644
--- a/packages/core/src/Basics/UniverDoc.ts
+++ b/packages/core/src/Basics/UniverDoc.ts
@@ -1,51 +1,60 @@
-import { Ctor, Dependency, Inject, Injector, Optional } from '@wendellhu/redi';
+import { Ctor, Dependency, Injector, Optional } from '@wendellhu/redi';
import { DocumentModel } from '../Docs/Domain/DocumentModel';
import { Plugin, PluginCtor, PluginStore } from '../plugin/plugin';
import { CommandService, ICommandService } from '../services/command/command.service';
import { LifecycleStages } from '../services/lifecycle/lifecycle';
import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';
-import { IDocumentData } from '../Types/Interfaces';
-
+import { Disposable, toDisposable } from '../Shared/lifecycle';
+import { IDocumentData } from '../Types/Interfaces/IDocumentData';
/**
* Externally provided UniverDoc root instance
*/
-export class UniverDoc {
- univerDocConfig: Partial<IDocumentData>;
-
- private readonly _document: DocumentModel;
-
+export class UniverDoc extends Disposable {
private readonly _pluginStore = new PluginStore();
private readonly _injector: Injector;
- constructor(
- docData: Partial<IDocumentData> = {},
- @Optional(Injector) _injector: Injector,
- @Inject(LifecycleService) private readonly _lifecycleService: LifecycleService
- ) {
- this.univerDocConfig = docData;
- this._injector = this._initializeDependencies(_injector);
- this._document = this._injector.createInstance(DocumentModel, docData);
+ constructor(@Optional(Injector) _injector: Injector) {
+ super();
- this._lifecycleService.lifecycle$.subscribe((stage) => {
- if (stage === LifecycleStages.Rendered) {
- this._pluginStore.forEachPlugin((p) => p.onRendered());
- }
- });
-
- this._injector.get(LifecycleInitializerService).start();
+ this._injector = this._initDependencies(_injector);
}
- getDocument(): DocumentModel {
- return this._document;
+ init(): void {
+ this.disposeWithMe(
+ toDisposable(
+ this._injector
+ .get(LifecycleService)
+ .subscribeWithPrevious()
+ .subscribe((stage) => {
+ if (stage === LifecycleStages.Starting) {
+ this._pluginStore.forEachPlugin((p) => p.onStarting(this._injector));
+ return;
+ }
+
+ if (stage === LifecycleStages.Ready) {
+ this._pluginStore.forEachPlugin((p) => p.onReady());
+ return;
+ }
+
+ if (stage === LifecycleStages.Rendered) {
+ this._pluginStore.forEachPlugin((p) => p.onRendered());
+ return;
+ }
+
+ if (stage === LifecycleStages.Steady) {
+ this._pluginStore.forEachPlugin((p) => p.onSteady());
+ }
+ })
+ )
+ );
+
+ this._injector.get(LifecycleInitializerService).start();
}
- /**
- * get unit id
- */
- getUnitId(): string {
- return this._document.getUnitId();
+ createDoc(docData: Partial<IDocumentData>): DocumentModel {
+ return this._injector.createInstance(DocumentModel, docData);
}
addPlugin<T extends Plugin>(pluginCtor: PluginCtor<T>, options: any): void {
@@ -54,11 +63,7 @@ export class UniverDoc {
this._pluginStore.addPlugin(pluginInstance);
}
- onReady(): void {
- this._pluginStore.forEachPlugin((p) => p.onReady());
- }
-
- private _initializeDependencies(parentInjector?: Injector): Injector {
+ private _initDependencies(parentInjector?: Injector): Injector {
const dependencies: Dependency[] = [
[ICommandService, { useClass: CommandService }],
[LifecycleInitializerService],
diff --git a/packages/core/src/Basics/UniverSheet.ts b/packages/core/src/Basics/UniverSheet.ts
index f97f444ee1..6a4aa43de9 100644
--- a/packages/core/src/Basics/UniverSheet.ts
+++ b/packages/core/src/Basics/UniverSheet.ts
@@ -1,56 +1,71 @@
-import { Ctor, Dependency, IDisposable, Injector, Optional } from '@wendellhu/redi';
+/* eslint-disable @typescript-eslint/no-explicit-any */
+import { Ctor, Dependency, IDisposable, Inject, Injector } from '@wendellhu/redi';
import { Plugin, PluginCtor, PluginStore } from '../plugin/plugin';
import { CommandService, ICommandService } from '../services/command/command.service';
-import { LifecycleInitializerService } from '../services/lifecycle/lifecycle.service';
+import { LifecycleStages } from '../services/lifecycle/lifecycle';
+import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';
import { GenName } from '../Shared/GenName';
-import { Logger } from '../Shared/Logger';
+import { Disposable, toDisposable } from '../Shared/lifecycle';
import { Workbook } from '../Sheets/Domain';
-import { IWorkbookConfig } from '../Types/Interfaces';
-import { VersionCode, VersionEnv } from './Version';
+import { IWorkbookConfig } from '../Types/Interfaces/IWorkbookData';
/**
* Externally provided UniverSheet root instance
*/
-export class UniverSheet implements IDisposable {
- univerSheetConfig: Partial<IWorkbookConfig>;
-
- private readonly _sheetInjector: Injector;
-
- // TODO@wzhudev: maybe we should support multiple workbooks in the future?
- private readonly _workbook: Workbook;
+export class UniverSheet extends Disposable implements IDisposable {
+ private readonly _injector: Injector;
private readonly _pluginStore = new PluginStore();
- constructor(univerSheetData: Partial<IWorkbookConfig> = {}, @Optional(Injector) parentInjector?: Injector) {
- this.univerSheetConfig = univerSheetData;
+ constructor(@Inject(Injector) parentInjector: Injector) {
+ super();
- this._sheetInjector = this._initDependencies(parentInjector);
- this._workbook = this._sheetInjector.createInstance(Workbook, univerSheetData);
- this._sheetInjector.get(LifecycleInitializerService).start();
+ this._injector = this._initDependencies(parentInjector);
}
- static newInstance(univerSheetData: Partial<IWorkbookConfig> = {}): UniverSheet {
- Logger.capsule(VersionEnv, VersionCode, 'powered by :: universheet :: ');
- return new UniverSheet(univerSheetData);
- }
+ init(): void {
+ this.disposeWithMe(
+ toDisposable(
+ this._injector
+ .get(LifecycleService)
+ .subscribeWithPrevious()
+ .subscribe((stage) => {
+ if (stage === LifecycleStages.Starting) {
+ this._pluginStore.forEachPlugin((p) => p.onStarting(this._injector));
+ return;
+ }
- /**
- * get unit id
- */
- getUnitId(): string {
- return this.getWorkBook().getUnitId();
- }
+ if (stage === LifecycleStages.Ready) {
+ this._pluginStore.forEachPlugin((p) => p.onReady());
+ return;
+ }
+
+ if (stage === LifecycleStages.Rendered) {
+ this._pluginStore.forEachPlugin((p) => p.onRendered());
+ return;
+ }
+
+ if (stage === LifecycleStages.Steady) {
+ this._pluginStore.forEachPlugin((p) => p.onSteady());
+ }
+ })
+ )
+ );
- getWorkBook(): Workbook {
- return this._workbook;
+ this._injector.get(LifecycleInitializerService).start();
}
- onReady(): void {
- this._pluginStore.forEachPlugin((p) => p.onReady());
+ createSheet(workbookConfig: Partial<IWorkbookConfig>): Workbook {
+ const workbook = this._injector.createInstance(Workbook, workbookConfig);
+ return workbook;
}
- dispose(): void {}
+ override dispose(): void {
+ super.dispose();
+
+ this._pluginStore.removePlugins();
+ }
/**
* Add a plugin into UniverSheet. UniverSheet should add dependencies exposed from this plugin to its DI system.
@@ -61,8 +76,7 @@ export class UniverSheet implements IDisposable {
* @internal
*/
addPlugin<T extends Plugin>(plugin: PluginCtor<T>, options: any): void {
- const pluginInstance: Plugin = this._sheetInjector.createInstance(plugin as unknown as Ctor<any>, options);
- pluginInstance.onStarting(this._sheetInjector);
+ const pluginInstance: Plugin = this._injector.createInstance(plugin as unknown as Ctor<any>, options);
this._pluginStore.addPlugin(pluginInstance);
}
diff --git a/packages/core/src/Basics/UniverSlide.ts b/packages/core/src/Basics/UniverSlide.ts
index b62744ce9d..0b8b580972 100644
--- a/packages/core/src/Basics/UniverSlide.ts
+++ b/packages/core/src/Basics/UniverSlide.ts
@@ -1,45 +1,71 @@
-import { Ctor, Dependency, Inject, Injector, Optional } from '@wendellhu/redi';
+import { Ctor, Dependency, Injector, Optional } from '@wendellhu/redi';
+import { ISlideData, SlideModel } from '..';
import { Plugin, PluginCtor, PluginStore } from '../plugin/plugin';
import { CommandService, ICommandService } from '../services/command/command.service';
import { LifecycleStages } from '../services/lifecycle/lifecycle';
import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';
import { GenName } from '../Shared';
-import { SlideModel } from '../Slides/Domain';
-import { ISlideData } from '../Types/Interfaces';
+import { Disposable, toDisposable } from '../Shared/lifecycle';
/**
* Externally provided UniverSlide root instance
*/
-export class UniverSlide {
- _univerSlideConfig: Partial<ISlideData>;
-
+export class UniverSlide extends Disposable {
private readonly _injector: Injector;
- private readonly _slideModel: SlideModel;
-
private readonly _pluginStore = new PluginStore();
- constructor(
- UniverSlideData: Partial<ISlideData> = {},
- @Optional(Injector) parentInjector: Injector,
- @Inject(LifecycleService) private readonly _lifecycleService: LifecycleService
- ) {
- this._univerSlideConfig = UniverSlideData;
- this._injector = this._initializeDependencies(parentInjector);
- this._slideModel = this._injector.createInstance(SlideModel, UniverSlideData);
+ constructor(@Optional(Injector) parentInjector: Injector) {
+ super();
+
+ this._injector = this._initDependencies(parentInjector);
+ // this._slideModel = this._injector.createInstance(SlideModel, UniverSlideData);
+
+ // this._lifecycleService.lifecycle$.subscribe((stage) => {
+ // if (stage === LifecycleStages.Rendered) {
+ // this._pluginStore.forEachPlugin((p) => p.onRendered());
+ // }
+ // });
+
+ // this._injector.get(LifecycleInitializerService).start();
+ }
+
+ init(): void {
+ this.disposeWithMe(
+ toDisposable(
+ this._injector
+ .get(LifecycleService)
+ .subscribeWithPrevious()
+ .subscribe((stage) => {
+ if (stage === LifecycleStages.Starting) {
+ this._pluginStore.forEachPlugin((p) => p.onStarting(this._injector));
+ return;
+ }
- this._lifecycleService.lifecycle$.subscribe((stage) => {
- if (stage === LifecycleStages.Rendered) {
- this._pluginStore.forEachPlugin((p) => p.onRendered());
- }
- });
+ if (stage === LifecycleStages.Ready) {
+ this._pluginStore.forEachPlugin((p) => p.onReady());
+ return;
+ }
+
+ if (stage === LifecycleStages.Rendered) {
+ this._pluginStore.forEachPlugin((p) => p.onRendered());
+ return;
+ }
+
+ if (stage === LifecycleStages.Steady) {
+ this._pluginStore.forEachPlugin((p) => p.onSteady());
+ }
+ })
+ )
+ );
this._injector.get(LifecycleInitializerService).start();
}
- getUnitId(): string {
- return this._slideModel.getUnitId();
+ createSlide(data: Partial<ISlideData>): SlideModel {
+ const slide = this._injector.createInstance(SlideModel, data);
+ return slide;
}
/**
@@ -52,20 +78,10 @@ export class UniverSlide {
*/
addPlugin<T extends Plugin>(plugin: PluginCtor<T>, options: any): void {
const pluginInstance: Plugin = this._injector.createInstance(plugin as unknown as Ctor<any>, options);
-
- pluginInstance.onRendered();
this._pluginStore.addPlugin(pluginInstance);
}
- onReady(): void {
- this._pluginStore.forEachPlugin((p) => p.onReady());
- }
-
- getSlideModel() {
- return this._slideModel;
- }
-
- private _initializeDependencies(parentInjector?: Injector): Injector {
+ private _initDependencies(parentInjector?: Injector): Injector {
const dependencies: Dependency[] = [
[GenName],
[LifecycleInitializerService],
diff --git a/packages/core/src/services/current.service.ts b/packages/core/src/services/current.service.ts
index a6a2f284c7..61a1b0984d 100644
--- a/packages/core/src/services/current.service.ts
+++ b/packages/core/src/services/current.service.ts
@@ -1,17 +1,17 @@
import { createIdentifier } from '@wendellhu/redi';
import { BehaviorSubject, Observable } from 'rxjs';
-import { UniverDoc } from '../Basics/UniverDoc';
-import { UniverSheet } from '../Basics/UniverSheet';
-import { UniverSlide } from '../Basics/UniverSlide';
+import { DocumentModel } from '../Docs/Domain/DocumentModel';
import { Nullable } from '../Shared';
import { Disposable } from '../Shared/lifecycle';
+import { Workbook } from '../Sheets/Domain/Workbook';
+import { SlideModel } from '../Slides/Domain/SlideModel';
import { IDocumentData } from '../Types/Interfaces';
import { FOCUSING_DOC, FOCUSING_SHEET, FOCUSING_SLIDE } from './context/context';
import { IContextService } from './context/context.service';
export interface IUniverHandler {
- createUniverDoc(data: Partial<IDocumentData>): UniverDoc;
+ createUniverDoc(data: Partial<IDocumentData>): DocumentModel;
}
/**
@@ -19,53 +19,65 @@ export interface IUniverHandler {
* the focused univer instance.
*/
export interface ICurrentUniverService {
- focused$: Observable<string | null>;
+ focused$: Observable<Nullable<string>>;
- createDoc(data: Partial<IDocumentData>): UniverDoc;
+ // TODO: sheet doc slide added event
- addSheet(sheet: UniverSheet): void;
- addSlide(slide: UniverSlide): void;
- addDoc(doc: UniverDoc): void;
+ createDoc(data: Partial<IDocumentData>): DocumentModel;
- getUniverSheetInstance(id: string): Nullable<UniverSheet>;
- getUniverDocInstance(id: string): Nullable<UniverDoc>;
- getUniverSlideInstance(id: string): Nullable<UniverSlide>;
+ addDoc(doc: DocumentModel): void;
+ addSheet(sheet: Workbook): void;
+ addSlide(slide: SlideModel): void;
- // TODO: this should be nullable
- getCurrentUniverSheetInstance(): UniverSheet;
- getCurrentUniverDocInstance(): UniverDoc;
- getCurrentUniverSlideInstance(): UniverSlide;
- getAllUniverSheetsInstance(): UniverSheet[];
- getAllUniverDocsInstance(): UniverDoc[];
- getAllUniverSlidesInstance(): UniverSlide[];
+ getUniverSheetInstance(id: string): Nullable<Workbook>;
+ getUniverDocInstance(id: string): Nullable<DocumentModel>;
+ getUniverSlideInstance(id: string): Nullable<SlideModel>;
- getFocusedUniverInstance(): UniverSheet | UniverDoc | UniverSlide | null;
+ getCurrentUniverSheetInstance(): Workbook;
+ getCurrentUniverDocInstance(): DocumentModel;
+ getCurrentUniverSlideInstance(): SlideModel;
+ setCurrentUniverSheetInstance(id: string): void;
+ setCurrentUniverDocInstance(id: string): void;
+ setCurrentUniverSlideInstance(id: string): void;
+
+ getAllUniverSheetsInstance(): Workbook[];
+ getAllUniverDocsInstance(): DocumentModel[];
+ getAllUniverSlidesInstance(): SlideModel[];
+
+ // TODO: set current method
+
+ getFocusedUniverInstance(): Workbook | DocumentModel | SlideModel | null;
focusUniverInstance(id: string | null): void;
}
export const ICurrentUniverService = createIdentifier<ICurrentUniverService>('univer.current');
export class CurrentUniverService extends Disposable implements ICurrentUniverService {
- readonly focused$: Observable<string | null>;
+ private readonly _focused$ = new BehaviorSubject<Nullable<string>>(null);
+ readonly focused$ = this._focused$.asObservable();
+
+ private readonly _currentSheet$ = new BehaviorSubject<Nullable<Workbook>>(null);
+ readonly currentSheet$ = this._currentSheet$.asObservable();
- private readonly _focused$: BehaviorSubject<string | null>;
+ private readonly _currentDoc$ = new BehaviorSubject<Nullable<DocumentModel>>(null);
+ readonly currentDoc$ = this._currentDoc$.asObservable();
- private _focused: UniverDoc | UniverSheet | UniverSlide | null = null;
+ private readonly _currentSlide$ = new BehaviorSubject<Nullable<SlideModel>>(null);
+ readonly currentSlide$ = this._currentSlide$.asObservable();
- private readonly _sheets: UniverSheet[] = [];
+ private _focused: DocumentModel | Workbook | SlideModel | null = null;
- private readonly _docs: UniverDoc[] = [];
+ private readonly _sheets: Workbook[] = [];
- private readonly _slides: UniverSlide[] = [];
+ private readonly _docs: DocumentModel[] = [];
+
+ private readonly _slides: SlideModel[] = [];
constructor(
private readonly _handler: IUniverHandler,
@IContextService private readonly _contextService: IContextService
) {
super();
-
- this._focused$ = new BehaviorSubject<string | null>(null);
- this.focused$ = this._focused$.asObservable();
}
override dispose(): void {
@@ -74,31 +86,34 @@ export class CurrentUniverService extends Disposable implements ICurrentUniverSe
this._focused$.complete();
}
- createDoc(data: Partial<IDocumentData>): UniverDoc {
+ createDoc(data: Partial<IDocumentData>): DocumentModel {
return this._handler.createUniverDoc(data);
}
- addSheet(sheet: UniverSheet): void {
+ addSheet(sheet: Workbook): void {
this._sheets.push(sheet);
+ this.setCurrentUniverSheetInstance(sheet.getUnitId());
}
- addDoc(doc: UniverDoc): void {
+ addDoc(doc: DocumentModel): void {
this._docs.push(doc);
+ this.setCurrentUniverDocInstance(doc.getUnitId());
}
- addSlide(slide: UniverSlide): void {
+ addSlide(slide: SlideModel): void {
this._slides.push(slide);
+ this.setCurrentUniverSlideInstance(slide.getUnitId());
}
- getUniverSheetInstance(id: string): Nullable<UniverSheet> {
+ getUniverSheetInstance(id: string): Nullable<Workbook> {
return this._sheets.find((sheet) => sheet.getUnitId() === id);
}
- getUniverDocInstance(id: string): Nullable<UniverDoc> {
+ getUniverDocInstance(id: string): Nullable<DocumentModel> {
return this._docs.find((doc) => doc.getUnitId() === id);
}
- getUniverSlideInstance(id: string): Nullable<UniverSlide> {
+ getUniverSlideInstance(id: string): Nullable<SlideModel> {
return this._slides.find((slide) => slide.getUnitId() === id);
}
@@ -114,20 +129,40 @@ export class CurrentUniverService extends Disposable implements ICurrentUniverSe
return this._slides;
}
- /**
- * get active universheet
- * @returns
- */
- getCurrentUniverSheetInstance() {
- return this._sheets[0];
+ setCurrentUniverSheetInstance(id: string): void {
+ this._currentSheet$.next(this.getUniverSheetInstance(id) || null);
+ }
+
+ setCurrentUniverSlideInstance(id: string): void {
+ this._currentSlide$.next(this.getUniverSlideInstance(id) || null);
}
- getCurrentUniverDocInstance() {
- return this._docs[0];
+ setCurrentUniverDocInstance(id: string): void {
+ this._currentDoc$.next(this.getUniverDocInstance(id) || null);
+ }
+
+ getCurrentUniverSheetInstance(): Workbook {
+ const sheet = this._currentSheet$.getValue();
+ if (!sheet) {
+ throw new Error('No current sheet!');
+ }
+ return sheet;
+ }
+
+ getCurrentUniverDocInstance(): DocumentModel {
+ const doc = this._currentDoc$.getValue();
+ if (!doc) {
+ throw new Error('No current doc!');
+ }
+ return doc;
}
getCurrentUniverSlideInstance() {
- return this._slides[0];
+ const slide = this._currentSlide$.getValue();
+ if (!slide) {
+ throw new Error('No current slide!');
+ }
+ return slide;
}
focusUniverInstance(id: string | null): void {
@@ -143,16 +178,16 @@ export class CurrentUniverService extends Disposable implements ICurrentUniverSe
[FOCUSING_DOC, FOCUSING_SHEET, FOCUSING_SLIDE].forEach((k) => this._contextService.setContextValue(k, false));
- if (this._focused instanceof UniverSheet) {
+ if (this._focused instanceof Workbook) {
this._contextService.setContextValue(FOCUSING_SHEET, true);
- } else if (this._focused instanceof UniverDoc) {
+ } else if (this._focused instanceof DocumentModel) {
this._contextService.setContextValue(FOCUSING_DOC, true);
- } else if (this._focused instanceof UniverSlide) {
+ } else if (this._focused instanceof SlideModel) {
this._contextService.setContextValue(FOCUSING_SLIDE, true);
}
}
- getFocusedUniverInstance(): UniverSheet | UniverDoc | UniverSlide | null {
+ getFocusedUniverInstance(): Workbook | DocumentModel | SlideModel | null {
return this._focused;
}
}
diff --git a/packages/core/src/services/lifecycle/lifecycle.service.ts b/packages/core/src/services/lifecycle/lifecycle.service.ts
index 7ebc11f1af..0cac3bdb0f 100644
--- a/packages/core/src/services/lifecycle/lifecycle.service.ts
+++ b/packages/core/src/services/lifecycle/lifecycle.service.ts
@@ -1,5 +1,5 @@
import { Inject, Injector } from '@wendellhu/redi';
-import { BehaviorSubject } from 'rxjs';
+import { BehaviorSubject, Observable } from 'rxjs';
import { Disposable, toDisposable } from '../../Shared/lifecycle';
import { ILogService } from '../log/log.service';
@@ -35,6 +35,26 @@ export class LifecycleService extends Disposable {
// this._logService.log('[LifecycleService]', `lifecycle progressed to "${LifecycleNameMap[stage]}".`);
this._lifecycle$.next(stage);
}
+
+ subscribeWithPrevious(): Observable<LifecycleStages> {
+ return new Observable<LifecycleStages>((subscriber) => {
+ // before subscribe, emit the current stage and all previous stages
+ if (this.stage === LifecycleStages.Starting) {
+ // do nothing
+ } else if (this.stage === LifecycleStages.Ready) {
+ subscriber.next(LifecycleStages.Starting);
+ } else if (this.stage === LifecycleStages.Rendered) {
+ subscriber.next(LifecycleStages.Starting);
+ subscriber.next(LifecycleStages.Ready);
+ } else {
+ subscriber.next(LifecycleStages.Starting);
+ subscriber.next(LifecycleStages.Ready);
+ subscriber.next(LifecycleStages.Rendered);
+ }
+
+ return this._lifecycle$.subscribe(subscriber);
+ });
+ }
}
export class LifecycleInitializerService extends Disposable {
@@ -47,7 +67,9 @@ export class LifecycleInitializerService extends Disposable {
start(): void {
this.disposeWithMe(
- toDisposable(this._lifecycleService.lifecycle$.subscribe((stage) => this._initModulesOnStage(stage)))
+ toDisposable(
+ this._lifecycleService.subscribeWithPrevious().subscribe((stage) => this._initModulesOnStage(stage))
+ )
);
}
diff --git a/packages/sheets-plugin-find/src/Domain/TextFind.ts b/packages/sheets-plugin-find/src/Domain/TextFind.ts
index 0269f8ce3d..1337895fd9 100644
--- a/packages/sheets-plugin-find/src/Domain/TextFind.ts
+++ b/packages/sheets-plugin-find/src/Domain/TextFind.ts
@@ -1,370 +1,370 @@
-import { ISelectionTransformerShapeManager } from '@univerjs/base-render';
-import { SelectionManagerService } from '@univerjs/base-sheets';
-import {
- FormatType,
- ICellData,
- ICurrentUniverService,
- IGridRange,
- Nullable,
- ObjectMatrix,
- Range,
- Worksheet,
-} from '@univerjs/core';
-import { Inject } from '@wendellhu/redi';
-
-import { FindType } from '../IData';
-import { getRegExpStr } from '../Util/util';
-import { SelectSearch } from '../View/UI/FindModal';
-
-export class TextFinder {
- private _text: string | FormatType = '';
-
- private _type: FindType = 'text'; // 查找类型
-
- private _searchRange: SelectSearch = SelectSearch.CurrentSheet; //查找范围
-
- private _range: IGridRange[] = []; // 保存匹配到的单元格range格式
-
- private _rangeData: IGridRange[] = []; // rangList每个单元格range格式
-
- private _index: number = -1;
-
- private _matchCase: boolean = false; // 大小写匹配
-
- private _matchEntire: boolean = false; // 完全匹配
-
- private _useRegEx: boolean = false; // 正则匹配
-
- private _matchFormula: boolean = false; // 匹配公式文字
-
- private _startRange: Nullable<Range>; // 从这个位置后开始找
-
- constructor(
- @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
- @Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
- @ISelectionTransformerShapeManager
- private readonly _selectionTransformerShapeManager: ISelectionTransformerShapeManager
- ) {}
-
- /**
- * Returns all cells matching the search criteria.
- */
- findAll(): Nullable<TextFinder> {
- this._match();
- if (!this._range.length) return null;
- return this;
- }
-
- /**
- * Returns the next cell matching the search criteria.
- */
- findNext(): Nullable<TextFinder> {
- if (this._range.length === 0) return null;
- this._index++;
- if (this._index > this._range.length - 1) this._index = 0;
- this._highlightCell(this._range[this._index]);
- return this;
- }
-
- /**
- * Returns the previous cell matching the search criteria.
- */
- findPrevious(): Nullable<TextFinder> {
- if (this._range.length === 0) return null;
- this._index--;
- if (this._index < 0) this._index = this._range.length - 1;
- this._highlightCell(this._range[this._index]);
- return this;
- }
-
- getCount(): number {
- return this._range.length;
- }
-
- getCurrentIndex(): number {
- return this._index;
- }
-
- /**
- * If true, configures the search to match the search text's case exactly, otherwise the search defaults to case-insensitive matching.
- */
- matchCase(matchCase: boolean): TextFinder {
- this._matchCase = matchCase;
- return this;
- }
-
- /**
- * If true, configures the search to match the entire contents of a cell; otherwise, the search defaults to partial matching.
- */
- matchEntireCell(matchEntire: boolean): TextFinder {
- this._matchEntire = matchEntire;
- return this;
- }
-
- /**
- * If true, configures the search to return matches that appear within formula text; otherwise cells with formulas are considered based on their displayed value.
- */
- matchFormulaText(matchFormulaText: boolean): TextFinder {
- this._matchFormula = matchFormulaText;
- return this;
- }
-
- /**
- * If true, configures the search to interpret the search string as a regular expression; otherwise the search interprets the search string as normal text.
- */
- useRegularExpression(useRegEx: boolean): TextFinder {
- this._useRegEx = useRegEx;
- return this;
- }
-
- /**
- * TODO
- * 替换还需考虑编辑模式和保护模式,整个workbook
- */
- /**
- * Replaces all matches with the specified text. Returns the number of occurrences replaced, which may be different from the number of matched cells.
- */
- replaceAllWith(replaceText: string): number {
- if (!this._range.length) return 0;
-
- let count = 0;
- const sheetId = this._range[0].sheetId;
- let sheet = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(sheetId);
- for (let i = 0; i < this._range.length; i++) {
- if (sheetId !== this._range[i].sheetId) {
- sheet = this._currentUniverService
- .getCurrentUniverSheetInstance()
- .getWorkBook()
- .getSheetBySheetId(this._range[i].sheetId);
- }
- const range = this._range[i];
- if (!sheet) continue;
-
- this._replaceText(sheet, range, replaceText);
- count++;
- }
- this._range = [];
- this._index = -1;
-
- return count;
- }
-
- /**
- * Replaces the search text in the currently matched cell with the specified text and returns the number of occurrences replaced.
- */
- replaceWith(replaceText: string): number {
- if (!this._range.length) return 0;
- const range = this._range[this._index];
- const sheet = this._currentUniverService
- .getCurrentUniverSheetInstance()
- .getWorkBook()
- .getSheetBySheetId(range.sheetId);
- if (!sheet) return 0;
-
- this._replaceText(sheet, range, replaceText);
-
- this._range.splice(this._index, 1);
- this._highlightCell(this._range[this._index]);
- return 1;
- }
-
- /**
- * Configures the search to start searching immediately after the specified cell range.
- */
- startFrom(startRange: Range): TextFinder {
- this._startRange = startRange;
- return this;
- }
-
- /**
- * Returns the current cell matching the search criteria.
- */
- getCurrentMatch(): IGridRange | null {
- if (this._index < 0) return null;
- return this._range[this._index];
- }
-
- // 开始查找
- searchText(
- text: string | FormatType,
- type: FindType = 'text',
- searchRange: SelectSearch = SelectSearch.CurrentSheet
- ): TextFinder | null {
- if (!text) return null;
- // 查找范围变化或者初始化rangeData
- if (this._searchRange !== searchRange || !this._rangeData.length) {
- this._getRange(searchRange);
- }
- // 查找文字或者类型变化
- if (this._text !== text || this._type !== type) {
- this._type = type;
- this._text = text;
- this._index = -1;
- this.findAll();
- }
- return this;
- }
-
- private _getRange(searchRange: SelectSearch) {
- if (searchRange === SelectSearch.CurrentSheet) {
- const sheet = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
- const sheetId = sheet.getSheetId();
- const rangeList: IGridRange = {
- sheetId,
- range: {
- startRow: 0,
- endRow: sheet.getLastRow(),
- startColumn: 0,
- endColumn: sheet.getLastColumn(),
- },
- };
- this._rangeData = [rangeList];
- }
- }
-
- /**
- * match rule
- */
- private _match = () => {
- const matchMap = new Map<string | FormatType, () => IGridRange[]>([
- ['text', this._mathTxt.bind(this)],
- // ['condition', this._matchCondition],
- // ['intervalRow', () => this._matchInterval('row')],
- // ['intervalColumn', () => this._matchInterval('column')],
- // ['null', this._matchNull],
- // ['format', this._matchFormat],
- ]);
- let range;
- if (this._type in FormatType) {
- range = matchMap.get('format')!();
- } else {
- range = matchMap.get(this._type)!();
- }
- // range.sort((a, b) => a.getRangeData().startRow - b.getRangeData().startRow).sort((a, b) => a.getRangeData().startColumn - b.getRangeData().startColumn);
- // if (this._startRange) {
- // const startRange = this._startRange.getRangeData();
- // for (let i = 0; i < range.length; i++) {
- // const cell = range[i].getRangeData();
- // if (cell.startColumn <= startRange.endColumn) {
- // range.splice(i, 1);
- // i--;
- // } else if (cell.startRow < startRange.startRow) {
- // range.splice(i, 1);
- // i--;
- // }
- // }
- // }
- this._range = range;
- };
-
- // 查找文本
- private _mathTxt(): IGridRange[] {
- const range: IGridRange[] = [];
- for (let i = 0; i < this._rangeData.length; i++) {
- const sheet = this._currentUniverService
- .getCurrentUniverSheetInstance()
- .getWorkBook()
- .getSheetBySheetId(this._rangeData[i].sheetId);
- if (!sheet) return [];
- let matrix: ObjectMatrix<ICellData> = new ObjectMatrix<ICellData>();
- if (this._matchFormula) {
- // matrix = this._rangeData[i].getValue().f;
- } else {
- matrix = sheet.getRange(this._rangeData[i].range).getMatrix();
- }
-
- if (this._matchEntire) {
- matrix.forValue((row, col, value) => {
- if (!value.m) return;
- if (
- (this._matchCase && value.m === this._text) ||
- (this._text as string).toLowerCase() === value.m.toLowerCase()
- ) {
- range.push({
- sheetId: this._rangeData[i].sheetId,
- range: {
- startRow: row,
- endRow: row,
- startColumn: col,
- endColumn: col,
- },
- });
- }
- });
- }
- // else if (this._useRegEx) {
- // let reg;
- // if (this._matchCase) {
- // reg = new RegExp(getRegExpStr(this._text), 'g');
- // } else {
- // reg = new RegExp(getRegExpStr(this._text), 'ig');
- // }
-
- // if (reg.test(value)) {
- // range.push(this._rangeData[i]);
- // }
- // }
- else {
- const reg = new RegExp(getRegExpStr(this._text as string), this._matchCase ? 'g' : 'ig');
-
- matrix.forValue((row, col, value) => {
- if (!value.m) return;
- if (reg.test(value.m)) {
- reg.lastIndex = 0;
- range.push({
- sheetId: this._rangeData[i].sheetId,
- range: {
- startRow: row,
- endRow: row,
- startColumn: col,
- endColumn: col,
- },
- });
- }
- });
- }
- }
- return range;
- }
-
- // 高亮匹配单元格
- private _highlightCell(range: IGridRange) {
- if (!range) return;
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
- const unitId = workbook.getUnitId();
- const sheetId = range.sheetId;
- const mergeData = workbook.getActiveSheet().getMergeData();
-
- const selectionRange = this._selectionManagerService.transformCellDataToSelectionData(
- range.range.startColumn,
- range.range.endColumn,
- mergeData
- );
- if (selectionRange == null) {
- return;
- }
-
- this._selectionManagerService.replace([
- {
- ...selectionRange,
- ...this._selectionManagerService.createDefaultSelection(),
- },
- ]);
- }
-
- private _replaceText(sheet: Worksheet, range: IGridRange, text: string) {
- const value = sheet.getRange(range.range).getValue();
- if (!value || !value.m) return 0;
- if (!this._matchEntire) {
- let match;
- match = 'ig';
- if (this._matchCase) {
- match = 'g';
- }
- const reg = new RegExp(getRegExpStr(this._text as string), match);
- // sheet.getRange(range.range).setValue(value.m.replace(reg, text));
- } else {
- // sheet.getRange(range.range).setValue(text);
- }
- }
-}
+import { ISelectionTransformerShapeManager } from '@univerjs/base-render';
+import { SelectionManagerService } from '@univerjs/base-sheets';
+import {
+ FormatType,
+ ICellData,
+ ICurrentUniverService,
+ IGridRange,
+ Nullable,
+ ObjectMatrix,
+ Range,
+ Worksheet,
+} from '@univerjs/core';
+import { Inject } from '@wendellhu/redi';
+
+import { FindType } from '../IData';
+import { getRegExpStr } from '../Util/util';
+import { SelectSearch } from '../View/UI/FindModal';
+
+export class TextFinder {
+ private _text: string | FormatType = '';
+
+ private _type: FindType = 'text'; // 查找类型
+
+ private _searchRange: SelectSearch = SelectSearch.CurrentSheet; //查找范围
+
+ private _range: IGridRange[] = []; // 保存匹配到的单元格range格式
+
+ private _rangeData: IGridRange[] = []; // rangList每个单元格range格式
+
+ private _index: number = -1;
+
+ private _matchCase: boolean = false; // 大小写匹配
+
+ private _matchEntire: boolean = false; // 完全匹配
+
+ private _useRegEx: boolean = false; // 正则匹配
+
+ private _matchFormula: boolean = false; // 匹配公式文字
+
+ private _startRange: Nullable<Range>; // 从这个位置后开始找
+
+ constructor(
+ @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,
+ @Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
+ @ISelectionTransformerShapeManager
+ private readonly _selectionTransformerShapeManager: ISelectionTransformerShapeManager
+ ) {}
+
+ /**
+ * Returns all cells matching the search criteria.
+ */
+ findAll(): Nullable<TextFinder> {
+ this._match();
+ if (!this._range.length) return null;
+ return this;
+ }
+
+ /**
+ * Returns the next cell matching the search criteria.
+ */
+ findNext(): Nullable<TextFinder> {
+ if (this._range.length === 0) return null;
+ this._index++;
+ if (this._index > this._range.length - 1) this._index = 0;
+ this._highlightCell(this._range[this._index]);
+ return this;
+ }
+
+ /**
+ * Returns the previous cell matching the search criteria.
+ */
+ findPrevious(): Nullable<TextFinder> {
+ if (this._range.length === 0) return null;
+ this._index--;
+ if (this._index < 0) this._index = this._range.length - 1;
+ this._highlightCell(this._range[this._index]);
+ return this;
+ }
+
+ getCount(): number {
+ return this._range.length;
+ }
+
+ getCurrentIndex(): number {
+ return this._index;
+ }
+
+ /**
+ * If true, configures the search to match the search text's case exactly, otherwise the search defaults to case-insensitive matching.
+ */
+ matchCase(matchCase: boolean): TextFinder {
+ this._matchCase = matchCase;
+ return this;
+ }
+
+ /**
+ * If true, configures the search to match the entire contents of a cell; otherwise, the search defaults to partial matching.
+ */
+ matchEntireCell(matchEntire: boolean): TextFinder {
+ this._matchEntire = matchEntire;
+ return this;
+ }
+
+ /**
+ * If true, configures the search to return matches that appear within formula text; otherwise cells with formulas are considered based on their displayed value.
+ */
+ matchFormulaText(matchFormulaText: boolean): TextFinder {
+ this._matchFormula = matchFormulaText;
+ return this;
+ }
+
+ /**
+ * If true, configures the search to interpret the search string as a regular expression; otherwise the search interprets the search string as normal text.
+ */
+ useRegularExpression(useRegEx: boolean): TextFinder {
+ this._useRegEx = useRegEx;
+ return this;
+ }
+
+ /**
+ * TODO
+ * 替换还需考虑编辑模式和保护模式,整个workbook
+ */
+ /**
+ * Replaces all matches with the specified text. Returns the number of occurrences replaced, which may be different from the number of matched cells.
+ */
+ replaceAllWith(replaceText: string): number {
+ if (!this._range.length) return 0;
+
+ let count = 0;
+ const sheetId = this._range[0].sheetId;
+ let sheet = this._currentUniverService.getCurrentUniverSheetInstance().getSheetBySheetId(sheetId);
+ for (let i = 0; i < this._range.length; i++) {
+ if (sheetId !== this._range[i].sheetId) {
+ sheet = this._currentUniverService
+ .getCurrentUniverSheetInstance()
+
+ .getSheetBySheetId(this._range[i].sheetId);
+ }
+ const range = this._range[i];
+ if (!sheet) continue;
+
+ this._replaceText(sheet, range, replaceText);
+ count++;
+ }
+ this._range = [];
+ this._index = -1;
+
+ return count;
+ }
+
+ /**
+ * Replaces the search text in the currently matched cell with the specified text and returns the number of occurrences replaced.
+ */
+ replaceWith(replaceText: string): number {
+ if (!this._range.length) return 0;
+ const range = this._range[this._index];
+ const sheet = this._currentUniverService
+ .getCurrentUniverSheetInstance()
+
+ .getSheetBySheetId(range.sheetId);
+ if (!sheet) return 0;
+
+ this._replaceText(sheet, range, replaceText);
+
+ this._range.splice(this._index, 1);
+ this._highlightCell(this._range[this._index]);
+ return 1;
+ }
+
+ /**
+ * Configures the search to start searching immediately after the specified cell range.
+ */
+ startFrom(startRange: Range): TextFinder {
+ this._startRange = startRange;
+ return this;
+ }
+
+ /**
+ * Returns the current cell matching the search criteria.
+ */
+ getCurrentMatch(): IGridRange | null {
+ if (this._index < 0) return null;
+ return this._range[this._index];
+ }
+
+ // 开始查找
+ searchText(
+ text: string | FormatType,
+ type: FindType = 'text',
+ searchRange: SelectSearch = SelectSearch.CurrentSheet
+ ): TextFinder | null {
+ if (!text) return null;
+ // 查找范围变化或者初始化rangeData
+ if (this._searchRange !== searchRange || !this._rangeData.length) {
+ this._getRange(searchRange);
+ }
+ // 查找文字或者类型变化
+ if (this._text !== text || this._type !== type) {
+ this._type = type;
+ this._text = text;
+ this._index = -1;
+ this.findAll();
+ }
+ return this;
+ }
+
+ private _getRange(searchRange: SelectSearch) {
+ if (searchRange === SelectSearch.CurrentSheet) {
+ const sheet = this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
+ const sheetId = sheet.getSheetId();
+ const rangeList: IGridRange = {
+ sheetId,
+ range: {
+ startRow: 0,
+ endRow: sheet.getLastRow(),
+ startColumn: 0,
+ endColumn: sheet.getLastColumn(),
+ },
+ };
+ this._rangeData = [rangeList];
+ }
+ }
+
+ /**
+ * match rule
+ */
+ private _match = () => {
+ const matchMap = new Map<string | FormatType, () => IGridRange[]>([
+ ['text', this._mathTxt.bind(this)],
+ // ['condition', this._matchCondition],
+ // ['intervalRow', () => this._matchInterval('row')],
+ // ['intervalColumn', () => this._matchInterval('column')],
+ // ['null', this._matchNull],
+ // ['format', this._matchFormat],
+ ]);
+ let range;
+ if (this._type in FormatType) {
+ range = matchMap.get('format')!();
+ } else {
+ range = matchMap.get(this._type)!();
+ }
+ // range.sort((a, b) => a.getRangeData().startRow - b.getRangeData().startRow).sort((a, b) => a.getRangeData().startColumn - b.getRangeData().startColumn);
+ // if (this._startRange) {
+ // const startRange = this._startRange.getRangeData();
+ // for (let i = 0; i < range.length; i++) {
+ // const cell = range[i].getRangeData();
+ // if (cell.startColumn <= startRange.endColumn) {
+ // range.splice(i, 1);
+ // i--;
+ // } else if (cell.startRow < startRange.startRow) {
+ // range.splice(i, 1);
+ // i--;
+ // }
+ // }
+ // }
+ this._range = range;
+ };
+
+ // 查找文本
+ private _mathTxt(): IGridRange[] {
+ const range: IGridRange[] = [];
+ for (let i = 0; i < this._rangeData.length; i++) {
+ const sheet = this._currentUniverService
+ .getCurrentUniverSheetInstance()
+
+ .getSheetBySheetId(this._rangeData[i].sheetId);
+ if (!sheet) return [];
+ let matrix: ObjectMatrix<ICellData> = new ObjectMatrix<ICellData>();
+ if (this._matchFormula) {
+ // matrix = this._rangeData[i].getValue().f;
+ } else {
+ matrix = sheet.getRange(this._rangeData[i].range).getMatrix();
+ }
+
+ if (this._matchEntire) {
+ matrix.forValue((row, col, value) => {
+ if (!value.m) return;
+ if (
+ (this._matchCase && value.m === this._text) ||
+ (this._text as string).toLowerCase() === value.m.toLowerCase()
+ ) {
+ range.push({
+ sheetId: this._rangeData[i].sheetId,
+ range: {
+ startRow: row,
+ endRow: row,
+ startColumn: col,
+ endColumn: col,
+ },
+ });
+ }
+ });
+ }
+ // else if (this._useRegEx) {
+ // let reg;
+ // if (this._matchCase) {
+ // reg = new RegExp(getRegExpStr(this._text), 'g');
+ // } else {
+ // reg = new RegExp(getRegExpStr(this._text), 'ig');
+ // }
+
+ // if (reg.test(value)) {
+ // range.push(this._rangeData[i]);
+ // }
+ // }
+ else {
+ const reg = new RegExp(getRegExpStr(this._text as string), this._matchCase ? 'g' : 'ig');
+
+ matrix.forValue((row, col, value) => {
+ if (!value.m) return;
+ if (reg.test(value.m)) {
+ reg.lastIndex = 0;
+ range.push({
+ sheetId: this._rangeData[i].sheetId,
+ range: {
+ startRow: row,
+ endRow: row,
+ startColumn: col,
+ endColumn: col,
+ },
+ });
+ }
+ });
+ }
+ }
+ return range;
+ }
+
+ // 高亮匹配单元格
+ private _highlightCell(range: IGridRange) {
+ if (!range) return;
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
+ const unitId = workbook.getUnitId();
+ const sheetId = range.sheetId;
+ const mergeData = workbook.getActiveSheet().getMergeData();
+
+ const selectionRange = this._selectionManagerService.transformCellDataToSelectionData(
+ range.range.startColumn,
+ range.range.endColumn,
+ mergeData
+ );
+ if (selectionRange == null) {
+ return;
+ }
+
+ this._selectionManagerService.replace([
+ {
+ ...selectionRange,
+ ...this._selectionManagerService.createDefaultSelection(),
+ },
+ ]);
+ }
+
+ private _replaceText(sheet: Worksheet, range: IGridRange, text: string) {
+ const value = sheet.getRange(range.range).getValue();
+ if (!value || !value.m) return 0;
+ if (!this._matchEntire) {
+ let match;
+ match = 'ig';
+ if (this._matchCase) {
+ match = 'g';
+ }
+ const reg = new RegExp(getRegExpStr(this._text as string), match);
+ // sheet.getRange(range.range).setValue(value.m.replace(reg, text));
+ } else {
+ // sheet.getRange(range.range).setValue(text);
+ }
+ }
+}
diff --git a/packages/sheets-plugin-formula/src/Controller/ArrayFormulaLineController.ts b/packages/sheets-plugin-formula/src/Controller/ArrayFormulaLineController.ts
index 89819cdbd6..5ee349a935 100644
--- a/packages/sheets-plugin-formula/src/Controller/ArrayFormulaLineController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/ArrayFormulaLineController.ts
@@ -34,7 +34,7 @@ export class ArrayFormulaLineControl {
* @returns Workbook
*/
getWorkBook(): Workbook {
- return this._currentUniverSheet.getCurrentUniverSheetInstance().getWorkBook();
+ return this._currentUniverSheet.getCurrentUniverSheetInstance();
}
dispose() {
diff --git a/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts b/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts
index b8f4cc5383..6c4c73c5ca 100644
--- a/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts
+++ b/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts
@@ -17,7 +17,7 @@ export function firstLoader(formulaController: FormulaController) {
// const commandManager = formulaController.getCommandManager();
- // const workBook = formulaController.getWorkbook();
+ // const workBook = formulaController;
// sheetDataPromise.then((data) => {
// if (!data) return;
diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
index b87f4f4d4c..911b8e035d 100644
--- a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts
@@ -35,7 +35,7 @@ export class FormulaController {
this._activeSheetId = this._currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getSheetId();
@@ -107,7 +107,7 @@ export class FormulaController {
}
getWorkbook() {
- return this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ return this._currentUniverService.getCurrentUniverSheetInstance();
}
getUnitId() {
@@ -177,8 +177,8 @@ export class FormulaController {
// }
private _toInterpreterCalculateProps(): IInterpreterDatasetConfig {
- const workbook = this.getWorkbook();
- const sheets = workbook.getSheets();
+ const workbook = this;
+ const sheets = workbook.getWorkbook().getSheets();
const sheetData: SheetDataType = {};
const unitData: UnitDataType = {};
const sheetNameMap: SheetNameMapType = {};
@@ -194,7 +194,7 @@ export class FormulaController {
const formulaData = this._formulaDataModel.getFormulaData();
- const activeSheet = workbook.getActiveSheet();
+ const activeSheet = workbook.getWorkbook().getActiveSheet();
const rowCount = activeSheet.getRowCount();
const columnCount = activeSheet.getColumnCount();
diff --git a/packages/sheets-plugin-image/src/services/upload.service.ts b/packages/sheets-plugin-image/src/services/upload.service.ts
index 020be6b383..a541783830 100644
--- a/packages/sheets-plugin-image/src/services/upload.service.ts
+++ b/packages/sheets-plugin-image/src/services/upload.service.ts
@@ -14,14 +14,14 @@ export class UploadService {
upload() {
const { _selectionManagerService, _currentUniverService, _injector } = this;
const selection = _selectionManagerService.getLast()?.range;
- const worksheet = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = this._currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
if (selection == null) {
return;
}
const activeRange = worksheet.getRange(selection);
const rowIndex = activeRange.getRowIndex();
const columnIndex = activeRange.getColumn();
- const workbook = _currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = _currentUniverService.getCurrentUniverSheetInstance();
FileSelected.chooseImage().then((file) => {
const reader = new FileReader();
const img = new Image();
diff --git a/packages/sheets-plugin-import-xlsx/src/services/upload.service.ts b/packages/sheets-plugin-import-xlsx/src/services/upload.service.ts
index 372338ff94..5f4c651eea 100644
--- a/packages/sheets-plugin-import-xlsx/src/services/upload.service.ts
+++ b/packages/sheets-plugin-import-xlsx/src/services/upload.service.ts
@@ -52,7 +52,7 @@ export class UploadService {
return console.error('No content');
}
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
if (!workbook) {
return false;
}
diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts
index 7a4f265b84..68cb4948b1 100644
--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts
+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts
@@ -128,7 +128,7 @@ export class NumfmtController extends Disposable {
// };
// const command = new Command(
// {
- // WorkBookUnit: this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook(),
+ // WorkBookUnit: this._currentUniverService.getCurrentUniverSheetInstance(),
// },
// config
// );
@@ -151,7 +151,7 @@ export class NumfmtController extends Disposable {
// };
// const command = new Command(
// {
- // WorkBookUnit: this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook(),
+ // WorkBookUnit: this._currentUniverService.getCurrentUniverSheetInstance(),
// },
// config
// );
diff --git a/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtRangeDataAction.ts b/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtRangeDataAction.ts
index 64dabb6780..875dee5270 100644
--- a/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtRangeDataAction.ts
+++ b/packages/sheets-plugin-numfmt/src/Model/Action/SetNumfmtRangeDataAction.ts
@@ -24,12 +24,12 @@
// redo(): ObjectMatrixPrimitiveType<string> {
// const { injector } = this._doActionData;
-// return SetNumfmtRangeData(this.getWorkBook(), this._doActionData.sheetId, this._doActionData.numfmtMatrix, injector!.get(NumfmtController));
+// return SetNumfmtRangeData(this, this._doActionData.sheetId, this._doActionData.numfmtMatrix, injector!.get(NumfmtController));
// }
// undo(): void {
// const { injector } = this._oldActionData;
-// SetNumfmtRangeData(this.getWorkBook(), this._oldActionData.sheetId, this._oldActionData.numfmtMatrix, injector!.get(NumfmtController));
+// SetNumfmtRangeData(this, this._oldActionData.sheetId, this._oldActionData.numfmtMatrix, injector!.get(NumfmtController));
// }
// validate(): boolean {
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
index fcbe08f0ba..302eb67e40 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
@@ -249,7 +249,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
const injector = this.context.injector!;
const currentUniverService = injector.get(ICurrentUniverService);
const commandService = injector.get(ICommandService);
- const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = currentUniverService.getCurrentUniverSheetInstance();
const sheets = workbook.getSheets();
const worksheetMenuItems = sheets.map((sheet, index) => ({
diff --git a/packages/ui-plugin-sheets/src/controller/clipboard/clipboard.controller.ts b/packages/ui-plugin-sheets/src/controller/clipboard/clipboard.controller.ts
index 8157d5dcc5..539f72038f 100644
--- a/packages/ui-plugin-sheets/src/controller/clipboard/clipboard.controller.ts
+++ b/packages/ui-plugin-sheets/src/controller/clipboard/clipboard.controller.ts
@@ -334,10 +334,7 @@ export class SheetClipboardController extends Disposable {
}
private _getWorksheet(workbookId: string, worksheetId: string): Worksheet {
- const worksheet = this._currentUniverSheet
- .getUniverSheetInstance(workbookId)
- ?.getWorkBook()
- .getSheetBySheetId(worksheetId);
+ const worksheet = this._currentUniverSheet.getUniverSheetInstance(workbookId)?.getSheetBySheetId(worksheetId);
if (!worksheet) {
throw new Error(
diff --git a/packages/ui-plugin-sheets/src/controller/menu/menu.ts b/packages/ui-plugin-sheets/src/controller/menu/menu.ts
index a3e368b43d..9c2c2c600b 100644
--- a/packages/ui-plugin-sheets/src/controller/menu/menu.ts
+++ b/packages/ui-plugin-sheets/src/controller/menu/menu.ts
@@ -139,7 +139,7 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let isBold = FontWeight.NORMAL;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -192,7 +192,7 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let isItalic = FontItalic.NORMAL;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -245,7 +245,7 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let isUnderline;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -298,7 +298,7 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIt
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let st;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -504,7 +504,7 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSel
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let ff;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -561,7 +561,7 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelec
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let fs;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -699,7 +699,7 @@ export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelect
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let ha;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -755,7 +755,7 @@ export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelector
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let va;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -811,7 +811,7 @@ export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let ws;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -882,7 +882,7 @@ export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorIte
}
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let tr;
if (primary != null) {
const range = worksheet.getRange(primary.startRow, primary.startColumn);
@@ -1074,7 +1074,7 @@ export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonIte
value$: new Observable((subscriber) => {
function update() {
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let rowHeight;
if (primary != null) {
rowHeight = worksheet.getRowHeight(primary.startRow);
@@ -1117,7 +1117,7 @@ export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem
value$: new Observable((subscriber) => {
function update() {
const primary = selectionManagerService.getLast()?.primary;
- const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();
+ const worksheet = currentUniverService.getCurrentUniverSheetInstance().getActiveSheet();
let colWidth: number = 0;
if (primary != null) {
diff --git a/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor-desktop.service.ts b/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor-desktop.service.ts
index b9f643ae39..073674bbf0 100644
--- a/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor-desktop.service.ts
+++ b/packages/ui-plugin-sheets/src/services/cell-editor/cell-editor-desktop.service.ts
@@ -130,13 +130,13 @@ export class DesktopCellEditorService extends RxDisposable implements ICellEdito
this._currentUniverService.focusUniverInstance(workbookId);
this._contextService.setContextValue(SHEET_EDITOR_ACTIVATED, false);
- const model = this._currentUniverService.getUniverDocInstance(SHEET_CELL_EDITOR_MODEL_ID)!.getDocument();
+ const model = this._currentUniverService.getUniverDocInstance(SHEET_CELL_EDITOR_MODEL_ID)!;
const dataStream = model.getBodyModel().getText();
this._getCellEditor()?.deactivate(true);
this._commandService.executeCommand(SetRangeValuesCommand.id, <ISetRangeValuesCommandParams>{
workbookId,
- worksheetId: currentUniverSheet.getWorkBook().getActiveSheet().getSheetId(),
+ worksheetId: currentUniverSheet.getActiveSheet().getSheetId(),
range: this._currentEditingCell,
value: {
v: dataStream,
@@ -179,7 +179,7 @@ export class DesktopCellEditorService extends RxDisposable implements ICellEdito
},
},
});
- const docModel = cellEditorDoc.getDocument();
+ const docModel = cellEditorDoc;
// rendering engine add document canvas
const engine = (this._editorEngine = new Engine());
@@ -283,9 +283,7 @@ export class DesktopCellEditorService extends RxDisposable implements ICellEdito
}
private async _updateDocumentModelFromCellModel(position: Nullable<ICellPosition>): Promise<void> {
- const cellEditorModel = this._currentUniverService
- .getUniverDocInstance(SHEET_CELL_EDITOR_MODEL_ID)
- ?.getDocument();
+ const cellEditorModel = this._currentUniverService.getUniverDocInstance(SHEET_CELL_EDITOR_MODEL_ID);
if (!cellEditorModel) {
throw new Error('Cell editor model not found!');
@@ -368,7 +366,7 @@ export class DesktopCellEditorService extends RxDisposable implements ICellEdito
return this._currentUniverService
.getCurrentUniverSheetInstance()
- .getWorkBook()
+
.getActiveSheet()
.getRange(actualRow, actualColumn);
}
diff --git a/packages/ui-plugin-sheets/src/services/clipboard/clipboard.service.ts b/packages/ui-plugin-sheets/src/services/clipboard/clipboard.service.ts
index 345056e2ba..e858863772 100644
--- a/packages/ui-plugin-sheets/src/services/clipboard/clipboard.service.ts
+++ b/packages/ui-plugin-sheets/src/services/clipboard/clipboard.service.ts
@@ -166,7 +166,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
// 3. calculate selection matrix, span cells would only - maybe warn uses that cells are too may in the future
const { startColumn, startRow, endColumn, endRow } = selection.range;
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const matrix = worksheet.getMatrixWithMergedCells(startRow, startColumn, endRow, endColumn);
@@ -364,7 +364,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard
// NOTE: why there are some differences between internal and external pasting?
private _getPastingTarget() {
- const workbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();
+ const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const worksheet = workbook.getActiveSheet();
const selection = this._selectionManagerService.getLast();
return {
diff --git a/packages/ui-plugin-slides/src/Controller/InfoBarUIController.ts b/packages/ui-plugin-slides/src/Controller/InfoBarUIController.ts
index ca919daca6..e8ea808f14 100644
--- a/packages/ui-plugin-slides/src/Controller/InfoBarUIController.ts
+++ b/packages/ui-plugin-slides/src/Controller/InfoBarUIController.ts
@@ -41,7 +41,7 @@ export class InfoBarUIController {
private _refreshComponent(): void {
const name = 'UniverSlide';
- // const name = this._plugin.getUniver().getCurrentUniverSlideInstance().getWorkBook().getConfig().name;
+ // const name = this._plugin.getUniver().getCurrentUniverSlideInstance().getConfig().name;
this._infoBarModel = new InfoBarModel(name);
this._infoList = {
back: {
diff --git a/packages/ui-plugin-slides/src/Controller/SlideBarUIController.ts b/packages/ui-plugin-slides/src/Controller/SlideBarUIController.ts
index f1ca408e95..4cb329ce1e 100644
--- a/packages/ui-plugin-slides/src/Controller/SlideBarUIController.ts
+++ b/packages/ui-plugin-slides/src/Controller/SlideBarUIController.ts
@@ -45,7 +45,7 @@ export class SlideBarUIController {
* Arrow functions must be used to bind `this`, otherwise `this` will be lost when the DOM component triggers the callback
*/
addSlide = () => {
- const model = this._currentUniverService.getCurrentUniverSlideInstance().getSlideModel();
+ const model = this._currentUniverService.getCurrentUniverSlideInstance();
const canvasView = this._getCanvasView();
const newPage = model.addPage();
this._pages.push(newPage);
@@ -71,7 +71,7 @@ export class SlideBarUIController {
}
private _generateModel() {
- const model = this._currentUniverService.getCurrentUniverSlideInstance().getSlideModel();
+ const model = this._currentUniverService.getCurrentUniverSlideInstance();
const pages = model.getPages();
const pageOrder = model.getPageOrder();
if (!pages || !pageOrder) {
diff --git a/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx b/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
index 3da957df41..f16d7b7a14 100644
--- a/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
+++ b/packages/ui-plugin-slides/src/View/SlideBar/SlideBar.tsx
@@ -67,7 +67,7 @@ export class SlideBar extends Component<{}, SlideBarState> {
private _init(): void {
// TODO: should subscribe to active slide change event
const currentUniverService = this.context.injector.get(ICurrentUniverService);
- const model = currentUniverService.getCurrentUniverSlideInstance().getSlideModel();
+ const model = currentUniverService.getCurrentUniverSlideInstance();
const pages = model.getPages();
const pageOrder = model.getPageOrder();
if (!pages || !pageOrder) {