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(ui): make config dynamic to support set by user through facade (#5044)
ZhangWei72ba8566b5e1
diff --git a/packages/docs-ui/src/controllers/doc-ui.controller.ts b/packages/docs-ui/src/controllers/doc-ui.controller.tsindex 6e479f47cb..e43102e8d0 100644--- a/packages/docs-ui/src/controllers/doc-ui.controller.ts+++ b/packages/docs-ui/src/controllers/doc-ui.controller.ts@@ -14,7 +14,6 @@* limitations under the License.*/-import type { IUniverDocsUIConfig } from './config.schema';import {Disposable,ICommandService,@@ -58,7 +57,6 @@ import {} from '../shortcuts/toolbar.shortcut';import { DocFooter } from '../views/doc-footer';import { DocSideMenu } from '../views/side-menu';-import { DOCS_UI_PLUGIN_CONFIG_KEY } from './config.schema';import { menuSchema } from './menu.schema';export class DocUIController extends Disposable {@@ -93,14 +91,8 @@ export class DocUIController extends Disposable {}private _initUiParts() {- const config = this._configService.getConfig<IUniverDocsUIConfig>(DOCS_UI_PLUGIN_CONFIG_KEY);- if (config?.layout?.docContainerConfig?.footer) {- this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(DocFooter, this._injector)));- }-- if (config?.layout?.docContainerConfig?.sideMenu ?? true) {- this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(DocSideMenu, this._injector)));- }+ this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(DocFooter, this._injector)));+ this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(DocSideMenu, this._injector)));}private _initMenus(): void {diff --git a/packages/docs-ui/src/views/doc-footer/DocFooter.tsx b/packages/docs-ui/src/views/doc-footer/DocFooter.tsxindex 34d18351bc..f72aa73aa8 100644--- a/packages/docs-ui/src/views/doc-footer/DocFooter.tsx+++ b/packages/docs-ui/src/views/doc-footer/DocFooter.tsx@@ -15,17 +15,21 @@*/import type { Workbook } from '@univerjs/core';+import type { IUniverDocsUIConfig } from '../../controllers/config.schema';import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';-import { useDependency, useObservable } from '@univerjs/ui';+import { useConfigValue, useDependency, useObservable } from '@univerjs/ui';+import { DOCS_UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';import { CountBar } from '../count-bar';export function DocFooter() {const univerInstanceService = useDependency(IUniverInstanceService);+ const config = useConfigValue<IUniverDocsUIConfig>(DOCS_UI_PLUGIN_CONFIG_KEY);const workbook = useObservable(() => univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET), undefined, undefined, []);+ const isShow = config?.layout?.docContainerConfig?.footer ?? true;return workbook? null- : (+ : isShow && (<div className="univer-box-border univer-flex univer-items-center univer-justify-between univer-px-5"><div /><CountBar />diff --git a/packages/docs-ui/src/views/side-menu/index.tsx b/packages/docs-ui/src/views/side-menu/index.tsxindex 514ec2b8a6..72bbc6ba60 100644--- a/packages/docs-ui/src/views/side-menu/index.tsx+++ b/packages/docs-ui/src/views/side-menu/index.tsx@@ -17,15 +17,17 @@import type { DocumentDataModel, IParagraph } from '@univerjs/core';import type { ISideMenuItem } from '@univerjs/design';import type { IRichTextEditingMutationParams } from '@univerjs/docs';+import type { IUniverDocsUIConfig } from '../../controllers/config.schema';import type { IMutiPageParagraphBound } from '../../services/doc-event-manager.service';import { debounce, fromEventSubject, getPlainText, ICommandService, isInternalEditorID, IUniverInstanceService, NamedStyleType, UniverInstanceType } from '@univerjs/core';import { SideMenu } from '@univerjs/design';import { RichTextEditingMutation } from '@univerjs/docs';import { IRenderManagerService } from '@univerjs/engine-render';-import { useDependency, useEvent, useObservable } from '@univerjs/ui';+import { useConfigValue, useDependency, useEvent, useObservable } from '@univerjs/ui';import { useEffect, useMemo, useState } from 'react';import { of, throttleTime } from 'rxjs';import { VIEWPORT_KEY } from '../../basics/docs-view-key';+import { DOCS_UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';import { DocEventManagerService } from '../../services/doc-event-manager.service';const transformNamedStyleTypeToLevel = (type: NamedStyleType) => {@@ -77,6 +79,16 @@ function findActiveHeading(boundMap: Map<number, IMutiPageParagraphBound> | undeconst TITLE_ID = '__title';export function DocSideMenu() {+ const config = useConfigValue<IUniverDocsUIConfig>(DOCS_UI_PLUGIN_CONFIG_KEY);++ if (config?.layout?.docContainerConfig?.sideMenu ?? true) {+ return <DocSideMenuContent />;+ }++ return null;+}++function DocSideMenuContent() {const commandService = useDependency(ICommandService);const instanceService = useDependency(IUniverInstanceService);const currentDoc = useObservable(useMemo(() => instanceService.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC), []));diff --git a/packages/sheets-data-validation-ui/src/services/dropdown-manager.service.ts b/packages/sheets-data-validation-ui/src/services/dropdown-manager.service.tsindex fd0bca825a..00882523ea 100644--- a/packages/sheets-data-validation-ui/src/services/dropdown-manager.service.ts+++ b/packages/sheets-data-validation-ui/src/services/dropdown-manager.service.ts@@ -18,7 +18,8 @@ import type { CellValue, IDisposable, Nullable, Workbook } from '@univerjs/core'import type { ISetRangeValuesCommandParams, ISheetLocation } from '@univerjs/sheets';import type { ListValidator } from '@univerjs/sheets-data-validation';import type { IDropdownParam, IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui';-import { CellValueType, DataValidationErrorStyle, DataValidationRenderMode, dayjs, Disposable, DisposableCollection, ICommandService, Inject, Injector, IUniverInstanceService, numfmt, UniverInstanceType } from '@univerjs/core';+import type { IUniverSheetsDataValidationUIConfig } from '../controllers/config.schema';+import { CellValueType, DataValidationErrorStyle, DataValidationRenderMode, dayjs, Disposable, DisposableCollection, ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, numfmt, UniverInstanceType } from '@univerjs/core';import { DataValidatorDropdownType, DataValidatorRegistryService } from '@univerjs/data-validation';import { DeviceInputEventType } from '@univerjs/engine-render';import { SetRangeValuesCommand, SheetsSelectionsService } from '@univerjs/sheets';@@ -28,6 +29,7 @@ import { IEditorBridgeService, ISheetCellDropdownManagerService, SetCellEditVisiimport { IZenZoneService, KeyCode } from '@univerjs/ui';import { Subject } from 'rxjs';import { OpenValidationPanelOperation } from '../commands/operations/data-validation.operation';+import { SHEETS_DATA_VALIDATION_UI_PLUGIN_CONFIG_KEY } from '../controllers/config.schema';import { DataValidationRejectInputController } from '../controllers/dv-reject-input.controller';export interface IDataValidationDropdownParam {@@ -98,7 +100,8 @@ export class DataValidationDropdownManagerService extends Disposable {@Inject(SheetDataValidationModel) private readonly _sheetDataValidationModel: SheetDataValidationModel,@ICommandService private readonly _commandService: ICommandService,@IEditorBridgeService private readonly _editorBridgeService: IEditorBridgeService,- @Inject(Injector) private readonly _injector: Injector+ @Inject(Injector) private readonly _injector: Injector,+ @IConfigService private readonly _configService: IConfigService) {super();this._init();@@ -149,7 +152,7 @@ export class DataValidationDropdownManagerService extends Disposable {}));}- // eslint-disable-next-line max-lines-per-function+ // eslint-disable-next-line max-lines-per-function, complexityshowDropdown(param: IDataValidationDropdownParam) {const { location } = param;const { row, col, unitId, subUnitId, workbook, worksheet } = location;@@ -355,6 +358,7 @@ export class DataValidationDropdownManagerService extends Disposable {onEdit: handleEdit,defaultValue: cellStr,multiple,+ showEdit: this._configService.getConfig<IUniverSheetsDataValidationUIConfig>(SHEETS_DATA_VALIDATION_UI_PLUGIN_CONFIG_KEY)?.showEditOnDropdown ?? true,},};break;diff --git a/packages/sheets-ui/src/controllers/config.schema.ts b/packages/sheets-ui/src/controllers/config.schema.tsindex d0cdb979e5..8884aab186 100644--- a/packages/sheets-ui/src/controllers/config.schema.ts+++ b/packages/sheets-ui/src/controllers/config.schema.ts@@ -38,6 +38,36 @@ export interface IUniverSheetsUIConfig {*/formulaBar?: boolean;+ /**+ * The config of the footer.+ * @default {}+ */+ footer?: false | {+ /**+ * Sheet bar is the manager of sub sheets, including add/switch/delete sub sheets.+ * @default true+ */+ sheetBar?: boolean;+ /**+ * statistic bar including statistic info current selections, such as count, sum, average, etc.+ * @default true+ */+ statisticBar?: boolean;+ /**+ * Including the menus in the footer. such as highlight, gridlines, etc.+ * @default true+ */+ menus?: boolean;+ /**+ * Zoom slider is the zoom slider in the footer.+ * @default true+ */+ zoomSlider?: boolean;+ };++ /**+ * @deprecated Use `footer.statisticBar` instead.+ */statusBarStatistic?: boolean;clipboardConfig?: {diff --git a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts b/packages/sheets-ui/src/controllers/sheet-ui.controller.tsindex b7a7208065..b20e15b80d 100644--- a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts+++ b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts@@ -14,7 +14,6 @@* limitations under the License.*/-import type { IUniverSheetsUIConfig } from './config.schema';import { Disposable, ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { DocSelectionRenderService } from '@univerjs/docs-ui';import { getCurrentTypeOfRenderer, IRenderManagerService } from '@univerjs/engine-render';@@ -108,7 +107,6 @@ import { MENU_ITEM_INPUT_COMPONENT, MenuItemInput } from '../components/menu-iteimport { 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 { SHEETS_UI_PLUGIN_CONFIG_KEY } from './config.schema';import { menuSchema } from './menu.schema';import {EditorBreakLineShortcut,@@ -356,10 +354,7 @@ export class SheetUIController extends Disposable {const uiController = this._uiPartsService;const injector = this._injector;- const config = this._configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);- if (config?.formulaBar !== false) {- this.disposeWithMe(uiController.registerComponent(BuiltInUIPart.HEADER, () => connectInjector(RenderSheetHeader, injector)));- }+ 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/dropdown/list-dropdown/index.tsx b/packages/sheets-ui/src/views/dropdown/list-dropdown/index.tsxindex a3c1edc3cc..248bb05838 100644--- a/packages/sheets-ui/src/views/dropdown/list-dropdown/index.tsx+++ b/packages/sheets-ui/src/views/dropdown/list-dropdown/index.tsx@@ -138,11 +138,12 @@ export interface IListDropdownProps {onChange?: (value: string[]) => boolean | Promise<boolean>;options: { label: string; value: string; color?: string }[];defaultValue?: string;+ showEdit?: boolean;}export function ListDropDown(props: { popup: IPopup<IListDropdownProps & IBaseDropdownProps> }) {const { popup: { extraProps } } = props;- const { location, hideFn, onChange, onEdit, options, defaultValue, multiple } = extraProps!;+ const { location, hideFn, onChange, onEdit, options, defaultValue, multiple, showEdit } = extraProps!;const { worksheet } = location;const [editingText, setEditingText] = useState('');const commandService = useDependency(ICommandService);@@ -192,6 +193,7 @@ export function ListDropDown(props: { popup: IPopup<IListDropdownProps & IBaseDronEdit={onEdit}filter={editingText}location={location}+ showEdit={showEdit}/>);}diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsxindex 678772679c..51173627ec 100644--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx@@ -18,7 +18,7 @@ import type { ICommandInfo } from '@univerjs/core';import type { IUniverUIConfig } from '@univerjs/ui';import type { IBaseSheetBarProps } from './SheetBarItem';import type { IScrollState } from './utils/slide-tab-bar';-import { ICommandService, IConfigService, IPermissionService, LocaleService, nameCharacterCheck, Quantity } from '@univerjs/core';+import { ICommandService, IPermissionService, LocaleService, nameCharacterCheck, Quantity } from '@univerjs/core';import { DropdownLegacy } from '@univerjs/design';import { LockSingle } from '@univerjs/icons';@@ -37,7 +37,7 @@ import {WorkbookRenameSheetPermission,WorksheetProtectionRuleModel,} from '@univerjs/sheets';-import { ContextMenuPosition, IConfirmService, UI_PLUGIN_CONFIG_KEY, UIMenu, useDependency, useObservable } from '@univerjs/ui';+import { ContextMenuPosition, IConfirmService, UI_PLUGIN_CONFIG_KEY, UIMenu, useConfigValue, useDependency, useObservable } from '@univerjs/ui';import React, { useCallback, useEffect, useRef, useState } from 'react';import { merge } from 'rxjs';import { useActiveWorkbook } from '../../../components/hook';@@ -60,7 +60,6 @@ export function SheetBarTabs() {const sheetBarService = useDependency(ISheetBarService);const localeService = useDependency(LocaleService);const confirmService = useDependency(IConfirmService);- const configService = useDependency(IConfigService);const editorBridgeService = useDependency(IEditorBridgeService, Quantity.OPTIONAL);const worksheetProtectionRuleModel = useDependency(WorksheetProtectionRuleModel);const rangeProtectionRuleModel = useDependency(RangeProtectionRuleModel);@@ -205,7 +204,7 @@ export function SheetBarTabs() {return { slideTabBar, disconnectResizeObserver };};- const config = configService.getConfig<IUniverUIConfig>(UI_PLUGIN_CONFIG_KEY);+ const config = useConfigValue<IUniverUIConfig>(UI_PLUGIN_CONFIG_KEY);const showContextMenu = config?.contextMenu ?? true;// TODO@Dushusir: the following callback functions should be wrapped by `useCallback`.diff --git a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsxindex e0ac89cf24..5586f3084d 100644--- a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx+++ b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx@@ -15,10 +15,12 @@*/import type { Workbook } from '@univerjs/core';+import type { IUniverSheetsUIConfig } from '../../controllers/config.schema';import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';-import { ContextMenuPosition, IMenuManagerService, ToolbarItem, useDependency, useObservable } from '@univerjs/ui';+import { ContextMenuPosition, IMenuManagerService, ToolbarItem, useConfigValue, useDependency, useObservable } from '@univerjs/ui';import { useMemo } from 'react';import { useActiveWorkbook } from '../../components/hook';+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';import { AutoFillPopupMenu } from '../auto-fill-popup-menu/AutoFillPopupMenu';import { CountBar } from '../count-bar/CountBar';import { EditorContainer } from '../editor-container/EditorContainer';@@ -29,12 +31,15 @@ import { StatusBar } from '../status-bar/StatusBar';export const SHEET_FOOTER_BAR_HEIGHT = 36;export function RenderSheetFooter() {+ const config = useConfigValue<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);const menuManagerService = useDependency(IMenuManagerService);-+ const showFooter = config?.footer ?? true;const workbook = useActiveWorkbook();- if (!workbook) return null;+ if (!workbook || !showFooter) return null;const footerMenus = menuManagerService.getMenuByPositionKey(ContextMenuPosition.FOOTER_MENU);+ const { sheetBar = true, statisticBar = true, menus = true, zoomSlider = true } = config?.footer || {};+ if (!sheetBar && !statisticBar && !menus && !zoomSlider) return null;return (<section@@ -48,10 +53,9 @@ export function RenderSheetFooter() {}}data-range-selector>- <SheetBar />- <StatusBar />-- {footerMenus.length && (+ {sheetBar && <SheetBar />}+ {statisticBar && <StatusBar />}+ {menus && footerMenus.length && (<div className="univer-mr-2 univer-flex univer-gap-2">{footerMenus.map((item) => item.children?.map((child) => (child?.item && (@@ -63,19 +67,21 @@ export function RenderSheetFooter() {)))}</div>)}-- <CountBar />+ {zoomSlider && <CountBar />}</section>);}export function RenderSheetHeader() {+ const config = useConfigValue<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);const hasWorkbook = useHasWorkbook();if (!hasWorkbook) return null;- return (- <FormulaBar />- );+ if (config?.formulaBar !== false) {+ return <FormulaBar />;+ }++ return null;}/**diff --git a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx b/packages/sheets-ui/src/views/status-bar/StatusBar.tsxindex 5e8781a650..2409989c01 100644--- a/packages/sheets-ui/src/views/status-bar/StatusBar.tsx+++ b/packages/sheets-ui/src/views/status-bar/StatusBar.tsx@@ -18,9 +18,9 @@ import type { Nullable } from '@univerjs/core';import type { IUniverSheetsUIConfig } from '../../controllers/config.schema';import type { IStatusBarServiceStatus, StatusBarService } from '../../services/status-bar.service';import type { IStatisticItem } from './CopyableStatisticItem';-import { debounce, IConfigService } from '@univerjs/core';+import { debounce } from '@univerjs/core';import { clsx } from '@univerjs/design';-import { useDependency } from '@univerjs/ui';+import { useConfigValue, useDependency } from '@univerjs/ui';import React, { useCallback, useEffect, useMemo, useState } from 'react';import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';import { IStatusBarService } from '../../services/status-bar.service';@@ -31,8 +31,7 @@ const SINGLE_MODE_WIDTH = 800;const ROW_COUNT_THRESHOLD = 3;export const StatusBar = () => {- const configService = useDependency(IConfigService);- const showStatistic = configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY)?.statusBarStatistic ?? true;+ const showStatistic = useConfigValue<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY)?.statusBarStatistic ?? true;const [isSingle, setIsSingle] = useState(window.innerWidth < SINGLE_MODE_WIDTH);diff --git a/packages/ui/src/components/hooks/index.ts b/packages/ui/src/components/hooks/index.tsindex be6b8b3e48..05bf1183e8 100644--- a/packages/ui/src/components/hooks/index.ts+++ b/packages/ui/src/components/hooks/index.ts@@ -15,6 +15,7 @@*/export { useEvent } from './event';+export { useConfigValue } from './layout';export { useUpdateEffect } from './update-effect';export { useClickOutSide } from './use-click-out-side';export { useVirtualList } from './virtual-list';diff --git a/packages/ui/src/components/hooks/layout.ts b/packages/ui/src/components/hooks/layout.tsindex 1e2a950099..ff3c8315f2 100644--- a/packages/ui/src/components/hooks/layout.ts+++ b/packages/ui/src/components/hooks/layout.ts@@ -15,8 +15,10 @@*/import type { Nullable } from '@univerjs/core';+import { IConfigService } from '@univerjs/core';import { isBrowser, resizeObserverCtor } from '@univerjs/design';-import { useEffect } from 'react';+import { useEffect, useMemo } from 'react';+import { useDependency, useObservable } from '../../utils/di';import { useEvent } from './event';/**@@ -70,3 +72,11 @@ export function useScrollYOverContainer(element: Nullable<HTMLElement>, containe};}, [element, container]);}++export function useConfigValue<T>(configKey: string) {+ const configService = useDependency(IConfigService);+ return useObservable(+ useMemo(() => configService.subscribeConfigValue$<T>(configKey), [configService]),+ configService.getConfig<T>(configKey)+ );+}diff --git a/packages/ui/src/views/workbench/Workbench.tsx b/packages/ui/src/views/workbench/Workbench.tsxindex 3c52aa8efb..fb0de8a5d5 100644--- a/packages/ui/src/views/workbench/Workbench.tsx+++ b/packages/ui/src/views/workbench/Workbench.tsx@@ -22,6 +22,7 @@ import { DocumentFlavor, IConfigService, IUniverInstanceService, LocaleService,import { clsx, ConfigContext, ConfigProvider, defaultTheme, themeInstance } from '@univerjs/design';import { useContext, useEffect, useMemo, useRef, useState } from 'react';import { createPortal } from 'react-dom';+import { useConfigValue } from '../../components/hooks';import { UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';import { BuiltInUIPart } from '../../services/parts/parts.service';import { useDependency } from '../../utils/di';@@ -39,6 +40,11 @@ export interface IUniverWorkbenchProps extends IWorkbenchOptions {}export function DesktopWorkbench(props: IUniverWorkbenchProps) {+ const uiConfig = useConfigValue<IUniverUIConfig>(UI_PLUGIN_CONFIG_KEY);+ return <DesktopWorkbenchContent {...props} {...uiConfig} />;+}++export function DesktopWorkbenchContent(props: IUniverWorkbenchProps) {const {header = true,toolbar = true,