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): optimize permission ui custom api (#5052)
ZhangWei5ac235214bd5
diff --git a/packages/sheets-ui/src/controllers/config.schema.ts b/packages/sheets-ui/src/controllers/config.schema.tsindex 8884aab186..acc1a91065 100644--- a/packages/sheets-ui/src/controllers/config.schema.ts+++ b/packages/sheets-ui/src/controllers/config.schema.ts@@ -16,7 +16,8 @@import type { DependencyOverride } from '@univerjs/core';import type { IScrollBarProps } from '@univerjs/engine-render';-import type { MenuConfig } from '@univerjs/ui';+import type { ComponentType, MenuConfig } from '@univerjs/ui';+import type { IPermissionDetailUserPartProps } from '../views/permission/panel-detail/PermissionDetailUserPart';export const SHEETS_UI_PLUGIN_CONFIG_KEY = 'sheets-ui.config';@@ -76,6 +77,26 @@ export interface IUniverSheetsUIConfig {scrollConfig?: IScrollBarProps;+ /**+ * Whether to show the protected range shadow.+ * @default true+ */+ protectedRangeShadow?: boolean;++ /**+ * The custom component of the protected range user selector.+ */+ protectedRangeUserSelector?: {+ /**+ * custom component, should implement the `IPermissionDetailUserPartProps` interface.+ */+ component: ComponentType<IPermissionDetailUserPartProps>;+ /**+ * The framework of the component. Must be passed correctly.+ */+ framework: 'react' | 'vue3';+ };+}export const defaultPluginConfig: IUniverSheetsUIConfig = {diff --git a/packages/sheets-ui/src/index.ts b/packages/sheets-ui/src/index.tsindex cd4520b383..a17133dd93 100644--- a/packages/sheets-ui/src/index.ts+++ b/packages/sheets-ui/src/index.ts@@ -97,7 +97,7 @@ export { SELECTION_SHAPE_DEPTH } from './services/selection/const';export { type IBaseSheetBarProps } from './views/sheet-bar/sheet-bar-tabs/SheetBarItem';export { type IDropdownParam, ISheetCellDropdownManagerService, SheetCellDropdownManagerService } from './services/cell-dropdown-manager.service';export { FormulaBar } from './views/formula-bar/FormulaBar';-+export { type IPermissionDetailUserPartProps } from './views/permission/panel-detail/PermissionDetailUserPart';// #region - all commandsexport { SetWorksheetColAutoWidthCommand } from './commands/commands/set-worksheet-auto-col-width.command';export { AutoClearContentCommand, AutoFillCommand } from './commands/commands/auto-fill.command';diff --git a/packages/sheets-ui/src/plugin.ts b/packages/sheets-ui/src/plugin.tsindex 6bfe5bdfd8..2030540427 100644--- a/packages/sheets-ui/src/plugin.ts+++ b/packages/sheets-ui/src/plugin.ts@@ -20,8 +20,9 @@ import type { IUniverSheetsUIConfig } from './controllers/config.schema';import { DependentOn, IConfigService, Inject, Injector, IUniverInstanceService, merge, mergeOverrideWithDependencies, Plugin, registerDependencies, touchDependencies, UniverInstanceType } from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';import { IRefSelectionsService, RefSelectionsService, UniverSheetsPlugin } from '@univerjs/sheets';-import { UI_PLUGIN_CONFIG_KEY } from '@univerjs/ui';+import { ComponentManager, UI_PLUGIN_CONFIG_KEY } from '@univerjs/ui';import { filter } from 'rxjs/operators';+import { UNIVER_SHEET_PERMISSION_BACKGROUND, UNIVER_SHEET_PERMISSION_USER_PART } from './consts/permission';import { ActiveWorksheetController } from './controllers/active-worksheet/active-worksheet.controller';import { AutoFillController } from './controllers/auto-fill.controller';import { AutoHeightController } from './controllers/auto-height.controller';@@ -103,7 +104,8 @@ export class UniverSheetsUIPlugin extends Plugin {@Inject(Injector) override readonly _injector: Injector,@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,@IConfigService private readonly _configService: IConfigService,- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,+ @Inject(ComponentManager) private readonly _componentManager: ComponentManager) {super();@@ -114,11 +116,27 @@ export class UniverSheetsUIPlugin extends Plugin {this._config);+ const { customComponents = new Set() } = rest;+ if (rest.protectedRangeShadow === false) {+ customComponents.add(UNIVER_SHEET_PERMISSION_BACKGROUND);+ }++ if (rest.protectedRangeUserSelector) {+ customComponents.add(UNIVER_SHEET_PERMISSION_USER_PART);+ this._componentManager.register(+ UNIVER_SHEET_PERMISSION_USER_PART,+ rest.protectedRangeUserSelector.component,+ {+ framework: rest.protectedRangeUserSelector.framework,+ }+ );+ }+if (menu) {this._configService.setConfig('menu', menu, { merge: true });}- this._configService.setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, rest);+ this._configService.setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, { ...rest, customComponents });}override onStarting(): void {diff --git a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailUserPart.tsx b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailUserPart.tsxindex 7b91c037c3..402a5b7609 100644--- a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailUserPart.tsx+++ b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailUserPart.tsx@@ -27,7 +27,7 @@ import { SheetPermissionUserManagerService } from '../../../services/permission/import { UserEmptyBase64 } from '../user-dialog/constant';import styles from './index.module.less';-interface IPermissionDetailUserPartProps {+export interface IPermissionDetailUserPartProps {editState: EditStateEnum;onEditStateChange: (v: EditStateEnum) => void;viewState: ViewStateEnum;diff --git a/packages/ui/src/common/component-manager.ts b/packages/ui/src/common/component-manager.tsindex f71bbe323a..25b42b84d2 100644--- a/packages/ui/src/common/component-manager.ts+++ b/packages/ui/src/common/component-manager.ts@@ -134,16 +134,16 @@ export interface IComponentOptions {framework?: ComponentFramework;}-export interface IVue3Component {+export interface IVue3Component<T extends Record<string, any> = Record<string, any>> {framework: 'vue3';- component: ReturnType<typeof defineComponent>;+ component: ReturnType<typeof defineComponent<T>>;}-export interface IReactComponent {+export interface IReactComponent<T extends Record<string, any> = Record<string, any>> {framework: 'react';- component: React.ForwardRefExoticComponent<any>;+ component: React.ForwardRefExoticComponent<T>;};-export type ComponentType = React.ForwardRefExoticComponent<any> | ReturnType<typeof defineComponent>;+export type ComponentType<T extends Record<string, any> = Record<string, any>> = React.ForwardRefExoticComponent<T> | ReturnType<typeof defineComponent>;export type ComponentList = Map<string, IVue3Component | IReactComponent>;