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): support shape text editing (#6479)

WEI ZHANGff5fef22d668
diff --git a/packages/core/src/services/context/context.ts b/packages/core/src/services/context/context.ts
index fa70029f19..efa4fe07ba 100644
--- a/packages/core/src/services/context/context.ts
+++ b/packages/core/src/services/context/context.ts
@@ -56,4 +56,9 @@ export const FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE = 'FOCUSING_UNIVER_ED
*/
export const FOCUSING_COMMON_DRAWINGS = 'FOCUSING_COMMON_DRAWINGS';
+/**
+ * The focusing state of the shape text editor.
+ */
+export const FOCUSING_SHAPE_TEXT_EDITOR = 'FOCUSING_SHAPE_TEXT_EDITOR';
+
export const FORMULA_EDITOR_ACTIVATED = 'FORMULA_EDITOR_ACTIVATED';
diff --git a/packages/docs-drawing-ui/src/controllers/drawing-popup-menu.controller.ts b/packages/docs-drawing-ui/src/controllers/drawing-popup-menu.controller.ts
index 0fd9a25666..dd7df6415f 100644
--- a/packages/docs-drawing-ui/src/controllers/drawing-popup-menu.controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/drawing-popup-menu.controller.ts
@@ -16,7 +16,7 @@
import type { DocumentDataModel, IDisposable, Nullable } from '@univerjs/core';
import type { BaseObject, Scene } from '@univerjs/engine-render';
-import { DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, IContextService, Inject, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
+import { DrawingTypeEnum, FOCUSING_COMMON_DRAWINGS, IContextService, Inject, isInternalEditorID, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
import { IDrawingManagerService } from '@univerjs/drawing';
import { COMPONENT_IMAGE_POPUP_MENU, ImageCropperObject, ImageResetSizeOperation, OpenImageCropOperation } from '@univerjs/drawing-ui';
@@ -69,6 +69,9 @@ export class DocDrawingPopupMenuController extends RxDisposable {
}
const unitId = documentDataModel.getUnitId();
+ if (isInternalEditorID(unitId)) {
+ return;
+ }
if (this._renderManagerService.has(unitId) && !this._initImagePopupMenu.has(unitId)) {
this._popupMenuListener(unitId);
this._initImagePopupMenu.add(unitId);
@@ -163,8 +166,7 @@ export class DocDrawingPopupMenuController extends RxDisposable {
disposePopups.length = 0;
this._contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, false);
this._drawingManagerService.focusDrawing(null);
- }
- )
+ })
);
this.disposeWithMe(
transformer.changing$.subscribe(() => {
diff --git a/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts b/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts
index f638e5a0d4..2a9450f76d 100644
--- a/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts
+++ b/packages/docs-ui/src/controllers/render-controllers/zoom.render-controller.ts
@@ -180,6 +180,9 @@ export class DocZoomRenderController extends Disposable implements IRenderModule
this._textSelectionManagerService.refreshSelection();
}
+ if (isInternalEditorID(this._context.unitId)) {
+ return;
+ }
docObject.scene.getTransformer()?.clearSelectedObjects();
}
diff --git a/packages/docs-ui/src/index.ts b/packages/docs-ui/src/index.ts
index e42fca83a8..4fcc0852d1 100644
--- a/packages/docs-ui/src/index.ts
+++ b/packages/docs-ui/src/index.ts
@@ -148,4 +148,4 @@ export { getAnchorBounding, getLineBounding, TEXT_RANGE_LAYER_INDEX, TextRange }
export { whenDocAndEditorFocused } from './shortcuts/utils';
export { DOC_VERTICAL_PADDING } from './types/const/padding';
export { type IRichTextEditorProps, RichTextEditor } from './views/rich-text-editor';
-export { type IKeyboardEventConfig, useKeyboardEvent, useResize } from './views/rich-text-editor/hooks';
+export { type IKeyboardEventConfig, useEditor, useEditorClickOutside, useIsFocusing, useKeyboardEvent, useLeftAndRightArrow, useOnChange, useResize } from './views/rich-text-editor/hooks';
diff --git a/packages/docs-ui/src/views/rich-text-editor/hooks/index.ts b/packages/docs-ui/src/views/rich-text-editor/hooks/index.ts
index cb2a465e26..42b0fce653 100644
--- a/packages/docs-ui/src/views/rich-text-editor/hooks/index.ts
+++ b/packages/docs-ui/src/views/rich-text-editor/hooks/index.ts
@@ -14,5 +14,10 @@
* limitations under the License.
*/
+export { useEditor } from './use-editor';
+export { useEditorClickOutside } from './use-editor-click-outside';
+export { useIsFocusing } from './use-is-focusing';
export { type IKeyboardEventConfig, useKeyboardEvent } from './use-keyboard-event';
+export { useLeftAndRightArrow } from './use-left-and-right-arrow';
+export { useOnChange } from './use-on-change';
export { useResize } from './use-resize';
diff --git a/packages/docs-ui/src/views/rich-text-editor/hooks/use-editor-click-outside.ts b/packages/docs-ui/src/views/rich-text-editor/hooks/use-editor-click-outside.ts
new file mode 100644
index 0000000000..2f48780fae
--- /dev/null
+++ b/packages/docs-ui/src/views/rich-text-editor/hooks/use-editor-click-outside.ts
@@ -0,0 +1,50 @@
+/**
+ * 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 { useDependency } from '@univerjs/ui';
+import { useEffect } from 'react';
+import { IEditorService } from '../../../services/editor/editor-manager.service';
+
+export const useEditorClickOutside = (
+ editorId: string,
+ containerRef: React.RefObject<HTMLElement | null>,
+ onClickOutside?: () => void
+) => {
+ const editorService = useDependency(IEditorService);
+
+ useEffect(() => {
+ const handleClickOutside = (event: MouseEvent) => {
+ if (editorService.getFocusId() !== editorId) return;
+
+ const id = (event.target as HTMLDivElement)?.dataset?.editorid;
+ if (id === editorId) return;
+
+ // Check if click is inside the editor container
+ if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
+ onClickOutside?.();
+ }
+ };
+
+ const timer = setTimeout(() => {
+ document.addEventListener('click', handleClickOutside);
+ }, 100);
+
+ return () => {
+ document.removeEventListener('click', handleClickOutside);
+ clearTimeout(timer);
+ };
+ }, [editorId, editorService, onClickOutside, containerRef]);
+};
diff --git a/packages/docs-ui/src/views/rich-text-editor/hooks/use-is-focusing.ts b/packages/docs-ui/src/views/rich-text-editor/hooks/use-is-focusing.ts
new file mode 100644
index 0000000000..aa78a81071
--- /dev/null
+++ b/packages/docs-ui/src/views/rich-text-editor/hooks/use-is-focusing.ts
@@ -0,0 +1,27 @@
+/**
+ * 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 { IRenderManagerService } from '@univerjs/engine-render';
+import { useDependency, useObservable } from '@univerjs/ui';
+import { DocSelectionRenderService } from '../../../services/selection/doc-selection-render.service';
+
+export function useIsFocusing(editorId: string) {
+ const renderManagerService = useDependency(IRenderManagerService);
+ const renderer = renderManagerService.getRenderById(editorId);
+ const docSelectionRenderService = renderer?.with(DocSelectionRenderService);
+ const selections = useObservable(docSelectionRenderService?.textSelectionInner$);
+ return Boolean((docSelectionRenderService?.isFocusing ?? false) && selections?.textRanges.some((r) => r.collapsed));
+}
diff --git a/packages/docs-ui/src/views/rich-text-editor/index.tsx b/packages/docs-ui/src/views/rich-text-editor/index.tsx
index 9e8298ec9f..4f62914f80 100644
--- a/packages/docs-ui/src/views/rich-text-editor/index.tsx
+++ b/packages/docs-ui/src/views/rich-text-editor/index.tsx
@@ -25,8 +25,7 @@ import { IRenderManagerService } from '@univerjs/engine-render';
import { useDependency, useEvent, useObservable } from '@univerjs/ui';
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { IEditorService } from '../../services/editor/editor-manager.service';
-import { DocSelectionRenderService } from '../../services/selection/doc-selection-render.service';
-import { useKeyboardEvent, useResize } from './hooks';
+import { useEditorClickOutside, useIsFocusing, useKeyboardEvent, useResize } from './hooks';
import { useEditor } from './hooks/use-editor';
import { useLeftAndRightArrow } from './hooks/use-left-and-right-arrow';
import { useOnChange } from './hooks/use-on-change';
@@ -49,6 +48,7 @@ export interface IRichTextEditorProps {
defaultHeight?: number;
icon?: ReactNode;
editorRef?: RefObject<Editor | null> | ((editor: Editor | null) => void);
+ noStyle?: boolean;
}
export const RichTextEditor = (props: IRichTextEditorProps) => {
@@ -70,6 +70,7 @@ export const RichTextEditor = (props: IRichTextEditorProps) => {
icon,
editorRef,
placeholder,
+ noStyle,
} = props;
const editorService = useDependency(IEditorService);
const onFocusChange = useEvent(_onFocusChange);
@@ -86,9 +87,7 @@ export const RichTextEditor = (props: IRichTextEditorProps) => {
});
const renderManagerService = useDependency(IRenderManagerService);
const renderer = renderManagerService.getRenderById(editorId);
- const docSelectionRenderService = renderer?.with(DocSelectionRenderService);
- const selections = useObservable(docSelectionRenderService?.textSelectionInner$);
- const isFocusing = Boolean((docSelectionRenderService?.isFocusing ?? false) && selections?.textRanges.some((r) => r.collapsed));
+ const isFocusing = useIsFocusing(editorId);
const sheetEmbeddingRef = useRef<HTMLDivElement>(null);
const [showPlaceholder, setShowPlaceholder] = useState(() => !BuildTextUtils.transform.getPlainText(editor?.getDocumentData().body?.dataStream ?? ''));
const { checkScrollBar } = useResize(editor, isSingle, true, true);
@@ -131,26 +130,7 @@ export const RichTextEditor = (props: IRichTextEditorProps) => {
onFocusChange?.(isFocusing, getPlainText(data?.body?.dataStream ?? ''));
}, [isFocusing, onFocusChange]);
- useEffect(() => {
- const handleClickOutside = (event: MouseEvent) => {
- if (editorService.getFocusId() !== editorId) return;
-
- const id = (event.target as HTMLDivElement)?.dataset?.editorid;
- if (id === editorId) return;
- if (sheetEmbeddingRef.current && !sheetEmbeddingRef.current.contains(event.target as any)) {
- onClickOutside?.();
- }
- };
-
- const timer = setTimeout(() => {
- document.addEventListener('click', handleClickOutside);
- }, 100);
-
- return () => {
- document.removeEventListener('click', handleClickOutside);
- clearTimeout(timer);
- };
- }, [editor, editorId, editorService, onClickOutside]);
+ useEditorClickOutside(editorId, sheetEmbeddingRef, onClickOutside);
useLeftAndRightArrow(isFocusing && moveCursor, false, editor);
useKeyboardEvent(isFocusing, keyboardEventConfig, editor);
@@ -159,13 +139,18 @@ export const RichTextEditor = (props: IRichTextEditorProps) => {
return (
<div className={className} style={style}>
<div
- className={clsx(`
- univer-relative univer-box-border univer-flex univer-h-8 univer-w-full univer-items-center
- univer-justify-around univer-gap-2 univer-rounded-md univer-pb-0.5 univer-pl-1.5 univer-pr-2
- univer-pt-1.5
- `, borderClassName, {
- 'univer-border-primary-500': isFocusing,
- })}
+ className={clsx(
+ {
+ 'univer-border-primary-500': isFocusing && !noStyle,
+ [`
+ univer-relative univer-box-border univer-flex univer-h-8 univer-w-full univer-items-center
+ univer-justify-around univer-gap-2 univer-rounded-md univer-pb-0.5 univer-pl-1.5 univer-pr-2
+ univer-pt-1.5
+ `]: !noStyle,
+ 'univer-h-full univer-w-full': noStyle,
+ [borderClassName]: !noStyle,
+ }
+ )}
style={{ height }}
ref={sheetEmbeddingRef}
>
diff --git a/packages/sheets-ui/src/controllers/menu/border.menu.ts b/packages/sheets-ui/src/controllers/menu/border.menu.ts
index 8e4a658f30..40c100f601 100644
--- a/packages/sheets-ui/src/controllers/menu/border.menu.ts
+++ b/packages/sheets-ui/src/controllers/menu/border.menu.ts
@@ -17,10 +17,10 @@
import type { IAccessor } from '@univerjs/core';
import type { IBorderInfo } from '@univerjs/sheets';
import type { IMenuSelectorItem } from '@univerjs/ui';
-import { ICommandService, UniverInstanceType } from '@univerjs/core';
+import { FOCUSING_COMMON_DRAWINGS, ICommandService, IContextService, UniverInstanceType } from '@univerjs/core';
import { BorderStyleManagerService, RangeProtectionPermissionEditPoint, SetBorderBasicCommand, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission } from '@univerjs/sheets';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
-import { Observable } from 'rxjs';
+import { combineLatest, map, Observable, startWith } from 'rxjs';
import { BORDER_LINE_CHILDREN, BORDER_PANEL_COMPONENT } from '../../components/border-panel/interface';
import { getCurrentRangeDisable$ } from './menu-util';
@@ -69,7 +69,10 @@ export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSel
},
],
value$: borderStyleManagerService.borderInfo$,
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ accessor.get(IContextService).subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false)),
+ ]).pipe(map(([hidden, focusingDrawing]) => hidden || focusingDrawing)),
disabled$,
};
}
diff --git a/packages/sheets-ui/src/controllers/menu/font.menu.ts b/packages/sheets-ui/src/controllers/menu/font.menu.ts
index cf25231cc3..c534cf370f 100644
--- a/packages/sheets-ui/src/controllers/menu/font.menu.ts
+++ b/packages/sheets-ui/src/controllers/menu/font.menu.ts
@@ -19,6 +19,7 @@ import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
import {
DEFAULT_STYLES,
EDITOR_ACTIVATED,
+ FOCUSING_SHAPE_TEXT_EDITOR,
FOCUSING_SHEET,
ICommandService,
IContextService,
@@ -85,7 +86,7 @@ function updateFontSizeValue(accessor: IAccessor, defaultValue: number) {
if (
(id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) &&
contextService.getContextValue(EDITOR_ACTIVATED) &&
- contextService.getContextValue(FOCUSING_SHEET)
+ (contextService.getContextValue(FOCUSING_SHEET) || contextService.getContextValue(FOCUSING_SHAPE_TEXT_EDITOR))
) {
updateSheetEditor();
}
diff --git a/packages/sheets-ui/src/controllers/menu/menu-util.ts b/packages/sheets-ui/src/controllers/menu/menu-util.ts
index 088a6c6801..602d6ac497 100644
--- a/packages/sheets-ui/src/controllers/menu/menu-util.ts
+++ b/packages/sheets-ui/src/controllers/menu/menu-util.ts
@@ -17,7 +17,7 @@
import type { IAccessor, IPermissionTypes, IRange, Nullable, Workbook, WorkbookPermissionPointConstructor, Worksheet } from '@univerjs/core';
import type { Observable } from 'rxjs';
import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';
-import { FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, IContextService, IPermissionService, IUniverInstanceService, Rectangle, Tools, UniverInstanceType, UserManagerService } from '@univerjs/core';
+import { FOCUSING_COMMON_DRAWINGS, FOCUSING_FX_BAR_EDITOR, FOCUSING_SHAPE_TEXT_EDITOR, IContextService, IPermissionService, IUniverInstanceService, Rectangle, Tools, UniverInstanceType, UserManagerService } from '@univerjs/core';
import { IExclusiveRangeService, RangeProtectionPermissionEditPoint, RangeProtectionRuleModel, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetProtectionRuleModel } from '@univerjs/sheets';
import { combineLatest, merge, of } from 'rxjs';
import { debounceTime, map, shareReplay, startWith, switchMap } from 'rxjs/operators';
@@ -117,8 +117,13 @@ export function getCurrentRangeDisable$(accessor: IAccessor, permissionTypes: IP
shareReplay(1)
);
- const observable = combineLatest([userManagerService.currentUser$, workbook$, editorVisible$, formulaEditorFocus$]).pipe(
- switchMap(([_, workbook, visible, formulaEditorFocus]) => {
+ const focusingShapeTextEditor$ = contextService.subscribeContextValue$(FOCUSING_SHAPE_TEXT_EDITOR).pipe(
+ startWith(false),
+ shareReplay(1)
+ );
+
+ const observable = combineLatest([userManagerService.currentUser$, workbook$, editorVisible$, formulaEditorFocus$, focusingShapeTextEditor$]).pipe(
+ switchMap(([_, workbook, visible, formulaEditorFocus, focusingShapeTextEditor]) => {
if (
!workbook ||
(visible?.visible && visible.unitId === workbook.getUnitId() && !supportCellEdit) ||
@@ -142,7 +147,7 @@ export function getCurrentRangeDisable$(accessor: IAccessor, permissionTypes: IP
return combineLatest([selectionManagerService.selectionMoveEnd$, focusedOnDrawing$]).pipe(
switchMap(([selection, focusOnDrawings]) => {
- if (focusOnDrawings) {
+ if (focusOnDrawings && !focusingShapeTextEditor) {
return of(true);
}
diff --git a/packages/sheets-ui/src/controllers/menu/menu.ts b/packages/sheets-ui/src/controllers/menu/menu.ts
index fb187c01db..37c064650c 100644
--- a/packages/sheets-ui/src/controllers/menu/menu.ts
+++ b/packages/sheets-ui/src/controllers/menu/menu.ts
@@ -21,6 +21,8 @@ import {
composeStyles,
DEFAULT_STYLES,
EDITOR_ACTIVATED,
+ FOCUSING_COMMON_DRAWINGS,
+ FOCUSING_SHAPE_TEXT_EDITOR,
FOCUSING_SHEET,
FontItalic,
FontWeight,
@@ -78,7 +80,7 @@ import {
IClipboardInterfaceService,
MenuItemType,
} from '@univerjs/ui';
-import { combineLatestWith, map, Observable } from 'rxjs';
+import { combineLatest, combineLatestWith, map, Observable, startWith } from 'rxjs';
import {
SheetCopyCommand,
SheetCutCommand,
@@ -173,7 +175,7 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
if (
(id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) &&
contextService.getContextValue(EDITOR_ACTIVATED) &&
- contextService.getContextValue(FOCUSING_SHEET)
+ (contextService.getContextValue(FOCUSING_SHEET) || contextService.getContextValue(FOCUSING_SHAPE_TEXT_EDITOR))
) {
const textRun = getFontStyleAtCursor(accessor);
if (textRun == null) {
@@ -242,7 +244,7 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
if (
(id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) &&
contextService.getContextValue(EDITOR_ACTIVATED) &&
- contextService.getContextValue(FOCUSING_SHEET)
+ (contextService.getContextValue(FOCUSING_SHEET) || contextService.getContextValue(FOCUSING_SHAPE_TEXT_EDITOR))
) {
const textRun = getFontStyleAtCursor(accessor);
if (textRun == null) return;
@@ -295,7 +297,7 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
if (
(id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) &&
contextService.getContextValue(EDITOR_ACTIVATED) &&
- contextService.getContextValue(FOCUSING_SHEET)
+ (contextService.getContextValue(FOCUSING_SHEET) || contextService.getContextValue(FOCUSING_SHAPE_TEXT_EDITOR))
) {
const textRun = getFontStyleAtCursor(accessor);
if (textRun == null) return;
@@ -358,7 +360,7 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIt
if (
(id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) &&
contextService.getContextValue(EDITOR_ACTIVATED) &&
- contextService.getContextValue(FOCUSING_SHEET)
+ (contextService.getContextValue(FOCUSING_SHEET) || contextService.getContextValue(FOCUSING_SHAPE_TEXT_EDITOR))
) {
const textRun = getFontStyleAtCursor(accessor);
@@ -444,6 +446,18 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSel
if (id === SetRangeValuesMutation.id || id === SetSelectionsOperation.id || id === SetWorksheetActiveOperation.id) {
updateSheet();
}
+
+ if (
+ (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) &&
+ accessor.get(IContextService).getContextValue(EDITOR_ACTIVATED) &&
+ (accessor.get(IContextService).getContextValue(FOCUSING_SHEET) || accessor.get(IContextService).getContextValue(FOCUSING_SHAPE_TEXT_EDITOR))
+ ) {
+ const textRun = getFontStyleAtCursor(accessor);
+ if (textRun != null) {
+ const ff = (textRun.ts?.ff ?? defaultValue);
+ subscriber.next(ff);
+ }
+ }
});
updateSheet();
@@ -573,7 +587,10 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMe
subscriber.next(defaultValue);
return disposable.dispose;
}),
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ accessor.get(IContextService).subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false)),
+ ]).pipe(map(([hidden, focusingDrawing]) => hidden || focusingDrawing)),
disabled$: getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookEditablePermission],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
@@ -645,7 +662,10 @@ export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelect
return disposable.dispose;
})),
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ accessor.get(IContextService).subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false)),
+ ]).pipe(map(([hidden, focusingDrawing]) => hidden || focusingDrawing)),
disabled$: getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookEditablePermission],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
@@ -717,7 +737,10 @@ export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelector
return disposable.dispose;
})),
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ accessor.get(IContextService).subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false)),
+ ]).pipe(map(([hidden, focusingDrawing]) => hidden || focusingDrawing)),
disabled$: getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookEditablePermission],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
@@ -789,7 +812,10 @@ export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<
return disposable.dispose;
})),
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ accessor.get(IContextService).subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false)),
+ ]).pipe(map(([hidden, focusingDrawing]) => hidden || focusingDrawing)),
disabled$: getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookEditablePermission],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
@@ -879,7 +905,10 @@ export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorIte
return disposable.dispose;
})),
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ accessor.get(IContextService).subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false)),
+ ]).pipe(map(([hidden, focusingDrawing]) => hidden || focusingDrawing)),
disabled$: getCurrentRangeDisable$(accessor, {
workbookTypes: [WorkbookEditablePermission],
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
diff --git a/packages/sheets-ui/src/controllers/menu/merge.menu.ts b/packages/sheets-ui/src/controllers/menu/merge.menu.ts
index 0e4aa4f6ea..dcacc53980 100644
--- a/packages/sheets-ui/src/controllers/menu/merge.menu.ts
+++ b/packages/sheets-ui/src/controllers/menu/merge.menu.ts
@@ -16,7 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
-import { UniverInstanceType } from '@univerjs/core';
+import { FOCUSING_COMMON_DRAWINGS, IContextService, UniverInstanceType } from '@univerjs/core';
import {
AddWorksheetMergeAllCommand,
AddWorksheetMergeCommand,
@@ -30,7 +30,7 @@ import {
WorksheetSetCellValuePermission,
} from '@univerjs/sheets';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
-import { combineLatestWith, map } from 'rxjs';
+import { combineLatest, combineLatestWith, map, startWith } from 'rxjs';
import { getSheetSelectionsDisabled$ } from '../utils/selections-tools';
import { getCurrentRangeDisable$, getObservableWithExclusiveRange$ } from './menu-util';
@@ -44,7 +44,10 @@ export function CellMergeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem
tooltip: 'toolbar.mergeCell.main',
type: MenuItemType.SUBITEMS,
// selections: [...MERGE_CHILDREN],
- hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ hidden$: combineLatest([
+ getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ accessor.get(IContextService).subscribeContextValue$(FOCUSING_COMMON_DRAWINGS).pipe(startWith(false)),
+ ]).pipe(map(([hidden, focusingDrawing]) => hidden || focusingDrawing)),
disabled$: editDisabled$.pipe(
combineLatestWith(selectionsHasCross$),
map(([disable, hasCross]) => disable || hasCross)
diff --git a/packages/sheets-ui/src/controllers/menu/utils.ts b/packages/sheets-ui/src/controllers/menu/utils.ts
index 0dbd646a16..6ae6a42d09 100644
--- a/packages/sheets-ui/src/controllers/menu/utils.ts
+++ b/packages/sheets-ui/src/controllers/menu/utils.ts
@@ -15,14 +15,17 @@
*/
import type { DocumentDataModel, IAccessor } from '@univerjs/core';
-import { DOCS_NORMAL_EDITOR_UNIT_ID_KEY, IUniverInstanceService } from '@univerjs/core';
+import { DOCS_NORMAL_EDITOR_UNIT_ID_KEY, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
+import { IEditorService } from '@univerjs/docs-ui';
export function getFontStyleAtCursor(accessor: IAccessor) {
const univerInstanceService = accessor.get(IUniverInstanceService);
const textSelectionService = accessor.get(DocSelectionManagerService);
+ const editorService = accessor.get(IEditorService);
- const editorDataModel = univerInstanceService.getUnit<DocumentDataModel>(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
+ const editorUnitId = editorService.getFocusId() ?? DOCS_NORMAL_EDITOR_UNIT_ID_KEY;
+ const editorDataModel = univerInstanceService.getUnit<DocumentDataModel>(editorUnitId, UniverInstanceType.UNIVER_DOC);
const activeTextRange = textSelectionService.getActiveTextRange();
if (editorDataModel == null || activeTextRange == null) return null;
diff --git a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx
index c544da6546..668488c8d4 100644
--- a/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx
+++ b/packages/sheets-ui/src/views/sheet-container/SheetContainer.tsx
@@ -17,7 +17,7 @@
import type { Workbook } from '@univerjs/core';
import type { IUniverSheetsUIConfig } from '../../controllers/config.schema';
import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { ContextMenuPosition, IMenuManagerService, ToolbarItem, useConfigValue, useDependency, useObservable } from '@univerjs/ui';
+import { ComponentManager, ContextMenuPosition, IMenuManagerService, ToolbarItem, useConfigValue, useDependency, useObservable } from '@univerjs/ui';
import { useMemo } from 'react';
import { useActiveWorkbook } from '../../components/hook';
import { SHEETS_UI_PLUGIN_CONFIG_KEY } from '../../controllers/config.schema';
@@ -90,10 +90,17 @@ export function RenderSheetHeader() {
export function RenderSheetContent() {
const config = useConfigValue<IUniverSheetsUIConfig>(SHEETS_UI_PLUGIN_CONFIG_KEY);
const hasWorkbook = useHasWorkbook();
+ const componentManager = useDependency(ComponentManager);
+
+ // Attempt to retrieve the registered ShapeTextEditorContainer
+ // We use a string key to avoid hard dependency on sheets-shape-ui
+ const ShapeTextEditorContainer = componentManager.get('ShapeTextEditorContainer');
+
if (!hasWorkbook) return null;
return (
<>
+ {ShapeTextEditorContainer && <ShapeTextEditorContainer />}
{!config?.disableEdit && <EditorContainer />}
<AutoFillPopupMenu />
</>