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!: clean up permission constants and improve component registration logic (#5583)

白熱4300df0a6e43
diff --git a/packages/sheets-ui/src/consts/permission.ts b/packages/sheets-ui/src/consts/permission.ts
index c9dd23630a..c4b2c5017d 100644
--- a/packages/sheets-ui/src/consts/permission.ts
+++ b/packages/sheets-ui/src/consts/permission.ts
@@ -19,7 +19,6 @@ import { UnitAction } from '@univerjs/protocol';
export const UNIVER_SHEET_PERMISSION_PLUGIN_NAME = 'UNIVER_SHEET_PERMISSION_PLUGIN';
export const UNIVER_SHEET_PERMISSION_PANEL = 'UNIVER_SHEET_PERMISSION_PANEL';
export const UNIVER_SHEET_PERMISSION_USER_PART = 'UNIVER_SHEET_PERMISSION_USER_PART';
-export const UNIVER_SHEET_PERMISSION_BACKGROUND = 'UNIVER_SHEET_PERMISSION_BACKGROUND';
export const UNIVER_SHEET_PERMISSION_PANEL_FOOTER = 'UNIVER_SHEET_PERMISSION_PANEL_FOOTER';
export const UNIVER_SHEET_PERMISSION_USER_DIALOG = 'UNIVER_SHEET_PERMISSION_USER_DIALOG';
export const UNIVER_SHEET_PERMISSION_DIALOG = 'UNIVER_SHEET_PERMISSION_DIALOG';
diff --git a/packages/sheets-ui/src/controllers/config.schema.ts b/packages/sheets-ui/src/controllers/config.schema.ts
index 947aeaee54..37fdad0cf3 100644
--- a/packages/sheets-ui/src/controllers/config.schema.ts
+++ b/packages/sheets-ui/src/controllers/config.schema.ts
@@ -27,7 +27,7 @@ export interface IUniverSheetsUIConfig {
menu?: MenuConfig;
disableAutoFocus?: true;
override?: DependencyOverride;
- customComponents?: Set<string>;
+
/**
* The maximum count of rows triggering auto height. This is used to avoid performance issue.
* @default 1000
@@ -95,7 +95,7 @@ export interface IUniverSheetsUIConfig {
/**
* The framework of the component. Must be passed correctly.
*/
- framework: 'react' | 'vue3';
+ framework: string;
};
/**
@@ -113,5 +113,6 @@ export interface IUniverSheetsUIConfig {
export const defaultPluginConfig: IUniverSheetsUIConfig = {
formulaBar: true,
statusBarStatistic: true,
+ protectedRangeShadow: true,
maxAutoHeightCount: 1000,
};
diff --git a/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts b/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts
index 3538f1bcac..888d263838 100644
--- a/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts
+++ b/packages/sheets-ui/src/controllers/permission/sheet-permission-render.controller.ts
@@ -17,20 +17,29 @@
import type { IRenderContext, IRenderModule, Spreadsheet } from '@univerjs/engine-render';
import type { MenuConfig } from '@univerjs/ui';
import type { IUniverSheetsUIConfig } from '../config.schema';
-import { Disposable, IConfigService, Inject, Injector, IPermissionService, IUniverInstanceService } from '@univerjs/core';
+import { Disposable, IConfigService, Inject, Injector, IPermissionService } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { CheckMarkIcon, DeleteIcon, LockIcon, ProtectIcon, WriteIcon } from '@univerjs/icons';
import { RangeProtectionRuleModel, WorksheetProtectionRuleModel } from '@univerjs/sheets';
-import { ComponentManager, connectInjector, IUIPartsService } from '@univerjs/ui';
+import { ComponentManager } from '@univerjs/ui';
import { merge, throttleTime } from 'rxjs';
-import { permissionCheckIconKey, permissionDeleteIconKey, permissionEditIconKey, permissionLockIconKey, permissionMenuIconKey, UNIVER_SHEET_PERMISSION_BACKGROUND, UNIVER_SHEET_PERMISSION_DIALOG, UNIVER_SHEET_PERMISSION_PANEL, UNIVER_SHEET_PERMISSION_USER_DIALOG, UNIVER_SHEET_PERMISSION_USER_PART } from '../../consts/permission';
+import {
+ permissionCheckIconKey,
+ permissionDeleteIconKey,
+ permissionEditIconKey,
+ permissionLockIconKey,
+ permissionMenuIconKey,
+ UNIVER_SHEET_PERMISSION_DIALOG,
+ UNIVER_SHEET_PERMISSION_PANEL,
+ UNIVER_SHEET_PERMISSION_USER_DIALOG,
+ UNIVER_SHEET_PERMISSION_USER_PART,
+} from '../../consts/permission';
import { SheetSkeletonManagerService } from '../../services/sheet-skeleton-manager.service';
import { SheetPermissionDialog, SheetPermissionPanel, SheetPermissionUserDialog } from '../../views/permission';
import { AlertDialog } from '../../views/permission/error-msg-dialog';
import { UNIVER_SHEET_PERMISSION_ALERT_DIALOG } from '../../views/permission/error-msg-dialog/interface';
import { RANGE_PROTECTION_CAN_NOT_VIEW_RENDER_EXTENSION_KEY, RANGE_PROTECTION_CAN_VIEW_RENDER_EXTENSION_KEY, RangeProtectionCanNotViewRenderExtension, RangeProtectionCanViewRenderExtension } from '../../views/permission/extensions/range-protection.render';
import { worksheetProtectionKey, WorksheetProtectionRenderExtension } from '../../views/permission/extensions/worksheet-permission.render';
-import { PermissionDetailUserPart } from '../../views/permission/panel-detail/PermissionDetailUserPart';
import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../config.schema';
export interface IUniverSheetsPermissionMenuConfig {
@@ -40,8 +49,7 @@ export interface IUniverSheetsPermissionMenuConfig {
export class SheetPermissionRenderManagerController extends Disposable {
constructor(
@Inject(Injector) private _injector: Injector,
- @Inject(ComponentManager) private _componentManager: ComponentManager,
- @Inject(IUIPartsService) private _uiPartsService: IUIPartsService
+ @Inject(ComponentManager) private _componentManager: ComponentManager
) {
super();
this._init();
@@ -74,8 +82,14 @@ export class SheetPermissionRenderManagerController extends Disposable {
private _initUiPartComponents(): void {
const configService = this._injector.get(IConfigService);
const config = configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);
- if (!config?.customComponents?.has(UNIVER_SHEET_PERMISSION_USER_PART)) {
- this.disposeWithMe(this._uiPartsService.registerComponent(UNIVER_SHEET_PERMISSION_USER_PART, () => connectInjector(PermissionDetailUserPart, this._injector)));
+
+ if (config?.protectedRangeUserSelector) {
+ const { component, framework } = config.protectedRangeUserSelector;
+ this.disposeWithMe(
+ this._componentManager.register(UNIVER_SHEET_PERMISSION_USER_PART, component, {
+ framework,
+ })
+ );
}
}
}
@@ -95,7 +109,7 @@ export class SheetPermissionRenderController extends Disposable implements IRend
const config = this._configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);
this._initSkeleton();
- if (config?.customComponents?.has(UNIVER_SHEET_PERMISSION_BACKGROUND)) {
+ if (config?.protectedRangeShadow === false) {
return;
}
this._initRender();
@@ -141,7 +155,6 @@ export class WorksheetProtectionRenderController extends Disposable implements I
constructor(
private readonly _context: IRenderContext,
@Inject(IRenderManagerService) private _renderManagerService: IRenderManagerService,
- @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService,
@Inject(SheetSkeletonManagerService) private _sheetSkeletonManagerService: SheetSkeletonManagerService,
@Inject(WorksheetProtectionRuleModel) private _worksheetProtectionRuleModel: WorksheetProtectionRuleModel,
@Inject(IConfigService) private _configService: IConfigService
@@ -150,7 +163,7 @@ export class WorksheetProtectionRenderController extends Disposable implements I
const config = this._configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);
this._initSkeleton();
- if (config?.customComponents?.has(UNIVER_SHEET_PERMISSION_BACKGROUND)) {
+ if (config?.protectedRangeShadow === false) {
return;
}
diff --git a/packages/sheets-ui/src/index.ts b/packages/sheets-ui/src/index.ts
index ef4161fe80..b437816878 100644
--- a/packages/sheets-ui/src/index.ts
+++ b/packages/sheets-ui/src/index.ts
@@ -89,7 +89,7 @@ export { SidebarDefinedNameOperation } from './commands/operations/sidebar-defin
export { EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY, RANGE_SELECTOR_COMPONENT_KEY, SHEET_VIEW_KEY } from './common/keys';
export { getCellRealRange } from './common/utils';
export { useActiveWorkbook, useActiveWorksheet, useWorkbooks } from './components/hook';
-export { UNIVER_SHEET_PERMISSION_BACKGROUND, UNIVER_SHEET_PERMISSION_USER_PART } from './consts/permission';
+export { UNIVER_SHEET_PERMISSION_USER_PART } from './consts/permission';
export { SHEET_UI_PLUGIN_NAME } from './consts/plugin-name';
export { SheetsUIPart } from './consts/ui-name';
export { AutoFillController } from './controllers/auto-fill.controller';
diff --git a/packages/sheets-ui/src/mobile-plugin.ts b/packages/sheets-ui/src/mobile-plugin.ts
index a721287497..375e922535 100644
--- a/packages/sheets-ui/src/mobile-plugin.ts
+++ b/packages/sheets-ui/src/mobile-plugin.ts
@@ -22,7 +22,7 @@ import { IRenderManagerService } from '@univerjs/engine-render';
import { IRefSelectionsService, RefSelectionsService, UniverSheetsPlugin } from '@univerjs/sheets';
import { ComponentManager, UI_PLUGIN_CONFIG_KEY, UniverMobileUIPlugin } from '@univerjs/ui';
import { filter } from 'rxjs/operators';
-import { UNIVER_SHEET_PERMISSION_BACKGROUND, UNIVER_SHEET_PERMISSION_USER_PART } from './consts/permission';
+import { 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';
@@ -76,10 +76,7 @@ import { DragManagerService } from './services/drag-manager.service';
import { EditorBridgeService, IEditorBridgeService } from './services/editor-bridge.service';
import { CellEditorManagerService, ICellEditorManagerService } from './services/editor/cell-editor-manager.service';
import { SheetCellEditorResizeService } from './services/editor/cell-editor-resize.service';
-import {
- FormulaEditorManagerService,
- IFormulaEditorManagerService,
-} from './services/editor/formula-editor-manager.service';
+import { FormulaEditorManagerService, IFormulaEditorManagerService } from './services/editor/formula-editor-manager.service';
import { FormatPainterService, IFormatPainterService } from './services/format-painter/format-painter.service';
import { HoverManagerService } from './services/hover-manager.service';
import { IMarkSelectionService, MarkSelectionService } from './services/mark-selection/mark-selection.service';
@@ -119,20 +116,15 @@ export class UniverSheetsMobileUIPlugin 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);
+ const { component, framework } = rest.protectedRangeUserSelector;
this.disposeWithMe(
this._componentManager.register(
UNIVER_SHEET_PERMISSION_USER_PART,
- rest.protectedRangeUserSelector.component,
+ component,
{
- framework: rest.protectedRangeUserSelector.framework,
+ framework,
}
)
);
@@ -142,7 +134,7 @@ export class UniverSheetsMobileUIPlugin extends Plugin {
this._configService.setConfig('menu', menu, { merge: true });
}
- this._configService.setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, { ...rest, customComponents });
+ this._configService.setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, { ...rest });
}
override onStarting(): void {
diff --git a/packages/sheets-ui/src/plugin.ts b/packages/sheets-ui/src/plugin.ts
index d00d12e1bf..d92dd3991f 100644
--- a/packages/sheets-ui/src/plugin.ts
+++ b/packages/sheets-ui/src/plugin.ts
@@ -22,7 +22,7 @@ import { IRenderManagerService } from '@univerjs/engine-render';
import { IRefSelectionsService, RefSelectionsService, UniverSheetsPlugin } from '@univerjs/sheets';
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 { 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';
@@ -118,20 +118,15 @@ 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);
+ const { component, framework } = rest.protectedRangeUserSelector;
this.disposeWithMe(
this._componentManager.register(
UNIVER_SHEET_PERMISSION_USER_PART,
- rest.protectedRangeUserSelector.component,
+ component,
{
- framework: rest.protectedRangeUserSelector.framework,
+ framework,
}
)
);
@@ -141,7 +136,7 @@ export class UniverSheetsUIPlugin extends Plugin {
this._configService.setConfig('menu', menu, { merge: true });
}
- this._configService.setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, { ...rest, customComponents });
+ this._configService.setConfig(SHEETS_UI_PLUGIN_CONFIG_KEY, { ...rest });
}
override onStarting(): void {
diff --git a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailPanel.tsx b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailPanel.tsx
index a7ab24cda2..435840e78a 100644
--- a/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailPanel.tsx
+++ b/packages/sheets-ui/src/views/permission/panel-detail/PermissionDetailPanel.tsx
@@ -18,7 +18,7 @@ import type { IRange, Workbook } from '@univerjs/core';
import type { IPermissionPanelRule } from '../../../services/permission/sheet-permission-panel.model';
import { Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { EditStateEnum, ViewStateEnum } from '@univerjs/sheets';
-import { ComponentContainer, ISidebarService, useComponentsOfPart, useDependency } from '@univerjs/ui';
+import { ComponentManager, ISidebarService, useDependency } from '@univerjs/ui';
import { useEffect, useState } from 'react';
import { UNIVER_SHEET_PERMISSION_USER_PART } from '../../../consts/permission';
import { checkRangeValid, generateDefaultRule, generateRuleByUnitType } from '../util';
@@ -34,6 +34,7 @@ interface ISheetPermissionPanelDetailProps {
export const SheetPermissionPanelDetail = (props: ISheetPermissionPanelDetailProps) => {
const { fromSheetBar, rule, oldRule } = props;
const injector = useDependency(Injector);
+ const componentManager = useDependency(ComponentManager);
const activeRule: IPermissionPanelRule = rule ? generateRuleByUnitType(injector, rule) : generateDefaultRule(injector, fromSheetBar);
const [ranges, setRanges] = useState<IRange[]>(activeRule.ranges);
@@ -43,12 +44,12 @@ export const SheetPermissionPanelDetail = (props: ISheetPermissionPanelDetailPro
const [desc, setDesc] = useState<string | undefined>(activeRule.description);
const [editState, setEditState] = useState<EditStateEnum>(activeRule.editState ?? EditStateEnum.OnlyMe);
const [viewState, setViewState] = useState<ViewStateEnum>(activeRule.viewState ?? ViewStateEnum.OthersCanView);
- const PermissionDetailUserPart = useComponentsOfPart(UNIVER_SHEET_PERMISSION_USER_PART);
+ const PermissionDetailUserPart = componentManager.get(UNIVER_SHEET_PERMISSION_USER_PART);
useEffect(() => {
const univerInstanceService = injector.get(IUniverInstanceService);
const sidebarService = injector.get(ISidebarService);
- const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
+ const workbook = univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) return;
const subUnitId = workbook.getActiveSheet().getSheetId();
const activeSheetSubscribe = workbook.activeSheet$.subscribe((sheet) => {
@@ -76,10 +77,9 @@ export const SheetPermissionPanelDetail = (props: ISheetPermissionPanelDetailPro
desc={desc}
onDescChange={(v) => setDesc(v)}
/>
- <ComponentContainer
+ <PermissionDetailUserPart
key="user-part"
- components={PermissionDetailUserPart}
- sharedProps={{
+ {...{
editState,
onEditStateChange: (v: EditStateEnum) => setEditState(v),
viewState,