mirror of
https://github.com/dream-num/univer.git
synced 2026-09-24 15:32:18 +08:00
feat(sheets-ui): introduce disableEdit configuration (#6489)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -112,6 +112,12 @@ export interface IUniverSheetsUIConfig {
|
||||
* @default false
|
||||
*/
|
||||
disableForceStringMark?: boolean;
|
||||
|
||||
/**
|
||||
* Whether to disable the edit.
|
||||
* @default false
|
||||
*/
|
||||
disableEdit?: boolean;
|
||||
}
|
||||
|
||||
export const defaultPluginConfig: IUniverSheetsUIConfig = {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 />
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user