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.

feat(sheets-ui): introduce `disableEdit` configuration (#6489)

WEI ZHANGaa95e9321ed6
diff --git a/packages/sheets-ui/src/commands/operations/cell-edit.operation.ts b/packages/sheets-ui/src/commands/operations/cell-edit.operation.ts
index 52557d40f3..644cf02e2a 100644
--- a/packages/sheets-ui/src/commands/operations/cell-edit.operation.ts
+++ b/packages/sheets-ui/src/commands/operations/cell-edit.operation.ts
@@ -15,9 +15,11 @@
*/
import type { IOperation, Workbook } from '@univerjs/core';
-import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
+import type { IUniverSheetsUIConfig } from '../../controllers/config.schema';
-import { CommandType, ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
+import { CommandType, ICommandService, IConfigService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
export const SetCellEditVisibleOperation: IOperation<IEditorBridgeServiceVisibleParam> = {
@@ -27,6 +29,13 @@ export const SetCellEditVisibleOperation: IOperation<IEditorBridgeServiceVisible
if (!params) {
return false;
}
+
+ const configService = accessor.get(IConfigService);
+ const disableEdit = configService.getConfig<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY)?.disableEdit;
+ if (disableEdit && params.visible) {
+ return false;
+ }
+
const { unitId } = params;
const univerInstanceService = accessor.get(IUniverInstanceService);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
diff --git a/packages/sheets-ui/src/controllers/config.schema.ts b/packages/sheets-ui/src/controllers/config.schema.ts
index 8bc9eed908..43e54e28fd 100644
--- a/packages/sheets-ui/src/controllers/config.schema.ts
+++ b/packages/sheets-ui/src/controllers/config.schema.ts
@@ -112,6 +112,12 @@ export interface IUniverSheetsUIConfig {
* @default false
*/
disableForceStringMark?: boolean;
+
+ /**
+ * Whether to disable the edit.
+ * @default false
+ */
+ disableEdit?: boolean;
}
export const defaultPluginConfig: IUniverSheetsUIConfig = {
diff --git a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
index e59b65a7fd..cf4fcc565a 100644
--- a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
+++ b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
@@ -15,6 +15,7 @@
*/
import type { Workbook } from '@univerjs/core';
+import type { IUniverSheetsUIConfig } from '../../controllers/config.schema';
import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
import {
DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
@@ -38,12 +39,13 @@ import {
WorksheetProtectionRuleModel,
WorksheetViewPermission,
} from '@univerjs/sheets';
-import { ComponentContainer, ComponentManager, KeyCode, useComponentsOfPart, useDependency, useObservable } from '@univerjs/ui';
+import { ComponentContainer, ComponentManager, KeyCode, useComponentsOfPart, useConfigValue, useDependency, useObservable } from '@univerjs/ui';
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { EMPTY, merge, of, switchMap } from 'rxjs';
import { SetCellEditVisibleOperation } from '../../commands/operations/cell-edit.operation';
import { EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY } from '../../common/keys';
import { SheetsUIPart } from '../../consts/ui-name';
+import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
import { IFormulaEditorManagerService } from '../../services/editor/formula-editor-manager.service';
import { DefinedName } from '../defined-name/DefinedName';
@@ -89,6 +91,8 @@ export function FormulaBar(props: IProps) {
const isFocusFxBar = contextService.getContextValue(FOCUSING_FX_BAR_EDITOR);
const ref = useRef<HTMLDivElement>(null);
const editorService = useDependency(IEditorService);
+ const config = useConfigValue<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);
+ const disableEdit = config?.disableEdit;
useLayoutEffect(() => {
const subscription = workbook.activeSheet$.pipe(
@@ -227,7 +231,8 @@ export function FormulaBar(props: IProps) {
}
// TODO Is there a need to disable an editor here?
- const { viewDisable, editDisable } = disableInfo;
+ const { viewDisable, editDisable: permissionEditDisable } = disableInfo;
+ const editDisable = permissionEditDisable || !!disableEdit;
const disabled = editDisable || imageDisable;
const shouldSkipFocus = useRef(false);
diff --git a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx
index e95f627cc4..c544da6546 100644
--- a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx
+++ b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx
@@ -88,12 +88,13 @@ export function RenderSheetHeader() {
* @deprecated We should not write into this component anymore.
*/
export function RenderSheetContent() {
+ const config = useConfigValue<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);
const hasWorkbook = useHasWorkbook();
if (!hasWorkbook) return null;
return (
<>
- <EditorContainer />
+ {!config?.disableEdit && <EditorContainer />}
<AutoFillPopupMenu />
</>
);