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): polish paragraph T menu (#7393)

Univer6104807c82b9
diff --git a/packages/docs-ui/src/menu/paragraph-menu.ts b/packages/docs-ui/src/menu/paragraph-menu.ts
index efb5622494..6aa334af99 100644
--- a/packages/docs-ui/src/menu/paragraph-menu.ts
+++ b/packages/docs-ui/src/menu/paragraph-menu.ts
@@ -95,7 +95,6 @@ export const BACKGROUND_COLOR_SWATCH_ICONS = [
'DocParagraphBackgroundColorSwatchIcon.12',
'DocParagraphBackgroundColorSwatchIcon.13',
'DocParagraphBackgroundColorSwatchIcon.14',
- 'DocParagraphBackgroundColorSwatchIcon.15',
] as const;
function getHeadingActivatedObservable(accessor: IAccessor, headingType: NamedStyleType): Observable<boolean> {
diff --git a/packages/docs-ui/src/views/Icon.tsx b/packages/docs-ui/src/views/Icon.tsx
index d4a84b93a3..f79f560591 100644
--- a/packages/docs-ui/src/views/Icon.tsx
+++ b/packages/docs-ui/src/views/Icon.tsx
@@ -92,22 +92,23 @@ export function TextColorSwatchIcon({ className, style, onClick, color }: ColorS
onClick={onClick}
>
<rect
- x={3}
- y={3}
- width={18}
- height={18}
- rx={4}
+ x={1}
+ y={1}
+ width={22}
+ height={22}
+ rx={2.5}
fill="none"
stroke="currentColor"
- strokeOpacity={0.16}
+ strokeWidth={1}
+ strokeOpacity={0.12}
/>
<text
x={12}
- y={16.5}
+ y={17.25}
direction="ltr"
fontFamily="Arial, sans-serif"
- fontSize={12}
- fontWeight={700}
+ fontSize={15}
+ fontWeight={400}
fill={color}
textAnchor="middle"
>
@@ -134,7 +135,7 @@ export function BackgroundColorSwatchIcon({ className, style, onClick, color }:
y={3}
width={18}
height={18}
- rx={5}
+ rx={3}
fill={color}
stroke="currentColor"
strokeOpacity={0.12}
diff --git a/packages/docs-ui/src/views/ParagraphMenu.tsx b/packages/docs-ui/src/views/ParagraphMenu.tsx
index edfb32e78e..250ec9c10c 100644
--- a/packages/docs-ui/src/views/ParagraphMenu.tsx
+++ b/packages/docs-ui/src/views/ParagraphMenu.tsx
@@ -141,6 +141,10 @@ const PARAGRAPH_MENU_HOVER_BRIDGE_EDGE_OVERLAP = 12;
const PARAGRAPH_MENU_HOVER_BRIDGE_VERTICAL_PADDING = 8;
type ParagraphMenuOpenMode = 'pointer' | 'slash';
+function getParagraphMenuIconSizeClass(iconKey: string): string {
+ return iconKey === 'TextTypeIcon' ? 'univer-size-3' : 'univer-size-4';
+}
+
export function shouldExecuteParagraphMenuMove(
validatorService: Pick<DocBlockMoveValidatorService, 'canMoveBlock'>,
context: IDocBlockMoveValidationContext
@@ -1298,7 +1302,15 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; t
hoverOpenSchedulerRef.current.openNow();
}}
>
- <TargetIcon />
+ <TargetIcon
+ className={clsx(
+ getParagraphMenuIconSizeClass(targetIconKey),
+ `
+ univer-shrink-0 univer-text-gray-700
+ dark:!univer-text-white
+ `
+ )}
+ />
{currentActiveTarget?.draggable && (
<button
type="button"
@@ -1438,6 +1450,7 @@ function ParagraphMenuBase({ popup, tableBlockOnly = false }: { popup: IPopup; t
<ContextMenuPanel
className="univer-w-[212px]"
menuType={resolvedParagraphMenuType}
+ flowQuickGroups
activeItemIds={currentActiveTarget?.kind === 'table' ? undefined : paragraphMenuActiveItemIds}
hiddenItemIds={openMode === 'slash' || currentActiveTarget?.kind === 'table' ? undefined : paragraphMenuHiddenItemIds}
autoFocus={openMode === 'slash'}
diff --git a/packages/docs-ui/src/views/__tests__/ParagraphMenu.spec.ts b/packages/docs-ui/src/views/__tests__/ParagraphMenu.spec.ts
index 6c6c44cf17..1ef3be3a22 100644
--- a/packages/docs-ui/src/views/__tests__/ParagraphMenu.spec.ts
+++ b/packages/docs-ui/src/views/__tests__/ParagraphMenu.spec.ts
@@ -21,6 +21,7 @@ import type { IMutiPageParagraphBound } from '../../services/doc-event-manager.s
import type { IDocBlockMenuTarget } from '../../services/doc-paragraph-menu.service';
import { DataStreamTreeTokenType, DocumentBlockRangeType, DocumentBlockType, JSONX, NamedStyleType } from '@univerjs/core';
import { DocBlockMoveValidatorService } from '@univerjs/docs';
+import { ContextMenuPosition } from '@univerjs/ui';
import { describe, expect, it } from 'vitest';
import {
DocCopyCurrentParagraphCommand,
@@ -32,7 +33,15 @@ import { HorizontalLineCommand } from '../../commands/commands/doc-horizontal-li
import { BulletListCommand } from '../../commands/commands/list.command';
import { AlignCenterCommand } from '../../commands/commands/paragraph-align.command';
import { H2HeadingCommand, SetParagraphNamedStyleCommand } from '../../commands/commands/set-heading.command';
-import { DOC_PARAGRAPH_T_EDIT_MENU_ID, INSERT_BELLOW_MENU_ID } from '../../menu/paragraph-menu';
+import {
+ BACKGROUND_COLOR_SWATCH_ICONS,
+ DOC_PARAGRAPH_T_EDIT_MENU_ID,
+ DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID,
+ DOC_PARAGRAPH_T_INSERT_MENU_ID,
+ INSERT_BELLOW_MENU_ID,
+ ParagraphMenuBackgroundColorSwatchMenuItemFactories,
+} from '../../menu/paragraph-menu';
+import { menuSchema } from '../../menu/schema';
import {
buildUnwrapBlockRangeActions,
getBlockRangeClipboardTargetRange,
@@ -96,6 +105,29 @@ function blockRangeBody(blockType: DocumentBlockRangeType, paragraphStyle: IPara
}
describe('ParagraphMenu command behavior', () => {
+ it('keeps the extensible T menu quick-action groups configured as icon grids', () => {
+ for (const menuId of [
+ DOC_PARAGRAPH_T_INSERT_MENU_ID,
+ DOC_PARAGRAPH_T_INSERT_BELOW_MENU_ID,
+ DOC_PARAGRAPH_T_EDIT_MENU_ID,
+ ]) {
+ expect(menuSchema).toHaveProperty(
+ [ContextMenuPosition.PARAGRAPH, menuId, 'quickTop', 'quickLayout'],
+ 'icon'
+ );
+ expect(menuSchema).toHaveProperty(
+ [ContextMenuPosition.PARAGRAPH, menuId, 'quickBottom', 'quickLayout'],
+ 'icon'
+ );
+ }
+ });
+
+ it('keeps the background palette within two eight-column rows', () => {
+ expect(BACKGROUND_COLOR_SWATCH_ICONS).toHaveLength(15);
+ expect(Object.keys(ParagraphMenuBackgroundColorSwatchMenuItemFactories)).toHaveLength(15);
+ expect(BACKGROUND_COLOR_SWATCH_ICONS).not.toContain('DocParagraphBackgroundColorSwatchIcon.15');
+ });
+
it('places the root menu on the right in rtl so submenus can open to the left', () => {
expect(getParagraphMenuPopupDirection(300, 212, 8, {
anchorRight: 340,
diff --git a/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx b/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx
index 73dac2166c..24ba9f598e 100644
--- a/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx
+++ b/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx
@@ -49,6 +49,7 @@ interface IContextMenuPanelProps {
className?: string;
activeItemIds?: string[];
hiddenItemIds?: string[];
+ flowQuickGroups?: boolean;
sizeVariant?: ContextMenuSizeVariant;
autoFocus?: boolean;
autoFocusTarget?: ContextMenuAutoFocusTarget;
@@ -68,6 +69,7 @@ interface IContextMenuMenuProps {
maxMenuHeight: number;
activeItemIds?: string[];
hiddenItemIds?: string[];
+ flowQuickGroups?: boolean;
hoverSuppressed?: boolean;
sizeVariant: ContextMenuSizeVariant;
onMenuPointerEnter?: () => void;
@@ -432,20 +434,18 @@ function getContextMenuGroupClassName(sizeVariant: ContextMenuSizeVariant) {
return contextMenuGroupVariants({ sizeVariant });
}
-function isParagraphTHeaderQuickGroup(menuSchema: IMenuSchema, sizeVariant: ContextMenuSizeVariant) {
- return sizeVariant === 'paragraph-t'
- && menuSchema.quickLayout === 'icon'
+function isHeaderQuickGroup(menuSchema: IMenuSchema) {
+ return menuSchema.quickLayout === 'icon'
&& CONTEXT_MENU_HEADER_QUICK_GROUP_KEYS.has(menuSchema.key);
}
-function shouldClusterParagraphTHeaderQuickGroups(
+function shouldClusterHeaderQuickGroups(
currentSchema: IMenuSchema,
- nextSchema: IMenuSchema | undefined,
- sizeVariant: ContextMenuSizeVariant
+ nextSchema: IMenuSchema | undefined
) {
- return isParagraphTHeaderQuickGroup(currentSchema, sizeVariant)
+ return isHeaderQuickGroup(currentSchema)
&& !!nextSchema
- && isParagraphTHeaderQuickGroup(nextSchema, sizeVariant);
+ && isHeaderQuickGroup(nextSchema);
}
function getContextMenuQuickGroupClassName(
@@ -604,7 +604,7 @@ export function getNextMenuButtonByDirection(
export function getContextMenuSchemaRenderGroups(
visibleSchemas: IMenuSchema[],
- sizeVariant: ContextMenuSizeVariant
+ flowQuickGroups = false
): IContextMenuSchemaRenderGroup[] {
const renderGroups: IContextMenuSchemaRenderGroup[] = [];
@@ -612,7 +612,7 @@ export function getContextMenuSchemaRenderGroups(
const menuSchema = visibleSchemas[index];
const nextSchema = visibleSchemas[index + 1];
- if (shouldClusterParagraphTHeaderQuickGroups(menuSchema, nextSchema, sizeVariant)) {
+ if (flowQuickGroups && shouldClusterHeaderQuickGroups(menuSchema, nextSchema)) {
renderGroups.push({
startIndex: index,
endIndex: index + 1,
@@ -632,6 +632,17 @@ export function getContextMenuSchemaRenderGroups(
return renderGroups;
}
+function mergeContextMenuQuickGroupSchemas(menuSchemas: IMenuSchema[]): IMenuSchema {
+ const firstSchema = menuSchemas[0];
+
+ return {
+ ...firstSchema,
+ key: menuSchemas.map((schema) => schema.key).join('-'),
+ quickColumns: getContextMenuQuickGroupColumns(firstSchema),
+ children: menuSchemas.flatMap((schema) => schema.children ?? []),
+ };
+}
+
function getContextMenuHeaderClassName(sizeVariant: ContextMenuSizeVariant) {
return contextMenuHeaderVariants({ sizeVariant });
}
@@ -653,6 +664,7 @@ export function ContextMenuPanel(props: IContextMenuPanelProps) {
className,
activeItemIds,
hiddenItemIds,
+ flowQuickGroups,
sizeVariant = 'default',
autoFocus,
autoFocusTarget = 'first-item',
@@ -821,6 +833,7 @@ export function ContextMenuPanel(props: IContextMenuPanelProps) {
rootMenuElement={menuElement}
activeItemIds={activeItemIds}
hiddenItemIds={hiddenItemIds}
+ flowQuickGroups={flowQuickGroups}
hoverSuppressed={hoverSuppressed}
sizeVariant={sizeVariant}
onMenuPointerEnter={onMenuPointerEnter}
@@ -833,7 +846,7 @@ export function ContextMenuPanel(props: IContextMenuPanelProps) {
}
function ContextMenuMenu(props: IContextMenuMenuProps) {
- const { menuSchemas, menuManagerService, menuSessionVersion, submenuPortalContainer, rootMenuElement, activeItemIds, hiddenItemIds, hoverSuppressed, sizeVariant, onMenuPointerEnter, onMenuPointerLeave, onOptionSelect, maxMenuHeight } = props;
+ const { menuSchemas, menuManagerService, menuSessionVersion, submenuPortalContainer, rootMenuElement, activeItemIds, hiddenItemIds, flowQuickGroups, hoverSuppressed, sizeVariant, onMenuPointerEnter, onMenuPointerLeave, onOptionSelect, maxMenuHeight } = props;
const localeService = useDependency(LocaleService);
const hiddenGroupStates = useContextGroupHiddenStates(menuSchemas);
const [activeSubmenuKey, setActiveSubmenuKey] = useState<string | null>(null);
@@ -852,8 +865,8 @@ function ContextMenuMenu(props: IContextMenuMenuProps) {
});
}, [hiddenGroupStates, menuSchemas]);
const renderGroups = useMemo(
- () => getContextMenuSchemaRenderGroups(visibleSchemas, sizeVariant),
- [sizeVariant, visibleSchemas]
+ () => getContextMenuSchemaRenderGroups(visibleSchemas, flowQuickGroups),
+ [flowQuickGroups, visibleSchemas]
);
const renderQuickLayoutGroup = (
@@ -909,6 +922,8 @@ function ContextMenuMenu(props: IContextMenuMenuProps) {
const titleNode = renderMenuSchemaHeader(menuSchema);
if (groupedSchemas.length > 1) {
+ const mergedMenuSchema = mergeContextMenuQuickGroupSchemas(groupedSchemas);
+
return (
<div
key={groupedSchemas.map((schema) => schema.key).join('-')}
@@ -917,11 +932,7 @@ function ContextMenuMenu(props: IContextMenuMenuProps) {
hasSeparator && borderBottomClassName
)}
>
- {groupedSchemas.map((groupedMenuSchema, groupedIndex) => renderQuickLayoutGroup(
- groupedMenuSchema,
- startIndex + groupedIndex,
- true
- ))}
+ {renderQuickLayoutGroup(mergedMenuSchema, startIndex, true)}
</div>
);
}
diff --git a/packages/ui/src/views/components/context-menu/__tests__/ContextMenuPanel.spec.tsx b/packages/ui/src/views/components/context-menu/__tests__/ContextMenuPanel.spec.tsx
index ee82be61d4..df388583af 100644
--- a/packages/ui/src/views/components/context-menu/__tests__/ContextMenuPanel.spec.tsx
+++ b/packages/ui/src/views/components/context-menu/__tests__/ContextMenuPanel.spec.tsx
@@ -176,7 +176,24 @@ describe('ContextMenuPanel', () => {
expect(shouldShowContextMenuGroupSeparator(schemas, 0)).toBe(false);
expect(shouldShowContextMenuGroupSeparator(schemas, 1)).toBe(true);
- expect(getContextMenuSchemaRenderGroups(schemas, 'paragraph-t')).toEqual([
+ expect(getContextMenuSchemaRenderGroups(schemas)).toEqual([
+ {
+ startIndex: 0,
+ endIndex: 0,
+ menuSchemas: [schemas[0]],
+ },
+ {
+ startIndex: 1,
+ endIndex: 1,
+ menuSchemas: [schemas[1]],
+ },
+ {
+ startIndex: 2,
+ endIndex: 2,
+ menuSchemas: [schemas[2]],
+ },
+ ]);
+ expect(getContextMenuSchemaRenderGroups(schemas, true)).toEqual([
{
startIndex: 0,
endIndex: 1,
@@ -192,10 +209,11 @@ describe('ContextMenuPanel', () => {
});
it('renders paragraph quick menus with real tiny groups and submits the clicked command', () => {
- renderWithDependencies(
+ const { container } = renderWithDependencies(
<ContextMenuPanel
menuType="paragraph-menu"
sizeVariant="paragraph-t"
+ flowQuickGroups
activeItemIds={['align-center']}
hiddenItemIds={['reset-format']}
onOptionSelect={(option) => TestState.selectedOptions.push(option)}
@@ -224,6 +242,10 @@ describe('ContextMenuPanel', () => {
order: 1,
quickLayout: 'icon',
children: [
+ createButtonItem('extension-item', {
+ icon: 'ResetIcon',
+ tooltip: 'extension-item',
+ }),
createButtonItem('reset-format', {
icon: 'ResetIcon',
tooltip: 'docs-ui.toolbar.resetFormat',
@@ -244,7 +266,11 @@ describe('ContextMenuPanel', () => {
}
);
+ const quickGrids = container.querySelectorAll('.univer-menu-item-group');
+ expect(quickGrids).toHaveLength(1);
+ expect(hasClassToken(quickGrids[0] as HTMLElement, 'univer-grid-cols-6')).toBe(true);
expect(screen.getByText('translated:docs-ui.paragraphMenu.align')).not.toBeNull();
+ expect(screen.getByRole('button', { name: 'translated:extension-item' })).not.toBeNull();
expect(screen.queryByRole('button', { name: 'translated:docs-ui.toolbar.resetFormat' })).toBeNull();
const alignCenterButton = screen.getByRole('button', { name: 'translated:docs-ui.toolbar.alignCenter' });