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(sheet): move sheetbar service outside core (#261)

YuHong47ceb58d345c
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index d9ae956693..1c4cc9cfca 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -12,7 +12,6 @@ import { LifecycleService } from '../services/lifecycle/lifecycle.service';
import { LocaleService } from '../services/locale/locale.service';
import { DesktopLogService, ILogService } from '../services/log/log.service';
import { DesktopPermissionService, IPermissionService } from '../services/permission/permission.service';
-import { ISheetBarService, SheetBarService } from '../services/sheetbar/sheetbar.service';
import { ThemeService } from '../services/theme/theme.service';
import { IUndoRedoService, LocalUndoRedoService } from '../services/undoredo/undoredo.service';
import { Workbook } from '../Sheets/Domain/Workbook';
@@ -177,7 +176,6 @@ export class Univer {
[IPermissionService, { useClass: DesktopPermissionService }],
[IConfigService, { useClass: ConfigService }],
[IContextService, { useClass: ContextService }],
- [ISheetBarService, { useClass: SheetBarService }],
]);
}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index cfe74ba41c..4af92a35f5 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -24,7 +24,6 @@ export { LifecycleService } from './services/lifecycle/lifecycle.service';
export { LocaleService } from './services/locale/locale.service';
export { DesktopLogService, ILogService } from './services/log/log.service';
export { DesktopPermissionService, IPermissionService } from './services/permission/permission.service';
-export { ISheetBarService, SheetBarService } from './services/sheetbar/sheetbar.service';
export { ThemeService } from './services/theme/theme.service';
export {
type IUndoRedoCommandInfos,
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/input-edit.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/input-edit.tsx
index eb6ea5a908..31b06546e1 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/input-edit.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/input-edit.tsx
@@ -1,16 +1,19 @@
import { SetWorksheetNameCommand } from '@univerjs/base-sheets';
-import { AppContext } from '@univerjs/base-ui';
import { useObservable } from '@univerjs/base-ui/Components/hooks/observable.js';
-import { ICommandService, ICurrentUniverService, ISheetBarService } from '@univerjs/core';
-import { useContext, useState } from 'react';
+import { ICommandService, ICurrentUniverService } from '@univerjs/core';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import { useState } from 'react';
+
+import { ISheetBarService } from '../../services/sheetbar/sheetbar.service';
interface IBaseInputProps {
sheetId: string | undefined;
sheetName: string;
}
-export function InputEdit(props: IBaseInputProps) {
- const context = useContext(AppContext);
- const sheetbarService = context.injector.get(ISheetBarService);
+export const InputEdit: React.FC<IBaseInputProps> = (props) => {
+ const sheetbarService = useDependency(ISheetBarService);
+ const commandService = useDependency(ICommandService);
+ const currentUniverService = useDependency(ICurrentUniverService);
const renameId = useObservable(sheetbarService.renameId$, '');
const oldValue = props.sheetName;
const [val, setVal] = useState(props.sheetName || '');
@@ -23,8 +26,6 @@ export function InputEdit(props: IBaseInputProps) {
const submit = () => {
if (val !== oldValue) {
- const commandService = context.injector.get(ICommandService);
- const currentUniverService = context.injector.get(ICurrentUniverService);
const workbookId = currentUniverService.getCurrentUniverSheetInstance()?.getUnitId();
commandService.executeCommand(SetWorksheetNameCommand.id, {
worksheetId: props.sheetId,
@@ -65,4 +66,4 @@ export function InputEdit(props: IBaseInputProps) {
) : (
<span>{props.sheetName}</span>
);
-}
+};
diff --git a/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts b/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts
index de2b24595b..3f2bca49b4 100644
--- a/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts
+++ b/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts
@@ -1,6 +1,8 @@
-import { CommandType, ICommand, ISheetBarService } from '@univerjs/core';
+import { CommandType, ICommand } from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
+import { ISheetBarService } from '../../services/sheetbar/sheetbar.service';
+
interface IRenameCommandParams {
worksheetId: string;
}
diff --git a/packages/core/src/services/sheetbar/sheetbar.service.ts b/packages/ui-plugin-sheets/src/services/sheetbar/sheetbar.service.ts
similarity index 92%
rename from packages/core/src/services/sheetbar/sheetbar.service.ts
rename to packages/ui-plugin-sheets/src/services/sheetbar/sheetbar.service.ts
index 29ffe7525c..e20758598e 100644
--- a/packages/core/src/services/sheetbar/sheetbar.service.ts
+++ b/packages/ui-plugin-sheets/src/services/sheetbar/sheetbar.service.ts
@@ -1,8 +1,7 @@
+import { Disposable } from '@univerjs/core/Shared/lifecycle.js';
import { createIdentifier } from '@wendellhu/redi';
import { BehaviorSubject, Observable } from 'rxjs';
-import { Disposable } from '../../Shared/lifecycle';
-
export interface ISheetBarService {
renameId$: Observable<string>;
setRenameId(id: string): void;
diff --git a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
index 770435e6e0..6ea409a14f 100644
--- a/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
+++ b/packages/ui-plugin-sheets/src/sheet-ui-plugin.ts
@@ -10,6 +10,7 @@ import { en } from './Locale';
import { ICellEditorService } from './services/cell-editor/cell-editor.service';
import { DesktopCellEditorService } from './services/cell-editor/cell-editor-desktop.service';
import { ISheetClipboardService, SheetClipboardService } from './services/clipboard/clipboard.service';
+import { ISheetBarService, SheetBarService } from './services/sheetbar/sheetbar.service';
export class SheetUIPlugin extends Plugin {
static override type = PluginType.Sheet;
@@ -35,6 +36,7 @@ export class SheetUIPlugin extends Plugin {
// services
[ICellEditorService, { useClass: DesktopCellEditorService }],
[ISheetClipboardService, { useClass: SheetClipboardService }],
+ [ISheetBarService, { useClass: SheetBarService }],
// controllers
[SheetClipboardController],