Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor(core): remove getUniverSheetInstance (#7343)
wpxp123456098bea0f424e
diff --git a/packages/core/src/services/instance/instance.service.ts b/packages/core/src/services/instance/instance.service.tsindex a6b03fba80..908e26c31e 100644--- a/packages/core/src/services/instance/instance.service.ts+++ b/packages/core/src/services/instance/instance.service.ts@@ -119,9 +119,6 @@ export interface IUniverInstanceService {getUnit<T extends UnitModel>(id: string, type?: UniverInstanceType): Nullable<T>;getAllUnitsForType<T>(type: UniverInstanceType): T[];getUnitType(unitId: string): UniverInstanceType;-- /** @deprecated */- getUniverSheetInstance(unitId: string): Nullable<Workbook>;}export const IUniverInstanceService = createIdentifier<IUniverInstanceService>('univer.current');@@ -257,10 +254,6 @@ export class UniverInstanceService extends Disposable implements IUniverInstancereturn this._unitCreateOptions.get(unitId) ?? null;}- getUniverSheetInstance(unitId: string): Nullable<Workbook> {- return this.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);- }-getAllUnitsForType<T>(type: UniverInstanceType): T[] {return (this._unitsByType.get(type) ?? []) as T[];}diff --git a/packages/find-replace/src/controllers/find-replace.controller.ts b/packages/find-replace/src/controllers/find-replace.controller.tsindex 626e72ee59..5786b1571c 100644--- a/packages/find-replace/src/controllers/find-replace.controller.ts+++ b/packages/find-replace/src/controllers/find-replace.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { IDisposable, Nullable } from '@univerjs/core';+import type { IDisposable, Nullable, Workbook } from '@univerjs/core';import type { LocaleKey } from '../locale/types';import {ICommandService,@@ -23,6 +23,7 @@ import {LocaleService,RxDisposable,toDisposable,+ UniverInstanceType,} from '@univerjs/core';import { IDialogService, ILayoutService, IMenuManagerService, IShortcutService } from '@univerjs/ui';import { takeUntil } from 'rxjs';@@ -129,7 +130,7 @@ export class FindReplaceController extends RxDisposable {this._closingListenerDisposable = toDisposable(this._univerInstanceService.focused$.pipe(takeUntil(this.dispose$)).subscribe((focused) => {- if (!focused || !this._univerInstanceService.getUniverSheetInstance(focused)) {+ if (!focused || !this._univerInstanceService.getUnit<Workbook>(focused, UniverInstanceType.UNIVER_SHEET)) {this.closePanel();}})diff --git a/packages/sheets-data-validation-ui/src/controllers/__tests__/dv-render.controller.spec.ts b/packages/sheets-data-validation-ui/src/controllers/__tests__/dv-render.controller.spec.tsindex 837a800f9e..d986e84763 100644--- a/packages/sheets-data-validation-ui/src/controllers/__tests__/dv-render.controller.spec.ts+++ b/packages/sheets-data-validation-ui/src/controllers/__tests__/dv-render.controller.spec.ts@@ -14,15 +14,23 @@* limitations under the License.*/-import { DataValidationStatus, DataValidationType } from '@univerjs/core';-import { INTERCEPTOR_POINT } from '@univerjs/sheets';+import type { IWorkbookData, Workbook } from '@univerjs/core';+import { DataValidationStatus, DataValidationType, InterceptorEffectEnum, LocaleType, Univer, UniverInstanceType } from '@univerjs/core';+import { DataValidatorRegistryService } from '@univerjs/data-validation';+import { IRenderManagerService } from '@univerjs/engine-render';+import { INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';+import { DataValidationCacheService, SheetDataValidationModel } from '@univerjs/sheets-data-validation';+import { AutoHeightController } from '@univerjs/sheets-ui';+import { IMenuManagerService } from '@univerjs/ui';import { Subject } from 'rxjs';import { describe, expect, it, vi } from 'vitest';+import { DataValidationDropdownManagerService } from '../../services/dropdown-manager.service';import { SheetsDataValidationRenderController } from '../dv-render.controller';describe('SheetsDataValidationRenderController', () => {it('adds invalid markers, dropdown canvas renderer and list-cell layout behavior through the cell interceptor', () => {- let interceptor: any;+ const univer = new Univer();+ const injector = univer.__getInjector();const canvasRender = {calcCellAutoHeight: vi.fn(() => 36),calcCellAutoWidth: vi.fn(() => 120),@@ -32,25 +40,28 @@ describe('SheetsDataValidationRenderController', () => {getStyles: vi.fn(() => ({ getStyleByCell: vi.fn(() => ({ fs: 11 })) })),getCellWithCoordByIndex: vi.fn(() => ({ startX: 10, startY: 20 })),};- const controller = new SheetsDataValidationRenderController(- { executeCommand: vi.fn() } as never,- { mergeMenu: vi.fn() } as never,- {++ injector.add([IMenuManagerService, { useValue: { mergeMenu: vi.fn() } as never }]);+ injector.add([IRenderManagerService, {+ useValue: {getRenderUnitById: vi.fn(() => ({with: vi.fn(() => ({getSkeletonParam: vi.fn(() => ({ skeleton })),})),})),} as never,- { getUniverSheetInstance: vi.fn() } as never,- { getUndoRedoParamsOfAutoHeight: vi.fn(() => ({ redos: [] })) } as never,- { activeDropdown: null, hideDropdown: vi.fn(), showDropdown: vi.fn() } as never,- {+ }]);+ injector.add([AutoHeightController, { useValue: { getUndoRedoParamsOfAutoHeight: vi.fn(() => ({ redos: [], undos: [] })) } as never }]);+ injector.add([DataValidationDropdownManagerService, { useValue: { activeDropdown: null, hideDropdown: vi.fn(), showDropdown: vi.fn() } as never }]);+ injector.add([SheetDataValidationModel, {+ useValue: {getRuleIdByLocation: vi.fn(() => 'rule-1'),getRuleById: vi.fn(() => ({ uid: 'rule-1', type: DataValidationType.LIST })),ruleChange$: new Subject(),} as never,- {+ }]);+ injector.add([DataValidatorRegistryService, {+ useValue: {getValidatorItem: vi.fn(() => ({canvasRender,dropdownType: 'list',@@ -58,20 +69,33 @@ describe('SheetsDataValidationRenderController', () => {getExtraStyle: vi.fn(() => ({ bg: { rgb: '#fff3cd' } })),})),} as never,- {- intercept: vi.fn((point, config) => {- expect(point).toBe(INTERCEPTOR_POINT.CELL_CONTENT);- interceptor = config;- return { dispose: vi.fn() };- }),- } as never,- { getValue: vi.fn(() => DataValidationStatus.INVALID) } as never- );- const rawCell = { v: 'bad', markers: { bl: { size: 1 } }, coverable: true };- const workbook = { getStyles: vi.fn(() => ({ get: vi.fn(() => ({ fs: 10 })) })) };- const worksheet = { getMergedCell: vi.fn(() => null) };+ }]);+ injector.add([SheetInterceptorService]);+ injector.add([DataValidationCacheService, { useValue: { getValue: vi.fn(() => DataValidationStatus.INVALID) } as never }]);+ injector.add([SheetsDataValidationRenderController]);- const result = interceptor.handler(rawCell, {+ const workbook = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, {+ id: 'unit-1',+ appVersion: '3.0.0-alpha',+ locale: LocaleType.EN_US,+ name: 'Test workbook',+ styles: {},+ sheetOrder: ['sheet-1'],+ sheets: {+ 'sheet-1': {+ id: 'sheet-1',+ name: 'Sheet 1',+ cellData: { 1: { 2: { v: 'bad' } } },+ },+ },+ });+ const worksheet = workbook.getSheetBySheetId('sheet-1')!;+ const controller = injector.get(SheetsDataValidationRenderController);+ const rawCell = { v: 'bad', markers: { bl: { size: 1 } }, coverable: true } as never;+ const result = injector.get(SheetInterceptorService).fetchThroughInterceptors(+ INTERCEPTOR_POINT.CELL_CONTENT,+ InterceptorEffectEnum.Style+ )(rawCell, {row: 1,col: 2,unitId: 'unit-1',@@ -79,20 +103,22 @@ describe('SheetsDataValidationRenderController', () => {rawData: rawCell,workbook,worksheet,- }, (cell: unknown) => cell);+ });+ const intercepted = result!;- expect(result).not.toBe(rawCell);- expect(result.markers).toEqual(expect.objectContaining({+ expect(intercepted).not.toBe(rawCell);+ expect(intercepted.markers).toEqual(expect.objectContaining({bl: { size: 1 },tr: { size: 6, color: '#fe4b4b' },}));- expect(result.customRender).toContain(canvasRender);- expect(result.fontRenderExtension.isSkip).toBe(true);- expect(result.interceptorStyle).toEqual({ bg: { rgb: '#fff3cd' } });- expect(result.coverable).toBe(false);- expect(result.interceptorAutoHeight()).toBe(36);- expect(result.interceptorAutoWidth()).toBe(120);+ expect(intercepted.customRender).toContain(canvasRender);+ expect(intercepted.fontRenderExtension?.isSkip).toBe(true);+ expect(intercepted.interceptorStyle).toEqual({ bg: { rgb: '#fff3cd' } });+ expect(intercepted.coverable).toBe(false);+ expect(intercepted.interceptorAutoHeight?.()).toBe(36);+ expect(intercepted.interceptorAutoWidth?.()).toBe(120);controller.dispose();+ univer.dispose();});});diff --git a/packages/sheets-data-validation-ui/src/controllers/dv-render.controller.ts b/packages/sheets-data-validation-ui/src/controllers/dv-render.controller.tsindex 757331ccc4..5b890bf245 100644--- a/packages/sheets-data-validation-ui/src/controllers/dv-render.controller.ts+++ b/packages/sheets-data-validation-ui/src/controllers/dv-render.controller.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { CellValue, ICellRenderContext, IRange, Nullable } from '@univerjs/core';-import { DataValidationStatus, DataValidationType, ICommandService, Inject, InterceptorEffectEnum, IUniverInstanceService, Optional, RxDisposable, sequenceExecute } from '@univerjs/core';+import type { CellValue, ICellRenderContext, IRange, Nullable, Workbook } from '@univerjs/core';+import { DataValidationStatus, DataValidationType, ICommandService, Inject, InterceptorEffectEnum, IUniverInstanceService, Optional, RxDisposable, sequenceExecute, UniverInstanceType } from '@univerjs/core';import { DataValidatorRegistryService } from '@univerjs/data-validation';import { IRenderManagerService } from '@univerjs/engine-render';import { InterceptCellContentPriority, INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';@@ -75,7 +75,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {const state = this._editorBridgeService!.getEditCellState();if (state) {const { unitId, sheetId, row, column } = state;- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return;}diff --git a/packages/sheets-data-validation/src/controllers/dv-sheet.controller.ts b/packages/sheets-data-validation/src/controllers/dv-sheet.controller.tsindex 8b99e508f3..9684f88539 100644--- a/packages/sheets-data-validation/src/controllers/dv-sheet.controller.ts+++ b/packages/sheets-data-validation/src/controllers/dv-sheet.controller.ts@@ -41,7 +41,7 @@ export class SheetDataValidationSheetController extends Disposable {if (commandInfo.id === RemoveSheetCommand.id) {const params = commandInfo.params as IRemoveSheetCommandParams;const unitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return { redos: [], undos: [] };}diff --git a/packages/sheets-data-validation/src/validators/__tests__/list-validator.spec.ts b/packages/sheets-data-validation/src/validators/__tests__/list-validator.spec.tsindex 032729a62b..7b74b06dbb 100644--- a/packages/sheets-data-validation/src/validators/__tests__/list-validator.spec.ts+++ b/packages/sheets-data-validation/src/validators/__tests__/list-validator.spec.ts@@ -14,11 +14,15 @@* limitations under the License.*/-import type { ICellData, Injector, LocaleService } from '@univerjs/core';+import type { ICellData, IWorkbookData, Workbook } from '@univerjs/core';import {CellValueType,DataValidationRenderMode,DataValidationType,+ IUniverInstanceService,+ LocaleService,+ LocaleType,+ Univer,UniverInstanceType,WrapStrategy,} from '@univerjs/core';@@ -29,33 +33,14 @@ import { DataValidationListCacheService } from '../../services/dv-list-cache.serimport { getRuleFormulaResultSet, isValidListFormula, ListValidator } from '../list-validator';import { getDataValidationCellValue, getSheetRangeValueSet, getTransformedFormula } from '../util';-function createWorksheet() {- return {- getSheetId: () => 'sheet1',- getName: () => 'Sheet1',- getCellRaw: vi.fn((row: number, col: number) => {- const cells: Record<string, any> = {- '0,0': { v: 'Red' },- '0,1': { v: 'Green,Blue' },- '1,0': { v: '' },- '1,1': { v: 10 },- };- return cells[`${row},${col}`];- }),- };-}+const univers: Univer[] = [];function createContext() {- const worksheet = createWorksheet();- const workbook = {- getUnitId: () => 'unit1',- getActiveSheet: () => worksheet,- getSheetBySheetId: vi.fn((sheetId: string) => (sheetId === 'sheet1' ? worksheet : undefined)),- getSheetBySheetName: vi.fn((sheetName: string) => (sheetName === 'Sheet1' ? worksheet : undefined)),- };- const localeService = {- t: vi.fn((key: string) => key),- } as unknown as LocaleService;+ const univer = new Univer();+ univers.push(univer);+ const injector = univer.__getInjector();+ const localeService = injector.get(LocaleService);+ localeService.load({ [LocaleType.ZH_CN]: {} } as never);const formulaService = {getRuleFormulaResult: vi.fn(async () => ([{result: [[[@@ -72,32 +57,31 @@ function createContext() {})),};const lexerTreeBuilder = new LexerTreeBuilder();- const univerInstanceService = {- getUnit: vi.fn(() => workbook),- getUniverSheetInstance: vi.fn(() => workbook),- getCurrentUnitOfType: vi.fn((type: UniverInstanceType) => (type === UniverInstanceType.UNIVER_SHEET ? workbook : undefined)),- };- const injector = {- get(token: unknown) {- if (token === DataValidationFormulaService) {- return formulaService;- }- if (token === DataValidationListCacheService) {- return listCacheService;- }- if (token === LexerTreeBuilder) {- return lexerTreeBuilder;- }- if (String(token) === 'univer.current') {- return univerInstanceService;- }-- throw new Error(`Unknown token: ${String(token)}`);+ injector.add([DataValidationFormulaService, { useValue: formulaService as never }]);+ injector.add([DataValidationListCacheService, { useValue: listCacheService as never }]);+ injector.add([LexerTreeBuilder, { useValue: lexerTreeBuilder }]);+ injector.add([ListValidator]);+ const workbook = univer.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, {+ id: 'unit1',+ appVersion: '3.0.0-alpha',+ locale: LocaleType.EN_US,+ name: 'Test workbook',+ styles: {},+ sheetOrder: ['sheet1'],+ sheets: {+ sheet1: {+ id: 'sheet1',+ name: 'Sheet1',+ cellData: {+ 0: { 0: { v: 'Red' }, 1: { v: 'Green,Blue' } },+ 1: { 0: { v: '' }, 1: { v: 10 } },+ },+ },},- } as unknown as Injector;+ });+ const univerInstanceService = injector.get(IUniverInstanceService);return {- worksheet,workbook,localeService,formulaService,@@ -105,12 +89,13 @@ function createContext() {lexerTreeBuilder,univerInstanceService,injector,- validator: new ListValidator(localeService, injector),+ validator: injector.get(ListValidator),};}describe('list-validator helpers', () => {afterEach(() => {+ univers.splice(0).forEach((univer) => univer.dispose());vi.restoreAllMocks();});@@ -256,20 +241,30 @@ describe('list-validator helpers', () => {expect(listCacheService.getOrCompute).toHaveBeenCalled();});- it('returns empty lists when no workbook or worksheet can be resolved', async () => {- const context = createContext();- context.univerInstanceService.getUniverSheetInstance.mockReturnValueOnce(undefined as any);- context.univerInstanceService.getCurrentUnitOfType.mockReturnValueOnce(undefined as any);+ it('returns empty lists when no workbook can be resolved', async () => {+ const testBed = createContext();+ testBed.univerInstanceService.disposeUnit('unit1');++ expect(testBed.validator.getList({ formula1: 'A,B' } as any, 'missing', 'sheet1')).toEqual([]);+ expect(testBed.validator.getListWithColor({ formula1: 'A,B' } as any, 'missing', 'sheet1')).toEqual([]);+ expect(testBed.validator.getListWithColorMap({ formula1: 'A,B' } as any, 'missing', 'sheet1')).toEqual({});+ await expect(testBed.validator.getListAsync({ formula1: 'A,B' } as any, 'missing', 'sheet1')).resolves.toEqual([]);+ });++ it('falls back to the active worksheet when the requested worksheet is missing', async () => {+ const { validator, workbook } = createContext();+ const rule = { formula1: 'A,B' } as any;- expect(context.validator.getList({ formula1: 'A,B' } as any, 'missing', 'sheet1')).toEqual([]);- context.univerInstanceService.getUniverSheetInstance.mockReturnValue({- getSheetBySheetId: () => undefined,- getActiveSheet: () => undefined,- } as any);- context.univerInstanceService.getCurrentUnitOfType.mockReturnValue(undefined as any);- expect(context.validator.getListWithColor({ formula1: 'A,B' } as any, 'unit1', 'missing')).toEqual([]);- expect(context.validator.getListWithColorMap({ formula1: 'A,B' } as any, 'unit1', 'missing')).toEqual({});- await expect(context.validator.getListAsync({ formula1: 'A,B' } as any, 'unit1', 'missing')).resolves.toEqual([]);+ expect(workbook.getSheetBySheetId('missing')).toBeUndefined();+ expect(validator.getListWithColor(rule, 'unit1', 'missing')).toEqual([+ { label: 'Red', color: '#ff0000' },+ { label: 'Green', color: '#00ff00' },+ ]);+ expect(validator.getListWithColorMap(rule, 'unit1', 'missing')).toEqual({+ Red: '#ff0000',+ Green: '#00ff00',+ });+ await expect(validator.getListAsync(rule, 'unit1', 'missing')).resolves.toEqual(['A', 'B']);});it('extracts values from sheet ranges and single cells', () => {diff --git a/packages/sheets-data-validation/src/validators/list-validator.ts b/packages/sheets-data-validation/src/validators/list-validator.tsindex cfd340a820..421fa5bc85 100644--- a/packages/sheets-data-validation/src/validators/list-validator.ts+++ b/packages/sheets-data-validation/src/validators/list-validator.ts@@ -218,7 +218,7 @@ export class ListValidator extends BaseSheetValidator {}private _getUnitAndSubUnit(currentUnitId?: string, currentSubUnitId?: string): { unitId: string; subUnitId: string } | null {- const workbook = (currentUnitId ? this._univerInstanceService.getUniverSheetInstance(currentUnitId) : undefined)+ const workbook = (currentUnitId ? this._univerInstanceService.getUnit<Workbook>(currentUnitId, UniverInstanceType.UNIVER_SHEET) : undefined)?? this._univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET);if (!workbook) return null;diff --git a/packages/sheets-data-validation/src/validators/util.ts b/packages/sheets-data-validation/src/validators/util.tsindex 4af1aaea43..e6ad8c0206 100644--- a/packages/sheets-data-validation/src/validators/util.ts+++ b/packages/sheets-data-validation/src/validators/util.ts@@ -24,7 +24,7 @@ import { getCellValueOrigin } from '../utils/get-cell-data-origin';export function getSheetRangeValueSet(grid: IUnitRangeName, univerInstanceService: IUniverInstanceService, currUnitId: string, currSubUnitId: string) {const set = new Set<string>();const unitId = grid.unitId || currUnitId;- const workbook = univerInstanceService.getUniverSheetInstance(unitId) ?? univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;+ const workbook = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET) ?? univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;const worksheet = workbook.getSheetBySheetName(grid.sheetName) ?? workbook.getSheetBySheetId(currSubUnitId) ?? workbook.getActiveSheet();Range.foreach(grid.range, (row, col) => {const data = worksheet?.getCellRaw(row, col);diff --git a/packages/sheets-drawing/src/commands/commands/__tests__/sheet-drawing.integration.spec.ts b/packages/sheets-drawing/src/commands/commands/__tests__/sheet-drawing.integration.spec.tsindex 5759d56532..bc383e4837 100644--- a/packages/sheets-drawing/src/commands/commands/__tests__/sheet-drawing.integration.spec.ts+++ b/packages/sheets-drawing/src/commands/commands/__tests__/sheet-drawing.integration.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { Injector, Univer } from '@univerjs/core';+import type { Injector, Univer, Workbook } from '@univerjs/core';import type { ISheetDrawing } from '../../../services/sheet-drawing.service';import {ArrangeTypeEnum,@@ -24,6 +24,7 @@ import {IUndoRedoService,IUniverInstanceService,UndoCommand,+ UniverInstanceType,} from '@univerjs/core';import { DRAWING_COPY_CONTEXT_KEY, IDrawingManagerService } from '@univerjs/drawing';import { CopySheetCommand, RemoveSheetCommand, SetWorksheetActivateCommand, SheetInterceptorService } from '@univerjs/sheets';@@ -542,7 +543,7 @@ describe('sheet drawing integration', () => {subUnitId: 'sheet1',})).toBe(true);- const workbook = get(IUniverInstanceService).getUniverSheetInstance('test')!;+ const workbook = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!;let copiedSheetId = '';const sheets = workbook.getSheets();for (const sheet of sheets) {@@ -593,7 +594,7 @@ describe('sheet drawing integration', () => {subUnitId: 'sheet1',})).toBe(true);- const workbook = get(IUniverInstanceService).getUniverSheetInstance('test')!;+ const workbook = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!;const copiedSheetId = workbook.getSheets().map((sheet) => sheet.getSheetId()).find((sheetId) => sheetId !== 'sheet1' && sheetId !== 'sheet2')!;diff --git a/packages/sheets-filter-ui/src/services/sheets-filter-panel.service.ts b/packages/sheets-filter-ui/src/services/sheets-filter-panel.service.tsindex a77031475d..1f702e4807 100644--- a/packages/sheets-filter-ui/src/services/sheets-filter-panel.service.ts+++ b/packages/sheets-filter-ui/src/services/sheets-filter-panel.service.ts@@ -14,11 +14,11 @@* limitations under the License.*/-import type { IDisposable, IRange, Nullable } from '@univerjs/core';+import type { IDisposable, IRange, Nullable, Workbook } from '@univerjs/core';import type { FilterColumn, FilterModel, IFilterColumn, ISetSheetsFilterCriteriaCommandParams } from '@univerjs/sheets-filter';import type { Observable } from 'rxjs';import type { FilterOperator, IFilterConditionFormParams, IFilterConditionItem } from '../models/conditions';-import { ColorKit, createIdentifier, Disposable, ICommandService, Inject, Injector, IUniverInstanceService, LocaleService, Quantity, Tools } from '@univerjs/core';+import { ColorKit, createIdentifier, Disposable, ICommandService, Inject, Injector, IUniverInstanceService, LocaleService, Quantity, Tools, UniverInstanceType } from '@univerjs/core';import { COLOR_BLACK_RGB } from '@univerjs/engine-render';import { RefRangeService } from '@univerjs/sheets';import { FilterBy, SetSheetsFilterCriteriaCommand } from '@univerjs/sheets-filter';@@ -440,7 +440,7 @@ export class ByValuesModel extends Disposable implements IFilterByModel {const generateFilterValuesService = injector.get(ISheetsGenerateFilterValuesService, Quantity.OPTIONAL);const { unitId, subUnitId } = filterModel;- const workbook = univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) throw new Error(`[ByValuesModel]: Workbook not found for filter model with unitId: ${unitId}!`);const worksheet = workbook?.getSheetBySheetId(subUnitId);@@ -702,7 +702,7 @@ export class ByColorsModel extends Disposable implements IFilterByModel {const univerInstanceService = injector.get(IUniverInstanceService);const { unitId, subUnitId } = filterModel;- const workbook = univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) throw new Error(`[ByColorsModel]: Workbook not found for filter model with unitId: ${unitId}!`);const worksheet = workbook?.getSheetBySheetId(subUnitId);diff --git a/packages/sheets-filter/src/controllers/sheets-filter.controller.ts b/packages/sheets-filter/src/controllers/sheets-filter.controller.tsindex 7653827952..991bf63cd4 100644--- a/packages/sheets-filter/src/controllers/sheets-filter.controller.ts+++ b/packages/sheets-filter/src/controllers/sheets-filter.controller.ts@@ -54,6 +54,7 @@ import {moveMatrixArray,Optional,Rectangle,+ UniverInstanceType,} from '@univerjs/core';import { DataSyncPrimaryController } from '@univerjs/rpc';import {@@ -178,7 +179,7 @@ export class SheetsFilterController extends Disposable {this.disposeWithMe(this._sheetsFilterService.loadedUnitId$.subscribe((unitId) => {if (unitId) {- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const sheet = workbook?.getActiveSheet();if (sheet) {this._registerRefRange(unitId, sheet.getSheetId());@@ -189,7 +190,7 @@ export class SheetsFilterController extends Disposable {private _registerRefRange(unitId: string, subUnitId: string): void {this._disposableCollection.dispose();- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const workSheet = workbook?.getSheetBySheetId(subUnitId);if (!workbook || !workSheet) return;const range = this._sheetsFilterService.getFilterModel(unitId, subUnitId)?.getRange();@@ -478,7 +479,7 @@ export class SheetsFilterController extends Disposable {undos.push({ id: SetSheetsFilterCriteriaMutation.id, params: setCriteriaMutationParams });});} else {- const worksheet = this._univerInstanceService.getUniverSheetInstance(unitId)?.getSheetBySheetId(subUnitId);+ const worksheet = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(subUnitId);if (!worksheet) {return this._handleNull();}diff --git a/packages/sheets-filter/src/services/__tests__/sheet-filter.service.spec.ts b/packages/sheets-filter/src/services/__tests__/sheet-filter.service.spec.tsindex f36e3c9170..f41a731960 100644--- a/packages/sheets-filter/src/services/__tests__/sheet-filter.service.spec.ts+++ b/packages/sheets-filter/src/services/__tests__/sheet-filter.service.spec.ts@@ -30,12 +30,14 @@ import {UniverInstanceService,Workbook,} from '@univerjs/core';-import { of } from 'rxjs';-import { describe, expect, it } from 'vitest';+import { afterEach, describe, expect, it } from 'vitest';import { SheetsFilterService } from '../sheet-filter.service';+const injectors: Injector[] = [];+function createService() {const injector = new Injector();+ injectors.push(injector);injector.add([ILogService, { useClass: DesktopLogService }]);injector.add([IConfigService, { useClass: ConfigService }]);injector.add([IContextService, { useClass: ContextService }]);@@ -57,16 +59,6 @@ function createService() {function createServiceWithCapturedResource() {let resourceConfig: any;- const sheet = {- getUnitId: () => 'unit-1',- getSheetId: () => 'sheet-1',- };- const workbook = {- getUnitId: () => 'unit-1',- getSheetBySheetId: (sheetId: string) => (sheetId === 'sheet-1' ? sheet : null),- getActiveSheet: () => sheet,- activeSheet$: of(sheet),- };class TestResourceManagerService {registerPluginResource(config: unknown) {@@ -75,25 +67,33 @@ function createServiceWithCapturedResource() {}}- class TestUniverInstanceService {- getUniverSheetInstance = (unitId: string) => (unitId === 'unit-1' ? workbook : null);- getCurrentUnitOfType = () => workbook;- getCurrentTypeOfUnit$ = () => of(workbook);- }-class TestCommandService {onCommandExecuted = () => ({ dispose: () => undefined });}const injector = new Injector();+ injectors.push(injector);+ injector.add([ILogService, { useClass: DesktopLogService }]);+ injector.add([IContextService, { useClass: ContextService }]);injector.add([IResourceManagerService, { useClass: TestResourceManagerService as never }]);- injector.add([IUniverInstanceService, { useClass: TestUniverInstanceService as never }]);+ injector.add([IUniverInstanceService, { useClass: UniverInstanceService }]);injector.add([ICommandService, { useClass: TestCommandService as never }]);injector.add([SheetsFilterService]);+ const univerInstanceService = injector.get(IUniverInstanceService) as UniverInstanceService;+ const workbook = injector.createInstance(Workbook, {+ id: 'unit-1',+ sheets: { 'sheet-1': { id: 'sheet-1' } },+ sheetOrder: ['sheet-1'],+ });+ univerInstanceService.__addUnit(workbook);+ univerInstanceService.focusUnit('unit-1');+return { service: injector.get(SheetsFilterService), getResourceConfig: () => resourceConfig };}+afterEach(() => injectors.splice(0).forEach((injector) => injector.dispose()));+describe('SheetsFilterService', () => {it('creates and removes filter models for workbook sheets', () => {const service = createService();diff --git a/packages/sheets-filter/src/services/sheet-filter.service.ts b/packages/sheets-filter/src/services/sheet-filter.service.tsindex 86957ecf22..0c9d10e8c3 100644--- a/packages/sheets-filter/src/services/sheet-filter.service.ts+++ b/packages/sheets-filter/src/services/sheet-filter.service.ts@@ -76,7 +76,7 @@ export class SheetsFilterService extends Disposable {return already;}- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {throw new Error(`[SheetsFilterService]: could not create "FilterModel" on a non-existing workbook ${unitId}!`);}@@ -165,7 +165,7 @@ export class SheetsFilterService extends Disposable {}private _deserializeAutoFiltersForUnit(unitId: string, json: ISheetsFilterResource): void {- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId)!;+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET)!;Object.keys(json).forEach((worksheetId: WorksheetID) => {const autoFilter = json[worksheetId]!;const filterModel = FilterModel.deserialize(unitId, worksheetId, workbook.getSheetBySheetId(worksheetId)!, autoFilter);diff --git a/packages/sheets-formula-ui/src/commands/operations/__tests__/insert-function.operation.spec.ts b/packages/sheets-formula-ui/src/commands/operations/__tests__/insert-function.operation.spec.tsindex d5977c41ef..fd0c4d5032 100644--- a/packages/sheets-formula-ui/src/commands/operations/__tests__/insert-function.operation.spec.ts+++ b/packages/sheets-formula-ui/src/commands/operations/__tests__/insert-function.operation.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, Injector, Nullable, Univer } from '@univerjs/core';+import type { ICellData, Injector, Nullable, Univer, Workbook } from '@univerjs/core';import type { IInsertFunctionOperationParams } from '../insert-function.operation';import {DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,@@ -25,6 +25,7 @@ import {RANGE_TYPE,RedoCommand,UndoCommand,+ UniverInstanceType,} from '@univerjs/core';import { IEditorService } from '@univerjs/docs-ui';import {@@ -99,7 +100,7 @@ describe('Test insert function operation', () => {function getValues() {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(2, 1, 3, 1).getValues();@@ -136,7 +137,7 @@ describe('Test insert function operation', () => {function getValues() {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(1, 2, 1, 3).getValues();@@ -209,7 +210,7 @@ describe('Test insert function operation', () => {function getValues(range: { startRow: number; startColumn: number; endRow: number; endColumn: number }) {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(range.startRow, range.startColumn, range.endRow, range.endColumn).getValues();diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/formula-auto-fill.controller.spec.ts b/packages/sheets-formula-ui/src/controllers/__tests__/formula-auto-fill.controller.spec.tsindex a5754d0e96..f88d7ee1b9 100644--- a/packages/sheets-formula-ui/src/controllers/__tests__/formula-auto-fill.controller.spec.ts+++ b/packages/sheets-formula-ui/src/controllers/__tests__/formula-auto-fill.controller.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, Injector, Nullable, Univer } from '@univerjs/core';+import type { ICellData, Injector, Nullable, Univer, Workbook } from '@univerjs/core';import {ICommandService,IUniverInstanceService,@@ -23,6 +23,7 @@ import {set,ThemeService,UndoCommand,+ UniverInstanceType,} from '@univerjs/core';import {AddWorksheetMergeMutation,@@ -106,7 +107,7 @@ describe('Test auto fill with formula', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/formula-clipboard.controller.spec.ts b/packages/sheets-formula-ui/src/controllers/__tests__/formula-clipboard.controller.spec.tsindex 8b0d9b0b00..aca7554cd7 100644--- a/packages/sheets-formula-ui/src/controllers/__tests__/formula-clipboard.controller.spec.ts+++ b/packages/sheets-formula-ui/src/controllers/__tests__/formula-clipboard.controller.spec.ts@@ -463,7 +463,7 @@ describe('Test cut command with formulas', () => {sheetId: string = 'sheet1'): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(sheetId)?.getRange(startRow, startColumn, endRow, endColumn).getValues();@@ -565,7 +565,7 @@ describe('Test cut command with formulas', () => {) {const testSheetClipboardService = sheetClipboardService as ITestSheetClipboardService;const copyContentCache = sheetClipboardService.copyContentCache();- const workbook = get(IUniverInstanceService).getUniverSheetInstance('test');+ const workbook = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET);const targetWorksheet = workbook?.getSheetBySheetId(toSubUnitId);if (targetWorksheet) {@@ -870,7 +870,7 @@ describe('Test paste with formula', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/formula-reorder.controller.spec.ts b/packages/sheets-formula-ui/src/controllers/__tests__/formula-reorder.controller.spec.tsindex 8e7a830422..66e3d68824 100644--- a/packages/sheets-formula-ui/src/controllers/__tests__/formula-reorder.controller.spec.ts+++ b/packages/sheets-formula-ui/src/controllers/__tests__/formula-reorder.controller.spec.ts@@ -14,50 +14,48 @@* limitations under the License.*/-import { ReorderRangeCommand, SetRangeValuesMutation } from '@univerjs/sheets';-import { describe, expect, it, vi } from 'vitest';+import type { IWorkbookData } from '@univerjs/core';+import { LocaleType } from '@univerjs/core';+import { ReorderRangeCommand, SetRangeValuesMutation, SheetInterceptorService } from '@univerjs/sheets';+import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { FormulaReorderController } from '../formula-reorder.controller';+import { createCommandTestBed } from './create-command-test-bed';-function createController(options?: { worksheet?: any }) {- let interceptor: any;- const disposable = { dispose: vi.fn() };- const sheetInterceptorService = {- interceptCommand: vi.fn((registeredInterceptor) => {- interceptor = registeredInterceptor;- return disposable;- }),- };- const workbook = {- getSheetBySheetId: vi.fn(() => options?.worksheet ?? null),- };- const controller = new FormulaReorderController(- sheetInterceptorService as any,- { getUniverSheetInstance: vi.fn(() => workbook) } as any,- { getFormulaStringByCell: vi.fn(() => '=A2') } as any,- { moveFormulaRefOffset: vi.fn(() => '=A1') } as any- );-- return { controller, interceptor, disposable };-}+const WORKBOOK_DATA: IWorkbookData = {+ id: 'unit',+ appVersion: '3.0.0-alpha',+ locale: LocaleType.EN_US,+ name: 'Test workbook',+ styles: {},+ sheetOrder: ['sheet'],+ sheets: {+ sheet: {+ id: 'sheet',+ name: 'Sheet 1',+ cellData: {+ 0: { 0: { v: 'old-row' } },+ 1: { 0: { f: '=A2', si: 'shared' } },+ },+ },+ },+};describe('FormulaReorderController', () => {- it('creates redo and undo mutations with formula references shifted to the reordered row', () => {- const matrix = {- getValue: vi.fn((row: number, col: number) => {- if (row === 1 && col === 0) {- return { f: '=A2', si: 'shared' };- }- if (row === 0 && col === 0) {- return { v: 'old-row' };- }- return { v: `cell-${row}-${col}` };- }),- };- const { controller, interceptor, disposable } = createController({- worksheet: { getCellMatrix: vi.fn(() => matrix) },- });+ let univer: ReturnType<typeof createCommandTestBed>['univer'];+ let controller: FormulaReorderController;+ let sheetInterceptorService: SheetInterceptorService;++ beforeEach(() => {+ const testBed = createCommandTestBed(WORKBOOK_DATA, [[FormulaReorderController]]);+ univer = testBed.univer;+ controller = testBed.get(FormulaReorderController);+ sheetInterceptorService = testBed.get(SheetInterceptorService);+ });- const result = interceptor.getMutations({+ afterEach(() => univer.dispose());++ it('creates redo and undo mutations with formula references shifted to the reordered row', () => {+ const result = sheetInterceptorService.onCommandExecute({id: ReorderRangeCommand.id,params: {unitId: 'unit',@@ -93,25 +91,23 @@ describe('FormulaReorderController', () => {}]);controller.dispose();- expect(disposable.dispose).toHaveBeenCalled();+ expect(sheetInterceptorService.onCommandExecute({ id: ReorderRangeCommand.id, params: {} })).toEqual({+ preUndos: [],+ undos: [],+ preRedos: [],+ redos: [],+ });});it('returns empty mutations for non-reorder commands, missing worksheets and ranges without formulas', () => {- const { interceptor } = createController();- expect(interceptor.getMutations({ id: 'other-command', params: {} })).toEqual({ redos: [], undos: [] });- expect(interceptor.getMutations({+ expect(sheetInterceptorService.onCommandExecute({ id: 'other-command', params: {} })).toMatchObject({ redos: [], undos: [] });+ expect(sheetInterceptorService.onCommandExecute({id: ReorderRangeCommand.id,params: { unitId: 'unit', subUnitId: 'missing', range: { startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }, order: {} },- })).toEqual({ redos: [], undos: [] });-- const noFormula = createController({- worksheet: {- getCellMatrix: vi.fn(() => ({ getValue: vi.fn(() => ({ v: 'plain' })) })),- },- });- expect(noFormula.interceptor.getMutations({+ })).toMatchObject({ redos: [], undos: [] });+ expect(sheetInterceptorService.onCommandExecute({id: ReorderRangeCommand.id,params: { unitId: 'unit', subUnitId: 'sheet', range: { startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }, order: {} },- })).toEqual({ redos: [], undos: [] });+ })).toMatchObject({ redos: [], undos: [] });});});diff --git a/packages/sheets-formula-ui/src/controllers/__tests__/update-defined-name.controller.spec.ts b/packages/sheets-formula-ui/src/controllers/__tests__/update-defined-name.controller.spec.tsindex 5b191d0a2c..a054dcd653 100644--- a/packages/sheets-formula-ui/src/controllers/__tests__/update-defined-name.controller.spec.ts+++ b/packages/sheets-formula-ui/src/controllers/__tests__/update-defined-name.controller.spec.ts@@ -14,9 +14,9 @@* limitations under the License.*/-import type { ICellData, Injector, IWorkbookData, Nullable, Univer } from '@univerjs/core';+import type { ICellData, Injector, IWorkbookData, Nullable, Univer, Workbook } from '@univerjs/core';import type { IDeleteRangeMoveLeftCommandParams, IDeleteRangeMoveUpCommandParams, IInsertColCommandParams, IInsertRangeMoveDownCommandParams, IInsertRangeMoveRightCommandParams, IInsertRowCommandParams, IMoveColsCommandParams, IMoveRangeCommandParams, IMoveRowsCommandParams, IRemoveRowColCommandParams, IRemoveSheetCommandParams, ISetWorksheetNameCommandParams } from '@univerjs/sheets';-import { Direction, ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, RedoCommand, UndoCommand } from '@univerjs/core';+import { Direction, ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, RedoCommand, UndoCommand, UniverInstanceType } from '@univerjs/core';import { IDefinedNamesService, RemoveDefinedNameMutation, SetArrayFormulaDataMutation, SetDefinedNameMutation, SetFormulaDataMutation } from '@univerjs/engine-formula';import { DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, InsertColByRangeCommand, InsertColCommand, InsertColMutation, InsertRangeMoveDownCommand, InsertRangeMoveRightCommand, InsertRowByRangeCommand, InsertRowCommand, InsertRowMutation, MoveColsCommand, MoveColsMutation, MoveRangeCommand, MoveRangeMutation, MoveRowsCommand, MoveRowsMutation, RemoveColByRangeCommand, RemoveColCommand, RemoveColMutation, RemoveRowByRangeCommand, RemoveRowCommand, RemoveRowMutation, RemoveSheetCommand, RemoveSheetMutation, SetDefinedNameCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetSelectionsOperation, SetWorksheetNameCommand, SetWorksheetNameMutation, SheetsSelectionsService } from '@univerjs/sheets';import { UpdateDefinedNameController } from '@univerjs/sheets-formula';@@ -132,7 +132,7 @@ describe('Test update defined name', () => {sheetId: string = 'sheet1'): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(sheetId)?.getRange(startRow, startColumn, endRow, endColumn).getValues();diff --git a/packages/sheets-formula-ui/src/controllers/formula-reorder.controller.ts b/packages/sheets-formula-ui/src/controllers/formula-reorder.controller.tsindex ea27b3cd10..743163d669 100644--- a/packages/sheets-formula-ui/src/controllers/formula-reorder.controller.ts+++ b/packages/sheets-formula-ui/src/controllers/formula-reorder.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, IMutationInfo, Nullable } from '@univerjs/core';+import type { ICellData, IMutationInfo, Nullable, Workbook } from '@univerjs/core';import type { IReorderRangeMutationParams } from '@univerjs/sheets';import {Disposable,@@ -23,6 +23,7 @@ import {ObjectMatrix,Range,Tools,+ UniverInstanceType,} from '@univerjs/core';import { FormulaDataModel, LexerTreeBuilder } from '@univerjs/engine-formula';import { ReorderRangeCommand, SetRangeValuesMutation, SheetInterceptorService } from '@univerjs/sheets';@@ -58,7 +59,7 @@ export class FormulaReorderController extends Disposable {const redos: IMutationInfo[] = [];const undos: IMutationInfo[] = [];const { unitId, subUnitId, range, order } = params;- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const worksheet = workbook?.getSheetBySheetId(subUnitId);if (!worksheet) {diff --git a/packages/sheets-formula-ui/src/views/more-functions/__tests__/MoreFunctions.spec.tsx b/packages/sheets-formula-ui/src/views/more-functions/__tests__/MoreFunctions.spec.tsxindex 710b0a1dd3..142d555028 100644--- a/packages/sheets-formula-ui/src/views/more-functions/__tests__/MoreFunctions.spec.tsx+++ b/packages/sheets-formula-ui/src/views/more-functions/__tests__/MoreFunctions.spec.tsx@@ -283,10 +283,6 @@ class TestUniverInstanceService {getUnitType() {return UniverInstanceType.UNIVER_SHEET;}-- getUniverSheetInstance() {- return this._workbook;- }}class SelectionState {diff --git a/packages/sheets-formula/src/controllers/active-dirty.controller.ts b/packages/sheets-formula/src/controllers/active-dirty.controller.tsindex 5ec928c09c..935ec845cc 100644--- a/packages/sheets-formula/src/controllers/active-dirty.controller.ts+++ b/packages/sheets-formula/src/controllers/active-dirty.controller.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, ICommandInfo, IObjectMatrixPrimitiveType, IRange, IUnitRange, Nullable } from '@univerjs/core';+import type { ICellData, ICommandInfo, IObjectMatrixPrimitiveType, IRange, IUnitRange, Nullable, Workbook } from '@univerjs/core';import type { IDirtyUnitDefinedNameMap, IDirtyUnitSheetNameMap, IFormulaDirtyData, ISetDefinedNameMutationParam } from '@univerjs/engine-formula';import type {IInsertColMutationParams,@@ -36,6 +36,7 @@ import {Inject,IUniverInstanceService,ObjectMatrix,+ UniverInstanceType,} from '@univerjs/core';import { FormulaDataModel, IActiveDirtyManagerService, RemoveDefinedNameMutation, SetDefinedNameMutation, SetTriggerFormulaCalculationStartMutation } from '@univerjs/engine-formula';import {@@ -386,7 +387,7 @@ export class ActiveDirtyController extends Disposable {const dirtyRanges: IUnitRange[] = [];- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const worksheet = workbook?.getSheetBySheetId(sheetId);diff --git a/packages/sheets-sort-ui/src/commands/commands/__tests__/formula-reorder.spec.ts b/packages/sheets-sort-ui/src/commands/commands/__tests__/formula-reorder.spec.tsindex 49e53436b0..40df919530 100644--- a/packages/sheets-sort-ui/src/commands/commands/__tests__/formula-reorder.spec.ts+++ b/packages/sheets-sort-ui/src/commands/commands/__tests__/formula-reorder.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { ICellData, Injector, Nullable, Univer } from '@univerjs/core';-import { ICommandService, IConfirmService, IUniverInstanceService, RANGE_TYPE, TestConfirmService } from '@univerjs/core';+import type { ICellData, Injector, Nullable, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IConfirmService, IUniverInstanceService, RANGE_TYPE, TestConfirmService, UniverInstanceType } from '@univerjs/core';import { ReorderRangeCommand, ReorderRangeMutation, SetRangeValuesMutation, SheetsSelectionsService } from '@univerjs/sheets';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { SheetsSortUIService } from '../../../services/sheets-sort-ui.service';@@ -54,7 +54,7 @@ describe('Test "Sort Range Commands"', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();diff --git a/packages/sheets-table/src/commands/commands/__tests__/sheet-table-row-col.command.spec.ts b/packages/sheets-table/src/commands/commands/__tests__/sheet-table-row-col.command.spec.tsindex 28b5112ce0..31eda8fba0 100644--- a/packages/sheets-table/src/commands/commands/__tests__/sheet-table-row-col.command.spec.ts+++ b/packages/sheets-table/src/commands/commands/__tests__/sheet-table-row-col.command.spec.ts@@ -142,10 +142,6 @@ class TestUniverInstanceService {getCurrentUnitOfType() {return this._workbook;}-- getUniverSheetInstance(unitId: string) {- return this.getUnit(unitId);- }}function createSheetContext(options: ICreateSheetContextOptions = {}) {diff --git a/packages/sheets-ui/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/add-worksheet-merge.command.spec.tsindex cfe65898e6..99714e4e54 100644--- a/packages/sheets-ui/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts+++ b/packages/sheets-ui/src/commands/commands/__tests__/add-worksheet-merge.command.spec.ts@@ -148,7 +148,7 @@ describe('Test add worksheet merge commands', () => {function getMerge(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getConfig().mergeData;@@ -195,7 +195,7 @@ describe('Test add worksheet merge commands', () => {function getMerge(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getConfig().mergeData;@@ -240,7 +240,7 @@ describe('Test add worksheet merge commands', () => {function getMerge(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getConfig().mergeData;@@ -273,7 +273,7 @@ describe('Test add worksheet merge commands', () => {function getMerge(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getConfig().mergeData;@@ -328,7 +328,7 @@ describe('Test add worksheet merge commands', () => {function getMerge(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getConfig().mergeData;diff --git a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.tsindex cbd472fad0..28ba7bd863 100644--- a/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts+++ b/packages/sheets-ui/src/commands/commands/__tests__/auto-fill.controller.spec.ts@@ -384,7 +384,7 @@ describe('Test auto fill rules in controller', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();@@ -396,7 +396,7 @@ describe('Test auto fill rules in controller', () => {endColumn: number): Array<Array<Nullable<IStyleData>>> | undefined => {const values = getValues(startRow, startColumn, endRow, endColumn);- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (values && styles) {return values.map((row) => row.map((cell) => styles.getStyleByCell(cell)));}diff --git a/packages/sheets-ui/src/commands/commands/__tests__/hide-row-col-confirm.command.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/hide-row-col-confirm.command.spec.tsindex 0602e1ab75..6482717688 100644--- a/packages/sheets-ui/src/commands/commands/__tests__/hide-row-col-confirm.command.spec.ts+++ b/packages/sheets-ui/src/commands/commands/__tests__/hide-row-col-confirm.command.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { Injector, IRange, Univer } from '@univerjs/core';-import { ICommandService, IConfirmService, IUniverInstanceService, LocaleService, RANGE_TYPE, TestConfirmService } from '@univerjs/core';+import type { Injector, IRange, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IConfirmService, IUniverInstanceService, LocaleService, RANGE_TYPE, TestConfirmService, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeAllCommand,AddWorksheetMergeCommand,@@ -86,7 +86,7 @@ describe('Test hide row col confirm commands', () => {function getHiddenRows(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRowManager().getHiddenRows();@@ -117,7 +117,7 @@ describe('Test hide row col confirm commands', () => {function getHiddenRows(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRowManager().getHiddenRows();@@ -141,7 +141,7 @@ describe('Test hide row col confirm commands', () => {function getHiddenCols(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getColumnManager().getHiddenCols();@@ -172,7 +172,7 @@ describe('Test hide row col confirm commands', () => {function getHiddenCols(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getColumnManager().getHiddenCols();diff --git a/packages/sheets-ui/src/commands/commands/__tests__/remove-row-col-confirm.command.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/remove-row-col-confirm.command.spec.tsindex d6aa01c862..34d7ce2c5e 100644--- a/packages/sheets-ui/src/commands/commands/__tests__/remove-row-col-confirm.command.spec.ts+++ b/packages/sheets-ui/src/commands/commands/__tests__/remove-row-col-confirm.command.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { Injector, Univer } from '@univerjs/core';-import { ICommandService, IConfirmService, IUniverInstanceService, LocaleService, RANGE_TYPE, TestConfirmService } from '@univerjs/core';+import type { Injector, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IConfirmService, IUniverInstanceService, LocaleService, RANGE_TYPE, TestConfirmService, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeAllCommand,AddWorksheetMergeCommand,@@ -99,7 +99,7 @@ describe('Test remove row col confirm commands', () => {function getRowCount(): number | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRowCount();}@@ -121,7 +121,7 @@ describe('Test remove row col confirm commands', () => {function getRowCount(): number | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRowCount();}@@ -145,7 +145,7 @@ describe('Test remove row col confirm commands', () => {function getColumnCount(): number | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getColumnCount();}@@ -167,7 +167,7 @@ describe('Test remove row col confirm commands', () => {function getColumnCount(): number | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getColumnCount();}diff --git a/packages/sheets-ui/src/commands/operations/scroll.operation.ts b/packages/sheets-ui/src/commands/operations/scroll.operation.tsindex ff0d1b929f..1d79490466 100644--- a/packages/sheets-ui/src/commands/operations/scroll.operation.ts+++ b/packages/sheets-ui/src/commands/operations/scroll.operation.ts@@ -34,11 +34,6 @@ export const SetScrollOperation: IOperation<IScrollStateWithSearchParam> = {const { unitId, sheetId, offsetX = 0, offsetY = 0, sheetViewStartColumn, sheetViewStartRow, duration, screenRatioX, screenRatioY } = params;const renderManagerService = accessor.get(IRenderManagerService);const scrollManagerService = renderManagerService.getRenderUnitById(unitId)!.with(SheetScrollManagerService);- // const currentService = accessor.get(IUniverInstanceService);- // const workbook = currentService.getUniverSheetInstance(unitId);- // const worksheet = workbook!.getSheetBySheetId(sheetId);- // const { xSplit, ySplit } = worksheet!.getConfig().freeze;-const renderUnit = renderManagerService.getRenderUnitById(unitId);if (!renderUnit) {diff --git a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.tsindex 0a8881d633..bf86ab2ef7 100644--- a/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts+++ b/packages/sheets-ui/src/controllers/clipboard/clipboard.controller.ts@@ -830,7 +830,7 @@ export class SheetClipboardController extends RxDisposable {}private _getWorksheet(unitId: string, subUnitId: string): Worksheet {- const worksheet = this._instanceService.getUniverSheetInstance(unitId)?.getSheetBySheetId(subUnitId);+ const worksheet = this._instanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(subUnitId);if (!worksheet) {throw new Error(diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-copy-filter.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-copy-filter.spec.tsindex 3b831c746a..27fc36a7ed 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-copy-filter.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-copy-filter.spec.ts@@ -14,9 +14,9 @@* limitations under the License.*/-import type { ICellData, Injector, Nullable, Univer } from '@univerjs/core';+import type { ICellData, Injector, Nullable, Univer, Workbook } from '@univerjs/core';import type { ISetSelectionsOperationParams } from '@univerjs/sheets';-import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, set, ThemeService } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, set, ThemeService, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeMutation,RemoveWorksheetMergeMutation,@@ -106,7 +106,7 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();@@ -118,7 +118,7 @@ describe('Test clipboard', () => {describe('Copy area where have filtered out rows', () => {it('Paste content should not have filtered out rows', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')!.getSheetBySheetId('sheet1')!;+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!.getSheetBySheetId('sheet1')!;worksheet.__interceptViewModel((viewModel) => {viewModel.registerRowFilteredInterceptor({getRowFiltered(row: number): boolean {diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-alignment.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-alignment.spec.tsindex 6022873f6a..e641460008 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-alignment.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-alignment.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { ICellData, Injector, IStyleData, Nullable, Univer } from '@univerjs/core';-import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';+import type { ICellData, Injector, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeMutation,RemoveWorksheetMergeMutation,@@ -91,14 +91,14 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();getStyles = (key) => {if (!key) return;- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();return styles?.get(key);};});@@ -129,7 +129,7 @@ describe('Test clipboard', () => {});});it('test font style paste from excel', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(alignmentSampleByExcel);expect(res).toBeTruthy();@@ -143,7 +143,7 @@ describe('Test clipboard', () => {});it('test font style paste from google', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(alignmentSampleByGoogle);expect(res).toBeTruthy();@@ -156,7 +156,7 @@ describe('Test clipboard', () => {});it('test font style paste from univer', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(alignmentSampleByUniver);expect(res).toBeTruthy();diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-border.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-border.spec.tsindex f1a4a50a4b..35d8d1a61b 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-border.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-border.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IBorderData, ICellData, Injector, IStyleData, Nullable, Univer } from '@univerjs/core';-import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';+import type { IBorderData, ICellData, Injector, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeMutation,RemoveWorksheetMergeMutation,@@ -92,14 +92,14 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();getStyles = (key) => {if (!key) return;- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();return styles?.get(key);};@@ -138,7 +138,7 @@ describe('Test clipboard', () => {});});it('test font style paste from excel', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(borderSampleByExcel);expect(res).toBeTruthy();@@ -187,7 +187,7 @@ describe('Test clipboard', () => {});it('test font style paste from google', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(borderSampleByGoogle);expect(res).toBeTruthy();@@ -230,7 +230,7 @@ describe('Test clipboard', () => {});it('test font style paste from univer', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(borderSampleByUniver);expect(res).toBeTruthy();diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-font.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-font.spec.tsindex 0d58d4c848..bdaf05594c 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-font.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-font.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { ICellData, Injector, IStyleData, Nullable, Univer } from '@univerjs/core';-import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';+import type { ICellData, Injector, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeMutation,RemoveWorksheetMergeMutation,@@ -92,14 +92,14 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();getStyles = (key) => {if (!key) return;- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();return styles?.get(key);};@@ -138,7 +138,7 @@ describe('Test clipboard', () => {});});it('test font style paste from excel', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(fontSampleByExcel);expect(res).toBeTruthy();@@ -172,7 +172,7 @@ describe('Test clipboard', () => {});it('test font style paste from google', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(fontSampleByGoogle);expect(res).toBeTruthy();@@ -206,7 +206,7 @@ describe('Test clipboard', () => {});it('test font style paste from univer', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(fontSampleByUniver);expect(res).toBeTruthy();diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.tsindex 27c50446dc..95fa1e4c63 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-form-excel.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, Injector, IStyleData, Nullable, Univer } from '@univerjs/core';+import type { ICellData, Injector, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';import {CellValueType,DEFAULT_TEXT_FORMAT_EXCEL,@@ -22,6 +22,7 @@ import {IUniverInstanceService,LocaleType,RANGE_TYPE,+ UniverInstanceType,} from '@univerjs/core';import {AddWorksheetMergeMutation,@@ -127,7 +128,7 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();@@ -139,7 +140,7 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<IStyleData>>> | undefined => {const values = getValues(startRow, startColumn, endRow, endColumn);- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (values && styles) {return values.map((row) => row.map((cell) => styles.getStyleByCell(cell)));}@@ -172,7 +173,7 @@ describe('Test clipboard', () => {});});it('test style with paste cell style', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(excelSample);expect(res).toBeTruthy();@@ -193,7 +194,7 @@ describe('Test clipboard', () => {});it('test style with paste rich text style', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(excelSample);expect(res).toBeTruthy();@@ -234,7 +235,7 @@ describe('Test clipboard', () => {});it('test numfmt with paste', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(excelSample);expect(res).toBeTruthy();@@ -243,7 +244,7 @@ describe('Test clipboard', () => {});it('test formula with paste', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste('', '=SUM(A1');expect(res).toBeTruthy();@@ -252,7 +253,7 @@ describe('Test clipboard', () => {});it('test paste to range K1:L1, K1 has style, L1 has text format', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;// set selection to K1:L1@@ -308,7 +309,7 @@ describe('Test clipboard', () => {});it('copy number 123456789123456789', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;// set selection to K1:L1@@ -338,7 +339,7 @@ describe('Test clipboard', () => {});it('copy value is 1,234.57, the format "#,##0.00", the origin value 1234.567', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;// set selection to K1:L1@@ -368,7 +369,7 @@ describe('Test clipboard', () => {});it('copy value is $ 23,123.00, the format "$#,##0.00", the origin value 23123', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;// set selection to K1:L1@@ -398,7 +399,7 @@ describe('Test clipboard', () => {});it('copy value is ` 1 3 `, no specific format', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;// set selection to K1:L1@@ -429,7 +430,7 @@ describe('Test clipboard', () => {});it('copy value is (30), (30,303,003,030), 3.14, 2015/2/2, 3000%, ¥ 1,234.57', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;// set selection to K1:L1diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-google.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-google.spec.tsindex debb87d813..cda9fad3dd 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-google.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-google.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { ICellData, Injector, IStyleData, Nullable, Univer } from '@univerjs/core';-import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';+import type { ICellData, Injector, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeMutation,MoveRangeMutation,@@ -96,7 +96,7 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();@@ -108,7 +108,7 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<IStyleData>>> | undefined => {const values = getValues(startRow, startColumn, endRow, endColumn);- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (values && styles) {return values.map((row) => row.map((cell) => styles.getStyleByCell(cell)));}@@ -141,7 +141,7 @@ describe('Test clipboard', () => {});});it('test style with paste cell style', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(googleSample);expect(res).toBeTruthy();@@ -157,7 +157,7 @@ describe('Test clipboard', () => {});it('test style with paste rich text style', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(googleSample);expect(res).toBeTruthy();@@ -199,7 +199,7 @@ describe('Test clipboard', () => {});it('test numfmt with paste', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(googleSample);expect(res).toBeTruthy();@@ -208,7 +208,7 @@ describe('Test clipboard', () => {});it('test merge style with paste', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste(googleSample);expect(res).toBeTruthy();diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-notepad.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-notepad.spec.tsindex 1ddf64d46e..1a777a39a8 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-notepad.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-from-notepad.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { ICellData, Injector, Nullable, Univer } from '@univerjs/core';-import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';+import type { ICellData, Injector, Nullable, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeMutation,MoveRangeMutation,@@ -91,7 +91,7 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();@@ -128,7 +128,7 @@ describe('Test clipboard', () => {});});it('test value with paste plain text', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');if (!worksheet) return false;const res = await sheetClipboardService.legacyPaste('', plainTextByNotepad);expect(res).toBeTruthy();diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-rotate.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-rotate.spec.tsindex 2229464750..cd0b49d0dc 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-rotate.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard-paste-rotate.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { ICellData, Injector, IStyleData, Nullable, Univer } from '@univerjs/core';-import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';+import type { ICellData, Injector, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeMutation,RemoveWorksheetMergeMutation,@@ -93,13 +93,13 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();getStyles = (key) => {- return get(IUniverInstanceService).getUniverSheetInstance('test')!.getStyles().get(key);+ return get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!.getStyles().get(key);};convertColor = (color) => {@@ -138,7 +138,7 @@ describe('Test clipboard', () => {});it('test font style paste from univer', async () => {- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')!.getSheetBySheetId('sheet1')!;+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!.getSheetBySheetId('sheet1')!;const res = await sheetClipboardService.legacyPaste(rotateSampleByUniver);expect(res).toBeTruthy();diff --git a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard.service.spec.ts b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard.service.spec.tsindex d160910cfd..d16225039a 100644--- a/packages/sheets-ui/src/services/clipboard/__tests__/clipboard.service.spec.ts+++ b/packages/sheets-ui/src/services/clipboard/__tests__/clipboard.service.spec.ts@@ -14,9 +14,9 @@* limitations under the License.*/-import type { ICellData, Injector, IRange, IStyleData, Nullable, Univer } from '@univerjs/core';+import type { ICellData, Injector, IRange, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';import type { IClipboardItem } from './mock-clipboard';-import { ICommandService, IUniverInstanceService, RANGE_TYPE, Rectangle, RedoCommand, UndoCommand } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, RANGE_TYPE, Rectangle, RedoCommand, UndoCommand, UniverInstanceType } from '@univerjs/core';import {AddWorksheetMergeMutation,discreteRangeToRange,@@ -97,7 +97,7 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();@@ -109,7 +109,7 @@ describe('Test clipboard', () => {endColumn: number): IRange[] | undefined => {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getMergeData().filter((rect) => Rectangle.intersects({ startRow, startColumn, endRow, endColumn }, rect));@@ -122,7 +122,7 @@ describe('Test clipboard', () => {endColumn: number): Array<Array<Nullable<IStyleData>>> | undefined => {const values = getValues(startRow, startColumn, endRow, endColumn);- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (values && styles) {return values.map((row) => row.map((cell) => styles.getStyleByCell(cell)));}@@ -165,7 +165,7 @@ describe('Test clipboard', () => {const values = getValues(startRow, startColumn, endRow, endColumn);const styles = getStyles(startRow, startColumn, endRow, endColumn);const mergedCells = getMergedCells(startRow, startColumn, endRow, endColumn);- const columnManager = get(IUniverInstanceService).getUniverSheetInstance('test')?.getSheetBySheetId('sheet1')?.getColumnManager();+ const columnManager = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getColumnManager();const columnWidth = columnManager?.getColumnWidth(0);expect(columnWidth).toBe(88);expect(values && values[0][0]?.v).toBe('row1col2');diff --git a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts b/packages/sheets-ui/src/services/clipboard/clipboard.service.tsindex 5f8105e37a..19a9eb3b04 100644--- a/packages/sheets-ui/src/services/clipboard/clipboard.service.ts+++ b/packages/sheets-ui/src/services/clipboard/clipboard.service.ts@@ -492,7 +492,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard}private _generateCopyContent(unitId: string, subUnitId: string, range: IRange, hooks: ISheetClipboardHook[], copyHookType: ICopyHookValueType = PREDEFINED_HOOK_NAME_COPY.DEFAULT_COPY): Nullable<ICopyContent> {- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const worksheet = workbook?.getSheetBySheetId(subUnitId);if (!workbook || !worksheet) {@@ -807,7 +807,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard}const worksheet = this._univerInstanceService- .getUniverSheetInstance(pasteTarget.unitId)+ .getUnit<Workbook>(pasteTarget.unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(pasteTarget.subUnitId);if (!worksheet) {return false;@@ -859,7 +859,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboard}const { mapFunc } = virtualizeDiscreteRanges([range]);- const worksheet = this._univerInstanceService.getUniverSheetInstance(copyUnitId)?.getSheetBySheetId(copySubUnitId);+ const worksheet = this._univerInstanceService.getUnit<Workbook>(copyUnitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(copySubUnitId);const cellMatrix = new ObjectMatrix<ICellDataWithSpanInfo>();cachedMatrix.forValue((row, col, value) => {@@ -893,7 +893,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardif (!pasteTarget) return false;const pasteToWorksheet = this._univerInstanceService- .getUniverSheetInstance(pasteTarget.unitId)+ .getUnit<Workbook>(pasteTarget.unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(pasteTarget.subUnitId);if (!pasteToWorksheet) {return false;@@ -1178,7 +1178,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardcellMatrix: ObjectMatrix<ICellDataWithSpanAndDisplay>,pasteType?: string) {- const worksheet = this._univerInstanceService.getUniverSheetInstance(unitId)?.getSheetBySheetId(subUnitId);+ const worksheet = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(subUnitId);if (!worksheet) {return null;}@@ -1454,7 +1454,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardconst pasteSelectionRangeColLen = discreteRange.cols.length;const worksheet = this._univerInstanceService- .getUniverSheetInstance(unitId)+ .getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(subUnitId);if (!worksheet) {return null;@@ -1492,7 +1492,7 @@ export class SheetClipboardService extends Disposable implements ISheetClipboardprivate _expandOrShrinkRowsCols(unitId: string, subUnitId: string, range: IDiscreteRange, colCount: number, rowCount: number) {const { rows, cols } = range;- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const worksheet = workbook?.getSheetBySheetId(subUnitId);let newRows: number[];let newCols: number[];diff --git a/packages/sheets/src/commands/commands/__tests__/add-merge.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/add-merge.command.spec.tsindex 3365d725ce..6c0cd3535f 100644--- a/packages/sheets/src/commands/commands/__tests__/add-merge.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/add-merge.command.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { Injector, IWorkbookData } from '@univerjs/core';+import type { Injector, IWorkbookData, Workbook } from '@univerjs/core';import {ICommandService,IConfirmService,@@ -23,6 +23,7 @@ import {LocaleType,RANGE_TYPE,TestConfirmService,+ UniverInstanceType,} from '@univerjs/core';import { beforeEach, describe, expect, it } from 'vitest';import enUS from '../../../locale/en-US';@@ -154,7 +155,7 @@ describe('add-merge-command', () => {let commandService: ICommandService;function getWorksheet(getter: Injector['get'] = get) {- const workbook = getter(IUniverInstanceService).getUniverSheetInstance('test');+ const workbook = getter(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET);if (!workbook) {throw new Error('Expected workbook test to exist.');}diff --git a/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.tsindex fc39772190..0389af3d83 100644--- a/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/clear-selection.command.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, Injector, IRange, IStyleData, Nullable, Univer } from '@univerjs/core';+import type { ICellData, Injector, IRange, IStyleData, Nullable, Univer, Workbook } from '@univerjs/core';import type { ISetRangeValuesCommandParams } from '../set-range-values.command';import {CellValueType,@@ -25,6 +25,7 @@ import {RedoCommand,TestConfirmService,UndoCommand,+ UniverInstanceType,} from '@univerjs/core';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { MergeCellController } from '../../../controllers/merge-cell.controller';@@ -84,7 +85,7 @@ describe('Test clear selection content commands', () => {function getValue(): Nullable<ICellData> {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getValue();@@ -129,7 +130,7 @@ describe('Test clear selection content commands', () => {function getValue(): Nullable<ICellData> {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getValue();@@ -137,7 +138,7 @@ describe('Test clear selection content commands', () => {function getStyle(): Nullable<IStyleData> {const value = getValue();- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (value && styles) {return styles.getStyleByCell(value);}@@ -188,7 +189,7 @@ describe('Test clear selection content commands', () => {function getValue(): Nullable<ICellData> {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getValue();@@ -196,7 +197,7 @@ describe('Test clear selection content commands', () => {function getStyle(): Nullable<IStyleData> {const value = getValue();- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (value && styles) {return styles.getStyleByCell(value);}@@ -204,7 +205,7 @@ describe('Test clear selection content commands', () => {function getMerge(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getConfig().mergeData;@@ -280,7 +281,7 @@ describe('Test clear selection content commands', () => {function getValue(): Nullable<ICellData> {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getValue();@@ -288,7 +289,7 @@ describe('Test clear selection content commands', () => {function getStyle(): Nullable<IStyleData> {const value = getValue();- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (value && styles) {return styles.getStyleByCell(value);}@@ -331,7 +332,7 @@ describe('Test clear selection content commands', () => {function getValue(): Nullable<ICellData> {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getValue();@@ -339,7 +340,7 @@ describe('Test clear selection content commands', () => {function getStyle(): Nullable<IStyleData> {const value = getValue();- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (value && styles) {return styles.getStyleByCell(value);}@@ -347,7 +348,7 @@ describe('Test clear selection content commands', () => {function getMerge(): IRange[] | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getConfig().mergeData;diff --git a/packages/sheets/src/commands/commands/__tests__/delete-range.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/delete-range.command.spec.tsindex 5f1bb545ac..8949cf2e53 100644--- a/packages/sheets/src/commands/commands/__tests__/delete-range.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/delete-range.command.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, Injector, IRange, IStyleData, IWorkbookData, Nullable, Univer } from '@univerjs/core';+import type { ICellData, Injector, IRange, IStyleData, IWorkbookData, Nullable, Univer, Workbook } from '@univerjs/core';import {ICommandService,IUniverInstanceService,@@ -23,6 +23,7 @@ import {Rectangle,RedoCommand,UndoCommand,+ UniverInstanceType,} from '@univerjs/core';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { SheetsSelectionsService } from '../../../services/selections/selection.service';@@ -207,7 +208,7 @@ describe('Test delete range commands', () => {endColumn: number): Nullable<ICellData> =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValue();@@ -219,7 +220,7 @@ describe('Test delete range commands', () => {endColumn: number): Nullable<IStyleData> => {const value = getValueByPosition(startRow, startColumn, endRow, endColumn);- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (value && styles) {return styles.getStyleByCell(value);}@@ -232,7 +233,7 @@ describe('Test delete range commands', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();@@ -244,7 +245,7 @@ describe('Test delete range commands', () => {endColumn: number): IRange[] | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getMergeData().filter((rect) => Rectangle.intersects({ startRow, startColumn, endRow, endColumn }, rect));diff --git a/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.tsindex 690dd0c5a1..aa7c68fe23 100644--- a/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/insert-range.command.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, Injector, IRange, IStyleData, IWorkbookData, Nullable, Univer } from '@univerjs/core';+import type { ICellData, Injector, IRange, IStyleData, IWorkbookData, Nullable, Univer, Workbook } from '@univerjs/core';import {ICommandService,IUniverInstanceService,@@ -24,6 +24,7 @@ import {RedoCommand,Tools,UndoCommand,+ UniverInstanceType,} from '@univerjs/core';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { MergeCellController } from '../../../controllers/merge-cell.controller';@@ -212,7 +213,7 @@ describe('Test insert range commands', () => {endRow: number,endColumn: number): Nullable<ICellData> => {- const worksheet = get(IUniverInstanceService)?.getUniverSheetInstance('test')?.getSheetBySheetId('sheet1');+ const worksheet = get(IUniverInstanceService)?.getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1');const value = worksheet?.getRange(startRow, startColumn, endRow, endColumn);return value?.getValue();};@@ -224,7 +225,7 @@ describe('Test insert range commands', () => {endColumn: number): Nullable<IStyleData> => {const value = getValueByPosition(startRow, startColumn, endRow, endColumn);- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (value && styles) {return styles.getStyleByCell(value);}@@ -253,7 +254,7 @@ describe('Test insert range commands', () => {endColumn: number): Array<Array<Nullable<ICellData>>> | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();@@ -265,7 +266,7 @@ describe('Test insert range commands', () => {endColumn: number): IRange[] | undefined =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getMergeData().filter((rect) => Rectangle.intersects({ startRow, startColumn, endRow, endColumn }, rect));@@ -543,7 +544,7 @@ describe('Test insert range commands', () => {range: { startRow: 1, endRow: 3, startColumn: 0, endColumn: 0 },})).resolves.toBe(true);- const worksheet = localGet(IUniverInstanceService).getUniverSheetInstance('test')!.getSheetBySheetId('sheet1')!;+ const worksheet = localGet(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!.getSheetBySheetId('sheet1')!;expect(worksheet.getRowCount()).toBe(13);expect(worksheet.getRowHeight(2)).toBe(40);expect(worksheet.getCell(4, 0)?.v).toBe('A2');diff --git a/packages/sheets/src/commands/commands/__tests__/insert-remove-rows-cols.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/insert-remove-rows-cols.command.spec.tsindex e2c3487608..178fa65aba 100644--- a/packages/sheets/src/commands/commands/__tests__/insert-remove-rows-cols.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/insert-remove-rows-cols.command.spec.ts@@ -274,7 +274,7 @@ describe('Test insert and remove rows cols commands', () => {});expect(result).toBeTruthy();- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')!.getSheetBySheetId('sheet1')!;+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!.getSheetBySheetId('sheet1')!;expect(worksheet.getRowHeight(1)).toBe(36);expect(getCellStyle(1, 0)).toBe('s1');});@@ -373,7 +373,7 @@ describe('Test insert and remove rows cols commands', () => {});expect(result).toBeTruthy();- const worksheet = get(IUniverInstanceService).getUniverSheetInstance('test')!.getSheetBySheetId('sheet1')!;+ const worksheet = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!.getSheetBySheetId('sheet1')!;expect(worksheet.getColumnWidth(1)).toBe(112);expect(getCellStyle(0, 1)).toBe('s1');});diff --git a/packages/sheets/src/commands/commands/__tests__/permission-and-worksheet-meta.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/permission-and-worksheet-meta.command.spec.tsindex 1a46562a5b..b5b96c464d 100644--- a/packages/sheets/src/commands/commands/__tests__/permission-and-worksheet-meta.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/permission-and-worksheet-meta.command.spec.ts@@ -120,7 +120,6 @@ function createWorkbookTarget() {const univerInstanceService = {getUnit: (unitId: string) => unitId === 'unit-1' ? workbook : null,getCurrentUnitOfType: () => workbook,- getUniverSheetInstance: (unitId: string) => unitId === 'unit-1' ? workbook : null,};return { worksheet, workbook, univerInstanceService };}diff --git a/packages/sheets/src/commands/commands/__tests__/set-border.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-border.command.spec.tsindex 119168f9bb..69c58a2163 100644--- a/packages/sheets/src/commands/commands/__tests__/set-border.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-border.command.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IBorderData, Injector, IRange, Univer } from '@univerjs/core';-import { BorderStyleTypes, BorderType, ICommandService, IConfirmService, IUniverInstanceService, RANGE_TYPE, TestConfirmService } from '@univerjs/core';+import type { IBorderData, Injector, IRange, Univer, Workbook } from '@univerjs/core';+import { BorderStyleTypes, BorderType, ICommandService, IConfirmService, IUniverInstanceService, RANGE_TYPE, TestConfirmService, UniverInstanceType } from '@univerjs/core';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { SheetsSelectionsService } from '../../../services/selections/selection.service';import { AddWorksheetMergeMutation } from '../../mutations/add-worksheet-merge.mutation';@@ -45,7 +45,7 @@ describe('Test style commands', () => {get = testBed.get;getBorder = ({ startRow, startColumn }: IRange): IBorderData | undefined => {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn).getBorder();diff --git a/packages/sheets/src/commands/commands/__tests__/set-range-custom-metadata.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-range-custom-metadata.command.spec.tsindex c66b072b85..3f250a0537 100644--- a/packages/sheets/src/commands/commands/__tests__/set-range-custom-metadata.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-range-custom-metadata.command.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IWorkbookData, Univer } from '@univerjs/core';-import { BorderStyleTypes, CellValueType, ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE } from '@univerjs/core';+import type { IWorkbookData, Univer, Workbook } from '@univerjs/core';+import { BorderStyleTypes, CellValueType, ICommandService, IUniverInstanceService, LocaleType, RANGE_TYPE, UniverInstanceType } from '@univerjs/core';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { SetRangeValuesMutation } from '../../mutations/set-range-values.mutation';import { SetRangeCustomMetadataCommand } from '../set-range-custom-metadata.command';@@ -84,7 +84,7 @@ describe('SetRangeCustomMetadataCommand', () => {},});- const workbook = univerInstanceService.getUniverSheetInstance('test')!;+ const workbook = univerInstanceService.getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!;const cell = workbook.getSheetBySheetId('sheet1')!.getCellRaw(0, 2);const style = workbook.getStyles().getStyleByCell(cell);diff --git a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.tsindex 727c9362e8..4cd5724a4c 100644--- a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts@@ -169,7 +169,7 @@ describe('Test set range values commands', () => {getValue = (sheetId?: string): Nullable<ICellData> =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(sheetId || 'sheet1')?.getRange(0, 0, 0, 0).getValue();@@ -181,14 +181,14 @@ describe('Test set range values commands', () => {endColumn: number): Nullable<Array<Array<Nullable<ICellData>>>> =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValues();getStyle = (): Nullable<IStyleData> => {const value = getValue();- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (value && styles) {return styles.getStyleByCell(value);}@@ -196,7 +196,7 @@ describe('Test set range values commands', () => {getStyles = (startRow: number, startColumn: number, endRow: number, endColumn: number): Nullable<Nullable<IStyleData>[][]> => {const values = getValues(startRow, startColumn, endRow, endColumn);- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();return values?.map((row, rowIndex) => {return row?.map((cell, columnIndex) => {diff --git a/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.tsindex 359c7a98cc..49bc0fa89e 100644--- a/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-style.command.spec.ts@@ -92,7 +92,7 @@ describe("Test commands used for updating cells' styles", () => {function getFontColor(row: number, col: number) {return get(IUniverInstanceService)- .getUniverSheetInstance('test')!+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)!.getSheetBySheetId('sheet1')!.getRange(row, col).getFontColor();@@ -154,7 +154,7 @@ describe("Test commands used for updating cells' styles", () => {function getFontBold(): FontWeight | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getFontWeight();@@ -209,7 +209,7 @@ describe("Test commands used for updating cells' styles", () => {endColumn: number): FontItalic | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getFontStyle();@@ -254,7 +254,7 @@ describe("Test commands used for updating cells' styles", () => {function getFontUnderline(): ITextDecoration | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getUnderline();@@ -306,7 +306,7 @@ describe("Test commands used for updating cells' styles", () => {function getFontThroughLine(): ITextDecoration | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getStrikeThrough();@@ -349,7 +349,7 @@ describe("Test commands used for updating cells' styles", () => {function getFontSize(): number | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getFontSize();@@ -390,7 +390,7 @@ describe("Test commands used for updating cells' styles", () => {function getFontFamily(): string | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getFontFamily();@@ -440,28 +440,28 @@ describe("Test commands used for updating cells' styles", () => {function getFontColor(): string | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getFontColor();}function getFontThroughLine(): ITextDecoration | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getStrikeThrough();}function getFontUnderline(): ITextDecoration | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getUnderline();}function getFontOverline(): ITextDecoration | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getOverline();@@ -528,7 +528,7 @@ describe("Test commands used for updating cells' styles", () => {function getBackgroundColor(): string | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getBackground();@@ -571,7 +571,7 @@ describe("Test commands used for updating cells' styles", () => {function getVerticalAlignment(): VerticalAlign | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getVerticalAlignment();@@ -614,7 +614,7 @@ describe("Test commands used for updating cells' styles", () => {function getHorizontalAlignment(): HorizontalAlign | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getHorizontalAlignment();@@ -659,7 +659,7 @@ describe("Test commands used for updating cells' styles", () => {function getTextWrap(): BooleanNumber | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getWrap();@@ -702,7 +702,7 @@ describe("Test commands used for updating cells' styles", () => {]);const getShrinkToFit = () => get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getComposedCellStyle(0, 0)?.stf;@@ -738,7 +738,7 @@ describe("Test commands used for updating cells' styles", () => {]);const getShrinkToFit = () => get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getComposedCellStyle(0, 0)?.stf;@@ -764,7 +764,7 @@ describe("Test commands used for updating cells' styles", () => {function getTextRotation(): ITextRotation | undefined {return get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(0, 0, 0, 0).getTextRotation();diff --git a/packages/sheets/src/commands/commands/__tests__/set-tab-color.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-tab-color.command.spec.tsindex 2704a97be9..c3a0a0eeff 100644--- a/packages/sheets/src/commands/commands/__tests__/set-tab-color.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-tab-color.command.spec.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { Injector, Univer } from '@univerjs/core';-import { ICommandService, IUniverInstanceService, RedoCommand, UndoCommand } from '@univerjs/core';+import type { Injector, Univer, Workbook } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, RedoCommand, UndoCommand, UniverInstanceType } from '@univerjs/core';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { SetTabColorMutation } from '../../mutations/set-tab-color.mutation';import { SetTabColorCommand } from '../set-tab-color.command';@@ -42,7 +42,7 @@ describe('Test tab color commands', () => {describe('Set several specific colors', () => {function getTabColor() {- return get(IUniverInstanceService).getUniverSheetInstance('test')?.getActiveSheet()?.getTabColor();+ return get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getActiveSheet()?.getTabColor();}describe('correct situations', () => {diff --git a/packages/sheets/src/commands/commands/__tests__/simple-command-handlers.spec.ts b/packages/sheets/src/commands/commands/__tests__/simple-command-handlers.spec.tsindex 95ee8a49aa..7d9e6d75d2 100644--- a/packages/sheets/src/commands/commands/__tests__/simple-command-handlers.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/simple-command-handlers.spec.ts@@ -80,7 +80,6 @@ function createUniverInstanceService(worksheet: unknown) {const workbook = createWorkbook(worksheet);return {getUnit: (unitId: string) => unitId === 'unit-1' ? workbook : null,- getUniverSheetInstance: (unitId: string) => unitId === 'unit-1' ? workbook : null,getCurrentUnitOfType: () => workbook,};}diff --git a/packages/sheets/src/commands/commands/move-range.command.ts b/packages/sheets/src/commands/commands/move-range.command.tsindex e61d4bcc32..8d258112e9 100644--- a/packages/sheets/src/commands/commands/move-range.command.ts+++ b/packages/sheets/src/commands/commands/move-range.command.ts@@ -125,7 +125,7 @@ function _resolveMoveRangeContext(accessor: IAccessor, params: IMoveRangeCommandreturn null;}- const workbook = univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const fromWorksheet = workbook?.getSheetBySheetId(fromSubUnitId);const toWorksheet = workbook?.getSheetBySheetId(toSubUnitId);diff --git a/packages/sheets/src/commands/mutations/__tests__/worksheet-meta.mutation.spec.ts b/packages/sheets/src/commands/mutations/__tests__/worksheet-meta.mutation.spec.tsindex 561692f80a..e31348289a 100644--- a/packages/sheets/src/commands/mutations/__tests__/worksheet-meta.mutation.spec.ts+++ b/packages/sheets/src/commands/mutations/__tests__/worksheet-meta.mutation.spec.ts@@ -14,9 +14,9 @@* limitations under the License.*/-import type { IAccessor } from '@univerjs/core';-import { BooleanNumber, IUniverInstanceService } from '@univerjs/core';-import { describe, expect, it, vi } from 'vitest';+import type { IWorkbookData } from '@univerjs/core';+import { BooleanNumber, LocaleType } from '@univerjs/core';+import { afterEach, beforeEach, describe, expect, it } from 'vitest';import {SetGridlinesColorMutation,SetGridlinesColorUndoMutationFactory,@@ -31,26 +31,44 @@ import {SetWorksheetRowIsAutoHeightMutation,SetWorksheetRowIsAutoHeightMutationFactory,} from '../set-worksheet-row-height.mutation';--function createAccessor(instanceService: unknown): IAccessor {- return {- get: (token: unknown) => {- if (token === IUniverInstanceService) {- return instanceService as never;- }- return null as never;+import { createCommandTestBed } from './create-command-test-bed';++const WORKBOOK_DATA: IWorkbookData = {+ id: 'unit-1',+ appVersion: '3.0.0-alpha',+ locale: LocaleType.EN_US,+ name: 'Test workbook',+ styles: {},+ sheetOrder: ['sheet-1'],+ sheets: {+ 'sheet-1': {+ id: 'sheet-1',+ name: 'old-name',+ hidden: BooleanNumber.TRUE,+ rowCount: 100,+ columnCount: 20,+ defaultRowHeight: 19,+ cellData: {},+ rowData: {+ 1: { h: 24, ia: BooleanNumber.TRUE, ah: 28 },+ 2: {},+ },},- has: () => true,- } as unknown as IAccessor;-}+ },+};describe('worksheet meta mutations', () => {+ let testBed: ReturnType<typeof createCommandTestBed>;++ beforeEach(() => {+ testBed = createCommandTestBed(WORKBOOK_DATA);+ });++ afterEach(() => testBed.univer.dispose());+it('SetGridlinesColorUndoMutationFactory should read current sheet and throw on null sheet', () => {- const goodAccessor = createAccessor({- getUniverSheetInstance: vi.fn(() => ({})),- });expect(- SetGridlinesColorUndoMutationFactory(goodAccessor, {+ SetGridlinesColorUndoMutationFactory(testBed, {unitId: 'unit-1',subUnitId: 'sheet-1',color: '#ff0000',@@ -61,12 +79,9 @@ describe('worksheet meta mutations', () => {color: '#ff0000',});- const badAccessor = createAccessor({- getUniverSheetInstance: vi.fn(() => null),- });expect(() =>- SetGridlinesColorUndoMutationFactory(badAccessor, {- unitId: 'unit-1',+ SetGridlinesColorUndoMutationFactory(testBed, {+ unitId: 'missing',subUnitId: 'sheet-1',color: '#ff0000',})@@ -74,33 +89,19 @@ describe('worksheet meta mutations', () => {});it('SetGridlinesColorMutation should set color and return false when target missing', () => {- const worksheetConfig: { gridlinesColor?: string } = {};- const worksheet = {- getConfig: () => worksheetConfig,- getSheetId: () => 'sheet-1',- };- const workbook = {- getSheetBySheetId: vi.fn(() => worksheet),- getUnitId: () => 'unit-1',- };- const accessor = createAccessor({- getUnit: vi.fn(() => workbook),- });+ const worksheet = testBed.sheet.getSheetBySheetId('sheet-1')!;expect(- SetGridlinesColorMutation.handler(accessor, {+ SetGridlinesColorMutation.handler(testBed, {unitId: 'unit-1',subUnitId: 'sheet-1',color: '#00ff00',})).toBe(true);- expect(worksheetConfig.gridlinesColor).toBe('#00ff00');+ expect(worksheet.getConfig().gridlinesColor).toBe('#00ff00');- const badAccessor = createAccessor({- getUnit: vi.fn(() => null),- });expect(- SetGridlinesColorMutation.handler(badAccessor, {- unitId: 'unit-1',+ SetGridlinesColorMutation.handler(testBed, {+ unitId: 'missing',subUnitId: 'sheet-1',color: '#00ff00',})@@ -108,96 +109,39 @@ describe('worksheet meta mutations', () => {});it('SetWorksheetHide mutation factory and handler should cover true/false paths', () => {- const worksheetConfig: { hidden?: number } = {};- const worksheet = {- getConfig: () => worksheetConfig,- getSheetId: () => 'sheet-1',- isSheetHidden: () => 1,- };- const workbook = {- getSheetBySheetId: vi.fn(() => worksheet),- };-- const accessor = createAccessor({- getUnit: vi.fn(() => workbook),- getUniverSheetInstance: vi.fn(() => workbook),- });+ const worksheet = testBed.sheet.getSheetBySheetId('sheet-1')!;expect(- SetWorksheetHideMutationFactory(accessor, {+ SetWorksheetHideMutationFactory(testBed, {unitId: 'unit-1',subUnitId: 'sheet-1',- hidden: 0,+ hidden: BooleanNumber.FALSE,})).toEqual({- hidden: 1,+ hidden: BooleanNumber.TRUE,unitId: 'unit-1',subUnitId: 'sheet-1',});expect(- SetWorksheetHideMutation.handler(accessor, {+ SetWorksheetHideMutation.handler(testBed, {unitId: 'unit-1',subUnitId: 'sheet-1',- hidden: 0,+ hidden: BooleanNumber.FALSE,})).toBe(true);- expect(worksheetConfig.hidden).toBe(0);-- const noWorkbookAccessor = createAccessor({- getUniverSheetInstance: vi.fn(() => null),- });- expect(- SetWorksheetHideMutation.handler(noWorkbookAccessor, {- unitId: 'unit-1',- subUnitId: 'sheet-1',- hidden: 0,- })- ).toBe(false);-- const noSheetAccessor = createAccessor({- getUniverSheetInstance: vi.fn(() => ({- getSheetBySheetId: vi.fn(() => null),- })),- });- expect(- SetWorksheetHideMutation.handler(noSheetAccessor, {- unitId: 'unit-1',- subUnitId: 'sheet-1',- hidden: 0,- })- ).toBe(false);-- const badFactoryAccessor = createAccessor({- getUnit: vi.fn(() => null),- });- expect(() =>- SetWorksheetHideMutationFactory(badFactoryAccessor, {- unitId: 'unit-1',- subUnitId: 'sheet-1',- hidden: 0,- })- ).toThrowError('[SetWorksheetHideMutationFactory]: worksheet is null error!');+ expect(worksheet.getConfig().hidden).toBe(BooleanNumber.FALSE);+ expect(SetWorksheetHideMutation.handler(testBed, { unitId: 'missing', subUnitId: 'sheet-1', hidden: BooleanNumber.FALSE })).toBe(false);+ expect(SetWorksheetHideMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'missing', hidden: BooleanNumber.FALSE })).toBe(false);+ expect(() => SetWorksheetHideMutationFactory(testBed, { unitId: 'missing', subUnitId: 'sheet-1', hidden: BooleanNumber.FALSE }))+ .toThrowError('[SetWorksheetHideMutationFactory]: worksheet is null error!');});it('SetWorksheetName mutation factory and handler should cover true/false paths', () => {- const worksheetConfig: { name?: string } = {};- const worksheet = {- getConfig: () => worksheetConfig,- getSheetId: () => 'sheet-1',- getName: () => 'old-name',- };- const workbook = {- getSheetBySheetId: vi.fn(() => worksheet),- };-- const accessor = createAccessor({- getUnit: vi.fn(() => workbook),- getUniverSheetInstance: vi.fn(() => workbook),- });+ const worksheet = testBed.sheet.getSheetBySheetId('sheet-1')!;expect(- SetWorksheetNameMutationFactory(accessor, {+ SetWorksheetNameMutationFactory(testBed, {unitId: 'unit-1',subUnitId: 'sheet-1',name: 'new-name',@@ -208,119 +152,56 @@ describe('worksheet meta mutations', () => {name: 'old-name',});- expect(- SetWorksheetNameMutation.handler(accessor, {- unitId: 'unit-1',- subUnitId: 'sheet-1',- name: 'new-name',- })- ).toBe(true);- expect(worksheetConfig.name).toBe('new-name');-- const noWorkbookAccessor = createAccessor({- getUniverSheetInstance: vi.fn(() => null),- });- expect(- SetWorksheetNameMutation.handler(noWorkbookAccessor, {- unitId: 'unit-1',- subUnitId: 'sheet-1',- name: 'new-name',- })- ).toBe(false);-- const noSheetAccessor = createAccessor({- getUniverSheetInstance: vi.fn(() => ({- getSheetBySheetId: vi.fn(() => null),- })),- });- expect(- SetWorksheetNameMutation.handler(noSheetAccessor, {- unitId: 'unit-1',- subUnitId: 'sheet-1',- name: 'new-name',- })- ).toBe(false);-- const badFactoryAccessor = createAccessor({- getUnit: vi.fn(() => null),- });- expect(() =>- SetWorksheetNameMutationFactory(badFactoryAccessor, {- unitId: 'unit-1',- subUnitId: 'sheet-1',- name: 'new-name',- })- ).toThrowError('[SetWorksheetNameMutationFactory]: worksheet is null error!');+ expect(SetWorksheetNameMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', name: 'new-name' })).toBe(true);+ expect(worksheet.getConfig().name).toBe('new-name');+ expect(SetWorksheetNameMutation.handler(testBed, { unitId: 'missing', subUnitId: 'sheet-1', name: 'new-name' })).toBe(false);+ expect(SetWorksheetNameMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'missing', name: 'new-name' })).toBe(false);+ expect(() => SetWorksheetNameMutationFactory(testBed, { unitId: 'missing', subUnitId: 'sheet-1', name: 'new-name' }))+ .toThrowError('[SetWorksheetNameMutationFactory]: worksheet is null error!');});it('row height mutations should update height, auto-height flag, and measured auto height', () => {- const rows: Record<number, { h?: number; ia?: BooleanNumber; ah?: number }> = {- 1: { h: 24, ia: BooleanNumber.TRUE, ah: 28 },- 2: {},- };- const manager = {- getRow: (row: number) => rows[row],- getRowOrCreate: (row: number) => {- rows[row] ??= {};- return rows[row];- },- setRowHeight: (row: number, height: number) => {- rows[row] ??= {};- rows[row].h = height;- },- };- const worksheet = {- getSheetId: () => 'sheet-1',- getConfig: () => ({ defaultRowHeight: 19 }),- getRowManager: () => manager,- };- const workbook = {- getUnitId: () => 'unit-1',- getSheetBySheetId: vi.fn((subUnitId: string) => subUnitId === 'sheet-1' ? worksheet : null),- };- const accessor = createAccessor({- getUnit: vi.fn((unitId: string) => unitId === 'unit-1' ? workbook : null),- getCurrentUnitOfType: vi.fn(() => workbook),- });+ const worksheet = testBed.sheet.getSheetBySheetId('sheet-1')!;+ const manager = worksheet.getRowManager();const ranges = [{ startRow: 1, endRow: 2, startColumn: 0, endColumn: 3 }];- expect(SetWorksheetRowHeightMutationFactory({ unitId: 'unit-1', subUnitId: 'sheet-1', ranges, rowHeight: 40 }, worksheet as never)).toEqual({+ expect(SetWorksheetRowHeightMutationFactory({ unitId: 'unit-1', subUnitId: 'sheet-1', ranges, rowHeight: 40 }, worksheet)).toEqual({unitId: 'unit-1',subUnitId: 'sheet-1',ranges,rowHeight: { 1: 24, 2: 19 },});- expect(SetWorksheetRowHeightMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', ranges, rowHeight: { 1: 31, 2: null } })).toBe(true);- expect(rows[1].h).toBe(31);- expect(rows[2].h).toBeUndefined();- expect(SetWorksheetRowHeightMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', ranges, rowHeight: 33 })).toBe(true);- expect(rows[1].h).toBe(33);- expect(rows[2].h).toBe(33);+ expect(SetWorksheetRowHeightMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', ranges, rowHeight: { 1: 31, 2: null } })).toBe(true);+ expect(manager.getRow(1)?.h).toBe(31);+ expect(manager.getRow(2)?.h).toBeUndefined();+ expect(SetWorksheetRowHeightMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', ranges, rowHeight: 33 })).toBe(true);+ expect(manager.getRow(1)?.h).toBe(33);+ expect(manager.getRow(2)?.h).toBe(33);- expect(SetWorksheetRowIsAutoHeightMutationFactory({ unitId: 'unit-1', subUnitId: 'sheet-1', ranges, autoHeightInfo: BooleanNumber.FALSE }, worksheet as never)).toEqual({+ expect(SetWorksheetRowIsAutoHeightMutationFactory({ unitId: 'unit-1', subUnitId: 'sheet-1', ranges, autoHeightInfo: BooleanNumber.FALSE }, worksheet)).toEqual({unitId: 'unit-1',subUnitId: 'sheet-1',ranges,autoHeightInfo: { 1: BooleanNumber.TRUE, 2: undefined },});- expect(SetWorksheetRowIsAutoHeightMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', ranges, autoHeightInfo: { 1: BooleanNumber.FALSE, 2: null } })).toBe(true);- expect(rows[1].ia).toBe(BooleanNumber.FALSE);- expect(rows[2].ia).toBeUndefined();- expect(SetWorksheetRowIsAutoHeightMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', ranges, autoHeightInfo: BooleanNumber.TRUE })).toBe(true);- expect(rows[1].ia).toBe(BooleanNumber.TRUE);- expect(rows[2].ia).toBe(BooleanNumber.TRUE);+ expect(SetWorksheetRowIsAutoHeightMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', ranges, autoHeightInfo: { 1: BooleanNumber.FALSE, 2: null } })).toBe(true);+ expect(manager.getRow(1)?.ia).toBe(BooleanNumber.FALSE);+ expect(manager.getRow(2)?.ia).toBeUndefined();+ expect(SetWorksheetRowIsAutoHeightMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', ranges, autoHeightInfo: BooleanNumber.TRUE })).toBe(true);+ expect(manager.getRow(1)?.ia).toBe(BooleanNumber.TRUE);+ expect(manager.getRow(2)?.ia).toBe(BooleanNumber.TRUE);- expect(SetWorksheetRowAutoHeightMutationFactory({ unitId: 'unit-1', subUnitId: 'sheet-1', rowsAutoHeightInfo: [{ row: 1, autoHeight: 50 }, { row: 2, autoHeight: 60 }] }, worksheet as never)).toEqual({+ expect(SetWorksheetRowAutoHeightMutationFactory({ unitId: 'unit-1', subUnitId: 'sheet-1', rowsAutoHeightInfo: [{ row: 1, autoHeight: 50 }, { row: 2, autoHeight: 60 }] }, worksheet)).toEqual({unitId: 'unit-1',subUnitId: 'sheet-1',rowsAutoHeightInfo: [{ row: 1, autoHeight: 28 }, { row: 2, autoHeight: 19 }],});- expect(SetWorksheetRowAutoHeightMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', rowsAutoHeightInfo: [{ row: 1, autoHeight: 51 }, { row: 3, autoHeight: 61 }] })).toBe(true);- expect(rows[1].ah).toBe(51);- expect(rows[3].ah).toBe(61);+ expect(SetWorksheetRowAutoHeightMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', rowsAutoHeightInfo: [{ row: 1, autoHeight: 51 }, { row: 3, autoHeight: 61 }] })).toBe(true);+ expect(manager.getRow(1)?.ah).toBe(51);+ expect(manager.getRow(3)?.ah).toBe(61);- expect(SetWorksheetRowHeightMutation.handler(createAccessor({ getUnit: vi.fn(() => null) }), { unitId: 'missing', subUnitId: 'sheet-1', ranges, rowHeight: 20 })).toBe(false);- expect(SetWorksheetRowIsAutoHeightMutation.handler(createAccessor({ getUnit: vi.fn(() => null) }), { unitId: 'missing', subUnitId: 'sheet-1', ranges, autoHeightInfo: BooleanNumber.TRUE })).toBe(false);- expect(SetWorksheetRowAutoHeightMutation.handler(createAccessor({ getUnit: vi.fn(() => null) }), { unitId: 'missing', subUnitId: 'sheet-1', rowsAutoHeightInfo: [] })).toBe(false);+ expect(SetWorksheetRowHeightMutation.handler(testBed, { unitId: 'missing', subUnitId: 'sheet-1', ranges, rowHeight: 20 })).toBe(false);+ expect(SetWorksheetRowIsAutoHeightMutation.handler(testBed, { unitId: 'missing', subUnitId: 'sheet-1', ranges, autoHeightInfo: BooleanNumber.TRUE })).toBe(false);+ expect(SetWorksheetRowAutoHeightMutation.handler(testBed, { unitId: 'missing', subUnitId: 'sheet-1', rowsAutoHeightInfo: [] })).toBe(false);});});diff --git a/packages/sheets/src/commands/mutations/__tests__/worksheet-protection-and-theme.mutation.spec.ts b/packages/sheets/src/commands/mutations/__tests__/worksheet-protection-and-theme.mutation.spec.tsindex 942204a8ec..67d80b6593 100644--- a/packages/sheets/src/commands/mutations/__tests__/worksheet-protection-and-theme.mutation.spec.ts+++ b/packages/sheets/src/commands/mutations/__tests__/worksheet-protection-and-theme.mutation.spec.ts@@ -14,12 +14,12 @@* limitations under the License.*/-import type { IAccessor, IRange } from '@univerjs/core';+import type { Dependency, IAccessor, IRange, IWorkbookData } from '@univerjs/core';import type { IRangeProtectionRule } from '../../../models/range-protection-rule.model';import type { IRangeThemeStyleJSON, RangeThemeStyle } from '../../../models/range-theme-util';-import { BooleanNumber, IUniverInstanceService } from '@univerjs/core';+import { BooleanNumber, LocaleType } from '@univerjs/core';import { UnitObject } from '@univerjs/protocol';-import { describe, expect, it } from 'vitest';+import { afterEach, describe, expect, it } from 'vitest';import { EditStateEnum, RangeProtectionRuleModel, ViewStateEnum } from '../../../models/range-protection-rule.model';import { SheetRangeThemeModel } from '../../../models/range-theme-model';import { WorksheetProtectionPointModel } from '../../../services/permission/worksheet-permission';@@ -39,6 +39,7 @@ import { SetWorksheetProtectionMutation } from '../set-worksheet-protection.mutaimport { SetWorksheetRightToLeftMutation, SetWorksheetRightToLeftUndoMutationFactory } from '../set-worksheet-right-to-left.mutation';import { SetWorksheetRowCountMutation, SetWorksheetRowCountUndoMutationFactory } from '../set-worksheet-row-count.mutation';import { UnregisterWorksheetRangeThemeStyleMutation } from '../unregister-range-theme-style.mutation';+import { createCommandTestBed } from './create-command-test-bed';function createAccessor(records: Map<unknown, unknown>): IAccessor {return {@@ -47,6 +48,39 @@ function createAccessor(records: Map<unknown, unknown>): IAccessor {} as IAccessor;}+const univers: Array<ReturnType<typeof createCommandTestBed>['univer']> = [];++const WORKBOOK_DATA: IWorkbookData = {+ id: 'unit-1',+ appVersion: '3.0.0-alpha',+ locale: LocaleType.EN_US,+ name: 'Test workbook',+ styles: {},+ sheetOrder: ['sheet-1'],+ sheets: {+ 'sheet-1': {+ id: 'sheet-1',+ name: 'Sheet 1',+ rowCount: 12,+ columnCount: 8,+ rightToLeft: BooleanNumber.FALSE,+ cellData: {+ 0: { 0: { v: '0:0' }, 1: { v: '0:1' } },+ 1: { 0: { v: '1:0' }, 1: { v: '1:1' } },+ 2: { 0: { v: '2:0' }, 1: { v: '2:1' } },+ },+ },+ },+};++function createWorkbookTestBed(dependencies?: Dependency[]) {+ const testBed = createCommandTestBed(WORKBOOK_DATA, dependencies);+ univers.push(testBed.univer);+ return testBed;+}++afterEach(() => univers.splice(0).forEach((univer) => univer.dispose()));+function createRangeRule(id: string, range: IRange = { startRow: 0, endRow: 1, startColumn: 0, endColumn: 1 }): IRangeProtectionRule {return {id,@@ -124,58 +158,36 @@ describe('worksheet protection mutations', () => {describe('worksheet count and direction mutations', () => {it('changes worksheet row and column counts and creates undo payloads from old dimensions', () => {- const worksheet = {- rowCount: 12,- columnCount: 8,- getRowCount() { return this.rowCount; },- setRowCount(rowCount: number) { this.rowCount = rowCount; },- getColumnCount() { return this.columnCount; },- setColumnCount(columnCount: number) { this.columnCount = columnCount; },- };- const workbook = {- getSheetBySheetId: (subUnitId: string) => subUnitId === 'sheet-1' ? worksheet : null,- };- const univerInstanceService = {- getUnit: (unitId: string) => unitId === 'unit-1' ? workbook : null,- };- const accessor = createAccessor(new Map<unknown, unknown>([[IUniverInstanceService, univerInstanceService]]));+ const testBed = createWorkbookTestBed();+ const worksheet = testBed.sheet.getSheetBySheetId('sheet-1')!;- expect(SetWorksheetRowCountUndoMutationFactory(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', rowCount: 20 })).toEqual({ unitId: 'unit-1', subUnitId: 'sheet-1', rowCount: 12 });- expect(SetWorksheetRowCountMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', rowCount: 20 })).toBe(true);- expect(worksheet.rowCount).toBe(20);+ expect(SetWorksheetRowCountUndoMutationFactory(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', rowCount: 20 })).toEqual({ unitId: 'unit-1', subUnitId: 'sheet-1', rowCount: 12 });+ expect(SetWorksheetRowCountMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', rowCount: 20 })).toBe(true);+ expect(worksheet.getRowCount()).toBe(20);- expect(SetWorksheetColumnCountUndoMutationFactory(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', columnCount: 14 })).toEqual({ unitId: 'unit-1', subUnitId: 'sheet-1', columnCount: 8 });- expect(SetWorksheetColumnCountMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', columnCount: 14 })).toBe(true);- expect(worksheet.columnCount).toBe(14);+ expect(SetWorksheetColumnCountUndoMutationFactory(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', columnCount: 14 })).toEqual({ unitId: 'unit-1', subUnitId: 'sheet-1', columnCount: 8 });+ expect(SetWorksheetColumnCountMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', columnCount: 14 })).toBe(true);+ expect(worksheet.getColumnCount()).toBe(14);- expect(SetWorksheetRowCountMutation.handler(accessor, { unitId: 'missing', subUnitId: 'sheet-1', rowCount: 30 })).toBe(false);- expect(SetWorksheetColumnCountMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'missing', columnCount: 30 })).toBe(false);- expect(() => SetWorksheetRowCountUndoMutationFactory(accessor, { unitId: 'missing', subUnitId: 'sheet-1', rowCount: 1 })).toThrowError('[SetWorksheetRowCountUndoMutationFactory]: worksheet is null error!');- expect(() => SetWorksheetColumnCountUndoMutationFactory(accessor, { unitId: 'unit-1', subUnitId: 'missing', columnCount: 1 })).toThrowError('[SetWorksheetColumnCountUndoMutationFactory]: worksheet is null error!');+ expect(SetWorksheetRowCountMutation.handler(testBed, { unitId: 'missing', subUnitId: 'sheet-1', rowCount: 30 })).toBe(false);+ expect(SetWorksheetColumnCountMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'missing', columnCount: 30 })).toBe(false);+ expect(() => SetWorksheetRowCountUndoMutationFactory(testBed, { unitId: 'missing', subUnitId: 'sheet-1', rowCount: 1 })).toThrowError('[SetWorksheetRowCountUndoMutationFactory]: worksheet is null error!');+ expect(() => SetWorksheetColumnCountUndoMutationFactory(testBed, { unitId: 'unit-1', subUnitId: 'missing', columnCount: 1 })).toThrowError('[SetWorksheetColumnCountUndoMutationFactory]: worksheet is null error!');});it('updates right-to-left state and returns previous state for undo', () => {- const config = { rightToLeft: BooleanNumber.FALSE };- const worksheet = {- getConfig: () => config,- };- const workbook = {- getSheetBySheetId: (subUnitId: string) => subUnitId === 'sheet-1' ? worksheet : null,- };- const univerInstanceService = {- getUniverSheetInstance: (unitId: string) => unitId === 'unit-1' ? workbook : null,- };- const accessor = createAccessor(new Map<unknown, unknown>([[IUniverInstanceService, univerInstanceService]]));+ const testBed = createWorkbookTestBed();+ const worksheet = testBed.sheet.getSheetBySheetId('sheet-1')!;- expect(SetWorksheetRightToLeftUndoMutationFactory(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', rightToLeft: BooleanNumber.TRUE })).toEqual({+ expect(SetWorksheetRightToLeftUndoMutationFactory(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', rightToLeft: BooleanNumber.TRUE })).toEqual({unitId: 'unit-1',subUnitId: 'sheet-1',rightToLeft: BooleanNumber.FALSE,});- expect(SetWorksheetRightToLeftMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', rightToLeft: BooleanNumber.TRUE })).toBe(true);- expect(config.rightToLeft).toBe(BooleanNumber.TRUE);- expect(SetWorksheetRightToLeftMutation.handler(accessor, { unitId: 'missing', subUnitId: 'sheet-1', rightToLeft: BooleanNumber.FALSE })).toBe(false);- expect(SetWorksheetRightToLeftMutation.handler(accessor, { unitId: 'unit-1', subUnitId: 'missing', rightToLeft: BooleanNumber.FALSE })).toBe(false);+ expect(SetWorksheetRightToLeftMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'sheet-1', rightToLeft: BooleanNumber.TRUE })).toBe(true);+ expect(worksheet.getConfig().rightToLeft).toBe(BooleanNumber.TRUE);+ expect(SetWorksheetRightToLeftMutation.handler(testBed, { unitId: 'missing', subUnitId: 'sheet-1', rightToLeft: BooleanNumber.FALSE })).toBe(false);+ expect(SetWorksheetRightToLeftMutation.handler(testBed, { unitId: 'unit-1', subUnitId: 'missing', rightToLeft: BooleanNumber.FALSE })).toBe(false);});});@@ -224,30 +236,11 @@ describe('range theme mutations', () => {const rangeThemeModel = {unregisterRangeThemeStyle: (unitId: string, themeName: string) => removed.push(`${unitId}:${themeName}`),};- const worksheet = {- getSheetId: () => 'sheet-1',- };- const workbook = {- getUnitId: () => 'unit-1',- getActiveSheet: () => worksheet,- };- const univerInstanceService = {- getUnit: (unitId: string) => unitId === 'unit-1' ? workbook : null,- getCurrentUnitOfType: () => workbook,- };- const accessor = createAccessor(new Map<unknown, unknown>([- [SheetRangeThemeModel, rangeThemeModel],- [IUniverInstanceService, univerInstanceService],- ]));+ const testBed = createWorkbookTestBed([[SheetRangeThemeModel, { useValue: rangeThemeModel }]]);- expect(UnregisterWorksheetRangeThemeStyleMutation.handler(accessor, { unitId: 'unit-1', themeName: 'sales' })).toBe(true);+ expect(UnregisterWorksheetRangeThemeStyleMutation.handler(testBed, { unitId: 'unit-1', themeName: 'sales' })).toBe(true);expect(removed).toEqual(['unit-1:sales']);-- const missingAccessor = createAccessor(new Map<unknown, unknown>([- [SheetRangeThemeModel, rangeThemeModel],- [IUniverInstanceService, { ...univerInstanceService, getUnit: () => null }],- ]));- expect(UnregisterWorksheetRangeThemeStyleMutation.handler(missingAccessor, { unitId: 'missing', themeName: 'sales' })).toBe(false);+ expect(UnregisterWorksheetRangeThemeStyleMutation.handler(testBed, { unitId: 'missing', themeName: 'sales' })).toBe(false);});});@@ -267,19 +260,8 @@ describe('filter dirty and reorder mutations', () => {});it('reorders range rows from the requested source rows and creates inverse order for undo', () => {- const writes: Array<{ row: number; col: number; value: unknown }> = [];- const worksheet = {- getCellRaw: (row: number, col: number) => ({ v: `${row}:${col}` }),- getCellMatrix: () => ({- setValue: (row: number, col: number, value: unknown) => writes.push({ row, col, value }),- }),- };- const workbook = {- getSheetBySheetId: (subUnitId: string) => subUnitId === 'sheet-1' ? worksheet : null,- };- const accessor = createAccessor(new Map<unknown, unknown>([[IUniverInstanceService, {- getUnit: (unitId: string) => unitId === 'unit-1' ? workbook : null,- }]]));+ const testBed = createWorkbookTestBed();+ const worksheet = testBed.sheet.getSheetBySheetId('sheet-1')!;const params = {unitId: 'unit-1',subUnitId: 'sheet-1',@@ -291,18 +273,16 @@ describe('filter dirty and reorder mutations', () => {...params,order: { 0: 1, 1: 2, 2: 0 },});- expect(ReorderRangeMutation.handler(accessor, params)).toBe(true);- expect(writes).toEqual([- { row: 0, col: 0, value: { v: '2:0' } },- { row: 0, col: 1, value: { v: '2:1' } },- { row: 1, col: 0, value: { v: '0:0' } },- { row: 1, col: 1, value: { v: '0:1' } },- { row: 2, col: 0, value: { v: '1:0' } },- { row: 2, col: 1, value: { v: '1:1' } },+ expect(ReorderRangeMutation.handler(testBed, params)).toBe(true);+ expect([0, 1, 2].flatMap((row) => [0, 1].map((col) => worksheet.getCellRaw(row, col)))).toEqual([+ { v: '2:0' },+ { v: '2:1' },+ { v: '0:0' },+ { v: '0:1' },+ { v: '1:0' },+ { v: '1:1' },]);- expect(ReorderRangeMutation.handler(createAccessor(new Map<unknown, unknown>([[IUniverInstanceService, {- getUnit: () => ({ getSheetBySheetId: () => null }),- }]])), params)).toBe(false);+ expect(ReorderRangeMutation.handler(testBed, { ...params, subUnitId: 'missing' })).toBe(false);});});diff --git a/packages/sheets/src/commands/mutations/insert-sheet.mutation.ts b/packages/sheets/src/commands/mutations/insert-sheet.mutation.tsindex 1d3c04ade8..9da90c9a3f 100644--- a/packages/sheets/src/commands/mutations/insert-sheet.mutation.ts+++ b/packages/sheets/src/commands/mutations/insert-sheet.mutation.ts@@ -14,12 +14,12 @@* limitations under the License.*/-import type { IAccessor, IMutation } from '@univerjs/core';+import type { IAccessor, IMutation, Workbook } from '@univerjs/core';import type {IInsertSheetMutationParams,IRemoveSheetMutationParams,} from '../../basics/interfaces/mutation-interface';-import { cloneWorksheetData, CommandType, IUniverInstanceService } from '@univerjs/core';+import { cloneWorksheetData, CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';/*** Generate undo mutation of a `InsertSheetMutation`@@ -43,7 +43,7 @@ export const InsertSheetMutation: IMutation<IInsertSheetMutationParams, boolean>handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);const { sheet, index, unitId, styles } = params;- const workbook = univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return false;}diff --git a/packages/sheets/src/commands/mutations/move-rows-cols.mutation.ts b/packages/sheets/src/commands/mutations/move-rows-cols.mutation.tsindex 1f93cbcd9c..4f83c52cb8 100644--- a/packages/sheets/src/commands/mutations/move-rows-cols.mutation.ts+++ b/packages/sheets/src/commands/mutations/move-rows-cols.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IAccessor, IMutation, IRange } from '@univerjs/core';-import { CommandType, IUniverInstanceService, moveMatrixArray, Rectangle } from '@univerjs/core';+import type { IAccessor, IMutation, IRange, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, moveMatrixArray, Rectangle, UniverInstanceType } from '@univerjs/core';export interface IMoveRowsMutationParams {unitId: string;@@ -75,7 +75,7 @@ export const MoveRowsMutation: IMutation<IMoveRowsMutationParams> = {const { unitId, subUnitId, sourceRange, targetRange } = params;const univerInstanceService = accessor.get(IUniverInstanceService);- const univerSheet = univerInstanceService.getUniverSheetInstance(unitId);+ const univerSheet = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!univerSheet) {throw new Error('[MoveRowMutation] univerSheet is null!');}@@ -156,7 +156,7 @@ export const MoveColsMutation: IMutation<IMoveColumnsMutationParams> = {const { unitId, subUnitId, sourceRange, targetRange } = params;const univerInstanceService = accessor.get(IUniverInstanceService);- const univerSheet = univerInstanceService.getUniverSheetInstance(unitId);+ const univerSheet = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!univerSheet) {throw new Error('[MoveColumnMutation] univerSheet is null!');}diff --git a/packages/sheets/src/commands/mutations/remove-row-col.mutation.ts b/packages/sheets/src/commands/mutations/remove-row-col.mutation.tsindex d811e90005..bae0f9a520 100644--- a/packages/sheets/src/commands/mutations/remove-row-col.mutation.ts+++ b/packages/sheets/src/commands/mutations/remove-row-col.mutation.ts@@ -14,14 +14,14 @@* limitations under the License.*/-import type { IAccessor, IColumnData, IMutation, IObjectArrayPrimitiveType, IRowData, Worksheet } from '@univerjs/core';+import type { IAccessor, IColumnData, IMutation, IObjectArrayPrimitiveType, IRowData, Workbook, Worksheet } from '@univerjs/core';import type {IInsertColMutationParams,IInsertRowMutationParams,IRemoveColMutationParams,IRemoveRowsMutationParams,} from '../../basics/interfaces/mutation-interface';-import { CommandType, concatMatrixArray, IUniverInstanceService, sliceMatrixArray, spliceArray } from '@univerjs/core';+import { CommandType, concatMatrixArray, IUniverInstanceService, sliceMatrixArray, spliceArray, UniverInstanceType } from '@univerjs/core';export const RemoveRowsUndoMutationFactory = (params: IRemoveRowsMutationParams,@@ -51,7 +51,7 @@ export const RemoveRowMutation: IMutation<IRemoveRowsMutationParams> = {handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');@@ -88,7 +88,7 @@ export const RemoveColMutationFactory = (params: IRemoveColMutationParams): IInsertColMutationParams => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');@@ -124,7 +124,7 @@ export const RemoveColMutation: IMutation<IRemoveColMutationParams> = {type: CommandType.MUTATION,handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');diff --git a/packages/sheets/src/commands/mutations/remove-sheet.mutation.ts b/packages/sheets/src/commands/mutations/remove-sheet.mutation.tsindex 3ed7f3ab13..5624daf1d4 100644--- a/packages/sheets/src/commands/mutations/remove-sheet.mutation.ts+++ b/packages/sheets/src/commands/mutations/remove-sheet.mutation.ts@@ -14,12 +14,12 @@* limitations under the License.*/-import type { IAccessor, IMutation } from '@univerjs/core';+import type { IAccessor, IMutation, Workbook } from '@univerjs/core';import type {IInsertSheetMutationParams,IRemoveSheetMutationParams,} from '../../basics/interfaces/mutation-interface';-import { CommandType, IUniverInstanceService } from '@univerjs/core';+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { getSheetMutationTarget } from '../commands/utils/target-util';/**@@ -59,7 +59,7 @@ export const RemoveSheetMutation: IMutation<IRemoveSheetMutationParams, boolean>handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);const { subUnitId, unitId } = params;- const workbook = univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return false;}diff --git a/packages/sheets/src/commands/mutations/set-col-visible.mutation.ts b/packages/sheets/src/commands/mutations/set-col-visible.mutation.tsindex bc6ac18746..8b2d561598 100644--- a/packages/sheets/src/commands/mutations/set-col-visible.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-col-visible.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IAccessor, IMutation, IRange } from '@univerjs/core';-import { BooleanNumber, CommandType, IUniverInstanceService } from '@univerjs/core';+import type { IAccessor, IMutation, IRange, Workbook } from '@univerjs/core';+import { BooleanNumber, CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';export interface ISetColHiddenMutationParams {unitId: string;@@ -25,7 +25,7 @@ export interface ISetColHiddenMutationParams {export const SetColHiddenUndoMutationFactory = (accessor: IAccessor, params: ISetColHiddenMutationParams) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');@@ -43,7 +43,7 @@ export const SetColHiddenMutation: IMutation<ISetColHiddenMutationParams> = {type: CommandType.MUTATION,handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (!universheet) {return false;@@ -72,7 +72,7 @@ export interface ISetColVisibleMutationParams {export const SetColVisibleUndoMutationFactory = (accessor: IAccessor, params: ISetColVisibleMutationParams) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');@@ -90,7 +90,7 @@ export const SetColVisibleMutation: IMutation<ISetColVisibleMutationParams> = {type: CommandType.MUTATION,handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (!universheet) {return false;diff --git a/packages/sheets/src/commands/mutations/set-frozen.mutation.ts b/packages/sheets/src/commands/mutations/set-frozen.mutation.tsindex bed3af4c33..55a4eb0a04 100644--- a/packages/sheets/src/commands/mutations/set-frozen.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-frozen.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IAccessor, IMutation } from '@univerjs/core';-import { CommandType, IUniverInstanceService } from '@univerjs/core';+import type { IAccessor, IMutation, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';export interface ISetFrozenMutationParams {unitId: string;@@ -40,7 +40,7 @@ export const SetFrozenMutationFactory = (params: ISetFrozenMutationParams): ISetFrozenMutationParams => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');@@ -65,7 +65,7 @@ export const SetFrozenMutation: IMutation<ISetFrozenMutationParams> = {type: CommandType.MUTATION,handler: (accessor: IAccessor, params: ISetFrozenMutationParams) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');diff --git a/packages/sheets/src/commands/mutations/set-gridlines-color.mutation.ts b/packages/sheets/src/commands/mutations/set-gridlines-color.mutation.tsindex 063ff808a1..3c8dcb7523 100644--- a/packages/sheets/src/commands/mutations/set-gridlines-color.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-gridlines-color.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IAccessor, IMutation } from '@univerjs/core';-import { CommandType, IUniverInstanceService } from '@univerjs/core';+import type { IAccessor, IMutation, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { getSheetCommandTarget } from '../commands/utils/target-util';export interface ISetGridlinesColorMutationParams {@@ -26,7 +26,7 @@ export interface ISetGridlinesColorMutationParams {export const SetGridlinesColorUndoMutationFactory = (accessor: IAccessor, params: ISetGridlinesColorMutationParams) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');diff --git a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/sheets/src/commands/mutations/set-range-values.mutation.tsindex 5d227b0b99..5382b4e9e1 100644--- a/packages/sheets/src/commands/mutations/set-range-values.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-range-values.mutation.ts@@ -25,7 +25,7 @@ import type {Styles,Workbook,} from '@univerjs/core';-import { CommandType, IUniverInstanceService, ObjectMatrix, Tools } from '@univerjs/core';+import { CommandType, IUniverInstanceService, ObjectMatrix, Tools, UniverInstanceType } from '@univerjs/core';import { handleStyle, transformStyle } from '../../basics/cell-style';import { getCellType } from '../../basics/cell-type';import { getCellValue, setNull } from '../../basics/cell-value';@@ -64,7 +64,7 @@ export const SetRangeValuesUndoMutationFactory = (): ISetRangeValuesMutationParams => {const { unitId, subUnitId, cellValue, isOverrideStyle } = params;const univerInstanceService = accessor.get(IUniverInstanceService);- const workbook = univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (workbook == null) {throw new Error('workbook is null error!');diff --git a/packages/sheets/src/commands/mutations/set-row-visible.mutation.ts b/packages/sheets/src/commands/mutations/set-row-visible.mutation.tsindex d83bcec820..007cf09094 100644--- a/packages/sheets/src/commands/mutations/set-row-visible.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-row-visible.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IAccessor, IMutation, IRange } from '@univerjs/core';-import { CommandType, IUniverInstanceService } from '@univerjs/core';+import type { IAccessor, IMutation, IRange, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';export interface ISetRowVisibleMutationParams {unitId: string;@@ -25,7 +25,7 @@ export interface ISetRowVisibleMutationParams {export const SetRowVisibleUndoMutationFactory = (accessor: IAccessor, params: ISetRowVisibleMutationParams) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');@@ -43,7 +43,7 @@ export const SetRowVisibleMutation: IMutation<ISetRowVisibleMutationParams> = {type: CommandType.MUTATION,handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');@@ -72,7 +72,7 @@ export interface ISetRowHiddenMutationParams {export const SetRowHiddenUndoMutationFactory = (accessor: IAccessor, params: ISetRowHiddenMutationParams) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');@@ -90,7 +90,7 @@ export const SetRowHiddenMutation: IMutation<ISetRowHiddenMutationParams> = {type: CommandType.MUTATION,handler: (accessor, params) => {const univerInstanceService = accessor.get(IUniverInstanceService);- const universheet = univerInstanceService.getUniverSheetInstance(params.unitId);+ const universheet = univerInstanceService.getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {throw new Error('universheet is null error!');diff --git a/packages/sheets/src/commands/mutations/set-tab-color.mutation.ts b/packages/sheets/src/commands/mutations/set-tab-color.mutation.tsindex ea06c99f96..7dca507673 100644--- a/packages/sheets/src/commands/mutations/set-tab-color.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-tab-color.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IAccessor, IMutation } from '@univerjs/core';-import { CommandType, IUniverInstanceService, Tools } from '@univerjs/core';+import type { IAccessor, IMutation, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, Tools, UniverInstanceType } from '@univerjs/core';export interface ISetTabColorMutationParams {color: string;@@ -27,7 +27,7 @@ export const SetTabColorUndoMutationFactory = (accessor: IAccessor,params: ISetTabColorMutationParams): ISetTabColorMutationParams => {- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);+ const workbook = accessor.get(IUniverInstanceService).getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);const worksheet = workbook!.getSheetBySheetId(params.subUnitId);const config = worksheet!.getConfig();@@ -43,7 +43,7 @@ export const SetTabColorMutation: IMutation<ISetTabColorMutationParams> = {id: 'sheet.mutation.set-tab-color',type: CommandType.MUTATION,handler: (accessor, params) => {- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);+ const workbook = accessor.get(IUniverInstanceService).getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) return false;const worksheet = workbook.getSheetBySheetId(params.subUnitId);if (!worksheet) return false;diff --git a/packages/sheets/src/commands/mutations/set-worksheet-hide.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-hide.mutation.tsindex 91de8272db..a7b97520bd 100644--- a/packages/sheets/src/commands/mutations/set-worksheet-hide.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-worksheet-hide.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { BooleanNumber, IAccessor, IMutation } from '@univerjs/core';-import { CommandType, IUniverInstanceService } from '@univerjs/core';+import type { BooleanNumber, IAccessor, IMutation, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { getSheetMutationTarget } from '../commands/utils/target-util';export interface ISetWorksheetHideMutationParams {@@ -45,7 +45,7 @@ export const SetWorksheetHideMutation: IMutation<ISetWorksheetHideMutationParamsid: 'sheet.mutation.set-worksheet-hidden',type: CommandType.MUTATION,handler: (accessor, params) => {- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);+ const universheet = accessor.get(IUniverInstanceService).getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {return false;diff --git a/packages/sheets/src/commands/mutations/set-worksheet-name.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-name.mutation.tsindex 0055433a46..26d7c8d9b4 100644--- a/packages/sheets/src/commands/mutations/set-worksheet-name.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-worksheet-name.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IAccessor, IMutation } from '@univerjs/core';-import { CommandType, IUniverInstanceService } from '@univerjs/core';+import type { IAccessor, IMutation, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { getSheetMutationTarget } from '../commands/utils/target-util';export interface ISetWorksheetNameMutationParams {@@ -45,7 +45,7 @@ export const SetWorksheetNameMutation: IMutation<ISetWorksheetNameMutationParamsid: 'sheet.mutation.set-worksheet-name',type: CommandType.MUTATION,handler: (accessor, params) => {- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);+ const universheet = accessor.get(IUniverInstanceService).getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (universheet == null) {return false;diff --git a/packages/sheets/src/commands/mutations/set-worksheet-order.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-order.mutation.tsindex 74a3377102..e0e2b224f0 100644--- a/packages/sheets/src/commands/mutations/set-worksheet-order.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-worksheet-order.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { IAccessor, IMutation } from '@univerjs/core';-import { CommandType, IUniverInstanceService, Tools } from '@univerjs/core';+import type { IAccessor, IMutation, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, Tools, UniverInstanceType } from '@univerjs/core';export interface ISetWorksheetOrderMutationParams {fromOrder: number;@@ -39,7 +39,7 @@ export const SetWorksheetOrderMutation: IMutation<ISetWorksheetOrderMutationParaid: 'sheet.mutation.set-worksheet-order',type: CommandType.MUTATION,handler: (accessor, params) => {- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);+ const workbook = accessor.get(IUniverInstanceService).getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) return false;const config = workbook.getConfig();config.sheetOrder.splice(params.fromOrder, 1);diff --git a/packages/sheets/src/commands/mutations/set-worksheet-right-to-left.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-right-to-left.mutation.tsindex 973c43a1b6..dcf141f106 100644--- a/packages/sheets/src/commands/mutations/set-worksheet-right-to-left.mutation.ts+++ b/packages/sheets/src/commands/mutations/set-worksheet-right-to-left.mutation.ts@@ -14,8 +14,8 @@* limitations under the License.*/-import type { BooleanNumber, IAccessor, IMutation } from '@univerjs/core';-import { CommandType, IUniverInstanceService, Tools } from '@univerjs/core';+import type { BooleanNumber, IAccessor, IMutation, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, Tools, UniverInstanceType } from '@univerjs/core';export interface ISetWorksheetRightToLeftMutationParams {rightToLeft: BooleanNumber;@@ -27,7 +27,7 @@ export const SetWorksheetRightToLeftUndoMutationFactory = (accessor: IAccessor,params: ISetWorksheetRightToLeftMutationParams): ISetWorksheetRightToLeftMutationParams => {- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);+ const workbook = accessor.get(IUniverInstanceService).getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);const worksheet = workbook!.getSheetBySheetId(params.subUnitId);const config = worksheet!.getConfig();@@ -43,7 +43,7 @@ export const SetWorksheetRightToLeftMutation: IMutation<ISetWorksheetRightToLeftid: 'sheet.mutation.set-worksheet-right-to-left',type: CommandType.MUTATION,handler: (accessor, params) => {- const workbook = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.unitId);+ const workbook = accessor.get(IUniverInstanceService).getUnit<Workbook>(params.unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) return false;const worksheet = workbook.getSheetBySheetId(params.subUnitId);if (!worksheet) return false;diff --git a/packages/sheets/src/commands/utils/handle-range.mutation.ts b/packages/sheets/src/commands/utils/handle-range.mutation.tsindex 65376791b5..065a6305ae 100644--- a/packages/sheets/src/commands/utils/handle-range.mutation.ts+++ b/packages/sheets/src/commands/utils/handle-range.mutation.ts@@ -14,10 +14,10 @@* limitations under the License.*/-import type { IAccessor, ICellData, IMutationInfo, IObjectMatrixPrimitiveType, IRange, Nullable } from '@univerjs/core';+import type { IAccessor, ICellData, IMutationInfo, IObjectMatrixPrimitiveType, IRange, Nullable, Workbook } from '@univerjs/core';import type { IDeleteRangeMutationParams, IInsertRangeMutationParams } from '../../basics/interfaces/mutation-interface';import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation';-import { Dimension, getArrayLength, IUniverInstanceService, ObjectMatrix, Tools } from '@univerjs/core';+import { Dimension, getArrayLength, IUniverInstanceService, ObjectMatrix, Tools, UniverInstanceType } from '@univerjs/core';import { generateNullCell } from '../../basics/utils';import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';import { getMoveRangeUndoRedoMutations } from '../commands/move-range.command';@@ -48,7 +48,7 @@ export const InsertRangeUndoMutationFactory = (// handler: (accessor, params) => {// const { unitId, subUnitId, range, cellValue, shiftDimension } = params;// const univerInstanceService = accessor.get(IUniverInstanceService);-// const workbook = univerInstanceService.getUniverSheetInstance(unitId);+// const workbook = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);// if (!workbook) return false;// const worksheet = workbook.getSheetBySheetId(subUnitId);// if (!worksheet) return false;@@ -77,7 +77,7 @@ export function getInsertRangeMutations(accessor: IAccessor, params: IInsertRangconst instanceService = accessor.get(IUniverInstanceService);const sheetInterceptorService = accessor.get(SheetInterceptorService);- const workbook = instanceService.getUniverSheetInstance(unitId);+ const workbook = instanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const worksheet = workbook?.getSheetBySheetId(subUnitId);if (worksheet) {const cellMatrix = worksheet.getCellMatrix();@@ -180,7 +180,7 @@ export function getRemoveRangeMutations(accessor: IAccessor, params: IDeleteRangconst instanceService = accessor.get(IUniverInstanceService);const sheetInterceptorService = accessor.get(SheetInterceptorService);- const workbook = instanceService.getUniverSheetInstance(unitId);+ const workbook = instanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const worksheet = workbook?.getSheetBySheetId(subUnitId);if (worksheet) {const cellMatrix = worksheet.getCellMatrix();diff --git a/packages/sheets/src/controllers/active-worksheet.controller.ts b/packages/sheets/src/controllers/active-worksheet.controller.tsindex 44430ed151..9c134798aa 100644--- a/packages/sheets/src/controllers/active-worksheet.controller.ts+++ b/packages/sheets/src/controllers/active-worksheet.controller.ts@@ -19,7 +19,7 @@ import type { IInsertSheetMutationParams, IRemoveSheetMutationParams } from '../import type { ISetWorksheetHideMutationParams } from '../commands/mutations/set-worksheet-hide.mutation';import type { ISetSelectionsOperationParams } from '../commands/operations/selection.operation';import type { ISetWorksheetActiveOperationParams } from '../commands/operations/set-worksheet-active.operation';-import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';+import { Disposable, ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { InsertSheetMutation } from '../commands/mutations/insert-sheet.mutation';import { RemoveSheetMutation } from '../commands/mutations/remove-sheet.mutation';import { SetWorksheetHideMutation } from '../commands/mutations/set-worksheet-hide.mutation';@@ -80,7 +80,7 @@ export class ActiveWorksheetController extends Disposable {private _adjustActiveSheetOnHideSheet(mutation: IMutationInfo<ISetWorksheetHideMutationParams>) {// If the active sheet is hidden, we need to change the active sheet to the next sheet.const { unitId, subUnitId } = mutation.params;- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return;}@@ -98,7 +98,7 @@ export class ActiveWorksheetController extends Disposable {private _beforeAdjustActiveSheetOnRemoveSheet(mutation: IMutationInfo<IRemoveSheetMutationParams>) {const { unitId, subUnitId } = mutation.params;- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return;}@@ -122,7 +122,7 @@ export class ActiveWorksheetController extends Disposable {// If the current sheet is not the deleted one, we don't have to call _switchToNextSheet.const { unitId } = mutation.params;- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return;}diff --git a/packages/sheets/src/controllers/auto-fill.controller.ts b/packages/sheets/src/controllers/auto-fill.controller.tsindex c3baeede11..683c4d32fb 100644--- a/packages/sheets/src/controllers/auto-fill.controller.ts+++ b/packages/sheets/src/controllers/auto-fill.controller.ts@@ -27,6 +27,7 @@ import {ObjectMatrix,Rectangle,Tools,+ UniverInstanceType,} from '@univerjs/core';import { discreteRangeToRange } from '../basics/utils';import { AddMergeUndoMutationFactory, AddWorksheetMergeMutation } from '../commands/mutations/add-worksheet-merge.mutation';@@ -484,7 +485,7 @@ export class AutoFillController extends Disposable {if (hasStyle) {const deleteMergeRanges: IRange[] = [];const mergeData = this._univerInstanceService- .getUniverSheetInstance(unitId)+ .getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(subUnitId)?.getMergeData();diff --git a/packages/sheets/src/controllers/calculate-result-apply.controller.ts b/packages/sheets/src/controllers/calculate-result-apply.controller.tsindex f44e766783..73f586bb0f 100644--- a/packages/sheets/src/controllers/calculate-result-apply.controller.ts+++ b/packages/sheets/src/controllers/calculate-result-apply.controller.ts@@ -14,9 +14,9 @@* limitations under the License.*/-import type { ICellData, ICommandInfo, IObjectMatrixPrimitiveType, Nullable } from '@univerjs/core';+import type { ICellData, ICommandInfo, IObjectMatrixPrimitiveType, Nullable, Workbook } from '@univerjs/core';import type { ISetFormulaCalculationResultMutation } from '@univerjs/engine-formula';-import { Disposable, ICommandService, Inject, IUniverInstanceService, ObjectMatrix, sequenceExecute } from '@univerjs/core';+import { Disposable, ICommandService, Inject, IUniverInstanceService, ObjectMatrix, sequenceExecute, UniverInstanceType } from '@univerjs/core';import { handleNumfmtInCell, SetFormulaCalculationResultMutation } from '@univerjs/engine-formula';import { SetRangeValuesMutation } from '../commands/mutations/set-range-values.mutation';@@ -48,7 +48,7 @@ export class CalculateResultApplyController extends Disposable {for (let i = 0; i < unitIds.length; i++) {const unitId = unitIds[i];- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {continue;}@@ -109,7 +109,7 @@ export class CalculateResultApplyController extends Disposable {* @returns*/private _getMergedCellData(unitId: string, sheetId: string, cellData: IObjectMatrixPrimitiveType<Nullable<ICellData>>) {- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);const styles = workbook?.getStyles();const worksheet = workbook?.getSheetBySheetId(sheetId);diff --git a/packages/sheets/src/controllers/merge-cell.controller.ts b/packages/sheets/src/controllers/merge-cell.controller.tsindex 3311b47c31..d15faf817d 100644--- a/packages/sheets/src/controllers/merge-cell.controller.ts+++ b/packages/sheets/src/controllers/merge-cell.controller.ts@@ -291,7 +291,7 @@ export class MergeCellController extends Disposable {private _onRefRangeChange() {const registerRefRange = (unitId: string, subUnitId: string) => {- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return;}@@ -1125,7 +1125,7 @@ export class MergeCellController extends Disposable {// 1. MoveRowsOrColsMutationif (mutationIdArrByMove.includes(command.id)) {if (!command.params) return;- const workbook = this._univerInstanceService.getUniverSheetInstance((command.params as IMoveRowsMutationParams).unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>((command.params as IMoveRowsMutationParams).unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) return;const worksheet = workbook.getSheetBySheetId((command.params as IMoveRowsMutationParams).subUnitId);if (!worksheet) return;@@ -1180,7 +1180,7 @@ export class MergeCellController extends Disposable {// 2. InsertRowsOrCols / RemoveRowsOrCols Mutationsif (mutationIdByRowCol.includes(command.id)) {- const workbook = this._univerInstanceService.getUniverSheetInstance((command.params as IInsertColMutationParams).unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>((command.params as IInsertColMutationParams).unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) return;const worksheet = workbook.getSheetBySheetId((command.params as IInsertColMutationParams).subUnitId);if (!worksheet) return;@@ -1249,7 +1249,7 @@ export class MergeCellController extends Disposable {function getWorkbook(univerInstanceService: IUniverInstanceService, unitId?: string) {if (unitId) {- return univerInstanceService.getUniverSheetInstance(unitId);+ return univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);}return univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;}diff --git a/packages/sheets/src/facade/__tests__/f-defined-name.spec.ts b/packages/sheets/src/facade/__tests__/f-defined-name.spec.tsindex becd21aa2d..b04cc25c4a 100644--- a/packages/sheets/src/facade/__tests__/f-defined-name.spec.ts+++ b/packages/sheets/src/facade/__tests__/f-defined-name.spec.ts@@ -14,9 +14,9 @@* limitations under the License.*/-import type { ICellData, Injector, Nullable } from '@univerjs/core';+import type { ICellData, Injector, Nullable, Workbook } from '@univerjs/core';import type { FUniver } from '@univerjs/core/facade';-import { ICommandService, IUniverInstanceService } from '@univerjs/core';+import { ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { RemoveDefinedNameMutation, SetDefinedNameMutation } from '@univerjs/engine-formula';import { RemoveDefinedNameCommand, SetDefinedNameCommand } from '@univerjs/sheets';import { beforeEach, describe, expect, it } from 'vitest';@@ -51,7 +51,7 @@ describe('Test FDefinedName', () => {endColumn: number): Nullable<ICellData> =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValue();diff --git a/packages/sheets/src/facade/__tests__/f-range.spec.ts b/packages/sheets/src/facade/__tests__/f-range.spec.tsindex 4cdecf07ef..84cd668111 100644--- a/packages/sheets/src/facade/__tests__/f-range.spec.ts+++ b/packages/sheets/src/facade/__tests__/f-range.spec.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { ICellData, IDocumentData, Injector, IStyleData, Nullable, RichTextValue } from '@univerjs/core';+import type { ICellData, IDocumentData, Injector, IStyleData, Nullable, RichTextValue, Workbook } from '@univerjs/core';import type { FUniver } from '@univerjs/core/facade';import {AbsoluteRefType,@@ -26,6 +26,7 @@ import {IUniverInstanceService,LifecycleStages,TestConfirmService,+ UniverInstanceType,VerticalAlign,WrapStrategy,} from '@univerjs/core';@@ -140,7 +141,7 @@ describe('Test FRange', () => {endColumn: number): Nullable<ICellData> =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValue();@@ -152,7 +153,7 @@ describe('Test FRange', () => {endColumn: number): Nullable<IStyleData> => {const value = getValueByPosition(startRow, startColumn, endRow, endColumn);- const styles = get(IUniverInstanceService).getUniverSheetInstance('test')?.getStyles();+ const styles = get(IUniverInstanceService).getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getStyles();if (value && styles) {return styles.getStyleByCell(value);}diff --git a/packages/sheets/src/facade/__tests__/f-workbook.spec.ts b/packages/sheets/src/facade/__tests__/f-workbook.spec.tsindex f6286ac308..2f5e0ea07c 100644--- a/packages/sheets/src/facade/__tests__/f-workbook.spec.ts+++ b/packages/sheets/src/facade/__tests__/f-workbook.spec.ts@@ -14,9 +14,9 @@* limitations under the License.*/-import type { ICellData, Injector, Nullable } from '@univerjs/core';+import type { ICellData, Injector, Nullable, Workbook } from '@univerjs/core';import type { FUniver } from '@univerjs/core/facade';-import { ICommandService, ILogService, IUniverInstanceService, LocaleType } from '@univerjs/core';+import { ICommandService, ILogService, IUniverInstanceService, LocaleType, UniverInstanceType } from '@univerjs/core';import {CopySheetCommand,getPrimaryForRange,@@ -101,7 +101,7 @@ describe('Test FWorkbook', () => {endColumn: number): Nullable<ICellData> =>get(IUniverInstanceService)- .getUniverSheetInstance('test')+ .getUnit<Workbook>('test', UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId('sheet1')?.getRange(startRow, startColumn, endRow, endColumn).getValue();diff --git a/packages/sheets/src/services/numfmt/numfmt.service.ts b/packages/sheets/src/services/numfmt/numfmt.service.tsindex 1d9bd2711f..ec967cfb2c 100644--- a/packages/sheets/src/services/numfmt/numfmt.service.ts+++ b/packages/sheets/src/services/numfmt/numfmt.service.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { IRange } from '@univerjs/core';+import type { IRange, Workbook } from '@univerjs/core';import type { INumfmtService } from './type';import {@@ -23,6 +23,7 @@ import {IResourceManagerService,IUniverInstanceService,Range,+ UniverInstanceType,} from '@univerjs/core';export class NumfmtService extends Disposable implements INumfmtService {@@ -35,7 +36,7 @@ export class NumfmtService extends Disposable implements INumfmtService {}getValue(unitId: string, subUnitId: string, row: number, col: number) {- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return;}@@ -55,7 +56,7 @@ export class NumfmtService extends Disposable implements INumfmtService {}deleteValues(unitId: string, subUnitId: string, values: IRange[]) {- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return;}@@ -86,7 +87,7 @@ export class NumfmtService extends Disposable implements INumfmtService {subUnitId: string,values: Array<{ ranges: IRange[]; pattern: string }>) {- const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) {return;}diff --git a/packages/sheets/src/services/permission/range-permission/range-protection.ref-range.ts b/packages/sheets/src/services/permission/range-permission/range-protection.ref-range.tsindex 74760bb6f4..edcb83e1b4 100644--- a/packages/sheets/src/services/permission/range-permission/range-protection.ref-range.ts+++ b/packages/sheets/src/services/permission/range-permission/range-protection.ref-range.ts@@ -455,7 +455,7 @@ export class RangeProtectionRefRangeService extends Disposable {// 2. InsertRowsOrCols / RemoveRowsOrCols Mutationsif (mutationIdByRowCol.includes(command.id)) {- const workbook = this._univerInstanceService.getUniverSheetInstance((command.params as IInsertColMutationParams).unitId);+ const workbook = this._univerInstanceService.getUnit<Workbook>((command.params as IInsertColMutationParams).unitId, UniverInstanceType.UNIVER_SHEET);if (!workbook) return;const worksheet = workbook.getSheetBySheetId((command.params as IInsertColMutationParams).subUnitId);if (!worksheet) return;