Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor: base-sheets not depends on base-ui (#360)

Wenzhao Hu5ddeb0fac393
diff --git a/packages/base-sheets/package.json b/packages/base-sheets/package.json
index d72fe6a2c1..41a6ca94b1 100644
--- a/packages/base-sheets/package.json
+++ b/packages/base-sheets/package.json
@@ -47,7 +47,6 @@
"dependencies": {
"@ctrl/tinycolor": "^4.0.2",
"@univerjs/base-render": "workspace:*",
- "@univerjs/base-ui": "workspace:*",
"@univerjs/core": "workspace:*",
"@wendellhu/redi": "^0.12.10",
"rxjs": "^7.8.1"
diff --git a/packages/base-sheets/src/Controller/scroll.controller.ts b/packages/base-sheets/src/Controller/scroll.controller.ts
index 5aa6146ac6..95095d19f3 100644
--- a/packages/base-sheets/src/Controller/scroll.controller.ts
+++ b/packages/base-sheets/src/Controller/scroll.controller.ts
@@ -2,7 +2,6 @@ import { IRenderManagerService } from '@univerjs/base-render';
import {
Direction,
Disposable,
- ICommandInfo,
ICommandService,
IUniverInstanceService,
LifecycleStages,
@@ -14,10 +13,8 @@ import { Inject } from '@wendellhu/redi';
import { getSheetObject } from '../Basics/component-tools';
import { VIEWPORT_KEY } from '../Basics/Const/DEFAULT_SPREADSHEET_VIEW';
import { ScrollCommand } from '../commands/commands/set-scroll.command';
-import { IMoveSelectionCommandParams, MoveSelectionCommand } from '../commands/commands/set-selections.command';
import { ScrollManagerService } from '../services/scroll-manager.service';
import { SelectionManagerService } from '../services/selection/selection-manager.service';
-import { ISelectionRenderService } from '../services/selection/selection-render.service';
import { ISheetSkeletonManagerParam, SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';
@OnLifecycle(LifecycleStages.Rendered, ScrollController)
@@ -27,9 +24,6 @@ export class ScrollController extends Disposable {
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
@ICommandService private readonly _commandService: ICommandService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
- @ISelectionRenderService
- private readonly _selectionRenderService: ISelectionRenderService,
-
@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
@Inject(ScrollManagerService) private readonly _scrollManagerService: ScrollManagerService
) {
@@ -44,11 +38,8 @@ export class ScrollController extends Disposable {
private _initialize() {
this._scrollEventBinding();
-
this._scrollSubscribeBinding();
-
this._skeletonListener();
- this._commandExecutedListener();
}
private _scrollEventBinding() {
@@ -91,20 +82,7 @@ export class ScrollController extends Disposable {
);
}
- private _commandExecutedListener() {
- const updateCommandList = [MoveSelectionCommand.id];
-
- this.disposeWithMe(
- this._commandService.onCommandExecuted((command: ICommandInfo) => {
- if (updateCommandList.includes(command.id)) {
- const params = command.params as IMoveSelectionCommandParams;
- this.scrollToVisible(params.direction);
- }
- })
- );
- }
-
- private scrollToVisible(direction: Direction) {
+ scrollToVisible(direction: Direction) {
let startSheetViewRow;
let startSheetViewColumn;
const selection = this._selectionManagerService.getLast();
diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/base-shees-plugin.ts
similarity index 97%
rename from packages/base-sheets/src/SheetPlugin.ts
rename to packages/base-sheets/src/base-shees-plugin.ts
index afb36a0371..ddc1288302 100644
--- a/packages/base-sheets/src/SheetPlugin.ts
+++ b/packages/base-sheets/src/base-shees-plugin.ts
@@ -24,7 +24,6 @@ import { ScrollManagerService } from './services/scroll-manager.service';
import { SelectionManagerService } from './services/selection/selection-manager.service';
import { ISelectionRenderService, SelectionRenderService } from './services/selection/selection-render.service';
import { SheetSkeletonManagerService } from './services/sheet-skeleton-manager.service';
-import { ShortcutExperienceService } from './services/shortcut-experience.service';
import { SheetCanvasView } from './View/sheet-canvas-view';
/**
@@ -67,7 +66,6 @@ export class SheetPlugin extends Plugin {
],
[ScrollManagerService],
[SelectionManagerService],
- [ShortcutExperienceService],
[RefRangeService],
// controllers
diff --git a/packages/base-sheets/src/commands/commands/__tests__/create-command-test-bed.ts b/packages/base-sheets/src/commands/commands/__tests__/create-command-test-bed.ts
index 539d0536fa..20d7715951 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/create-command-test-bed.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/create-command-test-bed.ts
@@ -11,7 +11,6 @@ import { Dependency, Inject, Injector } from '@wendellhu/redi';
import { BorderStyleManagerService } from '../../../services/border-style-manager.service';
import { SelectionManagerService } from '../../../services/selection/selection-manager.service';
-import { ShortcutExperienceService } from '../../../services/shortcut-experience.service';
const TEST_WORKBOOK_DATA_DEMO: IWorkbookConfig = {
id: 'test',
@@ -65,7 +64,6 @@ export function createCommandTestBed(workbookConfig?: IWorkbookConfig, dependenc
}
override onStarting(injector: Injector): void {
- injector.add([ShortcutExperienceService]);
injector.add([SelectionManagerService]);
injector.add([BorderStyleManagerService]);
diff --git a/packages/base-sheets/src/commands/commands/__tests__/move-rows-cols.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/move-rows-cols.command.spec.ts
index 76fc464442..fd36132c77 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/move-rows-cols.command.spec.ts
+++ b/packages/base-sheets/src/commands/commands/__tests__/move-rows-cols.command.spec.ts
@@ -1,5 +1,3 @@
-/* eslint-disable no-magic-numbers */
-import { IMessageService } from '@univerjs/base-ui';
import {
ICellData,
ICommandService,
@@ -10,7 +8,6 @@ import {
Nullable,
RANGE_TYPE,
RedoCommand,
- toDisposable,
Tools,
UndoCommand,
Univer,
@@ -396,7 +393,5 @@ const TEST_ROWS_COLS_MOVE_DEMO: IWorkbookConfig = {
};
function createMoveRowsColsTestBed() {
- return createCommandTestBed(Tools.deepClone(TEST_ROWS_COLS_MOVE_DEMO), [
- [IMessageService, { useValue: { show: () => toDisposable(() => {}) } as IMessageService }],
- ]);
+ return createCommandTestBed(Tools.deepClone(TEST_ROWS_COLS_MOVE_DEMO));
}
diff --git a/packages/base-sheets/src/commands/commands/move-rows-cols.command.ts b/packages/base-sheets/src/commands/commands/move-rows-cols.command.ts
index 49b9c283a3..6e59031f07 100644
--- a/packages/base-sheets/src/commands/commands/move-rows-cols.command.ts
+++ b/packages/base-sheets/src/commands/commands/move-rows-cols.command.ts
@@ -1,6 +1,6 @@
-import { IMessageService, MessageType } from '@univerjs/base-ui';
import {
CommandType,
+ ErrorService,
ICommand,
ICommandService,
IRange,
@@ -76,24 +76,18 @@ export const MoveRowsCommand: ICommand<IMoveRowsCommandParams> = {
const workbookId = workbook.getUnitId();
const worksheetId = worksheet.getSheetId();
- const messageService = accessor.get(IMessageService);
+ const errorService = accessor.get(ErrorService);
// Forbid action when some parts of a merged cell are selected.
const rangeToMove = filteredSelections[0].range;
const beforePrimary = filteredSelections[0].primary;
const alignedRange = alignToMergedCellsBorders(rangeToMove, worksheet, false);
if (!Rectangle.equals(rangeToMove, alignedRange)) {
- messageService.show({
- type: MessageType.Error,
- content: 'Only part of a merged cell is selected.',
- });
+ errorService.emit('Only part of a merged cell is selected.');
return false;
}
if (rowAcrossMergedCell(toRow, worksheet)) {
- messageService.show({
- type: MessageType.Error,
- content: 'Across a merged cell.',
- });
+ errorService.emit('Across a merged cell.');
return false;
}
@@ -258,24 +252,18 @@ export const MoveColsCommand: ICommand<IMoveColsCommandParams> = {
const workbookId = workbook.getUnitId();
const worksheetId = worksheet.getSheetId();
- const messageService = accessor.get(IMessageService);
+ const errorService = accessor.get(ErrorService);
// Forbid action when some parts of a merged cell are selected.
const rangeToMove = filteredSelections[0].range;
const beforePrimary = filteredSelections[0].primary;
const alignedRange = alignToMergedCellsBorders(rangeToMove, worksheet, false);
if (!Rectangle.equals(rangeToMove, alignedRange)) {
- messageService.show({
- type: MessageType.Error,
- content: 'Only part of a merged cell is selected.',
- });
+ errorService.emit('Only part of a merged cell is selected.');
return false;
}
if (columnAcrossMergedCell(toCol, worksheet)) {
- messageService.show({
- type: MessageType.Error,
- content: 'Across a merged cell.',
- });
+ errorService.emit('Across a merged cell.');
return false;
}
diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.ts
index 410abedd46..629dfcf435 100644
--- a/packages/base-sheets/src/index.ts
+++ b/packages/base-sheets/src/index.ts
@@ -1,5 +1,5 @@
+export * from './base-shees-plugin';
export * from './Basics';
-export * from './SheetPlugin';
// #region services
@@ -74,19 +74,6 @@ export {
} from './commands/commands/set-row-visible.command';
export type { IScrollCommandParams } from './commands/commands/set-scroll.command';
export { RestScrollCommand, ScrollCommand, SetScrollRelativeCommand } from './commands/commands/set-scroll.command';
-export type {
- IExpandSelectionCommandParams,
- IMoveSelectionCommandParams,
- ISelectAllCommandParams,
-} from './commands/commands/set-selections.command';
-export {
- ExpandSelectionCommand,
- type IMoveSelectionEnterAndTabCommandParams,
- JumpOver,
- MoveSelectionCommand,
- MoveSelectionEnterAndTabCommand,
- SelectAllCommand,
-} from './commands/commands/set-selections.command';
export {
ResetBackgroundColorCommand,
ResetTextColorCommand,
@@ -175,6 +162,11 @@ export { SetZoomRatioOperation } from './commands/operations/set-zoom-ratio.oper
export { RefRangeService } from './services/ref-range.service';
export { ISelectionRenderService, SelectionRenderService } from './services/selection/selection-render.service';
export { SheetSkeletonManagerService } from './services/sheet-skeleton-manager.service';
-export { ShortcutExperienceService } from './services/shortcut-experience.service';
// #endregion
+
+// #region controllers
+
+export { ScrollController } from './Controller/scroll.controller';
+
+// #endregion controllers
diff --git a/packages/base-sheets/src/services/selection/selection-manager.service.ts b/packages/base-sheets/src/services/selection/selection-manager.service.ts
index 5317e12612..60a9103751 100644
--- a/packages/base-sheets/src/services/selection/selection-manager.service.ts
+++ b/packages/base-sheets/src/services/selection/selection-manager.service.ts
@@ -21,13 +21,18 @@ export type ISelectionInfo = Map<string, Map<string, Map<string, ISelectionWithS
/**
* This service is responsible for managing the selection data.
+ *
* You can generally modify its data through SetSelectionsOperation.
+ *
* In the same app and sub-table, there will be different functional selection areas,
* such as charts, formulas, conditional formats, etc.,
* which are distinguished by the pluginName.
+ *
* The selection data drawn by the user through the SelectionRenderService will be saved to this service.
+ *
* Data changes within the service will also notify the SelectionController to redraw the selection area.
- * Not only will switching sub-tables trigger a redraw, but also changing row and column widths,
+ *
+ * Not only will switching sub-tables trigger a redraw, but also changing row and column widths,
* hiding rows and columns, automatic row height, dragging rows and columns, deleting rows and columns,
* and so on, will cause the size of the selection area to change.
*/
diff --git a/packages/base-sheets/tsconfig.json b/packages/base-sheets/tsconfig.json
index b37297a740..320c251254 100644
--- a/packages/base-sheets/tsconfig.json
+++ b/packages/base-sheets/tsconfig.json
@@ -12,5 +12,5 @@
"esModuleInterop": true, // auto allowSyntheticDefaultImports true
"strictPropertyInitialization": false
},
- "include": ["src/**/*", "test/**/*"]
+ "include": ["src/**/*", "test/**/*", "../ui-plugin-sheets/src/commands/commands/__tests__/create-selection-command-test-bed.ts", "../ui-plugin-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts"]
}
\ No newline at end of file
diff --git a/packages/base-ui/src/base-ui-plugin.ts b/packages/base-ui/src/base-ui-plugin.ts
index 29766c9866..bb1f580f36 100644
--- a/packages/base-ui/src/base-ui-plugin.ts
+++ b/packages/base-ui/src/base-ui-plugin.ts
@@ -3,6 +3,7 @@ import { Dependency, Inject, Injector } from '@wendellhu/redi';
import { ComponentManager } from './Common/ComponentManager';
import { ZIndexManager } from './Common/ZIndexManager';
+import { ErrorController } from './controllers/error/error.controller';
import { SharedController } from './controllers/shared-shortcut.controller';
import { IUIController, IWorkbenchOptions } from './controllers/ui/ui.controller';
import { DesktopUIController } from './controllers/ui/ui-desktop.controller';
@@ -18,6 +19,7 @@ import { DesktopNotificationService } from './services/notification/desktop-noti
import { INotificationService } from './services/notification/notification.service';
import { DesktopPlatformService, IPlatformService } from './services/platform/platform.service';
import { DesktopShortcutService, IShortcutService } from './services/shortcut/shortcut.service';
+import { ShortcutExperienceService } from './services/shortcut/shortcut-experience.service';
export interface IUIPluginConfig extends IWorkbenchOptions {}
@@ -59,6 +61,7 @@ export class UIPlugin extends Plugin {
[ComponentManager],
[ZIndexManager],
// services
+ [ShortcutExperienceService],
[IShortcutService, { useClass: DesktopShortcutService }],
[IPlatformService, { useClass: DesktopPlatformService }],
[IMenuService, { useClass: DesktopMenuService }],
@@ -69,8 +72,9 @@ export class UIPlugin extends Plugin {
[ILocalStorageService, { useClass: DesktopLocalStorageService, lazy: true }],
// controllers
[IFocusService, { useClass: DesktopFocusService }],
- [SharedController],
[IUIController, { useClass: DesktopUIController }],
+ [SharedController],
+ [ErrorController],
];
dependencies.forEach((dependency) => injector.add(dependency));
diff --git a/packages/base-ui/src/controllers/error/error.controller.ts b/packages/base-ui/src/controllers/error/error.controller.ts
new file mode 100644
index 0000000000..e3642797b7
--- /dev/null
+++ b/packages/base-ui/src/controllers/error/error.controller.ts
@@ -0,0 +1,25 @@
+import { Disposable, ErrorService, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core';
+import { Inject } from '@wendellhu/redi';
+
+import { IMessageService, MessageType } from '../../services/message/message.service';
+
+@OnLifecycle(LifecycleStages.Starting, ErrorController)
+export class ErrorController extends Disposable {
+ constructor(
+ @Inject(ErrorService) private readonly _errorService: ErrorService,
+ @IMessageService private readonly _messageService: IMessageService
+ ) {
+ super();
+
+ this.disposeWithMe(
+ toDisposable(
+ this._errorService.error$.subscribe((error) => {
+ this._messageService.show({
+ content: error.errorKey,
+ type: MessageType.Error,
+ });
+ })
+ )
+ );
+ }
+}
diff --git a/packages/base-ui/src/index.ts b/packages/base-ui/src/index.ts
index 26470ba980..285c37899e 100644
--- a/packages/base-ui/src/index.ts
+++ b/packages/base-ui/src/index.ts
@@ -43,4 +43,5 @@ export { INotificationService } from './services/notification/notification.servi
export { DesktopPlatformService, IPlatformService } from './services/platform/platform.service';
export { KeyCode, MetaKeys } from './services/shortcut/keycode';
export { DesktopShortcutService, type IShortcutItem, IShortcutService } from './services/shortcut/shortcut.service';
+export { ShortcutExperienceService } from './services/shortcut/shortcut-experience.service';
export * from './Utils';
diff --git a/packages/base-sheets/src/services/shortcut-experience.service.ts b/packages/base-ui/src/services/shortcut/shortcut-experience.service.ts
similarity index 98%
rename from packages/base-sheets/src/services/shortcut-experience.service.ts
rename to packages/base-ui/src/services/shortcut/shortcut-experience.service.ts
index f34067834a..646eda3b8b 100644
--- a/packages/base-sheets/src/services/shortcut-experience.service.ts
+++ b/packages/base-ui/src/services/shortcut/shortcut-experience.service.ts
@@ -1,7 +1,8 @@
-import { KeyCode } from '@univerjs/base-ui';
import { ISelection, ITextSelectionRangeParam, IUniverInstanceService, LocaleService, Nullable } from '@univerjs/core';
import { IDisposable, Inject } from '@wendellhu/redi';
+import { KeyCode } from './keycode';
+
export interface IShortcutExperienceSearch {
unitId: string;
sheetId: string;
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index 66e32ed2ae..b00cfa3149 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Ctor, Injector } from '@wendellhu/redi';
+import { ErrorService } from '..';
import { DocumentModel } from '../Docs/Domain/DocumentModel';
import { Plugin, PluginCtor, PluginRegistry, PluginStore, PluginType } from '../plugin/plugin';
import { CommandService, ICommandService } from '../services/command/command.service';
@@ -174,6 +175,7 @@ export class Univer {
deps: [IContextService],
},
],
+ [ErrorService],
[LocaleService],
[ThemeService],
[GenName],
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index ea05dbe46e..1d59d0ae0b 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -20,6 +20,7 @@ export {
export { IConfigService } from './services/config/config.service';
export * from './services/context/context';
export { IContextService } from './services/context/context.service';
+export { ErrorService, type IError } from './services/error/error.service';
export { IUniverInstanceService } from './services/instance/instance.service';
export { LifecycleStages, OnLifecycle } from './services/lifecycle/lifecycle';
export { LifecycleService } from './services/lifecycle/lifecycle.service';
diff --git a/packages/core/src/services/error/error.service.ts b/packages/core/src/services/error/error.service.ts
new file mode 100644
index 0000000000..198c8a8815
--- /dev/null
+++ b/packages/core/src/services/error/error.service.ts
@@ -0,0 +1,20 @@
+import { Subject } from 'rxjs';
+
+import { Disposable } from '../../Shared/lifecycle';
+
+export interface IError {
+ errorKey: string;
+}
+
+export class ErrorService extends Disposable {
+ private readonly _error$ = new Subject<IError>();
+ error$ = this._error$.asObservable();
+
+ override dispose(): void {
+ this._error$.complete();
+ }
+
+ emit(key: string): void {
+ this._error$.next({ errorKey: key });
+ }
+}
diff --git a/packages/base-sheets/src/commands/commands/__tests__/create-selection-command-test-bed.ts b/packages/ui-plugin-sheets/src/commands/commands/__tests__/create-selection-command-test-bed.ts
similarity index 91%
rename from packages/base-sheets/src/commands/commands/__tests__/create-selection-command-test-bed.ts
rename to packages/ui-plugin-sheets/src/commands/commands/__tests__/create-selection-command-test-bed.ts
index cbc254aa04..082867bb59 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/create-selection-command-test-bed.ts
+++ b/packages/ui-plugin-sheets/src/commands/commands/__tests__/create-selection-command-test-bed.ts
@@ -1,11 +1,14 @@
+import { SetSelectionsOperation } from '@univerjs/base-sheets';
+import { createCommandTestBed } from '@univerjs/base-sheets/commands/commands/__tests__/create-command-test-bed.js';
+import { ShortcutExperienceService } from '@univerjs/base-ui';
import { ICommandService, IWorkbookConfig, LocaleType } from '@univerjs/core';
-import { SetSelectionsOperation } from '../../operations/selection.operation';
-import { ExpandSelectionCommand, MoveSelectionCommand, SelectAllCommand } from '../set-selections.command';
-import { createCommandTestBed } from './create-command-test-bed';
+import { ExpandSelectionCommand, MoveSelectionCommand, SelectAllCommand } from '../set-selection.command';
export function createSelectionCommandTestBed(workbookConfig?: IWorkbookConfig) {
- const { univer, get, sheet } = createCommandTestBed(workbookConfig || SIMPLE_SELECTION_WORKBOOK_DATA);
+ const { univer, get, sheet } = createCommandTestBed(workbookConfig || SIMPLE_SELECTION_WORKBOOK_DATA, [
+ [ShortcutExperienceService],
+ ]);
const commandService = get(ICommandService);
[MoveSelectionCommand, ExpandSelectionCommand, SelectAllCommand, SetSelectionsOperation].forEach((c) => {
diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts b/packages/ui-plugin-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts
similarity index 97%
rename from packages/base-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts
rename to packages/ui-plugin-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts
index 993a1d41bd..4f4eb005db 100644
--- a/packages/base-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts
+++ b/packages/ui-plugin-sheets/src/commands/commands/__tests__/set-selections.command.spec.ts
@@ -1,5 +1,17 @@
/* eslint-disable no-magic-numbers */
+import {
+ NORMAL_SELECTION_PLUGIN_NAME,
+ SelectionManagerService,
+ SetColHiddenCommand,
+ SetColHiddenMutation,
+ SetColVisibleMutation,
+ SetRowHiddenCommand,
+ SetRowHiddenMutation,
+ SetRowVisibleMutation,
+ SetSelectedColsVisibleCommand,
+ SetSelectedRowsVisibleCommand,
+} from '@univerjs/base-sheets';
import {
Direction,
ICommandService,
@@ -11,14 +23,6 @@ import {
import { Injector } from '@wendellhu/redi';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import {
- NORMAL_SELECTION_PLUGIN_NAME,
- SelectionManagerService,
-} from '../../../services/selection/selection-manager.service';
-import { SetColHiddenMutation, SetColVisibleMutation } from '../../mutations/set-col-visible.mutation';
-import { SetRowHiddenMutation, SetRowVisibleMutation } from '../../mutations/set-row-visible.mutation';
-import { SetColHiddenCommand, SetSelectedColsVisibleCommand } from '../set-col-visible.command';
-import { SetRowHiddenCommand, SetSelectedRowsVisibleCommand } from '../set-row-visible.command';
import {
ExpandSelectionCommand,
IExpandSelectionCommandParams,
@@ -27,7 +31,7 @@ import {
JumpOver,
MoveSelectionCommand,
SelectAllCommand,
-} from '../set-selections.command';
+} from '../set-selection.command';
import {
createSelectionCommandTestBed,
SELECTION_WITH_EMPTY_CELLS_DATA,
diff --git a/packages/base-sheets/src/commands/commands/set-selections.command.ts b/packages/ui-plugin-sheets/src/commands/commands/set-selection.command.ts
similarity index 97%
rename from packages/base-sheets/src/commands/commands/set-selections.command.ts
rename to packages/ui-plugin-sheets/src/commands/commands/set-selection.command.ts
index dc8e3be6e4..a4242f3701 100644
--- a/packages/base-sheets/src/commands/commands/set-selections.command.ts
+++ b/packages/ui-plugin-sheets/src/commands/commands/set-selection.command.ts
@@ -1,39 +1,37 @@
-import { KeyCode } from '@univerjs/base-ui';
-import {
- CommandType,
- Direction,
- ICommand,
- ICommandService,
- IRange,
- IUniverInstanceService,
- RANGE_TYPE,
- Rectangle,
- Tools,
-} from '@univerjs/core';
-
import {
+ findNextGapRange,
+ findNextRange,
+ getCellAtRowCol,
+ getStartRange,
NORMAL_SELECTION_PLUGIN_NAME,
SelectionManagerService,
-} from '../../services/selection/selection-manager.service';
-import { ShortcutExperienceService } from '../../services/shortcut-experience.service';
-import { SetSelectionsOperation } from '../operations/selection.operation';
+ SetSelectionsOperation,
+} from '@univerjs/base-sheets';
import {
checkIfShrink,
expandToContinuousRange,
expandToNextCell,
expandToNextGapRange,
expandToWholeSheet,
- findNextGapRange,
- findNextRange,
- getCellAtRowCol,
- getStartRange,
shrinkToNextCell,
shrinkToNextGapRange,
-} from './utils/selection-util';
+} from '@univerjs/base-sheets/commands/commands/utils/selection-util.js';
+import { KeyCode, ShortcutExperienceService } from '@univerjs/base-ui';
+import {
+ CommandType,
+ Direction,
+ ICommand,
+ ICommandService,
+ IRange,
+ IUniverInstanceService,
+ RANGE_TYPE,
+ Rectangle,
+ Tools,
+} from '@univerjs/core';
// TODO@wzhudev: we also need to handle when the current selection is the whole spreadsheet, whole rows or whole columns
-
// TODO@DR-UNIVER: moveStepPage and moveStepEnd implement
+
export enum JumpOver {
moveStopeOne,
moveGap,
@@ -80,7 +78,9 @@ export const MoveSelectionCommand: ICommand<IMoveSelectionCommandParams> = {
return false;
}
- // If there are changes to the selection, clear the start position saved by the tab. This function works in conjunction with the enter and tab shortcuts.
+ // If there are changes to the selection, clear the start position saved by the tab.
+ // This function works in conjunction with the enter and tab shortcuts.
+ // TODO@wzhudev: this should be removed to sheets-ui, listening command execution
accessor.get(ShortcutExperienceService).remove({
unitId: workbook.getUnitId(),
sheetId: worksheet.getSheetId(),
diff --git a/packages/ui-plugin-sheets/src/controller/editor/end-edit.controller.ts b/packages/ui-plugin-sheets/src/controller/editor/end-edit.controller.ts
index 438f71ceeb..1e8e1bb3b8 100644
--- a/packages/ui-plugin-sheets/src/controller/editor/end-edit.controller.ts
+++ b/packages/ui-plugin-sheets/src/controller/editor/end-edit.controller.ts
@@ -6,12 +6,7 @@ import {
IPointerEvent,
IRenderManagerService,
} from '@univerjs/base-render';
-import {
- MoveSelectionCommand,
- MoveSelectionEnterAndTabCommand,
- SelectionManagerService,
- SetRangeValuesCommand,
-} from '@univerjs/base-sheets';
+import { SelectionManagerService, SetRangeValuesCommand } from '@univerjs/base-sheets';
import { KeyCode } from '@univerjs/base-ui';
import {
DEFAULT_EMPTY_DOCUMENT_VALUE,
@@ -35,6 +30,7 @@ import { Inject } from '@wendellhu/redi';
import { Subscription } from 'rxjs';
import { getEditorObject } from '../../Basics/editor/get-editor-object';
+import { MoveSelectionCommand, MoveSelectionEnterAndTabCommand } from '../../commands/commands/set-selection.command';
import { SetCellEditVisibleArrowOperation } from '../../commands/operations/cell-edit.operation';
import { ICellEditorManagerService } from '../../services/editor/cell-editor-manager.service';
import { IEditorBridgeService, IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
diff --git a/packages/ui-plugin-sheets/src/controller/navigation/navigation.controller.ts b/packages/ui-plugin-sheets/src/controller/navigation/navigation.controller.ts
new file mode 100644
index 0000000000..6f81eb7026
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/controller/navigation/navigation.controller.ts
@@ -0,0 +1,26 @@
+import { ScrollController } from '@univerjs/base-sheets';
+import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import { Inject } from '@wendellhu/redi';
+
+import { IMoveSelectionCommandParams, MoveSelectionCommand } from '../../commands/commands/set-selection.command';
+
+const SHEET_NAVIGATION_COMMANDS = [MoveSelectionCommand.id];
+
+@OnLifecycle(LifecycleStages.Rendered, SheetNavigationController)
+export class SheetNavigationController extends Disposable {
+ constructor(
+ @ICommandService private readonly _commandService: ICommandService,
+ @Inject(ScrollController) private readonly _scrollController: ScrollController
+ ) {
+ super();
+
+ this.disposeWithMe(
+ this._commandService.onCommandExecuted((command) => {
+ if (SHEET_NAVIGATION_COMMANDS.includes(command.id)) {
+ const params = command.params as IMoveSelectionCommandParams;
+ this._scrollController.scrollToVisible(params.direction);
+ }
+ })
+ );
+ }
+}
diff --git a/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts b/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts
index e160b329ed..287e50398c 100644
--- a/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts
+++ b/packages/ui-plugin-sheets/src/controller/sheet-ui.controller.ts
@@ -1,8 +1,4 @@
import {
- ExpandSelectionCommand,
- MoveSelectionCommand,
- MoveSelectionEnterAndTabCommand,
- SelectAllCommand,
SetBoldCommand,
SetFontFamilyCommand,
SetFontSizeCommand,
@@ -30,6 +26,12 @@ import {
SetInfiniteFormatPainterCommand,
SetOnceFormatPainterCommand,
} from '../commands/commands/set-format-painter.command';
+import {
+ ExpandSelectionCommand,
+ MoveSelectionCommand,
+ MoveSelectionEnterAndTabCommand,
+ SelectAllCommand,
+} from '../commands/commands/set-selection.command';
import { ShowMenuListCommand } from '../commands/commands/unhide.command';
import { SetActivateCellEditOperation } from '../commands/operations/activate-cell-edit.operation';
import {
diff --git a/packages/ui-plugin-sheets/src/controller/shortcuts/selection.shortcut.ts b/packages/ui-plugin-sheets/src/controller/shortcuts/selection.shortcut.ts
index e91eda014f..0fd2703cb5 100644
--- a/packages/ui-plugin-sheets/src/controller/shortcuts/selection.shortcut.ts
+++ b/packages/ui-plugin-sheets/src/controller/shortcuts/selection.shortcut.ts
@@ -1,3 +1,6 @@
+import { IShortcutItem, KeyCode, MetaKeys } from '@univerjs/base-ui';
+import { Direction } from '@univerjs/core';
+
import {
ExpandSelectionCommand,
IExpandSelectionCommandParams,
@@ -8,10 +11,7 @@ import {
MoveSelectionCommand,
MoveSelectionEnterAndTabCommand,
SelectAllCommand,
-} from '@univerjs/base-sheets';
-import { IShortcutItem, KeyCode, MetaKeys } from '@univerjs/base-ui';
-import { Direction } from '@univerjs/core';
-
+} from '../../commands/commands/set-selection.command';
import { whenEditorNotActivated } from './utils';
export const MoveSelectionDownShortcutItem: IShortcutItem<IMoveSelectionCommandParams> = {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 6de8bcb0eb..20f5be9ef8 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -146,7 +146,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
examples/univer-sheet-ts:
dependencies:
@@ -301,7 +301,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/base-docs:
dependencies:
@@ -344,7 +344,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/base-formula-engine:
dependencies:
@@ -372,7 +372,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/base-numfmt-engine:
dependencies:
@@ -397,7 +397,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/base-render:
dependencies:
@@ -428,7 +428,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/base-sheets:
dependencies:
@@ -438,9 +438,6 @@ importers:
'@univerjs/base-render':
specifier: workspace:*
version: link:../base-render
- '@univerjs/base-ui':
- specifier: workspace:*
- version: link:../base-ui
'@univerjs/core':
specifier: workspace:*
version: link:../core
@@ -502,7 +499,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/base-ui:
dependencies:
@@ -633,7 +630,7 @@ importers:
version: 0.19.5
vitest:
specifier: ^0.34.6
packages/core:
dependencies:
@@ -852,7 +849,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/sheets-plugin-formula:
dependencies:
@@ -910,7 +907,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/sheets-plugin-image:
dependencies:
@@ -968,7 +965,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/sheets-plugin-import-xlsx:
dependencies:
@@ -1014,7 +1011,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/sheets-plugin-numfmt:
dependencies:
@@ -1072,7 +1069,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/ui-plugin-docs:
dependencies:
@@ -1121,7 +1118,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages/ui-plugin-sheets:
dependencies:
@@ -1231,7 +1228,7 @@ importers:
version: 10.9.1(@types/[email protected])([email protected])
vitest:
specifier: ^0.34.6
packages: