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
feat(sheets-ui): add `formulaBar` option (#3632)
白熱d0a9f2423478
diff --git a/packages-experimental/uni-sheets-ui/src/controllers/uni-sheets-ui.controller.tsx b/packages-experimental/uni-sheets-ui/src/controllers/uni-sheets-ui.controller.tsxindex 263435d71a..8c380a137e 100644--- a/packages-experimental/uni-sheets-ui/src/controllers/uni-sheets-ui.controller.tsx+++ b/packages-experimental/uni-sheets-ui/src/controllers/uni-sheets-ui.controller.tsx@@ -15,13 +15,13 @@*/import type { Workbook } from '@univerjs/core';-import { connectInjector, ICommandService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType, useDependency } from '@univerjs/core';+import { connectInjector, ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType, useDependency } from '@univerjs/core';+import { SetBackgroundColorCommand } from '@univerjs/sheets';+import { IMAGE_MENU_ID as SheetsImageMenuId } from '@univerjs/sheets-drawing-ui';import { RenderSheetContent, SetRangeBoldCommand, SetRangeFontFamilyCommand, SetRangeFontSizeCommand, SetRangeItalicCommand, SetRangeStrickThroughCommand, SetRangeTextColorCommand, SetRangeUnderlineCommand, SheetUIController } from '@univerjs/sheets-ui';import { BuiltInUIPart, ComponentManager, ILayoutService, IMenuManagerService, IShortcutService, IUIPartsService, useObservable } from '@univerjs/ui';import { BuiltinUniToolbarItemId, generateCloneMutation, UniToolbarService, UniUIPart } from '@univerjs/uniui';import React from 'react';-import { SetBackgroundColorCommand } from '@univerjs/sheets';-import { IMAGE_MENU_ID as SheetsImageMenuId } from '@univerjs/sheets-drawing-ui';import { UniSheetBar } from '../views/uni-sheet-bar/UniSheetBar';import { SHEET_BOLD_MUTATION_ID, SHEET_ITALIC_MUTATION_ID, SHEET_STRIKE_MUTATION_ID, SHEET_UNDERLINE_MUTATION_ID } from './menu';import { menuSchema } from './menu.schema';@@ -36,6 +36,7 @@ export class UniSheetsUIController extends SheetUIController {@IShortcutService shortcutService: IShortcutService,@IMenuManagerService menuManagerService: IMenuManagerService,@IUIPartsService uiPartsService: IUIPartsService,+ @IConfigService configService: IConfigService,@Inject(UniToolbarService) private readonly _toolbarService: UniToolbarService) {super(@@ -45,7 +46,8 @@ export class UniSheetsUIController extends SheetUIController {commandService,shortcutService,menuManagerService,- uiPartsService+ uiPartsService,+ configService);this._initUniMenus();this._initMutations();diff --git a/packages/sheets-ui/src/controllers/config.schema.ts b/packages/sheets-ui/src/controllers/config.schema.tsindex 5acb5c94aa..2ab5a50b3e 100644--- a/packages/sheets-ui/src/controllers/config.schema.ts+++ b/packages/sheets-ui/src/controllers/config.schema.ts@@ -25,6 +25,13 @@ export interface IUniverSheetsUIConfig {menu?: MenuConfig;disableAutoFocus?: true;override?: DependencyOverride;++ /**+ * Whether to show the formula bar.+ */+ formulaBar?: boolean;}-export const defaultPluginConfig: IUniverSheetsUIConfig = {};+export const defaultPluginConfig: IUniverSheetsUIConfig = {+ formulaBar: true,+};diff --git a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts b/packages/sheets-ui/src/controllers/sheet-ui.controller.tsindex 5246a1d705..6a11be131d 100644--- a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts+++ b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts@@ -14,10 +14,11 @@* limitations under the License.*/-import { connectInjector, Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';+import type { IUniverSheetsUIConfig } from './config.schema';+import { connectInjector, Disposable, ICommandService, IConfigService, Inject, Injector, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';import { DocSelectionRenderService } from '@univerjs/docs-ui';-import { IRenderManagerService } from '@univerjs/engine-render';+import { IRenderManagerService } from '@univerjs/engine-render';import {SetBoldCommand,SetFontFamilyCommand,@@ -92,18 +93,19 @@ import { SidebarDefinedNameOperation } from '../commands/operations/sidebar-defiimport { BorderPanel } from '../components/border-panel/BorderPanel';import { BORDER_PANEL_COMPONENT } from '../components/border-panel/interface';import { COLOR_PICKER_COMPONENT, ColorPicker } from '../components/color-picker';+import {FONT_FAMILY_COMPONENT,FONT_FAMILY_ITEM_COMPONENT,FontFamily,FontFamilyItem,} from '../components/font-family';-import { FONT_SIZE_COMPONENT, FontSize } from '../components/font-size';import { MENU_ITEM_INPUT_COMPONENT, MenuItemInput } from '../components/menu-item-input';import { DEFINED_NAME_CONTAINER } from '../views/defined-name/component-name';import { DefinedNameContainer } from '../views/defined-name/DefinedNameContainer';import { RenderSheetContent, RenderSheetFooter, RenderSheetHeader } from '../views/sheet-container/SheetContainer';+import { PLUGIN_CONFIG_KEY } from './config.schema';import { menuSchema } from './menu.schema';import {EditorBreakLineShortcut,@@ -165,7 +167,8 @@ export class SheetUIController extends Disposable {@ICommandService protected readonly _commandService: ICommandService,@IShortcutService protected readonly _shortcutService: IShortcutService,@IMenuManagerService protected readonly _menuManagerService: IMenuManagerService,- @IUIPartsService protected readonly _uiPartsService: IUIPartsService+ @IUIPartsService protected readonly _uiPartsService: IUIPartsService,+ @IConfigService protected readonly _configService: IConfigService) {super();@@ -342,7 +345,10 @@ export class SheetUIController extends Disposable {const uiController = this._uiPartsService;const injector = this._injector;- this.disposeWithMe(uiController.registerComponent(BuiltInUIPart.HEADER, () => connectInjector(RenderSheetHeader, injector)));+ const config = this._configService.getConfig<IUniverSheetsUIConfig>(PLUGIN_CONFIG_KEY);+ if (config?.formulaBar !== false) {+ this.disposeWithMe(uiController.registerComponent(BuiltInUIPart.HEADER, () => connectInjector(RenderSheetHeader, injector)));+ }this.disposeWithMe(uiController.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(RenderSheetFooter, injector)));this.disposeWithMe(uiController.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(RenderSheetContent, injector)));}diff --git a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsxindex d7dfcf55e6..4ef1c21d4f 100644--- a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx+++ b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx@@ -14,22 +14,23 @@* limitations under the License.*/-import { IUniverInstanceService, UniverInstanceType, useDependency } from '@univerjs/core';import type { Workbook } from '@univerjs/core';-import React, { useMemo } from 'react';+import { IUniverInstanceService, UniverInstanceType, useDependency } from '@univerjs/core';import { ContextMenuPosition, IMenuManagerService, ToolbarItem, useObservable } from '@univerjs/ui';+import React, { useMemo } from 'react';+import { useActiveWorkbook } from '../../components/hook';import { CountBar } from '../count-bar/CountBar';import { EditorContainer } from '../editor-container/EditorContainer';import { FormulaBar } from '../formula-bar/FormulaBar';import { OperateContainer } from '../operate-container/OperateContainer';import { SheetBar } from '../sheet-bar/SheetBar';import { StatusBar } from '../status-bar/StatusBar';-import { useActiveWorkbook } from '../../components/hook';import styles from './index.module.less';export function RenderSheetFooter() {const menuManagerService = useDependency(IMenuManagerService);+const workbook = useActiveWorkbook();const footerMenus = menuManagerService.getMenuByPositionKey(ContextMenuPosition.FOOTER_MENU);diff --git a/packages/sheets/src/sheets-plugin.ts b/packages/sheets/src/sheets-plugin.tsindex 93f0277038..9a8f2f7854 100644--- a/packages/sheets/src/sheets-plugin.ts+++ b/packages/sheets/src/sheets-plugin.ts@@ -117,7 +117,7 @@ export class UniverSheetsPlugin extends Plugin {this._injector.get(IExclusiveRangeService);}- override onStarting(_injector?: Injector): void {+ override onStarting(): void {this._injector.get(MergeCellController);}}