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.

fix(docs-ui): ui issues about paragraph menu (#4952)

ZhangWeib5493c016fdc
diff --git a/packages/design/src/components/menu/index.module.less b/packages/design/src/components/menu/index.module.less
index 219bfd6e0d..0da3988e28 100644
--- a/packages/design/src/components/menu/index.module.less
+++ b/packages/design/src/components/menu/index.module.less
@@ -11,7 +11,7 @@
outline: none;
box-shadow: var(--box-shadow-lg);
border: 1px solid rgb(var(--border-color));
- width: 212px;
+ min-width: 212px;
&-vertical {
display: grid;
diff --git a/packages/docs-ui/src/components/paragraph-menu/index.tsx b/packages/docs-ui/src/components/paragraph-menu/index.tsx
index b6c1c0d09e..81dfbee408 100644
--- a/packages/docs-ui/src/components/paragraph-menu/index.tsx
+++ b/packages/docs-ui/src/components/paragraph-menu/index.tsx
@@ -41,10 +41,12 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
const docEventManagerService = renderUnit?.with(DocEventManagerService);
const paragraph = useObservable(docEventManagerService?.hoverParagraph$);
const paragraphLeft = useObservable(docEventManagerService?.hoverParagraphLeft$);
- const startIndex = (paragraph ?? paragraphLeft)?.startIndex;
+ const activeParagraph = paragraph ?? paragraphLeft;
+ const startIndex = activeParagraph?.startIndex;
const paragraphObj = useMemo(() => doc?.getBody()?.paragraphs?.find((p) => p.startIndex === startIndex), [doc, startIndex]);
const namedStyleType = paragraphObj?.paragraphStyle?.namedStyleType;
const icon = HEADING_ICON_MAP[namedStyleType ?? NamedStyleType.NORMAL_TEXT];
+ const dataStream = doc?.getBody()?.dataStream ?? '';
const anchorRect$ = useMemo(() => new BehaviorSubject({
left: 0,
right: 0,
@@ -56,6 +58,12 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
setVisible(false);
docParagraphMenuService?.hideParagraphMenu(true);
};
+ if (!activeParagraph) return null;
+
+ const paragraphDataStream = dataStream.slice(activeParagraph.paragraphStart, activeParagraph.paragraphEnd);
+ const isOnlyImage = paragraphDataStream === '\b';
+
+ if (isOnlyImage) return null;
return (
<>
@@ -93,7 +101,7 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
mask
maskZIndex={100}
anchorRect$={anchorRect$}
- direction="left-center"
+ direction="left"
onMaskClick={handleHideMenu}
>
<section
@@ -107,6 +115,7 @@ export const ParagraphMenu = ({ popup }: { popup: IPopup }) => {
}}
>
<DesktopMenu
+ style={{ width: 212 }}
menuType={ContextMenuPosition.PARAGRAPH}
onOptionSelect={(params) => {
const { label: id, commandId, value } = params;
diff --git a/packages/docs-ui/src/controllers/menu.schema.ts b/packages/docs-ui/src/controllers/menu.schema.ts
index fd0850f2fe..4856ad9ab2 100644
--- a/packages/docs-ui/src/controllers/menu.schema.ts
+++ b/packages/docs-ui/src/controllers/menu.schema.ts
@@ -75,7 +75,7 @@ import {
TextColorSelectorMenuItemFactory,
UnderlineMenuItemFactory,
} from './menu/menu';
-import { CopyCurrentParagraphMenuItemFactory, CutCurrentParagraphMenuItemFactory, DeleteCurrentParagraphMenuItemFactory, H1HeadingMenuItemFactory, H2HeadingMenuItemFactory, H3HeadingMenuItemFactory, H4HeadingMenuItemFactory, H5HeadingMenuItemFactory, InsertBulletListBellowMenuItemFactory, InsertCheckListBellowMenuItemFactory, InsertHorizontalLineBellowMenuItemFactory, InsertOrderListBellowMenuItemFactory, NormalTextHeadingMenuItemFactory } from './menu/paragraph-menu';
+import { CopyCurrentParagraphMenuItemFactory, CutCurrentParagraphMenuItemFactory, DeleteCurrentParagraphMenuItemFactory, DocInsertBellowMenuItemFactory, H1HeadingMenuItemFactory, H2HeadingMenuItemFactory, H3HeadingMenuItemFactory, H4HeadingMenuItemFactory, H5HeadingMenuItemFactory, INSERT_BELLOW_MENU_ID, InsertBulletListBellowMenuItemFactory, InsertCheckListBellowMenuItemFactory, InsertHorizontalLineBellowMenuItemFactory, InsertOrderListBellowMenuItemFactory, NormalTextHeadingMenuItemFactory } from './menu/paragraph-menu';
export const menuSchema: MenuSchemaType = {
[RibbonStartGroup.FORMAT]: {
@@ -294,22 +294,25 @@ export const menuSchema: MenuSchemaType = {
},
},
[ContextMenuGroup.LAYOUT]: {
- title: 'rightClick.insertBellow',
- [InsertBulletListBellowCommand.id]: {
- order: 0,
- menuItemFactory: InsertBulletListBellowMenuItemFactory,
- },
- [InsertOrderListBellowCommand.id]: {
- order: 1,
- menuItemFactory: InsertOrderListBellowMenuItemFactory,
- },
- [InsertCheckListBellowCommand.id]: {
- order: 2,
- menuItemFactory: InsertCheckListBellowMenuItemFactory,
- },
- [InsertHorizontalLineBellowCommand.id]: {
- order: 3,
- menuItemFactory: InsertHorizontalLineBellowMenuItemFactory,
+ // title: 'rightClick.insertBellow',
+ [INSERT_BELLOW_MENU_ID]: {
+ menuItemFactory: DocInsertBellowMenuItemFactory,
+ [InsertBulletListBellowCommand.id]: {
+ order: 0,
+ menuItemFactory: InsertBulletListBellowMenuItemFactory,
+ },
+ [InsertOrderListBellowCommand.id]: {
+ order: 1,
+ menuItemFactory: InsertOrderListBellowMenuItemFactory,
+ },
+ [InsertCheckListBellowCommand.id]: {
+ order: 2,
+ menuItemFactory: InsertCheckListBellowMenuItemFactory,
+ },
+ [InsertHorizontalLineBellowCommand.id]: {
+ order: 3,
+ menuItemFactory: InsertHorizontalLineBellowMenuItemFactory,
+ },
},
},
},
diff --git a/packages/docs-ui/src/controllers/menu/paragraph-menu.ts b/packages/docs-ui/src/controllers/menu/paragraph-menu.ts
index 2c55606c90..ee94065653 100644
--- a/packages/docs-ui/src/controllers/menu/paragraph-menu.ts
+++ b/packages/docs-ui/src/controllers/menu/paragraph-menu.ts
@@ -15,7 +15,7 @@
*/
import type { IAccessor, ICommand } from '@univerjs/core';
-import type { IMenuItem } from '@univerjs/ui';
+import type { IMenuItem, IMenuSelectorItem } from '@univerjs/ui';
import { ICommandService, NamedStyleType, UniverInstanceType } from '@univerjs/core';
import { SetTextSelectionsOperation } from '@univerjs/docs';
import { H1Single, H2Single, H3Single, H4Single, H5Single, TextTypeSingle } from '@univerjs/icons';
@@ -158,15 +158,6 @@ export const InsertCheckListBellowMenuItemFactory = (accessor: IAccessor): IMenu
};
};
-// export const InsertTableBellowMenuItemFactory = (accessor: IAccessor): IMenuItem => {
-// return {
-// id: InsertTableBellowCommand.id,
-// type: MenuItemType.BUTTON,
-// icon: 'Table',
-// title: 'rightClick.insertTableBellow',
-// };
-// };
-
export const InsertHorizontalLineBellowMenuItemFactory = (accessor: IAccessor): IMenuItem => {
return {
id: InsertHorizontalLineBellowCommand.id,
@@ -175,3 +166,14 @@ export const InsertHorizontalLineBellowMenuItemFactory = (accessor: IAccessor):
title: 'toolbar.horizontalLine',
};
};
+
+export const INSERT_BELLOW_MENU_ID = 'doc.menu.insert-bellow';
+
+export function DocInsertBellowMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ return {
+ id: INSERT_BELLOW_MENU_ID,
+ type: MenuItemType.SUBITEMS,
+ title: 'rightClick.insertBellow',
+ icon: 'FreezeToSelectedSingle',
+ };
+}
diff --git a/packages/ui/src/components/menu/desktop/Menu.tsx b/packages/ui/src/components/menu/desktop/Menu.tsx
index 2515d2979a..2d8df44efd 100644
--- a/packages/ui/src/components/menu/desktop/Menu.tsx
+++ b/packages/ui/src/components/menu/desktop/Menu.tsx
@@ -59,6 +59,7 @@ export interface IBaseMenuProps {
*/
overViewport?: 'scroll';
onOptionSelect?: (option: IValueOption) => void;
+ style?: React.CSSProperties;
}
/** @deprecated */
@@ -187,7 +188,7 @@ function MenuOptionsWrapper(props: IBaseMenuProps) {
/** @deprecated */
export const Menu = (props: IBaseMenuProps) => {
- const { overViewport, ...restProps } = props;
+ const { overViewport, style, ...restProps } = props;
const [menuEl, setMenuEl] = useState<HTMLDListElement>();
const layoutService = useDependency(ILayoutService);
@@ -200,6 +201,7 @@ export const Menu = (props: IBaseMenuProps) => {
}
return (
<DesignMenu
+ style={style}
ref={handleSetMenuEl}
selectable={false}
>