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(facade): add cell image facade & remove rich-text cell-image (#4729)

zhangwf0b2d4849c92
diff --git a/packages/docs-drawing-ui/src/views/menu/image.menu.ts b/packages/docs-drawing-ui/src/views/menu/image.menu.ts
index 4e95d5ea41..ed56860d28 100644
--- a/packages/docs-drawing-ui/src/views/menu/image.menu.ts
+++ b/packages/docs-drawing-ui/src/views/menu/image.menu.ts
@@ -15,10 +15,11 @@
*/
import type { IAccessor } from '@univerjs/core';
-import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { DocSelectionManagerService } from '@univerjs/docs';
+import type { IMenuItem } from '@univerjs/ui';
+import { DOCS_ZEN_EDITOR_UNIT_ID_KEY, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { getMenuHiddenObservable, type IMenuItem, MenuItemType } from '@univerjs/ui';
+import { DocSelectionManagerService } from '@univerjs/docs';
+import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { Observable } from 'rxjs';
import { InsertDocImageCommand } from '../../commands/commands/insert-image.command';
@@ -68,7 +69,7 @@ export function ImageMenuFactory(accessor: IAccessor): IMenuItem {
icon: ImageUploadIcon,
tooltip: 'docImage.title',
disabled$: getDisableWhenSelectionInTableObservable(accessor),
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC, undefined, DOCS_ZEN_EDITOR_UNIT_ID_KEY),
};
}
@@ -77,6 +78,6 @@ export function UploadFloatImageMenuFactory(_accessor: IAccessor): IMenuItem {
id: IMAGE_MENU_UPLOAD_FLOAT_ID,
title: 'docImage.upload.float',
type: MenuItemType.BUTTON,
- hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC),
+ hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_DOC, undefined, DOCS_ZEN_EDITOR_UNIT_ID_KEY),
};
}
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-cell-image.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-cell-image.controller.ts
index 8274f12031..7702f2ed2c 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-cell-image.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-cell-image.controller.ts
@@ -15,14 +15,17 @@
*/
import type { ICellData, IDocDrawingBase, IRange, Nullable } from '@univerjs/core';
+import type { IReplaceSnapshotCommandParams } from '@univerjs/docs-ui';
import type { IImageData } from '@univerjs/drawing';
import type { IAddWorksheetMergeMutationParams, IRemoveWorksheetMergeMutationParams, ISetWorksheetColWidthMutationParams, ISetWorksheetRowAutoHeightMutationParams, ISetWorksheetRowHeightMutationParams, ISetWorksheetRowIsAutoHeightMutationParams, ISheetLocationBase } from '@univerjs/sheets';
+import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui';
import { Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, ICommandService, Inject, Injector, InterceptorEffectEnum, IUniverInstanceService, Range } from '@univerjs/core';
import { DocDrawingController } from '@univerjs/docs-drawing';
-import { type IReplaceSnapshotCommandParams, ReplaceSnapshotCommand } from '@univerjs/docs-ui';
+import { ReplaceSnapshotCommand } from '@univerjs/docs-ui';
import { IDrawingManagerService } from '@univerjs/drawing';
+import { DeviceInputEventType } from '@univerjs/engine-render';
import { AddWorksheetMergeMutation, AFTER_CELL_EDIT, getSheetCommandTarget, InterceptCellContentPriority, INTERCEPTOR_POINT, RemoveWorksheetMergeMutation, SetWorksheetColWidthMutation, SetWorksheetRowAutoHeightMutation, SetWorksheetRowHeightMutation, SetWorksheetRowIsAutoHeightMutation, SheetInterceptorService } from '@univerjs/sheets';
-import { IEditorBridgeService } from '@univerjs/sheets-ui';
+import { IEditorBridgeService, SetCellEditVisibleOperation } from '@univerjs/sheets-ui';
import { getDrawingSizeByCell } from './sheet-drawing-update.controller';
export function resizeImageByCell(injector: Injector, location: ISheetLocationBase, cell: Nullable<ICellData>) {
@@ -76,6 +79,23 @@ export class SheetCellImageController extends Disposable {
this._handleInitEditor();
this._handleWriteCell();
this._initCellContentInterceptor();
+ this._initDisableEdit();
+ }
+
+ private _initDisableEdit() {
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((commandInfo) => {
+ if (commandInfo.id === SetCellEditVisibleOperation.id) {
+ const params = commandInfo.params as IEditorBridgeServiceVisibleParam;
+ const { visible, eventType } = params;
+ if (visible && eventType === DeviceInputEventType.Dblclick) {
+ const editState = this._editorBridgeService.getEditCellState();
+ const drawingCount = editState?.documentLayoutObject.documentModel?.getDrawingsOrder()?.length ?? 0;
+ if (drawingCount > 0) {
+ throw new Error('Can not edit when there are drawings.');
+ }
+ }
+ }
+ }));
}
private _initHandleResize() {
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
index c9faa89b0c..79b3b2be3b 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
@@ -21,7 +21,7 @@ import type { ISheetLocationBase, WorkbookSelectionModel } from '@univerjs/sheet
import type { ISheetDrawing, ISheetDrawingPosition } from '@univerjs/sheets-drawing';
import type { IInsertDrawingCommandParams, ISetDrawingCommandParams } from '../commands/commands/interfaces';
import type { ISetDrawingArrangeCommandParams } from '../commands/commands/set-drawing-arrange.command';
-import { BooleanNumber, BuildTextUtils, createDocumentModelWithStyle, Disposable, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, Inject, Injector, LocaleService, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, WrapTextType } from '@univerjs/core';
+import { BooleanNumber, BuildTextUtils, createDocumentModelWithStyle, Disposable, DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, generateRandomId, ICommandService, IContextService, ImageSourceType, Inject, Injector, LocaleService, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, WrapTextType } from '@univerjs/core';
import { MessageType } from '@univerjs/design';
import { docDrawingPositionToTransform } from '@univerjs/docs-ui';
import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_ALLOW_SIZE, DRAWING_IMAGE_COUNT_LIMIT, DRAWING_IMAGE_HEIGHT_LIMIT, DRAWING_IMAGE_WIDTH_LIMIT, getImageSize, IDrawingManagerService, IImageIoService, ImageUploadStatusType, SetDrawingSelectedOperation } from '@univerjs/drawing';
@@ -154,6 +154,10 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
return false;
}
+ insertCellImageByFile(file: File, location?: ISheetLocationBase) {
+ return this._insertCellImage(file, location);
+ }
+
async insertFloatImageByFile(file: File) {
let imageParam: Nullable<IImageIoServiceParam>;
@@ -222,7 +226,7 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
}
// eslint-disable-next-line max-lines-per-function
- private async _insertCellImage(file: File) {
+ private async _insertCellImage(file: File, location?: ISheetLocationBase) {
let imageParam: Nullable<IImageIoServiceParam>;
try {
imageParam = await this._imageIoService.saveImage(file);
@@ -247,7 +251,7 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
}
if (imageParam == null) {
- return;
+ return false;
}
const { imageId, imageSourceType, source, base64Cache } = imageParam;
@@ -319,17 +323,109 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
},
});
+ if (jsonXActions) {
+ docDataModel.apply(jsonXActions);
+
+ return this._commandService.syncExecuteCommand(SetRangeValuesCommand.id, {
+ value: {
+ [location?.row ?? selection.primary.actualRow]: {
+ [location?.col ?? selection.primary.actualColumn]: {
+ p: (docDataModel.getSnapshot()),
+ t: 1,
+ },
+ },
+ },
+ unitId: location?.unitId,
+ subUnitId: location?.subUnitId,
+ });
+ }
+
+ return false;
+ }
+
+ // eslint-disable-next-line max-lines-per-function
+ async insertCellImageByUrl(url: string, location?: ISheetLocationBase) {
+ const { width, height, image } = await getImageSize(url || '');
+ this._imageIoService.addImageSourceCache(url, ImageSourceType.URL, image);
+ const selection = this._workbookSelections.getCurrentLastSelection();
+ if (!selection) {
+ return false;
+ }
+ const docDataModel = createDocumentModelWithStyle('', {});
+
+ const imageSize = getDrawingSizeByCell(
+ this._injector,
+ {
+ unitId: this._context.unitId,
+ subUnitId: this._context.unit.getActiveSheet().getSheetId(),
+ row: selection.primary.actualRow,
+ col: selection.primary.actualColumn,
+ },
+ width,
+ height,
+ 0
+ );
+ if (!imageSize) {
+ return false;
+ }
+ const docTransform = {
+ size: {
+ width: imageSize.width,
+ height: imageSize.height,
+ },
+ positionH: {
+ relativeFrom: ObjectRelativeFromH.PAGE,
+ posOffset: 0,
+ },
+ positionV: {
+ relativeFrom: ObjectRelativeFromV.PARAGRAPH,
+ posOffset: 0,
+ },
+ angle: 0,
+ };
+ const docDrawingParam = {
+ unitId: docDataModel.getUnitId(),
+ subUnitId: docDataModel.getUnitId(),
+ drawingId: generateRandomId(),
+ drawingType: DrawingTypeEnum.DRAWING_IMAGE,
+ imageSourceType: ImageSourceType.URL,
+ source: url,
+ transform: docDrawingPositionToTransform(docTransform),
+ docTransform,
+ behindDoc: BooleanNumber.FALSE,
+ title: '',
+ description: '',
+ layoutType: PositionedObjectLayoutType.INLINE, // Insert inline drawing by default.
+ wrapText: WrapTextType.BOTH_SIDES,
+ distB: 0,
+ distL: 0,
+ distR: 0,
+ distT: 0,
+ };
+
+ const jsonXActions = BuildTextUtils.drawing.add({
+ documentDataModel: docDataModel,
+ drawings: [docDrawingParam],
+ selection: {
+ collapsed: true,
+ startOffset: 0,
+ endOffset: 0,
+ },
+ });
+
if (jsonXActions) {
docDataModel.apply(jsonXActions);
return this._commandService.syncExecuteCommand(SetRangeValuesCommand.id, {
value: {
- [selection.primary.actualRow]: {
- [selection.primary.actualColumn]: {
+ [location?.row ?? selection.primary.actualRow]: {
+ [location?.col ?? selection.primary.actualColumn]: {
p: (docDataModel.getSnapshot()),
t: 1,
},
},
},
+ unitId: location?.unitId,
+ subUnitId: location?.subUnitId,
});
}
diff --git a/packages/sheets-drawing-ui/src/facade/f-range.ts b/packages/sheets-drawing-ui/src/facade/f-range.ts
new file mode 100644
index 0000000000..f1673f2d81
--- /dev/null
+++ b/packages/sheets-drawing-ui/src/facade/f-range.ts
@@ -0,0 +1,68 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ISheetLocationBase } from '@univerjs/sheets';
+import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { getCurrentTypeOfRenderer, IRenderManagerService } from '@univerjs/engine-render';
+import { SheetDrawingUpdateController } from '@univerjs/sheets-drawing-ui';
+import { FRange } from '@univerjs/sheets/facade';
+
+export interface IFRangeSheetDrawingMixin {
+ /**
+ * Inserts an image into the current cell.
+ *
+ * @param {string | File} file File or URL string
+ * @returns True if the image is inserted successfully, otherwise false
+ * @example
+ * ```ts
+ * const fWorkbook = univerAPI.getActiveWorkbook();
+ * const fWorksheet = fWorkbook.getActiveSheet();
+ * const fRange = fWorksheet.getRange('A10');
+ * const result = fRange.insertCellImageAsync('https://avatars.githubusercontent.com/u/61444807?s=48&v=4');
+ * console.log(result);
+ * ```
+ */
+ insertCellImageAsync(file: File | string): Promise<boolean>;
+}
+
+export class FRangeSheetDrawingUI extends FRange implements IFRangeSheetDrawingMixin {
+ override async insertCellImageAsync(file: File | string): Promise<boolean> {
+ const renderManagerService = this._injector.get(IRenderManagerService);
+ const controller = getCurrentTypeOfRenderer(UniverInstanceType.UNIVER_SHEET, this._injector.get(IUniverInstanceService), renderManagerService)
+ ?.with(SheetDrawingUpdateController);
+ if (!controller) {
+ return false;
+ }
+ const location: ISheetLocationBase = {
+ unitId: this._workbook.getUnitId(),
+ subUnitId: this._worksheet.getSheetId(),
+ row: this.getRow(),
+ col: this.getColumn(),
+ };
+
+ if (typeof file === 'string') {
+ return controller.insertCellImageByUrl(file, location);
+ } else {
+ return controller.insertCellImageByFile(file, location);
+ }
+ }
+}
+
+FRange.extend(FRangeSheetDrawingUI);
+declare module '@univerjs/sheets/facade' {
+ // eslint-disable-next-line ts/naming-convention
+ interface FRange extends IFRangeSheetDrawingMixin { }
+}
diff --git a/packages/sheets-drawing-ui/src/facade/f-worksheet.ts b/packages/sheets-drawing-ui/src/facade/f-worksheet.ts
index 7478d0640a..18ce7b798c 100644
--- a/packages/sheets-drawing-ui/src/facade/f-worksheet.ts
+++ b/packages/sheets-drawing-ui/src/facade/f-worksheet.ts
@@ -547,6 +547,7 @@ export class FWorksheetLegacy extends FWorksheet implements IFWorksheetLegacy {
}
const param = await imageBuilder.buildAsync();
+ // param.drawingId
return this._commandService.syncExecuteCommand(InsertSheetDrawingCommand.id, { unitId: this._fWorkbook.getId(), drawings: [param] });
}
diff --git a/packages/sheets-drawing-ui/src/facade/index.ts b/packages/sheets-drawing-ui/src/facade/index.ts
index 7591fe8dde..babb95a9c2 100644
--- a/packages/sheets-drawing-ui/src/facade/index.ts
+++ b/packages/sheets-drawing-ui/src/facade/index.ts
@@ -19,9 +19,11 @@ import './f-worksheet';
import './f-enum';
import './f-event';
import './f-univer';
+import './f-range';
export type * from './f-enum';
export type * from './f-event';
export type * from './f-over-grid-image';
+export type * from './f-range';
export type * from './f-univer';
export type * from './f-worksheet';
diff --git a/packages/sheets-drawing-ui/src/index.ts b/packages/sheets-drawing-ui/src/index.ts
index cb13bbf2e4..eda61668eb 100644
--- a/packages/sheets-drawing-ui/src/index.ts
+++ b/packages/sheets-drawing-ui/src/index.ts
@@ -19,7 +19,7 @@ import './global.css';
export { UniverSheetsDrawingUIPlugin } from './plugin';
export { type ICanvasFloatDom, type IDOMAnchor, SheetCanvasFloatDomManagerService } from './services/canvas-float-dom-manager.service';
export { SHEETS_IMAGE_MENU_ID } from './views/menu/image.menu';
-
+export { SheetDrawingUpdateController } from './controllers/sheet-drawing-update.controller';
// #region - all commands
export { DeleteDrawingsCommand } from './commands/commands/delete-drawings.command';
diff --git a/packages/sheets-drawing-ui/src/views/menu/image.menu.ts b/packages/sheets-drawing-ui/src/views/menu/image.menu.ts
index 5bea9048b3..7098a50c2f 100644
--- a/packages/sheets-drawing-ui/src/views/menu/image.menu.ts
+++ b/packages/sheets-drawing-ui/src/views/menu/image.menu.ts
@@ -15,10 +15,11 @@
*/
import type { IAccessor } from '@univerjs/core';
+import type { IMenuItem } from '@univerjs/ui';
import { UniverInstanceType } from '@univerjs/core';
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission } from '@univerjs/sheets';
import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
-import { getMenuHiddenObservable, type IMenuItem, MenuItemType } from '@univerjs/ui';
+import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { InsertCellImageCommand, InsertFloatImageCommand } from '../../commands/commands/insert-image.command';
export const IMAGE_UPLOAD_ICON = 'addition-and-subtraction-single';
@@ -49,5 +50,6 @@ export function UploadCellImageMenuFactory(_accessor: IAccessor): IMenuItem {
id: InsertCellImageCommand.id,
title: 'sheetImage.upload.cell',
type: MenuItemType.BUTTON,
+ hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.UNIVER_SHEET),
};
}
diff --git a/packages/sheets-hyper-link-ui/src/controllers/menu.ts b/packages/sheets-hyper-link-ui/src/controllers/menu.ts
index 3df2ee6014..cf5abbae79 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/menu.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/menu.ts
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-import type { IAccessor, Nullable, Workbook } from '@univerjs/core';
+import type { DocumentDataModel, IAccessor, Nullable } from '@univerjs/core';
import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui';
import type { IMenuItem, IShortcutItem } from '@univerjs/ui';
-import { DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, FOCUSING_FX_BAR_EDITOR, IContextService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionRenderService } from '@univerjs/docs-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
-import { getSheetCommandTarget, RangeProtectionPermissionEditPoint, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, WorksheetSetCellValuePermission } from '@univerjs/sheets';
+import { getSheetCommandTarget, RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetInsertHyperlinkPermission, WorksheetSetCellValuePermission } from '@univerjs/sheets';
import { getCurrentRangeDisable$, IEditorBridgeService, whenSheetEditorFocused } from '@univerjs/sheets-ui';
import { getMenuHiddenObservable, KeyCode, MenuItemType, MetaKeys } from '@univerjs/ui';
-import { combineLatest, distinctUntilChanged, filter, map, of, switchMap } from 'rxjs';
+import { combineLatest, map, of, switchMap } from 'rxjs';
import { InsertHyperLinkOperation, InsertHyperLinkToolbarOperation } from '../commands/operations/popup.operations';
import { DisableLinkType, getShouldDisableCellLink, shouldDisableAddLink } from '../utils';
@@ -56,54 +56,48 @@ const getEditingLinkDisable$ = (accessor: IAccessor, unitId = DOCS_ZEN_EDITOR_UN
const getLinkDisable$ = (accessor: IAccessor) => {
const disableRange$ = getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetInsertHyperlinkPermission], rangeTypes: [RangeProtectionPermissionEditPoint] }, true);
const univerInstanceService = accessor.get(IUniverInstanceService);
- const sheetSelectionService = accessor.get(SheetsSelectionsService);
const editorBridgeService = accessor.has(IEditorBridgeService) ? accessor.get(IEditorBridgeService) : null;
- const disableCell$ = univerInstanceService.focused$.pipe(
- filter((focused) => Boolean(focused)),
- map((focused) => univerInstanceService.getUnit<Workbook>(focused!, UniverInstanceType.UNIVER_SHEET)),
- filter((unit) => Boolean(unit)),
- switchMap((unit) => unit!.activeSheet$),
- switchMap((sheet) => sheetSelectionService.selectionMoveEnd$.pipe(map((selections) => sheet && { selections, sheet }))),
- map((sheetWithSelection) => {
- if (!sheetWithSelection) {
- return DisableLinkType.DISABLED_BY_CELL;
+ const disableCell$ = editorBridgeService?.currentEditCellState$.pipe(
+ map((state) => {
+ if (!state) {
+ return (DisableLinkType.DISABLED_BY_CELL);
}
- const { selections, sheet } = sheetWithSelection;
- if (!selections.length) {
- return DisableLinkType.DISABLED_BY_CELL;
+ const target = getSheetCommandTarget(univerInstanceService, { unitId: state.unitId, subUnitId: state.sheetId });
+ if (!target) {
+ return (DisableLinkType.DISABLED_BY_CELL);
}
- const row = selections[0].range.startRow;
- const col = selections[0].range.startColumn;
- return getShouldDisableCellLink(accessor, sheet, row, col);
+ return (getShouldDisableCellLink(accessor, target.worksheet, state.row, state.column));
}),
switchMap((disableCell) => {
if (disableCell === DisableLinkType.DISABLED_BY_CELL) {
return of(true);
}
- const isEditing$ = (editorBridgeService ? editorBridgeService.visible$ : of<Nullable<IEditorBridgeServiceVisibleParam>>(null))
- .pipe(map((visible) => visible?.visible ? DOCS_NORMAL_EDITOR_UNIT_ID_KEY : undefined));
- const focusingFxBarEditor$ = accessor.get(IContextService).subscribeContextValue$(FOCUSING_FX_BAR_EDITOR);
-
- return combineLatest([isEditing$, focusingFxBarEditor$]).pipe(
+ const isEditing$ = (editorBridgeService ? editorBridgeService.visible$ : of<Nullable<IEditorBridgeServiceVisibleParam>>(null));
+ return combineLatest([isEditing$, univerInstanceService.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)]).pipe(
switchMap(
- ([editing, focusingFxBarEditor]) => {
- return editing ?
- focusingFxBarEditor
+ ([editing, focusingDoc]) => {
+ return editing?.visible ?
+ focusingDoc?.getUnitId() === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY
? of(true)
- : getEditingLinkDisable$(accessor, editing)
- : of(disableCell === DisableLinkType.ALLOW_ON_EDITING);
+ : getEditingLinkDisable$(accessor, DOCS_NORMAL_EDITOR_UNIT_ID_KEY)
+ : of(disableCell !== DisableLinkType.ALLOWED);
}
)
);
})
- );
+ ) ?? of(true);
- return disableRange$.pipe(
- distinctUntilChanged(),
- switchMap((disableRange) => disableCell$.pipe(map((disableCell) => disableRange || disableCell)))
+ return disableCell$.pipe(
+ switchMap((disableCell) => {
+ if (disableCell) {
+ return of(true);
+ } else {
+ return disableRange$;
+ }
+ })
);
};
diff --git a/packages/sheets-hyper-link-ui/src/utils/index.ts b/packages/sheets-hyper-link-ui/src/utils/index.ts
index 2c6c59834e..df7eb2f7a4 100644
--- a/packages/sheets-hyper-link-ui/src/utils/index.ts
+++ b/packages/sheets-hyper-link-ui/src/utils/index.ts
@@ -37,6 +37,10 @@ export const getShouldDisableCellLink = (accessor: IAccessor, worksheet: Workshe
return DisableLinkType.DISABLED_BY_CELL;
}
+ if (cell?.p?.body?.customBlocks?.length) {
+ return DisableLinkType.DISABLED_BY_CELL;
+ }
+
const dataValidationModel = accessor.has(SheetDataValidationModel) ? accessor.get(SheetDataValidationModel) : null;
const rule = dataValidationModel?.getRuleByLocation(worksheet.getUnitId(), worksheet.getSheetId(), row, col);
if (rule && disables.has(rule.type)) {
diff --git a/packages/sheets-ui/src/controllers/menu/menu-util.ts b/packages/sheets-ui/src/controllers/menu/menu-util.ts
index 5544a5bce9..3cfabf81fc 100644
--- a/packages/sheets-ui/src/controllers/menu/menu-util.ts
+++ b/packages/sheets-ui/src/controllers/menu/menu-util.ts
@@ -18,7 +18,8 @@ import type { IAccessor, IPermissionTypes, IRange, Nullable, Workbook, WorkbookP
import type { Observable } from 'rxjs';
import { FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, IContextService, IPermissionService, IUniverInstanceService, Rectangle, Tools, UniverInstanceType, UserManagerService } from '@univerjs/core';
import { IExclusiveRangeService, RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel } from '@univerjs/sheets';
-import { combineLatest, debounceTime, map, merge, of, startWith, switchMap } from 'rxjs';
+import { BehaviorSubject, combineLatest, merge, of } from 'rxjs';
+import { debounceTime, finalize, map, startWith, switchMap } from 'rxjs/operators';
import { IEditorBridgeService } from '../../services/editor-bridge.service';
interface IActive {
@@ -103,10 +104,18 @@ export function getCurrentRangeDisable$(accessor: IAccessor, permissionTypes: IP
const userManagerService = accessor.get(UserManagerService);
const editorBridgeService = accessor.has(IEditorBridgeService) ? accessor.get(IEditorBridgeService) : null;
const contextService = accessor.get(IContextService);
- const formulaEditorFocus$ = contextService.subscribeContextValue$(FOCUSING_FX_BAR_EDITOR);
+ const formulaEditorFocus$ = new BehaviorSubject<boolean>(false);
const editorVisible$ = editorBridgeService?.visible$ ?? of(null);
- return combineLatest([userManagerService.currentUser$, workbook$, editorVisible$, formulaEditorFocus$]).pipe(
+ const subscription = contextService.subscribeContextValue$(FOCUSING_FX_BAR_EDITOR).subscribe((visible) => {
+ formulaEditorFocus$.next(visible);
+ });
+
+ const observable = combineLatest([userManagerService.currentUser$, workbook$, editorVisible$, formulaEditorFocus$]).pipe(
+ finalize(() => {
+ subscription.unsubscribe();
+ formulaEditorFocus$.complete();
+ }),
switchMap(([_, workbook, visible, formulaEditorFocus]) => {
if (
!workbook ||
@@ -182,6 +191,8 @@ export function getCurrentRangeDisable$(accessor: IAccessor, permissionTypes: IP
);
})
);
+
+ return observable;
}
export function getBaseRangeMenuHidden$(accessor: IAccessor) {
diff --git a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
index 1a258c98b1..fe2c12a9d5 100644
--- a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
+++ b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
@@ -68,7 +68,7 @@ export function FormulaBar(props: IProps) {
const componentManager = useDependency(ComponentManager);
const workbook = useObservable(() => univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET), undefined, undefined, [])!;
const isRefSelecting = useRef<0 | 1 | 2>(0);
- const editState = editorBridgeService.getEditLocation();
+ const editState = useObservable(editorBridgeService.currentEditCellState$);
const keyCodeConfig = useKeyEventConfig(isRefSelecting, editState?.unitId ?? '');
const FormulaEditor = componentManager.get(EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY);
const formulaAuxUIParts = useComponentsOfPart(SheetsUIPart.FORMULA_AUX);
@@ -219,8 +219,6 @@ export function FormulaBar(props: IProps) {
const disabled = editDisable || imageDisable;
const shouldSkipFocus = useRef(false);
- const unitId = currentWorkbook?.getUnitId() ?? '';
-
const handlePointerDown = () => {
try {
// When clicking on the formula bar, the cell editor also needs to enter the edit state
@@ -254,6 +252,9 @@ export function FormulaBar(props: IProps) {
shouldSkipFocus.current = false;
};
+ const isCellImage = (editState?.documentLayoutObject.documentModel?.getDrawingsOrder()?.length ?? 0) > 0;
+ const hideEditor = isCellImage || viewDisable;
+
return (
<div
className={clsx(styles.formulaBox, className)}
@@ -295,6 +296,7 @@ export function FormulaBar(props: IProps) {
onPointerDown={handlePointerDown}
onPointerUp={handlePointerUp}
ref={ref}
+ style={{ pointerEvents: hideEditor ? 'none' : 'auto' }}
>
{FormulaEditor && (
<FormulaEditor
@@ -322,6 +324,7 @@ export function FormulaBar(props: IProps) {
disableContextMenu={false}
/>
)}
+ {hideEditor ? <div className={styles.formulaInputMask} /> : null}
</div>
<div className={clsx(styles.arrowContainer, { [styles.arrowContainerDisable]: editDisable })} onClick={handleArrowClick}>
{arrowDirection === ArrowDirection.Down
diff --git a/packages/sheets-ui/src/views/formula-bar/index.module.less b/packages/sheets-ui/src/views/formula-bar/index.module.less
index ee2f027910..5b5261dbc5 100644
--- a/packages/sheets-ui/src/views/formula-bar/index.module.less
+++ b/packages/sheets-ui/src/views/formula-bar/index.module.less
@@ -99,6 +99,8 @@
height: 100%;
pointer-events: none;
z-index: 100;
+ background: rgb(var(--color-white));
+ cursor: not-allowed;
}
.formula-container {
diff --git a/packages/sheets-zen-editor/src/views/menu.ts b/packages/sheets-zen-editor/src/views/menu.ts
index 61c3b9912a..cd59e85d48 100644
--- a/packages/sheets-zen-editor/src/views/menu.ts
+++ b/packages/sheets-zen-editor/src/views/menu.ts
@@ -15,19 +15,24 @@
*/
import type { IAccessor } from '@univerjs/core';
-
+import type { IMenuButtonItem } from '@univerjs/ui';
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission } from '@univerjs/sheets';
-import { getCurrentExclusiveRangeInterest$, getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
-import { type IMenuButtonItem, MenuItemType } from '@univerjs/ui';
+import { getCurrentExclusiveRangeInterest$, getCurrentRangeDisable$, IEditorBridgeService } from '@univerjs/sheets-ui';
+import { MenuItemType } from '@univerjs/ui';
+import { map, switchMap } from 'rxjs';
import { OpenZenEditorCommand } from '../commands/commands/zen-editor.command';
export function ZenEditorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ const editorBridgeService = accessor.get(IEditorBridgeService);
return {
id: OpenZenEditorCommand.id,
type: MenuItemType.BUTTON,
title: 'rightClick.zenEditor',
icon: 'AmplifySingle',
hidden$: getCurrentExclusiveRangeInterest$(accessor),
- disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] }),
+ disabled$: editorBridgeService.currentEditCell$.pipe(
+ switchMap((cell) => getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellValuePermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
+ .pipe(map((disabled) => disabled || (cell?.documentLayoutObject.documentModel?.getBody()?.customBlocks?.length ?? 0) > 0)))
+ ),
};
}
diff --git a/packages/ui/src/common/menu-hidden-observable.ts b/packages/ui/src/common/menu-hidden-observable.ts
index 424379acf6..eca006d426 100644
--- a/packages/ui/src/common/menu-hidden-observable.ts
+++ b/packages/ui/src/common/menu-hidden-observable.ts
@@ -34,6 +34,7 @@ export function getMenuHiddenObservable(
if (matchUnitId && matchUnitId !== unitId) {
return subscriber.next(true);
}
+
if (needHideUnitId && (Array.isArray(needHideUnitId) ? needHideUnitId.includes(unitId) : needHideUnitId === unitId)) {
return subscriber.next(true);
}