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(ui): improve RTL layout support (#7440)

白熱185b9169aead
diff --git a/packages/design/src/components/accordion/Accordion.tsx b/packages/design/src/components/accordion/Accordion.tsx
index 7ceeabb93c..d4c0e9945d 100644
--- a/packages/design/src/components/accordion/Accordion.tsx
+++ b/packages/design/src/components/accordion/Accordion.tsx
@@ -70,8 +70,9 @@ export function Accordion(props: IAccordionProps) {
onClick={() => toggleItem(index)}
>
<DownIcon
+ aria-hidden="true"
className={clsx('univer-size-2.5 univer-flex-shrink-0 univer-transition-transform', {
- '-univer-rotate-90': openIndex !== index,
+ '-univer-rotate-90 rtl:univer-rotate-90': openIndex !== index,
'univer-rotate-0': openIndex === index,
})}
/>
diff --git a/packages/design/src/components/accordion/__tests__/index.spec.tsx b/packages/design/src/components/accordion/__tests__/index.spec.tsx
index e8edc3a58f..97c01d5319 100644
--- a/packages/design/src/components/accordion/__tests__/index.spec.tsx
+++ b/packages/design/src/components/accordion/__tests__/index.spec.tsx
@@ -28,14 +28,18 @@ describe('Accordion', () => {
{ label: 'Item 3', children: <div>Content 3</div> },
];
const { getByText, queryByText } = render(<Accordion items={items} />);
+ const firstTrigger = getByText('Item 1').closest('button');
+ const firstArrow = firstTrigger?.querySelector('[aria-hidden="true"]');
// Should be hidden by default
+ expect(firstArrow?.getAttribute('class')).toContain('rtl:univer-rotate-90');
expect(queryByText('Content 1')?.parentElement?.parentElement?.className).toContain('univer-max-h-0');
expect(queryByText('Content 2')?.parentElement?.parentElement?.className).toContain('univer-max-h-0');
expect(queryByText('Content 3')?.parentElement?.parentElement?.className).toContain('univer-max-h-0');
// Should expand the first item
fireEvent.click(getByText('Item 1'));
+ expect(firstArrow?.getAttribute('class')).not.toContain('rtl:univer-rotate-90');
expect(getByText('Content 1').parentElement?.parentElement?.className).toContain('univer-max-h-screen');
expect(queryByText('Content 2')?.parentElement?.parentElement?.className).toContain('univer-max-h-0');
expect(queryByText('Content 3')?.parentElement?.parentElement?.className).toContain('univer-max-h-0');
diff --git a/packages/design/src/components/color-picker/ColorPicker.tsx b/packages/design/src/components/color-picker/ColorPicker.tsx
index d6d6373850..0c863b829b 100644
--- a/packages/design/src/components/color-picker/ColorPicker.tsx
+++ b/packages/design/src/components/color-picker/ColorPicker.tsx
@@ -131,6 +131,7 @@ export function ColorPicker({ format = 'hex', value, onChange }: IColorPickerPro
<Dialog
className="!univer-z-[1090] !univer-w-fit !univer-p-2.5"
+ overlayClassName="!univer-z-[1090]"
closable={false}
maskClosable={false}
open={visible}
diff --git a/packages/design/src/components/color-picker/__tests__/index.spec.tsx b/packages/design/src/components/color-picker/__tests__/index.spec.tsx
index b81178768e..ee215f061f 100644
--- a/packages/design/src/components/color-picker/__tests__/index.spec.tsx
+++ b/packages/design/src/components/color-picker/__tests__/index.spec.tsx
@@ -96,7 +96,10 @@ describe('ColorPicker', () => {
fireEvent.click(moreLink);
const dialog = document.querySelector('[role="dialog"]');
+ const overlay = document.querySelector('[data-state="open"].univer-fixed.univer-inset-0');
+
expect(dialog?.className).toContain('!univer-z-[1090]');
+ expect(overlay?.className).toContain('!univer-z-[1090]');
});
it('should call onChange when rgb input changes in dialog', () => {
diff --git a/packages/design/src/components/dialog/Dialog.tsx b/packages/design/src/components/dialog/Dialog.tsx
index 35d0747de4..ce45fe4510 100644
--- a/packages/design/src/components/dialog/Dialog.tsx
+++ b/packages/design/src/components/dialog/Dialog.tsx
@@ -86,6 +86,11 @@ export interface IDialogProps {
*/
className?: string;
+ /**
+ * Additional className for the dialog overlay.
+ */
+ overlayClassName?: string;
+
/**
* whether show close button
*/
@@ -244,6 +249,7 @@ function useDraggable(
export function Dialog(props: IDialogProps) {
const {
className,
+ overlayClassName,
children,
style,
open = false,
@@ -337,6 +343,7 @@ export function Dialog(props: IDialogProps) {
}}
closable={closable}
mountContainer={mountContainer}
+ overlayClassName={overlayClassName}
dir={direction}
onClickClose={handleClickClose}
onEscapeKeyDown={(e) => {
diff --git a/packages/design/src/components/dialog/DialogPrimitive.tsx b/packages/design/src/components/dialog/DialogPrimitive.tsx
index be7d16fbed..7642d5669c 100644
--- a/packages/design/src/components/dialog/DialogPrimitive.tsx
+++ b/packages/design/src/components/dialog/DialogPrimitive.tsx
@@ -52,13 +52,14 @@ interface IDialogContentProps {
closable?: boolean;
onClickClose?: () => void;
mountContainer?: HTMLElement | null;
+ overlayClassName?: string;
}
const DialogContent = forwardRef<
ElementRef<typeof Content>,
ComponentPropsWithoutRef<typeof Content> & IDialogContentProps
->(({ className, children, closable = true, onClickClose, mountContainer, ...props }, ref) => (
+>(({ className, children, closable = true, onClickClose, mountContainer, overlayClassName, ...props }, ref) => (
<DialogPortal container={mountContainer ?? undefined}>
- <DialogOverlay />
+ <DialogOverlay className={overlayClassName} />
<Content
ref={ref}
className={clsx(
diff --git a/packages/design/src/components/panel/Panel.tsx b/packages/design/src/components/panel/Panel.tsx
index 62c9daf315..29c78007e7 100644
--- a/packages/design/src/components/panel/Panel.tsx
+++ b/packages/design/src/components/panel/Panel.tsx
@@ -78,8 +78,9 @@ export function PanelSection(props: IPanelSectionProps) {
>
{collapsible && (
<DownIcon
+ aria-hidden="true"
className={clsx('univer-size-2.5 univer-flex-shrink-0 univer-transition-transform', {
- '-univer-rotate-90': !expanded,
+ '-univer-rotate-90 rtl:univer-rotate-90': !expanded,
'univer-rotate-0': expanded,
})}
/>
diff --git a/packages/design/src/components/panel/__tests__/Panel.spec.tsx b/packages/design/src/components/panel/__tests__/Panel.spec.tsx
index 69f6d636e4..26d2d6b7be 100644
--- a/packages/design/src/components/panel/__tests__/Panel.spec.tsx
+++ b/packages/design/src/components/panel/__tests__/Panel.spec.tsx
@@ -52,6 +52,7 @@ describe('PanelSection', () => {
expect(button).toHaveAttribute('aria-expanded', 'true');
fireEvent.click(button);
+ expect(button.querySelector('[aria-hidden="true"]')?.getAttribute('class')).toContain('rtl:univer-rotate-90');
expect(button).toHaveAttribute('aria-expanded', 'false');
fireEvent.click(button);
diff --git a/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx b/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx
index 3e13e47f53..548daf21c5 100644
--- a/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx
+++ b/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx
@@ -24,7 +24,6 @@ import {
LocateFixedIcon,
LockIcon,
MoreDownIcon,
- MoreRightIcon,
UnlockIcon,
} from '@univerjs/icons';
import { useEffect, useMemo, useRef, useState } from 'react';
@@ -476,7 +475,11 @@ export function ObjectListPanelBase(props: IObjectListPanelBaseProps) {
univer-items-center univer-justify-center
"
>
- {sectionCollapsed ? <MoreRightIcon /> : <MoreDownIcon />}
+ <MoreDownIcon
+ className={clsx({
+ '-univer-rotate-90 rtl:univer-rotate-90': sectionCollapsed,
+ })}
+ />
</span>
)
: <span className="univer-size-4 univer-shrink-0" />}
@@ -658,7 +661,11 @@ function ObjectListRow(props: {
onToggleExpanded();
}}
>
- {item.expanded ? <MoreDownIcon /> : <MoreRightIcon />}
+ <MoreDownIcon
+ className={clsx({
+ '-univer-rotate-90 rtl:univer-rotate-90': !item.expanded,
+ })}
+ />
</button>
)
: <span className="univer-size-5 univer-shrink-0" />}
diff --git a/packages/find-replace/src/controllers/__tests__/find-replace.controller.spec.ts b/packages/find-replace/src/controllers/__tests__/find-replace.controller.spec.ts
new file mode 100644
index 0000000000..e0679ba1ec
--- /dev/null
+++ b/packages/find-replace/src/controllers/__tests__/find-replace.controller.spec.ts
@@ -0,0 +1,33 @@
+/**
+ * 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 { afterEach, describe, expect, it } from 'vitest';
+import { getFindReplaceDialogDefaultPosition } from '../find-replace.controller';
+
+const ORIGINAL_INNER_WIDTH = window.innerWidth;
+
+afterEach(() => {
+ Object.defineProperty(window, 'innerWidth', { configurable: true, value: ORIGINAL_INNER_WIDTH });
+});
+
+describe('getFindReplaceDialogDefaultPosition', () => {
+ it('anchors the dialog to the matching physical edge for each UI direction', () => {
+ Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1000 });
+
+ expect(getFindReplaceDialogDefaultPosition('ltr')).toEqual({ x: 630, y: 64 });
+ expect(getFindReplaceDialogDefaultPosition('rtl')).toEqual({ x: 20, y: 64 });
+ });
+});
diff --git a/packages/find-replace/src/controllers/find-replace.controller.ts b/packages/find-replace/src/controllers/find-replace.controller.ts
index 8afd5d3c4b..e2115392f8 100644
--- a/packages/find-replace/src/controllers/find-replace.controller.ts
+++ b/packages/find-replace/src/controllers/find-replace.controller.ts
@@ -48,7 +48,7 @@ import {
const FIND_REPLACE_DIALOG_ID = 'DESKTOP_FIND_REPLACE_DIALOG';
const FIND_REPLACE_PANEL_WIDTH = 350;
-const FIND_REPLACE_PANEL_RIGHT_PADDING = 20;
+const FIND_REPLACE_PANEL_HORIZONTAL_PADDING = 20;
const FIND_REPLACE_PANEL_TOP_PADDING = 64;
export class FindReplaceController extends RxDisposable {
@@ -122,7 +122,7 @@ export class FindReplaceController extends RxDisposable {
children: { label: 'FindReplaceDialog' },
mask: false,
maskClosable: false,
- defaultPosition: getFindReplaceDialogDefaultPosition(),
+ defaultPosition: getFindReplaceDialogDefaultPosition(this._localeService.getDirection()),
preservePositionOnDestroy: true,
onClose: () => this.closePanel(),
});
@@ -152,9 +152,11 @@ export class FindReplaceController extends RxDisposable {
}
}
-function getFindReplaceDialogDefaultPosition(): { x: number; y: number } {
+export function getFindReplaceDialogDefaultPosition(direction: 'ltr' | 'rtl'): { x: number; y: number } {
const { innerWidth } = window;
- const x = (innerWidth - FIND_REPLACE_PANEL_WIDTH) - FIND_REPLACE_PANEL_RIGHT_PADDING;
+ const x = direction === 'rtl'
+ ? FIND_REPLACE_PANEL_HORIZONTAL_PADDING
+ : (innerWidth - FIND_REPLACE_PANEL_WIDTH) - FIND_REPLACE_PANEL_HORIZONTAL_PADDING;
const y = FIND_REPLACE_PANEL_TOP_PADDING;
return { x, y };
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx
index dfa38e5ad3..8693f1cfb5 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleList.tsx
@@ -304,7 +304,7 @@ export function RuleList(props: IRuleListProps) {
/>
).map((ele, index) => <span key={index}>{ele}</span>)}
</div>
- <div className="univer-flex univer-justify-end univer-space-x-2">
+ <div className="univer-flex univer-justify-end univer-gap-2">
<Tooltip title={localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.createRule')} placement="bottom">
<a
className="univer-size-5 univer-cursor-pointer"
@@ -351,6 +351,7 @@ export function RuleList(props: IRuleListProps) {
univer-group univer-relative univer-flex univer-items-center univer-justify-between
univer-rounded univer-py-2 univer-pl-5 univer-pr-8
hover:univer-bg-gray-100
+ rtl:univer-pl-8 rtl:univer-pr-5
dark:hover:!univer-bg-gray-700
`, {
'univer-bg-gray-100 dark:!univer-bg-gray-700': draggingId === rule.cfId,
@@ -368,6 +369,7 @@ export function RuleList(props: IRuleListProps) {
univer-absolute univer-left-0 univer-hidden univer-size-5 univer-cursor-grab
univer-items-center univer-justify-center univer-rounded
group-hover:univer-flex
+ rtl:univer-left-auto rtl:univer-right-0
`, 'draggableHandle')}
onClick={(e) => e.stopPropagation()}
>
@@ -402,6 +404,7 @@ export function RuleList(props: IRuleListProps) {
univer-items-center univer-justify-center univer-rounded univer-text-red-500
group-hover:univer-flex
hover:univer-bg-gray-200
+ rtl:univer-left-1 rtl:univer-right-auto
`, {
'univer-flex univer-items-center univer-justify-center': draggingId === rule.cfId,
})}
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/__tests__/RuleList.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/__tests__/RuleList.spec.tsx
index a0db80d471..2d734e21d0 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/__tests__/RuleList.spec.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/__tests__/RuleList.spec.tsx
@@ -489,6 +489,39 @@ describe('RuleList', () => {
).toEqual(ruleIdsBeforeCreate);
});
+ it('mirrors rule list controls in RTL layouts', async () => {
+ currentTestBed = await createRuleListTestBed();
+ container = document.createElement('div');
+ container.dir = 'rtl';
+ document.body.appendChild(container);
+ root = createRoot(container);
+
+ await act(async () => {
+ root!.render(
+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>
+ <RuleList onClick={() => undefined} onCreate={() => undefined} />
+ </RediContext.Provider>
+ );
+ await Promise.resolve();
+ });
+
+ const createRuleButton = container.querySelectorAll('a')[0];
+ const actionGroup = createRuleButton?.parentElement?.parentElement;
+ const draggableItem = container.querySelector<HTMLElement>('[data-draggable-list-item-id]');
+ const ruleRow = draggableItem?.firstElementChild as HTMLElement | undefined;
+ const dragHandle = ruleRow?.querySelector<HTMLElement>('.draggableHandle');
+ const deleteControl = ruleRow?.lastElementChild as HTMLElement | undefined;
+
+ expect(actionGroup?.className).toContain('univer-gap-2');
+ expect(actionGroup?.className).not.toContain('univer-space-x-2');
+ expect(ruleRow?.className).toContain('rtl:univer-pl-8');
+ expect(ruleRow?.className).toContain('rtl:univer-pr-5');
+ expect(dragHandle?.className).toContain('rtl:univer-left-auto');
+ expect(dragHandle?.className).toContain('rtl:univer-right-0');
+ expect(deleteControl?.className).toContain('rtl:univer-left-1');
+ expect(deleteControl?.className).toContain('rtl:univer-right-auto');
+ });
+
it('moves a dragged worksheet rule after the drop target rule', async () => {
currentTestBed = await createRuleListTestBed();
container = document.createElement('div');
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx
index 96a3273ac8..93a3c6d334 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx
@@ -138,7 +138,11 @@ const IconGroupList = (props: IIconGroupListProps) => {
>
{localeService.t(group.title)}
</div>
- <div className="univer-grid univer-grid-cols-2 univer-gap-1">
+ <div
+ dir={direction}
+ data-u-comp="cf-icon-set-group-grid"
+ className="univer-grid univer-grid-cols-2 univer-gap-1"
+ >
{group.group.map((groupItem, groupItemIndex) => {
const selected = groupItem.name === iconType;
return (
@@ -150,11 +154,10 @@ const IconGroupList = (props: IIconGroupListProps) => {
className={clsx(
`
univer-flex univer-h-8 univer-w-full univer-cursor-pointer
- univer-items-center univer-rounded-md univer-border-0
+ univer-items-center univer-justify-start univer-rounded-md univer-border-0
univer-bg-transparent univer-px-2 univer-outline-none
univer-transition-colors
focus-visible:univer-ring-2 focus-visible:univer-ring-primary-600
- rtl:univer-flex-row-reverse
`,
selected
? `
@@ -168,7 +171,7 @@ const IconGroupList = (props: IIconGroupListProps) => {
)}
onClick={() => { onClick(groupItem.name); }}
>
- <span className="univer-flex univer-items-center univer-gap-0.5">
+ <span dir={direction} className="univer-flex univer-items-center univer-gap-0.5">
{groupItem.list.map((base64, index) => (
<img
key={index}
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/RuleEditors.spec.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/RuleEditors.spec.tsx
index 2f03f23135..513f53d293 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/RuleEditors.spec.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/__tests__/RuleEditors.spec.tsx
@@ -186,6 +186,31 @@ describe('conditional formatting rule editors', () => {
currentTestBed = undefined;
});
+ it('keeps the icon-set gallery grid RTL when the locale direction is RTL', async () => {
+ currentTestBed = createEditorTestBed();
+ currentTestBed.get(LocaleService).setDirection('rtl');
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+ const interceptorManager = createRuleInterceptorManager();
+
+ await act(async () => {
+ root!.render(
+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>
+ <IconSet interceptorManager={interceptorManager} onChange={() => undefined} />
+ </RediContext.Provider>
+ );
+ await Promise.resolve();
+ });
+
+ await openDropdown(0);
+
+ expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"]')?.getAttribute('dir')).toBe('rtl');
+ expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"] button')?.className).toContain('univer-justify-start');
+ expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"] button > span')?.getAttribute('dir')).toBe('rtl');
+ expect(document.querySelector('[data-u-comp="cf-icon-set-group-grid"] button > span')?.className).not.toContain('univer-flex-row-reverse');
+ });
+
it('blocks submitting an empty text condition and submits the entered text condition rule', async () => {
currentTestBed = createEditorTestBed();
container = document.createElement('div');
diff --git a/packages/sheets-data-validation-ui/src/views/components/DataValidationItem.tsx b/packages/sheets-data-validation-ui/src/views/components/DataValidationItem.tsx
index e0253f1fa4..9d74032f09 100644
--- a/packages/sheets-data-validation-ui/src/views/components/DataValidationItem.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/DataValidationItem.tsx
@@ -81,6 +81,7 @@ export const DataValidationItem = (props: IDataValidationDetailProps) => {
univer-bg-secondary univer-relative univer--mx-2 univer-box-border univer-flex univer-w-[287px]
univer-cursor-pointer univer-flex-col univer-justify-between univer-overflow-hidden univer-rounded-md
univer-p-2 univer-pr-9
+ rtl:univer-pl-9 rtl:univer-pr-2
`,
{
'hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700': !disable,
@@ -127,6 +128,7 @@ export const DataValidationItem = (props: IDataValidationDetailProps) => {
univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-size-5 univer-items-center
univer-justify-center univer-rounded
hover:univer-bg-gray-200
+ rtl:univer-left-2 rtl:univer-right-auto
dark:!univer-text-gray-300
dark:hover:!univer-bg-gray-700
`}
diff --git a/packages/sheets-data-validation-ui/src/views/components/__tests__/DataValidationItem.spec.tsx b/packages/sheets-data-validation-ui/src/views/components/__tests__/DataValidationItem.spec.tsx
index a9e33078e5..ca3f86c41c 100644
--- a/packages/sheets-data-validation-ui/src/views/components/__tests__/DataValidationItem.spec.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/__tests__/DataValidationItem.spec.tsx
@@ -578,9 +578,10 @@ describe('DataValidationItem', () => {
expect(currentTestBed.markSelectionService.removed).toEqual(['shape-0', 'shape-1']);
});
- it('removes the hovered rule through the sheet data-validation command without selecting the item', async () => {
+ it('positions and runs the hovered rule delete action in RTL without selecting the item', async () => {
currentTestBed = createItemTestBed();
container = document.createElement('div');
+ container.dir = 'rtl';
document.body.appendChild(container);
root = createRoot(container);
let selectedCount = 0;
@@ -595,6 +596,11 @@ describe('DataValidationItem', () => {
const deleteButton = container.querySelector('.univer-absolute') as HTMLElement;
+ expect(item.className).toContain('rtl:univer-pl-9');
+ expect(item.className).toContain('rtl:univer-pr-2');
+ expect(deleteButton.className).toContain('rtl:univer-left-2');
+ expect(deleteButton.className).toContain('rtl:univer-right-auto');
+
await act(async () => {
deleteButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
await Promise.resolve();
diff --git a/packages/sheets-table-ui/src/const.ts b/packages/sheets-table-ui/src/const.ts
index 3905c58660..ff7c0ae3de 100644
--- a/packages/sheets-table-ui/src/const.ts
+++ b/packages/sheets-table-ui/src/const.ts
@@ -24,6 +24,7 @@ export const SHEET_TABLE_RENAME_DIALOG_ID = 'SHEET_TABLE_RENAME_DIALOG_ID';
export const SHEET_TABLE_THEME_PANEL_ID = 'SHEET_TABLE_THEME_PANEL_ID';
export const SHEET_TABLE_THEME_PANEL = 'SHEET_TABLE_THEME_PANEL';
+export const SHEET_TABLE_MENU = 'SHEET_TABLE_MENU';
export const TABLE_CUSTOM_NAME_PREFIX = 'table-custom-';
export const TABLE_DEFAULT_NAME_PREFIX = 'table-default-';
diff --git a/packages/sheets-table-ui/src/controllers/__tests__/sheet-table-controls-render.controller.spec.ts b/packages/sheets-table-ui/src/controllers/__tests__/sheet-table-controls-render.controller.spec.ts
index 4777a5601a..b443125823 100644
--- a/packages/sheets-table-ui/src/controllers/__tests__/sheet-table-controls-render.controller.spec.ts
+++ b/packages/sheets-table-ui/src/controllers/__tests__/sheet-table-controls-render.controller.spec.ts
@@ -16,17 +16,29 @@
import { CommandType } from '@univerjs/core';
import { SelectRangeCommand } from '@univerjs/sheets';
+import { DeleteSheetTableCommand } from '@univerjs/sheets-table';
import { MoveSelectionCommand, SelectAllCommand } from '@univerjs/sheets-ui';
import { Subject } from 'rxjs';
import { describe, expect, it, vi } from 'vitest';
+import { SHEET_TABLE_MENU } from '../../const';
import { SheetTableControlsRenderController } from '../sheet-table-controls-render.controller';
-function createController(hasSkeleton = true) {
+interface ITestTable {
+ getId: () => string;
+ getDisplayName: () => string;
+ getRange: () => { startRow: number; endRow: number; startColumn: number; endColumn: number };
+ getTableStyleId: () => string;
+}
+
+function createController(hasSkeleton = true, tables: ITestTable[] = []) {
const activeSheet$ = new Subject();
const currentSkeleton$ = new Subject();
const tableAdd$ = new Subject();
const selectionChanged$ = new Subject();
const sceneMakeDirty = vi.fn();
+ const executeTableCommand = vi.fn();
+ const popupDisposable = { dispose: vi.fn() };
+ const attachPopupByPosition = vi.fn((_bound: unknown, _popup: unknown, _location: unknown) => popupDisposable);
const skeleton = hasSkeleton ? { gapConfig: { rowGaps: {} } } : null;
let commandListener: ((command: { id: string; type: CommandType }) => void) | undefined;
@@ -56,6 +68,7 @@ function createController(hasSkeleton = true) {
commandListener = listener;
return { dispose: vi.fn() };
},
+ executeCommand: executeTableCommand,
} as never,
{
tableAdd$,
@@ -63,7 +76,8 @@ function createController(hasSkeleton = true) {
tableNameChanged$: new Subject(),
tableRangeChanged$: new Subject(),
tableThemeChanged$: new Subject(),
- getTablesBySubunitId: () => [],
+ getTablesBySubunitId: () => tables,
+ getTableById: (_unitId: string, tableId: string) => tables.find((table) => table.getId() === tableId),
} as never,
{ getRangeThemeStyle: vi.fn() } as never,
{ unitPermissionInitStateChange$: new Subject() } as never,
@@ -79,7 +93,8 @@ function createController(hasSkeleton = true) {
{ refreshTable$: new Subject() } as never,
{ t: (key: string) => key } as never,
{} as never,
- {} as never
+ {} as never,
+ { attachPopupByPosition } as never
);
sceneMakeDirty.mockClear();
@@ -88,6 +103,9 @@ function createController(hasSkeleton = true) {
sceneMakeDirty,
selectionChanged$,
tableAdd$,
+ attachPopupByPosition,
+ executeTableCommand,
+ popupDisposable,
executeCommand: (command: { id: string; type: CommandType }) => commandListener?.(command),
};
}
@@ -126,4 +144,56 @@ describe('SheetTableControlsRenderController', () => {
controller.dispose();
});
+
+ it('opens the registered design menu and routes its actions through the existing table commands', async () => {
+ const table: ITestTable = {
+ getId: () => 'table-1',
+ getDisplayName: () => 'Orders',
+ getRange: () => ({ startRow: 1, endRow: 3, startColumn: 2, endColumn: 4 }),
+ getTableStyleId: () => 'theme-1',
+ };
+ const { attachPopupByPosition, controller, executeTableCommand, popupDisposable } = createController(true, [table]);
+ const shape = Reflect.get(controller, '_shape') as {
+ getAnchorRegion: (tableId: string) => unknown;
+ };
+ vi.spyOn(shape, 'getAnchorRegion').mockReturnValue({
+ type: 'anchor-main',
+ tableId: 'table-1',
+ left: 40,
+ top: 20,
+ width: 122,
+ height: 28,
+ });
+ const handleHit = Reflect.get(controller, '_handleHit') as (hit: object) => void;
+
+ handleHit.call(controller, { type: 'anchor-menu-toggle', tableId: 'table-1' });
+
+ expect(attachPopupByPosition).toHaveBeenCalledWith(
+ { left: 40, right: 162, top: 20, bottom: 48 },
+ expect.objectContaining({ componentKey: SHEET_TABLE_MENU }),
+ { unitId: 'unit-1', subUnitId: 'sheet-1', row: 1, col: 2 }
+ );
+ const popup = attachPopupByPosition.mock.calls[0][1] as {
+ extraProps: {
+ labels: Record<string, string>;
+ onSelect: (action: 'delete') => void | Promise<void>;
+ };
+ };
+ expect(popup.extraProps.labels).toEqual({
+ rename: 'sheets-table-ui.rename',
+ 'update-range': 'sheets-table-ui.updateRange',
+ 'set-theme': 'sheets-table-ui.setTheme',
+ delete: 'sheets-table-ui.removeTable',
+ });
+
+ await popup.extraProps.onSelect('delete');
+
+ expect(popupDisposable.dispose).toHaveBeenCalledOnce();
+ expect(executeTableCommand).toHaveBeenCalledWith(DeleteSheetTableCommand.id, {
+ tableId: 'table-1',
+ subUnitId: 'sheet-1',
+ unitId: 'unit-1',
+ });
+ controller.dispose();
+ });
});
diff --git a/packages/sheets-table-ui/src/controllers/components.controller.ts b/packages/sheets-table-ui/src/controllers/components.controller.ts
index 6673d85474..08b0e8cf9d 100644
--- a/packages/sheets-table-ui/src/controllers/components.controller.ts
+++ b/packages/sheets-table-ui/src/controllers/components.controller.ts
@@ -17,8 +17,15 @@
import { Disposable, Inject } from '@univerjs/core';
import { TableIcon } from '@univerjs/icons';
import { ComponentManager, IconManager } from '@univerjs/ui';
-import { SHEET_TABLE_RENAME_DIALOG, SHEET_TABLE_THEME_PANEL, SHEETS_TABLE_FILTER_PANEL_OPENED_KEY, TABLE_SELECTOR_DIALOG } from '../const';
+import {
+ SHEET_TABLE_MENU,
+ SHEET_TABLE_RENAME_DIALOG,
+ SHEET_TABLE_THEME_PANEL,
+ SHEETS_TABLE_FILTER_PANEL_OPENED_KEY,
+ TABLE_SELECTOR_DIALOG,
+} from '../const';
import { SheetTableFilterPanel } from '../views/components/SheetTableFilterPanel';
+import { SheetTableMenu } from '../views/components/SheetTableMenu';
import { SheetTableRenameDialog } from '../views/components/SheetTableRenameDialog';
import { SheetTableSelector } from '../views/components/SheetTableSelector';
import { SheetTableThemePanel } from '../views/components/SheetTableThemePanel';
@@ -37,6 +44,7 @@ export class ComponentsController extends Disposable {
private _registerComponents(): void {
([
[SHEETS_TABLE_FILTER_PANEL_OPENED_KEY, SheetTableFilterPanel],
+ [SHEET_TABLE_MENU, SheetTableMenu],
[SHEET_TABLE_RENAME_DIALOG, SheetTableRenameDialog],
] as const).forEach(([key, comp]) => {
this.disposeWithMe(this._componentManager.register(key, comp));
diff --git a/packages/sheets-table-ui/src/controllers/sheet-table-controls-render.controller.ts b/packages/sheets-table-ui/src/controllers/sheet-table-controls-render.controller.ts
index e99f4ef4f2..6598453cdf 100644
--- a/packages/sheets-table-ui/src/controllers/sheet-table-controls-render.controller.ts
+++ b/packages/sheets-table-ui/src/controllers/sheet-table-controls-render.controller.ts
@@ -14,9 +14,16 @@
* limitations under the License.
*/
-import type { EventState, IRange, Workbook } from '@univerjs/core';
-import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, SpreadsheetSkeleton } from '@univerjs/engine-render';
+import type { EventState, IDisposable, IRange, Workbook } from '@univerjs/core';
+import type {
+ IMouseEvent,
+ IPointerEvent,
+ IRenderContext,
+ IRenderModule,
+ SpreadsheetSkeleton,
+} from '@univerjs/engine-render';
import type { LocaleKey } from '../locale/types';
+import type { SheetTableMenuAction } from '../views/components/SheetTableMenu';
import type { ITableControlHitRegion } from '../views/widgets/table-controls-util';
import {
CommandType,
@@ -54,12 +61,14 @@ import {
SetScrollOperation,
SetZoomRatioOperation,
SHEET_VIEW_KEY,
+ SheetCanvasPopManagerService,
SheetSkeletonManagerService,
} from '@univerjs/sheets-ui';
import { IDialogService, ISidebarService } from '@univerjs/ui';
import { filter, merge } from 'rxjs';
import { openRangeSelector } from '../commands/operations/open-table-selector.operation';
import {
+ SHEET_TABLE_MENU,
SHEET_TABLE_RENAME_DIALOG,
SHEET_TABLE_RENAME_DIALOG_ID,
SHEET_TABLE_THEME_PANEL,
@@ -97,6 +106,7 @@ function isSameTopGap(left: TopGapSnapshot, right: TopGapSnapshot): boolean {
export class SheetTableControlsRenderController extends Disposable implements IRenderModule {
private readonly _shape: SheetTableControlsShape;
private readonly _topGapBaseBySkeleton = new WeakMap<SpreadsheetSkeleton, TopGapSnapshot>();
+ private _menuPopup: IDisposable | null = null;
constructor(
private readonly _context: IRenderContext<Workbook>,
@@ -112,7 +122,8 @@ export class SheetTableControlsRenderController extends Disposable implements IR
@Inject(SheetTableThemeUIController) private readonly _sheetTableThemeUIController: SheetTableThemeUIController,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@IDialogService private readonly _dialogService: IDialogService,
- @ISidebarService private readonly _sidebarService: ISidebarService
+ @ISidebarService private readonly _sidebarService: ISidebarService,
+ @Inject(SheetCanvasPopManagerService) private readonly _sheetCanvasPopupService: SheetCanvasPopManagerService
) {
super();
this._shape = new SheetTableControlsShape(
@@ -127,6 +138,7 @@ export class SheetTableControlsRenderController extends Disposable implements IR
private _initShape(): void {
this._context.scene.addObjects([this._shape], TABLE_CONTROLS_LAYER_INDEX);
this.disposeWithMe(toDisposable(() => {
+ this._closeFloatingControls();
this._context.scene.removeObjects([this._shape]);
}));
@@ -200,13 +212,6 @@ export class SheetTableControlsRenderController extends Disposable implements IR
}
this._syncTopTableGap(skeleton);
- this._shape.setMenuLabels({
- rename: this._localeService.t<LocaleKey>('sheets-table-ui.rename'),
- 'update-range': this._localeService.t<LocaleKey>('sheets-table-ui.updateRange'),
- 'set-theme': this._localeService.t<LocaleKey>('sheets-table-ui.setTheme'),
- delete: this._localeService.t<LocaleKey>('sheets-table-ui.removeTable'),
- });
-
const unitId = this._context.unit.getUnitId();
const subUnitId = worksheet.getSheetId();
const items = this._tableManager.getTablesBySubunitId(unitId, subUnitId).map((table) => {
@@ -290,7 +295,7 @@ export class SheetTableControlsRenderController extends Disposable implements IR
const subUnitId = worksheet.getSheetId();
if (hit.type === 'anchor-menu-toggle' || hit.type === 'anchor-main') {
- this._shape.setOpenedMenuTableId(this._shape.getOpenedMenuTableId() === hit.tableId ? null : hit.tableId);
+ this._toggleTableMenu(unitId, subUnitId, hit.tableId);
return;
}
@@ -315,33 +320,81 @@ export class SheetTableControlsRenderController extends Disposable implements IR
count: 1,
});
this._closeFloatingControls();
+ }
+ }
+
+ private _toggleTableMenu(unitId: string, subUnitId: string, tableId: string): void {
+ if (this._shape.getOpenedMenuTableId() === tableId) {
+ this._closeFloatingControls();
return;
}
- if (hit.type !== 'menu-item') {
+ const table = this._tableManager.getTableById(unitId, tableId);
+ const anchor = this._shape.getAnchorRegion(tableId);
+ if (!table || !anchor) {
return;
}
- switch (hit.action) {
+ this._closeFloatingControls();
+ this._shape.setOpenedMenuTableId(tableId);
+ const range = table.getRange();
+
+ this._menuPopup = this._sheetCanvasPopupService.attachPopupByPosition(
+ {
+ left: anchor.left,
+ right: anchor.left + anchor.width,
+ top: anchor.top,
+ bottom: anchor.top + anchor.height,
+ },
+ {
+ componentKey: SHEET_TABLE_MENU,
+ direction: 'bottom-left',
+ extraProps: {
+ anchorWidth: anchor.width,
+ tableName: table.getDisplayName(),
+ labels: {
+ rename: this._localeService.t<LocaleKey>('sheets-table-ui.rename'),
+ 'update-range': this._localeService.t<LocaleKey>('sheets-table-ui.updateRange'),
+ 'set-theme': this._localeService.t<LocaleKey>('sheets-table-ui.setTheme'),
+ delete: this._localeService.t<LocaleKey>('sheets-table-ui.removeTable'),
+ },
+ onSelect: (action: SheetTableMenuAction) => this._handleTableMenuAction(action, unitId, subUnitId, tableId),
+ onClose: () => this._closeFloatingControls(),
+ },
+ },
+ {
+ unitId,
+ subUnitId,
+ row: range.startRow,
+ col: range.startColumn,
+ }
+ ) ?? null;
+
+ if (!this._menuPopup) {
+ this._shape.setOpenedMenuTableId(null);
+ }
+ }
+
+ private _handleTableMenuAction(action: SheetTableMenuAction, unitId: string, subUnitId: string, tableId: string): void | Promise<void> {
+ this._closeFloatingControls();
+
+ switch (action) {
case 'rename':
- this._openRenameDialog(unitId, hit.tableId);
+ this._openRenameDialog(unitId, tableId);
break;
case 'update-range':
- this._openRangeSelector(unitId, subUnitId, hit.tableId);
- break;
+ return this._openRangeSelector(unitId, subUnitId, tableId);
case 'set-theme':
- this._openThemePanel(unitId, subUnitId, hit.tableId);
+ this._openThemePanel(unitId, subUnitId, tableId);
break;
case 'delete':
this._commandService.executeCommand(DeleteSheetTableCommand.id, {
- tableId: hit.tableId,
+ tableId,
subUnitId,
unitId,
});
break;
}
-
- this._closeFloatingControls();
}
private _openRenameDialog(unitId: string, tableId: string): void {
@@ -395,12 +448,16 @@ export class SheetTableControlsRenderController extends Disposable implements IR
id: SHEET_TABLE_THEME_PANEL_ID,
header: { title: this._localeService.t<LocaleKey>('sheets-table-ui.tableStyle') },
children: {
- label: SHEET_TABLE_THEME_PANEL,
- oldConfig: table.getTableConfig(),
- unitId,
- subUnitId,
- tableId,
- } as any,
+ label: {
+ name: SHEET_TABLE_THEME_PANEL,
+ props: {
+ oldConfig: table.getTableConfig(),
+ unitId,
+ subUnitId,
+ tableId,
+ },
+ },
+ },
width: 330,
});
}
@@ -519,6 +576,9 @@ export class SheetTableControlsRenderController extends Disposable implements IR
}
private _closeFloatingControls(): void {
+ const menuPopup = this._menuPopup;
+ this._menuPopup = null;
+ menuPopup?.dispose();
this._shape.setOpenedMenuTableId(null);
this._shape.setHoveredInsertRegion(null);
this._shape.setHoveredRegion(null);
diff --git a/packages/sheets-table-ui/src/locale/ar-SA.ts b/packages/sheets-table-ui/src/locale/ar-SA.ts
index 5f743e5870..6c30692e9d 100644
--- a/packages/sheets-table-ui/src/locale/ar-SA.ts
+++ b/packages/sheets-table-ui/src/locale/ar-SA.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'إلغاء',
confirm: 'تأكيد',
'search-placeholder': 'استخدم المسافة لفصل الكلمات المفتاحية',
+ 'input-values-placeholder': 'إدخال القيم',
'select-all': 'تحديد الكل',
},
},
diff --git a/packages/sheets-table-ui/src/locale/ca-ES.ts b/packages/sheets-table-ui/src/locale/ca-ES.ts
index 7db916179c..89d7f09852 100644
--- a/packages/sheets-table-ui/src/locale/ca-ES.ts
+++ b/packages/sheets-table-ui/src/locale/ca-ES.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'Cancel·la',
confirm: 'Confirma',
'search-placeholder': 'Utilitza espai per separar paraules clau',
+ 'input-values-placeholder': 'Introdueix valors',
'select-all': 'Selecciona-ho tot',
},
},
diff --git a/packages/sheets-table-ui/src/locale/de-DE.ts b/packages/sheets-table-ui/src/locale/de-DE.ts
index 8f5b0c777e..1f3f2da5b9 100644
--- a/packages/sheets-table-ui/src/locale/de-DE.ts
+++ b/packages/sheets-table-ui/src/locale/de-DE.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'Abbrechen',
confirm: 'Bestätigen',
'search-placeholder': 'Leerzeichen zum Trennen von Schlüsselwörtern verwenden',
+ 'input-values-placeholder': 'Werte eingeben',
'select-all': 'Alle auswählen',
},
},
diff --git a/packages/sheets-table-ui/src/locale/en-US.ts b/packages/sheets-table-ui/src/locale/en-US.ts
index 53183451c6..a1631863b2 100644
--- a/packages/sheets-table-ui/src/locale/en-US.ts
+++ b/packages/sheets-table-ui/src/locale/en-US.ts
@@ -146,6 +146,7 @@ const locale = {
cancel: 'Cancel',
confirm: 'Confirm',
'search-placeholder': 'Use space to separate keywords',
+ 'input-values-placeholder': 'Input Values',
'select-all': 'Select All',
},
},
diff --git a/packages/sheets-table-ui/src/locale/es-ES.ts b/packages/sheets-table-ui/src/locale/es-ES.ts
index 77193212b3..cd5ddeb903 100644
--- a/packages/sheets-table-ui/src/locale/es-ES.ts
+++ b/packages/sheets-table-ui/src/locale/es-ES.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'Cancelar',
confirm: 'Confirmar',
'search-placeholder': 'Usa espacio para separar palabras clave',
+ 'input-values-placeholder': 'Introducir valores',
'select-all': 'Seleccionar todo',
},
},
diff --git a/packages/sheets-table-ui/src/locale/fa-IR.ts b/packages/sheets-table-ui/src/locale/fa-IR.ts
index 84f0f36218..4610eae61a 100644
--- a/packages/sheets-table-ui/src/locale/fa-IR.ts
+++ b/packages/sheets-table-ui/src/locale/fa-IR.ts
@@ -150,6 +150,7 @@ const locale: typeof enUS = {
cancel: 'انصراف',
confirm: 'تایید',
'search-placeholder': 'برای جداسازی کلیدواژه‌ها از فاصله استفاده کنید',
+ 'input-values-placeholder': 'ورود مقادیر',
'select-all': 'انتخاب همه',
},
},
diff --git a/packages/sheets-table-ui/src/locale/fr-FR.ts b/packages/sheets-table-ui/src/locale/fr-FR.ts
index 337f7e30f5..56ffd08804 100644
--- a/packages/sheets-table-ui/src/locale/fr-FR.ts
+++ b/packages/sheets-table-ui/src/locale/fr-FR.ts
@@ -149,6 +149,7 @@ const locale: typeof enUS = {
cancel: 'Annuler',
confirm: 'Confirmer',
'search-placeholder': 'Utilisez un espace pour séparer les mots-clés',
+ 'input-values-placeholder': 'Saisir des valeurs',
'select-all': 'Tout sélectionner',
},
},
diff --git a/packages/sheets-table-ui/src/locale/id-ID.ts b/packages/sheets-table-ui/src/locale/id-ID.ts
index 779e0c17b2..32614ebc61 100644
--- a/packages/sheets-table-ui/src/locale/id-ID.ts
+++ b/packages/sheets-table-ui/src/locale/id-ID.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'Batal',
confirm: 'Konfirmasi',
'search-placeholder': 'Gunakan spasi untuk memisahkan kata kunci',
+ 'input-values-placeholder': 'Masukkan Nilai',
'select-all': 'Pilih Semua',
},
},
diff --git a/packages/sheets-table-ui/src/locale/it-IT.ts b/packages/sheets-table-ui/src/locale/it-IT.ts
index 9889d5a083..4c3b001f8e 100644
--- a/packages/sheets-table-ui/src/locale/it-IT.ts
+++ b/packages/sheets-table-ui/src/locale/it-IT.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'Annulla',
confirm: 'Conferma',
'search-placeholder': 'Usa lo spazio per separare le parole chiave',
+ 'input-values-placeholder': 'Inserisci valori',
'select-all': 'Seleziona Tutto',
},
},
diff --git a/packages/sheets-table-ui/src/locale/ja-JP.ts b/packages/sheets-table-ui/src/locale/ja-JP.ts
index 8fde4a036b..e7aaa0fe81 100644
--- a/packages/sheets-table-ui/src/locale/ja-JP.ts
+++ b/packages/sheets-table-ui/src/locale/ja-JP.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'キャンセル',
confirm: '確認',
'search-placeholder': '検索語はスペースで区切る',
+ 'input-values-placeholder': '値を入力',
'select-all': 'すべて選択',
},
},
diff --git a/packages/sheets-table-ui/src/locale/ko-KR.ts b/packages/sheets-table-ui/src/locale/ko-KR.ts
index f07d62daf4..1e689a7819 100644
--- a/packages/sheets-table-ui/src/locale/ko-KR.ts
+++ b/packages/sheets-table-ui/src/locale/ko-KR.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: '취소',
confirm: '확인',
'search-placeholder': '검색어는 공백으로 구분',
+ 'input-values-placeholder': '값 입력',
'select-all': '전체 선택',
},
},
diff --git a/packages/sheets-table-ui/src/locale/pl-PL.ts b/packages/sheets-table-ui/src/locale/pl-PL.ts
index f7fa92a818..1f82e3ae14 100644
--- a/packages/sheets-table-ui/src/locale/pl-PL.ts
+++ b/packages/sheets-table-ui/src/locale/pl-PL.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'Anuluj',
confirm: 'Potwierdź',
'search-placeholder': 'Użyj spacji do rozdzielenia słów kluczowych',
+ 'input-values-placeholder': 'Wprowadź wartości',
'select-all': 'Zaznacz wszystko',
},
},
diff --git a/packages/sheets-table-ui/src/locale/pt-BR.ts b/packages/sheets-table-ui/src/locale/pt-BR.ts
index 6680e4e9de..0b102ce3ef 100644
--- a/packages/sheets-table-ui/src/locale/pt-BR.ts
+++ b/packages/sheets-table-ui/src/locale/pt-BR.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'Cancelar',
confirm: 'Confirmar',
'search-placeholder': 'Use espaço para separar palavras-chave',
+ 'input-values-placeholder': 'Inserir Valores',
'select-all': 'Selecionar Tudo',
},
},
diff --git a/packages/sheets-table-ui/src/locale/ru-RU.ts b/packages/sheets-table-ui/src/locale/ru-RU.ts
index f53b0d77c5..07429cb388 100644
--- a/packages/sheets-table-ui/src/locale/ru-RU.ts
+++ b/packages/sheets-table-ui/src/locale/ru-RU.ts
@@ -150,6 +150,7 @@ const locale: typeof enUS = {
cancel: 'Отмена',
confirm: 'Подтвердить',
'search-placeholder': 'Используйте пробел для разделения ключевых слов',
+ 'input-values-placeholder': 'Введите значения',
'select-all': 'Выбрать все',
},
},
diff --git a/packages/sheets-table-ui/src/locale/sk-SK.ts b/packages/sheets-table-ui/src/locale/sk-SK.ts
index 43179c7c44..17f6c11edf 100644
--- a/packages/sheets-table-ui/src/locale/sk-SK.ts
+++ b/packages/sheets-table-ui/src/locale/sk-SK.ts
@@ -148,6 +148,7 @@ const locale: typeof enUS = {
cancel: 'Zrušiť',
confirm: 'Potvrdiť',
'search-placeholder': 'Použite medzeru na oddelenie kľúčových slov',
+ 'input-values-placeholder': 'Zadajte hodnoty',
'select-all': 'Vybrať všetko',
},
},
diff --git a/packages/sheets-table-ui/src/locale/vi-VN.ts b/packages/sheets-table-ui/src/locale/vi-VN.ts
index ca27a7828b..48eb623322 100644
--- a/packages/sheets-table-ui/src/locale/vi-VN.ts
+++ b/packages/sheets-table-ui/src/locale/vi-VN.ts
@@ -150,6 +150,7 @@ const locale: typeof enUS = {
cancel: 'Hủy bỏ',
confirm: 'Xác nhận',
'search-placeholder': 'Sử dụng khoảng trắng để tách các từ khóa',
+ 'input-values-placeholder': 'Vui lòng nhập',
'select-all': 'Chọn tất cả',
},
},
diff --git a/packages/sheets-table-ui/src/locale/zh-CN.ts b/packages/sheets-table-ui/src/locale/zh-CN.ts
index 8ae3758379..926557cd39 100644
--- a/packages/sheets-table-ui/src/locale/zh-CN.ts
+++ b/packages/sheets-table-ui/src/locale/zh-CN.ts
@@ -151,6 +151,7 @@ const locale: typeof enUS = {
cancel: '取消',
confirm: '确认',
'search-placeholder': '使用空格分隔关键字',
+ 'input-values-placeholder': '请输入',
'select-all': '全选',
},
},
diff --git a/packages/sheets-table-ui/src/locale/zh-HK.ts b/packages/sheets-table-ui/src/locale/zh-HK.ts
index d1147a5ca4..12a5918909 100644
--- a/packages/sheets-table-ui/src/locale/zh-HK.ts
+++ b/packages/sheets-table-ui/src/locale/zh-HK.ts
@@ -150,6 +150,7 @@ const locale: typeof enUS = {
cancel: '取消',
confirm: '確認',
'search-placeholder': '使用空格分隔關鍵字',
+ 'input-values-placeholder': '請輸入',
'select-all': '全選',
},
},
diff --git a/packages/sheets-table-ui/src/locale/zh-TW.ts b/packages/sheets-table-ui/src/locale/zh-TW.ts
index d1147a5ca4..12a5918909 100644
--- a/packages/sheets-table-ui/src/locale/zh-TW.ts
+++ b/packages/sheets-table-ui/src/locale/zh-TW.ts
@@ -150,6 +150,7 @@ const locale: typeof enUS = {
cancel: '取消',
confirm: '確認',
'search-placeholder': '使用空格分隔關鍵字',
+ 'input-values-placeholder': '請輸入',
'select-all': '全選',
},
},
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableConditionPanel.tsx b/packages/sheets-table-ui/src/views/components/SheetTableConditionPanel.tsx
index 633c37723c..703536eed8 100644
--- a/packages/sheets-table-ui/src/views/components/SheetTableConditionPanel.tsx
+++ b/packages/sheets-table-ui/src/views/components/SheetTableConditionPanel.tsx
@@ -15,6 +15,7 @@
*/
import type { ITableFilterItem } from '@univerjs/sheets-table';
+import type { LocaleKey } from '../../locale/types';
import type { IConditionCompareTypeEnum, IConditionExpect, IConditionInfo, ITableConditionTypeEnumWithoutLogic } from './type';
import { Injector, LocaleService } from '@univerjs/core';
import { borderClassName, CascaderList, clsx, DatePicker, DateRangePicker, Dropdown, Input, InputNumber, Select } from '@univerjs/design';
@@ -130,7 +131,7 @@ export const SheetTableConditionPanel = (props: IConditionFilterProps) => {
? (
<Input
className="univer-w-full"
- placeholder="请输入"
+ placeholder={localeService.t<LocaleKey>('sheets-table-ui.filter.input-values-placeholder')}
value={conditionInfo.info.string}
onChange={(v) => handleConditionInfo({ string: v })}
/>
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableFilterPanel.tsx b/packages/sheets-table-ui/src/views/components/SheetTableFilterPanel.tsx
index 4971c92ee8..15f69a572d 100644
--- a/packages/sheets-table-ui/src/views/components/SheetTableFilterPanel.tsx
+++ b/packages/sheets-table-ui/src/views/components/SheetTableFilterPanel.tsx
@@ -324,8 +324,8 @@ export function SheetTableFilterPanel() {
>
{localeService.t<LocaleKey>('sheets-table-ui.filter.clear-filter')}
</Button>
- <div>
- <Button className="univer-mr-2" onClick={onCancel}>{localeService.t<LocaleKey>('sheets-table-ui.filter.cancel')}</Button>
+ <div className="univer-flex univer-gap-x-2">
+ <Button onClick={onCancel}>{localeService.t<LocaleKey>('sheets-table-ui.filter.cancel')}</Button>
<Button variant="primary" onClick={onApply}>{localeService.t<LocaleKey>('sheets-table-ui.filter.confirm')}</Button>
</div>
</div>
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableMenu.tsx b/packages/sheets-table-ui/src/views/components/SheetTableMenu.tsx
new file mode 100644
index 0000000000..3366087169
--- /dev/null
+++ b/packages/sheets-table-ui/src/views/components/SheetTableMenu.tsx
@@ -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 { ICanvasPopup } from '@univerjs/sheets-ui';
+import { DropdownMenu } from '@univerjs/design';
+
+export type SheetTableMenuAction = 'rename' | 'update-range' | 'set-theme' | 'delete';
+
+export interface ISheetTableMenuExtraProps {
+ anchorWidth: number;
+ tableName: string;
+ labels: Record<SheetTableMenuAction, string>;
+ onSelect: (action: SheetTableMenuAction) => void | Promise<void>;
+ onClose: () => void;
+}
+
+interface ISheetTableMenuProps {
+ popup: ICanvasPopup;
+}
+
+export function SheetTableMenu({ popup }: ISheetTableMenuProps) {
+ const menu = popup.extraProps as unknown as ISheetTableMenuExtraProps | undefined;
+
+ if (!menu) {
+ return null;
+ }
+
+ return (
+ <DropdownMenu
+ align="start"
+ className="univer-min-w-40"
+ items={[
+ { type: 'item', children: menu.labels.rename, onSelect: () => menu.onSelect('rename') },
+ { type: 'item', children: menu.labels['update-range'], onSelect: () => menu.onSelect('update-range') },
+ { type: 'item', children: menu.labels['set-theme'], onSelect: () => menu.onSelect('set-theme') },
+ { type: 'item', children: menu.labels.delete, variant: 'destructive', onSelect: () => menu.onSelect('delete') },
+ ]}
+ open
+ sideOffset={0}
+ onOpenChange={(open) => {
+ if (!open) {
+ menu.onClose();
+ }
+ }}
+ >
+ <button
+ type="button"
+ aria-label={menu.tableName}
+ className="univer-block univer-h-px univer-opacity-0"
+ style={{ width: menu.anchorWidth }}
+ tabIndex={-1}
+ />
+ </DropdownMenu>
+ );
+}
diff --git a/packages/sheets-table-ui/src/views/components/SheetTableThemePanel.tsx b/packages/sheets-table-ui/src/views/components/SheetTableThemePanel.tsx
index 49925f3cbb..6cb7689049 100644
--- a/packages/sheets-table-ui/src/views/components/SheetTableThemePanel.tsx
+++ b/packages/sheets-table-ui/src/views/components/SheetTableThemePanel.tsx
@@ -19,7 +19,7 @@ import type { IAddTableThemeCommandParams, ISetSheetTableCommandParams, ITableSe
import type { LocaleKey } from '../../locale/types';
import { ColorKit, ErrorService, ICommandService, LocaleService } from '@univerjs/core';
import { borderClassName, clsx, ColorPicker, Dropdown } from '@univerjs/design';
-import { DownIcon } from '@univerjs/icons';
+import { CloseIcon, DownIcon, IncreaseIcon } from '@univerjs/icons';
import { RangeThemeStyle, SetRangeThemeMutation, SheetRangeThemeModel } from '@univerjs/sheets';
import {
AddTableThemeCommand,
@@ -88,7 +88,7 @@ export const SheetTableThemePanel = (props: ISheetTableThemePanelProps) => {
const firstRowBg = customStyle?.getFirstRowStyle()?.bg?.rgb ?? TABLE_DEFAULT_BG_COLOR;
const secondRowBg = customStyle?.getSecondRowStyle()?.bg?.rgb ?? TABLE_DEFAULT_BG_COLOR;
const lastRowBg = customStyle?.getLastRowStyle()?.bg?.rgb ?? TABLE_DEFAULT_BG_COLOR;
- const [hoverCustomId, setHoverCustomId] = useState<string | null>(null);
+ const direction = useObservable(localeService.direction$, localeService.getDirection());
const handleThemeChange = (theme: string) => {
commandService.executeCommand<ISetSheetTableCommandParams>(SetSheetTableCommand.id, {
@@ -145,302 +145,279 @@ export const SheetTableThemePanel = (props: ISheetTableThemePanelProps) => {
const secondRowBgIsDark = new ColorKit(secondRowBg).isDark();
const lastRowBgIsDark = new ColorKit(lastRowBg).isDark();
- return (
- <div>
- <h5>{localeService.t<LocaleKey>('sheets-table-ui.defaultStyle')}</h5>
- <div className="univer-flex univer-gap-2">
- {defaultRangeThemes.map((item) => {
- const rangeThemeItem = rangeThemeModel.getDefaultRangeThemeStyle(item);
- const headerRowBg = rangeThemeItem?.getHeaderRowStyle()?.bg?.rgb || TABLE_DEFAULT_BG_COLOR;
- const firstRowBg = rangeThemeItem?.getFirstRowStyle()?.bg?.rgb || TABLE_DEFAULT_BG_COLOR;
- const secondRowBg = rangeThemeItem?.getSecondRowStyle()?.bg?.rgb || TABLE_DEFAULT_BG_COLOR;
- const lastRowBg = rangeThemeItem?.getLastRowStyle()?.bg?.rgb || TABLE_DEFAULT_BG_COLOR;
-
- return (
- <div
- key={item}
- className={clsx(`
- univer-h-10 univer-w-8 univer-cursor-pointer univer-border univer-border-solid
- univer-border-gray-200 univer-p-px
- [&>div]:univer-box-border [&>div]:univer-h-2.5
- `, {
- 'univer-border-blue-500': item === themeConfig.theme,
- })}
- onClick={() => handleThemeChange(item)}
- >
- <div style={{ background: headerRowBg, border: `${headerRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}` }} />
- <div style={{ background: firstRowBg, border: `${firstRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}` }} />
- <div style={{ background: secondRowBg, border: `${secondRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}` }} />
- <div style={{ background: lastRowBg, border: `${lastRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}` }} />
- </div>
- );
- })}
- </div>
+ const customThemeRows = [
+ {
+ key: 'header',
+ label: localeService.t<LocaleKey>('sheets-table-ui.header'),
+ background: headerBg,
+ isDark: headerBgIsDark,
+ onChange: (value: string) => {
+ const headerRowStyle = processStyleWithBorderStyle('headerRowStyle', {
+ bg: { rgb: value },
+ cl: { rgb: new ColorKit(value).isDark() ? '#fff' : '#000' },
+ });
+ setCustomTheme(table.getTableStyleId(), { headerRowStyle });
+ },
+ },
+ {
+ key: 'first-row',
+ label: localeService.t<LocaleKey>('sheets-table-ui.firstLine'),
+ background: firstRowBg,
+ isDark: firstRowBgIsDark,
+ onChange: (value: string) => {
+ setCustomTheme(table.getTableStyleId(), {
+ firstRowStyle: {
+ bg: { rgb: value },
+ cl: { rgb: new ColorKit(value).isDark() ? '#fff' : '#000' },
+ },
+ });
+ },
+ },
+ {
+ key: 'second-row',
+ label: localeService.t<LocaleKey>('sheets-table-ui.secondLine'),
+ background: secondRowBg,
+ isDark: secondRowBgIsDark,
+ onChange: (value: string) => {
+ setCustomTheme(table.getTableStyleId(), {
+ secondRowStyle: {
+ bg: { rgb: value },
+ cl: { rgb: new ColorKit(value).isDark() ? '#fff' : '#000' },
+ },
+ });
+ },
+ },
+ {
+ key: 'last-row',
+ label: localeService.t<LocaleKey>('sheets-table-ui.footer'),
+ background: lastRowBg,
+ isDark: lastRowBgIsDark,
+ onChange: (value: string) => {
+ const lastRowStyle = processStyleWithBorderStyle('lastRowStyle', {
+ bg: { rgb: value },
+ cl: { rgb: new ColorKit(value).isDark() ? '#fff' : '#000' },
+ });
+ setCustomTheme(table.getTableStyleId(), { lastRowStyle });
+ },
+ },
+ ];
- <h5>{localeService.t<LocaleKey>('sheets-table-ui.customStyle')}</h5>
- <div className={clsx('univer-w-full univer-rounded-sm', borderClassName)}>
- <div className="univer-flex univer-flex-wrap univer-gap-2 univer-p-2">
- <div
- className={clsx(`
- univer-h-10 univer-w-8 univer-cursor-pointer univer-p-px univer-text-center univer-leading-10
- `, borderClassName)}
- onClick={handleAddCustomTheme}
- >
- +
- </div>
- {customRangeThemes.map((item) => {
- const rangeThemeItem = rangeThemeModel.getCustomRangeThemeStyle(unitId, item);
- const headerRowBg = rangeThemeItem?.getHeaderRowStyle()?.bg?.rgb;
- const firstRowBg = rangeThemeItem?.getFirstRowStyle()?.bg?.rgb;
- const secondRowBg = rangeThemeItem?.getSecondRowStyle()?.bg?.rgb;
- const lastRowBg = rangeThemeItem?.getLastRowStyle()?.bg?.rgb;
+ return (
+ <div dir={direction} className="univer-flex univer-flex-col univer-gap-5 univer-pb-4">
+ <section className="univer-flex univer-flex-col univer-gap-2">
+ <h5
+ className="
+ univer-m-0 univer-text-xs univer-font-medium univer-text-gray-500
+ dark:!univer-text-gray-300
+ "
+ >
+ {localeService.t<LocaleKey>('sheets-table-ui.defaultStyle')}
+ </h5>
+ <div className="univer-grid univer-grid-cols-6 univer-gap-2">
+ {defaultRangeThemes.map((item) => {
+ const rangeThemeItem = rangeThemeModel.getDefaultRangeThemeStyle(item);
+ const rowBackgrounds = [
+ rangeThemeItem?.getHeaderRowStyle()?.bg?.rgb || TABLE_DEFAULT_BG_COLOR,
+ rangeThemeItem?.getFirstRowStyle()?.bg?.rgb || TABLE_DEFAULT_BG_COLOR,
+ rangeThemeItem?.getSecondRowStyle()?.bg?.rgb || TABLE_DEFAULT_BG_COLOR,
+ rangeThemeItem?.getLastRowStyle()?.bg?.rgb || TABLE_DEFAULT_BG_COLOR,
+ ];
+ const selected = item === themeConfig.theme;
return (
- <div
+ <button
key={item}
+ type="button"
+ title={item}
+ aria-label={item}
+ aria-pressed={selected}
className={clsx(`
- univer-relative univer-h-10 univer-w-8 univer-cursor-pointer univer-border
- univer-border-solid univer-border-gray-200 univer-p-px
- `, {
- 'univer-border-blue-500': item === themeConfig.theme,
+ univer-flex univer-h-12 univer-w-full univer-cursor-pointer univer-flex-col
+ univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-1 univer-shadow-sm
+ univer-transition-all
+ hover:univer-border-gray-400 hover:univer-shadow-md
+ focus:univer-outline-none focus:univer-ring-2 focus:univer-ring-primary-200
+ dark:!univer-bg-gray-800
+ `, borderClassName, {
+ '!univer-border-primary-500 univer-ring-2 univer-ring-primary-100': selected,
})}
onClick={() => handleThemeChange(item)}
- onMouseEnter={() => setHoverCustomId(item)}
- onMouseLeave={() => setHoverCustomId(null)}
>
- <div className="univer-box-border univer-h-2.5" style={{ background: headerRowBg ?? TABLE_BORDER_NONE, border: `${headerRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}` }} />
- <div className="univer-box-border univer-h-2.5" style={{ background: firstRowBg ?? TABLE_BORDER_NONE, border: `${firstRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}` }} />
- <div className="univer-box-border univer-h-2.5" style={{ background: secondRowBg ?? TABLE_BORDER_NONE, border: `${secondRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}` }} />
- <div className="univer-box-border univer-h-2.5" style={{ background: lastRowBg ?? TABLE_BORDER_NONE, border: `${lastRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}` }} />
-
- <div
- className={`
- univer-absolute univer-right-[-3px] univer-top-[-3px] univer-size-3
- univer-rounded-md univer-bg-gray-200 univer-text-center univer-text-xs
- univer-leading-[10px]
- `}
- style={{ display: hoverCustomId === item ? 'block' : 'none' }}
- onClick={(e) => {
- e.stopPropagation();
- removeCustomTheme(item);
- }}
- >
- x
- </div>
- </div>
+ {rowBackgrounds.map((background, index) => (
+ <span
+ key={index}
+ className="univer-min-h-0 univer-w-full univer-flex-1"
+ style={{
+ background,
+ border: background ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT,
+ }}
+ />
+ ))}
+ </button>
);
})}
</div>
+ </section>
- {customSelected && (
- <>
- <div className="univer-h-px univer-w-full univer-bg-gray-200" />
- <div className="univer-flex univer-flex-col univer-gap-2 univer-p-2">
- <div className="univer-flex univer-h-9 univer-gap-2">
- <div
+ <section className="univer-flex univer-flex-col univer-gap-2">
+ <h5
+ className="
+ univer-m-0 univer-text-xs univer-font-medium univer-text-gray-500
+ dark:!univer-text-gray-300
+ "
+ >
+ {localeService.t<LocaleKey>('sheets-table-ui.customStyle')}
+ </h5>
+ <div
+ className="
+ univer-grid univer-grid-cols-5 univer-gap-2 univer-rounded-lg univer-bg-gray-50 univer-p-2
+ dark:!univer-bg-gray-800
+ "
+ >
+ <button
+ type="button"
+ data-u-comp="sheet-table-theme-add"
+ aria-label={localeService.t<LocaleKey>('sheets-table-ui.setTheme')}
+ className="
+ univer-flex univer-h-12 univer-w-full univer-cursor-pointer univer-items-center
+ univer-justify-center univer-rounded-lg univer-border univer-border-dashed
+ univer-border-gray-300 univer-bg-white univer-p-0 univer-text-gray-500
+ univer-transition-colors
+ hover:univer-border-primary-500 hover:univer-text-primary-600
+ focus:univer-outline-none focus:univer-ring-2 focus:univer-ring-primary-200
+ dark:!univer-border-gray-600 dark:!univer-bg-gray-900 dark:!univer-text-gray-300
+ "
+ onClick={handleAddCustomTheme}
+ >
+ <IncreaseIcon className="univer-size-4" />
+ </button>
+ {customRangeThemes.map((item) => {
+ const rangeThemeItem = rangeThemeModel.getCustomRangeThemeStyle(unitId, item);
+ const rowBackgrounds = [
+ rangeThemeItem?.getHeaderRowStyle()?.bg?.rgb,
+ rangeThemeItem?.getFirstRowStyle()?.bg?.rgb,
+ rangeThemeItem?.getSecondRowStyle()?.bg?.rgb,
+ rangeThemeItem?.getLastRowStyle()?.bg?.rgb,
+ ];
+ const selected = item === themeConfig.theme;
+
+ return (
+ <div key={item} className="univer-group univer-relative univer-h-12 univer-min-w-0">
+ <button
+ type="button"
+ title={item}
+ aria-label={item}
+ aria-pressed={selected}
className={clsx(`
- univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center
- univer-leading-9
+ univer-flex univer-size-full univer-cursor-pointer univer-flex-col
+ univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-1
+ univer-shadow-sm univer-transition-all
+ hover:univer-border-gray-400 hover:univer-shadow-md
+ focus:univer-outline-none focus:univer-ring-2 focus:univer-ring-primary-200
+ dark:!univer-bg-gray-900
`, borderClassName, {
- 'univer-text-white': headerBgIsDark,
- 'univer-text-gray-900': !headerBgIsDark,
+ '!univer-border-primary-500 univer-ring-2 univer-ring-primary-100': selected,
})}
- style={{
- background: headerBg,
- }}
+ onClick={() => handleThemeChange(item)}
>
- {localeService.t<LocaleKey>('sheets-table-ui.header')}
- </div>
- <Dropdown
- overlay={(
- <div className="univer-p-2">
- <ColorPicker
- value={headerBg}
- onChange={(val) => {
- const headerRowStyle = processStyleWithBorderStyle('headerRowStyle', {
- bg: {
- rgb: val,
- },
- cl: {
- rgb: new ColorKit(val).isDark() ? '#fff' : '#000',
- },
- });
- setCustomTheme(table.getTableStyleId(), { headerRowStyle });
- }}
- />
- </div>
- )}
- >
- <div
- className={clsx(`
- univer-flex univer-cursor-pointer univer-items-center univer-gap-2
- univer-rounded-sm univer-bg-white univer-p-1
- `, borderClassName)}
- >
- <div
- className={clsx('univer-size-4 univer-rounded-lg univer-bg-gray-400', borderClassName, {
- 'univer-text-white': headerBgIsDark,
- 'univer-text-gray-900': !headerBgIsDark,
- })}
+ {rowBackgrounds.map((background, index) => (
+ <span
+ key={index}
+ className="univer-min-h-0 univer-w-full univer-flex-1"
style={{
- background: headerBg,
+ background: background ?? TABLE_BORDER_NONE,
+ border: background ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT,
}}
/>
- <DownIcon className="univer-size-2" />
- </div>
- </Dropdown>
- </div>
- <div className="univer-flex univer-h-9 univer-gap-2">
- <div
+ ))}
+ </button>
+ <button
+ type="button"
+ data-u-comp="sheet-table-theme-remove"
+ aria-label={`${localeService.t<LocaleKey>('sheets-table-ui.customStyle')} ${item}`}
className={clsx(`
- univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center
- univer-leading-9
- `, borderClassName, {
- 'univer-text-white': firstRowBgIsDark,
- 'univer-text-gray-900': !firstRowBgIsDark,
+ univer-absolute univer-right-[-6px] univer-top-[-6px] univer-z-10 univer-flex
+ univer-size-5 univer-cursor-pointer univer-items-center univer-justify-center
+ univer-rounded-full univer-border univer-border-solid univer-border-gray-200
+ univer-bg-white univer-p-0 univer-text-gray-500 univer-shadow-sm
+ univer-transition-all
+ hover:univer-border-red-200 hover:univer-bg-red-50 hover:univer-text-red-600
+ focus:univer-opacity-100 focus:univer-outline-none focus:univer-ring-2
+ focus:univer-ring-primary-200
+ rtl:univer-left-[-6px] rtl:univer-right-auto
+ dark:!univer-border-gray-600 dark:!univer-bg-gray-900
+ `, {
+ 'univer-opacity-100': selected,
+ 'univer-opacity-0 group-focus-within:univer-opacity-100 group-hover:univer-opacity-100': !selected,
})}
- style={{
- background: firstRowBg,
- }}
- >
- {localeService.t<LocaleKey>('sheets-table-ui.firstLine')}
- </div>
- <Dropdown
- overlay={(
- <div className="univer-p-2">
- <ColorPicker
- value={firstRowBg}
- onChange={(val) => {
- setCustomTheme(table.getTableStyleId(), {
- firstRowStyle: {
- bg: {
- rgb: val,
- },
- cl: {
- rgb: new ColorKit(val).isDark() ? '#fff' : '#000',
- },
- },
- });
- }}
- />
- </div>
- )}
- >
- <div
- className={clsx(`
- univer-flex univer-cursor-pointer univer-items-center univer-gap-2
- univer-rounded-sm univer-bg-white univer-p-1
- `, borderClassName)}
- >
- <div
- className={clsx('univer-size-4 univer-rounded-lg univer-bg-gray-400', borderClassName)}
- style={{ background: firstRowBg }}
- />
- <DownIcon className="univer-size-2" />
- </div>
- </Dropdown>
- </div>
- <div className="univer-flex univer-h-9 univer-gap-2">
- <div
- className={clsx(`
- univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center
- univer-leading-9
- `, borderClassName, {
- 'univer-text-white': secondRowBgIsDark,
- 'univer-text-gray-900': !secondRowBgIsDark,
- })}
- style={{
- background: secondRowBg,
+ onClick={(event) => {
+ event.stopPropagation();
+ removeCustomTheme(item);
}}
>
- {localeService.t<LocaleKey>('sheets-table-ui.secondLine')}
- </div>
- <Dropdown
- overlay={(
- <div className="univer-p-2">
- <ColorPicker
- value={secondRowBg}
- onChange={(val) => setCustomTheme(table.getTableStyleId(), {
- secondRowStyle: {
- bg: {
- rgb: val,
- },
- cl: {
- rgb: new ColorKit(val).isDark() ? '#fff' : '#000',
- },
- },
- })}
- />
- </div>
- )}
- >
- <div
- className={clsx(`
- univer-flex univer-cursor-pointer univer-items-center univer-gap-2
- univer-rounded-sm univer-bg-white univer-p-1
- `, borderClassName)}
- >
- <div
- className={clsx('univer-size-4 univer-rounded-lg univer-bg-gray-400', borderClassName)}
- style={{ background: secondRowBg }}
- />
- <DownIcon className="univer-size-2" />
- </div>
- </Dropdown>
+ <CloseIcon className="univer-size-3" />
+ </button>
</div>
- <div className="univer-flex univer-h-9 univer-gap-2">
+ );
+ })}
+ </div>
+
+ {customSelected && (
+ <div
+ className="
+ univer-flex univer-flex-col univer-gap-2 univer-rounded-lg univer-bg-gray-50 univer-p-3
+ dark:!univer-bg-gray-800
+ "
+ >
+ {customThemeRows.map((row) => (
+ <div key={row.key} className="univer-flex univer-h-10 univer-min-w-0 univer-gap-2">
<div
className={clsx(`
- univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center
- univer-leading-9
+ univer-flex univer-min-w-0 univer-flex-1 univer-items-center univer-rounded-md
+ univer-px-3 univer-text-sm univer-font-medium
+ rtl:univer-text-right
`, borderClassName, {
- 'univer-text-white': lastRowBgIsDark,
- 'univer-text-gray-900': !lastRowBgIsDark,
+ 'univer-text-white': row.isDark,
+ 'univer-text-gray-900': !row.isDark,
})}
- style={{
- background: lastRowBg,
- }}
+ style={{ background: row.background }}
>
- {localeService.t<LocaleKey>('sheets-table-ui.footer')}
+ <span className="univer-truncate">{row.label}</span>
</div>
<Dropdown
overlay={(
- <div className="univer-p-2">
+ <div dir={direction} className="univer-p-2">
<ColorPicker
- value={lastRowBg}
- onChange={(val) => {
- const lastRowStyle = processStyleWithBorderStyle('lastRowStyle', {
- bg: {
- rgb: val,
- },
- cl: {
- rgb: new ColorKit(val).isDark() ? '#fff' : '#000',
- },
- });
- setCustomTheme(table.getTableStyleId(), { lastRowStyle });
- }}
+ value={new ColorKit(row.background).toHexString()}
+ onChange={row.onChange}
/>
</div>
)}
>
- <div
+ <button
+ type="button"
+ aria-label={`${row.label} ${localeService.t<LocaleKey>('sheets-table-ui.setTheme')}`}
className={clsx(`
- univer-flex univer-cursor-pointer univer-items-center univer-gap-2
- univer-rounded-sm univer-bg-white univer-p-1
+ univer-flex univer-h-10 univer-cursor-pointer univer-items-center univer-gap-2
+ univer-rounded-md univer-bg-white univer-px-2 univer-text-gray-600
+ univer-transition-colors
+ hover:univer-bg-gray-100
+ focus:univer-outline-none focus:univer-ring-2 focus:univer-ring-primary-200
+ dark:!univer-bg-gray-900 dark:!univer-text-gray-300
`, borderClassName)}
>
- <div
- className={clsx('univer-size-4 univer-rounded-lg univer-bg-gray-400', borderClassName)}
- style={{ background: lastRowBg }}
+ <span
+ className={clsx('univer-size-4 univer-rounded-full', borderClassName)}
+ style={{ background: row.background }}
/>
- <DownIcon className="univer-size-2" />
- </div>
+ <DownIcon className="univer-size-3" />
+ </button>
</Dropdown>
</div>
- </div>
- </>
+ ))}
+ </div>
)}
- </div>
+ </section>
</div>
);
};
diff --git a/packages/sheets-table-ui/src/views/components/__tests__/SheetTableComponents.spec.tsx b/packages/sheets-table-ui/src/views/components/__tests__/SheetTableComponents.spec.tsx
index 6496b0c399..a5feb15b6a 100644
--- a/packages/sheets-table-ui/src/views/components/__tests__/SheetTableComponents.spec.tsx
+++ b/packages/sheets-table-ui/src/views/components/__tests__/SheetTableComponents.spec.tsx
@@ -686,9 +686,7 @@ function clickCheckboxByText(container: HTMLElement, text: string): void {
}
function clickCustomThemeAddControl(container: HTMLElement): void {
- const addControl = Array.from(container.querySelectorAll('div')).find((item) => {
- return item.textContent?.trim() === '+' && item.className.includes('univer-leading-10');
- });
+ const addControl = container.querySelector('[data-u-comp="sheet-table-theme-add"]');
if (!addControl) {
throw new Error('Custom theme add control was not found.');
}
@@ -697,9 +695,7 @@ function clickCustomThemeAddControl(container: HTMLElement): void {
}
function clickCustomThemeRemoveControl(container: HTMLElement): void {
- const removeControl = Array.from(container.querySelectorAll('div')).find((item) => {
- return item.textContent?.trim() === 'x' && item.className.includes('univer-absolute');
- });
+ const removeControl = container.querySelector('[data-u-comp="sheet-table-theme-remove"]');
if (!removeControl) {
throw new Error('Custom theme remove control was not found.');
}
@@ -1389,6 +1385,45 @@ describe('sheet table view components', () => {
expect(table.getTableStyleId()).toBe('table-custom-1');
});
+ it('opens a custom table theme color without NaN channel values', async () => {
+ testBed = createTestBed();
+ const unitId = testBed.workbook.getUnitId();
+ const rendered = renderWithRediContext(
+ testBed,
+ <SheetTableThemePanel
+ unitId={unitId}
+ subUnitId="sheet1"
+ tableId="table-orders"
+ oldConfig={{}}
+ />
+ );
+ root = rendered.root;
+ container = rendered.container;
+
+ clickCustomThemeAddControl(container);
+ await flushCommands();
+
+ const headerColorButton = Array.from(container.querySelectorAll('button'))
+ .find((button) => button.getAttribute('aria-label')?.startsWith('Header '));
+ if (!headerColorButton) {
+ throw new Error('Header color control was not found.');
+ }
+ clickElement(headerColorButton);
+
+ const colorPicker = document.querySelector('[data-u-comp="color-picker"]');
+ const moreColorControl = colorPicker?.querySelector('a');
+ if (!moreColorControl) {
+ throw new Error('More color control was not found.');
+ }
+ clickElement(moreColorControl);
+
+ const channelValues = Array.from(document.querySelectorAll('input[maxlength="6"], input[maxlength="3"]'))
+ .map((input) => (input as HTMLInputElement).value);
+
+ expect(channelValues).toHaveLength(4);
+ expect(channelValues.every((value) => !value.toLowerCase().includes('nan'))).toBe(true);
+ });
+
it('removes an unused custom theme without changing the table style', async () => {
testBed = createTestBed();
const unitId = testBed.workbook.getUnitId();
diff --git a/packages/sheets-table-ui/src/views/widgets/__tests__/table-controls-util.spec.ts b/packages/sheets-table-ui/src/views/widgets/__tests__/table-controls-util.spec.ts
index fb514c9af3..303f78e27b 100644
--- a/packages/sheets-table-ui/src/views/widgets/__tests__/table-controls-util.spec.ts
+++ b/packages/sheets-table-ui/src/views/widgets/__tests__/table-controls-util.spec.ts
@@ -18,7 +18,6 @@ import type { SpreadsheetSkeleton, UniverRenderingContext } from '@univerjs/engi
import { describe, expect, it } from 'vitest';
import {
buildCenteredPlusSegments,
- buildTableMenuRegions,
hitTestTableControl,
TABLE_CONTROL_INSERT_BUTTON_SIZE,
} from '../table-controls-util';
@@ -74,13 +73,6 @@ describe('table controls geometry', () => {
], 0, 0)).toBeNull();
});
- it('builds menu item regions under the anchor', () => {
- const regions = buildTableMenuRegions('t1', 20, 30);
-
- expect(regions.map((item) => item.action)).toEqual(['rename', 'update-range', 'set-theme', 'delete']);
- expect(regions[0]).toMatchObject({ left: 20, top: 30 });
- });
-
it('builds centered plus segments around the insert button center', () => {
const segments = buildCenteredPlusSegments(20, 30, 8);
@@ -90,7 +82,7 @@ describe('table controls geometry', () => {
]);
});
- it('opens a table menu whose action rows can be hit-tested', () => {
+ it('keeps menu action rows out of canvas hit testing', () => {
const shape = new DrawableSheetTableControlsShape('table-controls', createSkeleton);
shape.setItems([{
tableId: 'table-orders',
@@ -103,11 +95,7 @@ describe('table controls geometry', () => {
shape.drawForTest(createCanvasContext());
- expect(shape.hitTest(56, 170)).toMatchObject({
- type: 'menu-item',
- tableId: 'table-orders',
- action: 'delete',
- });
+ expect(shape.hitTest(56, 170)).toBeNull();
});
it('activates the hovered insert region for row and column insertion', () => {
diff --git a/packages/sheets-table-ui/src/views/widgets/table-controls-util.ts b/packages/sheets-table-ui/src/views/widgets/table-controls-util.ts
index 4f19ad2cfa..e4913b99b9 100644
--- a/packages/sheets-table-ui/src/views/widgets/table-controls-util.ts
+++ b/packages/sheets-table-ui/src/views/widgets/table-controls-util.ts
@@ -16,20 +16,15 @@
export const TABLE_CONTROL_ANCHOR_HEIGHT = 28;
export const TABLE_CONTROL_ANCHOR_RADIUS = 14;
-export const TABLE_CONTROL_MENU_WIDTH = 168;
-export const TABLE_CONTROL_MENU_ITEM_HEIGHT = 32;
export const TABLE_CONTROL_INSERT_BUTTON_SIZE = 22;
export const TABLE_CONTROL_TOP_GAP_SIZE = 32;
export type TableControlHitType =
| 'anchor-main'
| 'anchor-menu-toggle'
- | 'menu-item'
| 'insert-row'
| 'insert-column';
-export type TableControlMenuAction = 'rename' | 'update-range' | 'set-theme' | 'delete';
-
export interface ITableControlHitRegion {
type: TableControlHitType;
tableId: string;
@@ -37,7 +32,6 @@ export interface ITableControlHitRegion {
top: number;
width: number;
height: number;
- action?: TableControlMenuAction;
index?: number;
}
@@ -48,8 +42,6 @@ export interface ITableControlLineSegment {
toY: number;
}
-export const TABLE_CONTROL_MENU_ACTIONS: TableControlMenuAction[] = ['rename', 'update-range', 'set-theme', 'delete'];
-
export function isPointInTableControlRegion(region: ITableControlHitRegion, x: number, y: number): boolean {
return x >= region.left && x <= region.left + region.width && y >= region.top && y <= region.top + region.height;
}
@@ -64,18 +56,6 @@ export function hitTestTableControl(regions: ITableControlHitRegion[], x: number
return null;
}
-export function buildTableMenuRegions(tableId: string, left: number, top: number): ITableControlHitRegion[] {
- return TABLE_CONTROL_MENU_ACTIONS.map((action, index) => ({
- type: 'menu-item',
- tableId,
- action,
- left,
- top: top + index * TABLE_CONTROL_MENU_ITEM_HEIGHT,
- width: TABLE_CONTROL_MENU_WIDTH,
- height: TABLE_CONTROL_MENU_ITEM_HEIGHT,
- }));
-}
-
export function buildCenteredPlusSegments(centerX: number, centerY: number, size: number): [ITableControlLineSegment, ITableControlLineSegment] {
const halfSize = size / 2;
diff --git a/packages/sheets-table-ui/src/views/widgets/table-controls.shape.ts b/packages/sheets-table-ui/src/views/widgets/table-controls.shape.ts
index 382657d15c..2267afbd1d 100644
--- a/packages/sheets-table-ui/src/views/widgets/table-controls.shape.ts
+++ b/packages/sheets-table-ui/src/views/widgets/table-controls.shape.ts
@@ -15,16 +15,13 @@
*/
import type { IShapeProps, SpreadsheetSkeleton, UniverRenderingContext, Vector2 } from '@univerjs/engine-render';
-import type { ITableControlHitRegion, TableControlMenuAction } from './table-controls-util';
-import { DEFAULT_FONTFACE_PLANE, Rect, Shape } from '@univerjs/engine-render';
+import type { ITableControlHitRegion } from './table-controls-util';
+import { DEFAULT_FONTFACE_PLANE, Shape } from '@univerjs/engine-render';
import {
buildCenteredPlusSegments,
- buildTableMenuRegions,
hitTestTableControl,
TABLE_CONTROL_ANCHOR_HEIGHT,
TABLE_CONTROL_ANCHOR_RADIUS,
- TABLE_CONTROL_MENU_ITEM_HEIGHT,
- TABLE_CONTROL_MENU_WIDTH,
} from './table-controls-util';
const ANCHOR_MIN_WIDTH = 122;
@@ -35,9 +32,6 @@ const ANCHOR_OFFSET_Y = 0;
const ANCHOR_BORDER = 'rgba(0, 0, 0, 0.22)';
const ANCHOR_DIVIDER = 'rgba(0, 0, 0, 0.20)';
const ANCHOR_TOGGLE_BG_ACTIVE = 'rgba(0, 0, 0, 0.12)';
-const MENU_RADIUS = 8;
-const MENU_BORDER = '#d9dee7';
-const MENU_HOVER_BG = '#f1f3f4';
const INSERT_BUTTON_VISUAL_SIZE = 18;
const INSERT_BUTTON_PLUS_SIZE = 8;
@@ -49,25 +43,12 @@ export interface ITableControlRenderItem {
text: string;
}
-export interface ITableControlMenuLabels {
- rename: string;
- 'update-range': string;
- 'set-theme': string;
- delete: string;
-}
-
export class SheetTableControlsShape extends Shape<IShapeProps> {
private _items: ITableControlRenderItem[] = [];
private _regions: ITableControlHitRegion[] = [];
private _openedMenuTableId: string | null = null;
private _hoveredRegion: ITableControlHitRegion | null = null;
private _hoveredInsertRegion: ITableControlHitRegion | null = null;
- private _menuLabels: ITableControlMenuLabels = {
- rename: 'Rename table',
- 'update-range': 'Update range',
- 'set-theme': 'Set theme',
- delete: 'Remove table',
- };
constructor(
key: string,
@@ -85,11 +66,6 @@ export class SheetTableControlsShape extends Shape<IShapeProps> {
this.makeDirty(true);
}
- setMenuLabels(labels: ITableControlMenuLabels): void {
- this._menuLabels = labels;
- this.makeDirty(true);
- }
-
setOpenedMenuTableId(tableId: string | null): void {
if (this._openedMenuTableId === tableId) {
return;
@@ -103,6 +79,10 @@ export class SheetTableControlsShape extends Shape<IShapeProps> {
return this._openedMenuTableId;
}
+ getAnchorRegion(tableId: string): ITableControlHitRegion | null {
+ return this._regions.find((region) => region.type === 'anchor-main' && region.tableId === tableId) ?? null;
+ }
+
setHoveredRegion(region: ITableControlHitRegion | null): void {
if (this._hoveredRegion === region) {
return;
@@ -202,10 +182,6 @@ export class SheetTableControlsShape extends Shape<IShapeProps> {
height: TABLE_CONTROL_ANCHOR_HEIGHT,
});
this._regions.push(toggleRegion);
-
- if (this._openedMenuTableId === item.tableId) {
- this._drawMenu(ctx, item.tableId, left, top + TABLE_CONTROL_ANCHOR_HEIGHT);
- }
}
private _drawAnchorToggle(ctx: UniverRenderingContext, anchorWidth: number, color: string, active: boolean): void {
@@ -277,40 +253,6 @@ export class SheetTableControlsShape extends Shape<IShapeProps> {
ctx.restore();
}
- private _drawMenu(ctx: UniverRenderingContext, tableId: string, left: number, top: number): void {
- const regions = buildTableMenuRegions(tableId, left, top);
-
- ctx.save();
- ctx.translateWithPrecision(left, top);
- Rect.drawWith(ctx, {
- width: TABLE_CONTROL_MENU_WIDTH,
- height: regions.length * TABLE_CONTROL_MENU_ITEM_HEIGHT,
- radius: MENU_RADIUS,
- fill: '#fff',
- stroke: MENU_BORDER,
- });
- ctx.restore();
-
- for (const region of regions) {
- const hovered = this._isSameRegion(this._hoveredRegion, region);
- if (hovered) {
- ctx.save();
- ctx.fillStyle = MENU_HOVER_BG;
- ctx.fillRectByPrecision(region.left, region.top, region.width, region.height);
- ctx.restore();
- }
-
- ctx.save();
- ctx.font = `12px ${DEFAULT_FONTFACE_PLANE}`;
- ctx.fillStyle = region.action === 'delete' ? '#d92d20' : '#344054';
- ctx.textAlign = 'left';
- ctx.fillText(this._menuLabels[region.action as TableControlMenuAction], region.left + 12, region.top + region.height / 2);
- ctx.restore();
- }
-
- this._regions.push(...regions);
- }
-
private _drawInsertButton(ctx: UniverRenderingContext, region: ITableControlHitRegion, fill: string): void {
const centerX = region.left + region.width / 2;
const centerY = region.top + region.height / 2;
@@ -336,6 +278,6 @@ export class SheetTableControlsShape extends Shape<IShapeProps> {
}
private _isSameRegion(a: ITableControlHitRegion | null, b: ITableControlHitRegion): boolean {
- return Boolean(a && a.type === b.type && a.tableId === b.tableId && a.action === b.action && a.index === b.index);
+ return Boolean(a && a.type === b.type && a.tableId === b.tableId && a.index === b.index);
}
}
diff --git a/packages/sheets-ui/src/views/cell-alert/CellAlertPopup.tsx b/packages/sheets-ui/src/views/cell-alert/CellAlertPopup.tsx
index ea03a54893..e01bed03ec 100644
--- a/packages/sheets-ui/src/views/cell-alert/CellAlertPopup.tsx
+++ b/packages/sheets-ui/src/views/cell-alert/CellAlertPopup.tsx
@@ -98,9 +98,9 @@ export function CellAlert({ popup }: { popup: ICanvasPopup }) {
}
const iconMap = {
- [CellAlertType.ERROR]: <ErrorIcon className="univer-mr-1.5 univer-text-red-500" />,
- [CellAlertType.INFO]: <InfoIcon className="univer-mr-1.5 univer-text-blue-500" />,
- [CellAlertType.WARNING]: <WarningIcon className="univer-mr-1.5 univer-text-yellow-500" />,
+ [CellAlertType.ERROR]: <ErrorIcon className="univer-text-red-500" />,
+ [CellAlertType.INFO]: <InfoIcon className="univer-text-blue-500" />,
+ [CellAlertType.WARNING]: <WarningIcon className="univer-text-yellow-500" />,
};
return (
@@ -113,8 +113,8 @@ export function CellAlert({ popup }: { popup: ICanvasPopup }) {
>
<div
className={`
- univer-mb-1.5 univer-flex univer-h-5 univer-flex-row univer-items-center univer-text-sm
- univer-font-medium
+ univer-mb-1.5 univer-flex univer-h-5 univer-flex-row univer-items-center univer-gap-x-1.5
+ univer-text-sm univer-font-medium
`}
>
{type ? iconMap[type] : null}
diff --git a/packages/sheets-ui/src/views/cell-alert/__tests__/CellAlertPopup.spec.tsx b/packages/sheets-ui/src/views/cell-alert/__tests__/CellAlertPopup.spec.tsx
new file mode 100644
index 0000000000..73b28f1041
--- /dev/null
+++ b/packages/sheets-ui/src/views/cell-alert/__tests__/CellAlertPopup.spec.tsx
@@ -0,0 +1,49 @@
+/**
+ * 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 { ICanvasPopup } from '../../../services/canvas-pop-manager.service';
+import { act } from 'react';
+import { createRoot } from 'react-dom/client';
+import { describe, expect, it } from 'vitest';
+import { CellAlertType } from '../../../services/cell-alert-manager.service';
+import { CellAlert } from '../CellAlertPopup';
+
+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+describe('CellAlert', () => {
+ it('uses flex gap instead of a physical icon margin', () => {
+ const container = document.createElement('div');
+ const root = createRoot(container);
+ const popup = {
+ componentKey: 'univer.sheet.cell-alert',
+ extraProps: {
+ alert: {
+ type: CellAlertType.ERROR,
+ title: 'Invalid value',
+ message: 'Value must be at least 100',
+ },
+ },
+ } as ICanvasPopup;
+
+ act(() => root.render(<CellAlert popup={popup} />));
+
+ const titleRow = Array.from(container.querySelectorAll('div')).find((element) => element.textContent === 'Invalid value');
+ expect(titleRow?.className).toContain('univer-gap-x-1.5');
+ expect(container.querySelector('svg')?.getAttribute('class')).not.toContain('univer-mr-1.5');
+
+ act(() => root.unmount());
+ });
+});
diff --git a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
index 9d52316651..0b732377d3 100644
--- a/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
+++ b/packages/sheets-ui/src/views/formula-bar/FormulaBar.tsx
@@ -297,6 +297,7 @@ export function FormulaBar(props: IProps) {
return (
<div
+ dir="ltr"
data-u-comp="formula-bar"
className={clsx(`
univer-box-border univer-flex univer-bg-white univer-transition-[height] univer-ease-linear
diff --git a/packages/sheets-ui/src/views/formula-bar/__tests__/FormulaBar.spec.tsx b/packages/sheets-ui/src/views/formula-bar/__tests__/FormulaBar.spec.tsx
index 4a57d42c91..f8c916247a 100644
--- a/packages/sheets-ui/src/views/formula-bar/__tests__/FormulaBar.spec.tsx
+++ b/packages/sheets-ui/src/views/formula-bar/__tests__/FormulaBar.spec.tsx
@@ -326,6 +326,15 @@ describe('FormulaBar', () => {
currentBed = undefined;
});
+ it('keeps its toolbar layout LTR when the sheet host is RTL', () => {
+ currentBed = createFormulaBarTestBed();
+ const rendered = renderWithDependencies(<FormulaBar disableDefinedName />, currentBed.injector);
+ root = rendered.root;
+ container = rendered.container;
+
+ expect(rendered.container.querySelector('[data-u-comp="formula-bar"]')?.getAttribute('dir')).toBe('ltr');
+ });
+
it('closes editing through the command service when cancel is clicked', async () => {
currentBed = createFormulaBarTestBed();
const rendered = renderWithDependencies(<FormulaBar disableDefinedName />, currentBed.injector);
diff --git a/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx b/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx
index 160c9a4115..a9bba456c9 100644
--- a/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx
+++ b/packages/thread-comment-ui/src/views/ThreadCommentTree.tsx
@@ -104,6 +104,7 @@ function formatCommentDateTime(value: string, region: LocaleType): string {
hour: '2-digit',
minute: '2-digit',
hour12: false,
+ numberingSystem: 'latn',
});
}
@@ -134,6 +135,7 @@ const ThreadCommentItem = (props: IThreadCommentItemProps) => {
const uiConfig = useConfigValue<IUniverUIConfig>(UI_PLUGIN_CONFIG_KEY);
const avatarFallback = uiConfig?.avatarFallback;
const currentRegion = useObservable(regionService.currentRegion$, regionService.getCurrentRegion());
+ const direction = useObservable(localeService.direction$, localeService.getDirection());
const dateText = isMock ? null : formatCommentDateTime(item.dT, currentRegion);
const handleDeleteItem = () => {
@@ -205,11 +207,12 @@ const ThreadCommentItem = (props: IThreadCommentItemProps) => {
? (
<Dropdown
overlay={(
- <div className="univer-rounded-lg">
+ <div dir={direction} className="univer-rounded-lg">
<ul
className={`
univer-m-0 univer-box-border univer-grid univer-list-none
univer-p-1.5 univer-text-sm
+ rtl:univer-text-right
[&_a]:univer-block [&_a]:univer-cursor-pointer
[&_a]:univer-rounded [&_a]:univer-px-2 [&_a]:univer-py-1.5
[&_a]:univer-transition-colors
@@ -259,6 +262,7 @@ const ThreadCommentItem = (props: IThreadCommentItemProps) => {
dir="ltr"
className={`
univer-mb-1 univer-block univer-text-xs/normal univer-text-gray-600
+ rtl:univer-text-right
dark:!univer-text-gray-200
`}
>
@@ -529,7 +533,11 @@ export const ThreadCommentTree = (props: IThreadCommentTreeProps) => {
</div>
<div
ref={scroller}
- className={clsx('univer-max-h-80 univer-overflow-y-auto univer-overflow-x-hidden', scrollbarClassName)}
+ className={clsx(
+ 'univer-max-h-80 univer-overflow-y-auto univer-overflow-x-hidden',
+ scrollbarClassName,
+ location === ThreadCommentTreeLocation.PANEL && '-univer-mx-4 univer-px-4'
+ )}
>
{renderComments.map(
(item) => (
diff --git a/packages/thread-comment-ui/src/views/__tests__/ThreadCommentPanel.spec.tsx b/packages/thread-comment-ui/src/views/__tests__/ThreadCommentPanel.spec.tsx
index 39ed713486..c39d6b283b 100644
--- a/packages/thread-comment-ui/src/views/__tests__/ThreadCommentPanel.spec.tsx
+++ b/packages/thread-comment-ui/src/views/__tests__/ThreadCommentPanel.spec.tsx
@@ -82,6 +82,8 @@ interface IEditorRecord {
class TestLocaleService {
private readonly _currentLocale$ = new BehaviorSubject<LocaleType>(LocaleType.ZH_CN);
readonly currentLocale$ = this._currentLocale$.asObservable();
+ private readonly _direction$ = new BehaviorSubject<'ltr' | 'rtl'>('ltr');
+ readonly direction$ = this._direction$.asObservable();
t(key: string) {
return key;
@@ -90,6 +92,10 @@ class TestLocaleService {
getCurrentLocale() {
return this._currentLocale$.getValue();
}
+
+ getDirection() {
+ return this._direction$.getValue();
+ }
}
class TestEditor {
diff --git a/packages/thread-comment-ui/src/views/__tests__/ThreadCommentTree.spec.tsx b/packages/thread-comment-ui/src/views/__tests__/ThreadCommentTree.spec.tsx
index 7120d97395..37c0729f75 100644
--- a/packages/thread-comment-ui/src/views/__tests__/ThreadCommentTree.spec.tsx
+++ b/packages/thread-comment-ui/src/views/__tests__/ThreadCommentTree.spec.tsx
@@ -95,6 +95,8 @@ class TestState {
class TestLocaleService {
private readonly _currentLocale$ = new BehaviorSubject<LocaleType>(LocaleType.ZH_CN);
readonly currentLocale$ = this._currentLocale$.asObservable();
+ private readonly _direction$ = new BehaviorSubject<'ltr' | 'rtl'>('ltr');
+ readonly direction$ = this._direction$.asObservable();
t(key: string) {
return key;
@@ -107,6 +109,14 @@ class TestLocaleService {
getCurrentLocale() {
return this._currentLocale$.getValue();
}
+
+ setDirection(direction: 'ltr' | 'rtl') {
+ this._direction$.next(direction);
+ }
+
+ getDirection() {
+ return this._direction$.getValue();
+ }
}
class TestEditor {
@@ -496,6 +506,18 @@ function getReplyAction(container: HTMLElement, commentId: string) {
return action as HTMLElement;
}
+function getMoreAction(container: HTMLElement, commentId: string) {
+ const item = getRootCommentItem(container, commentId);
+ const nameRow = item.children[1] as HTMLElement | undefined;
+ const controls = nameRow?.lastElementChild as HTMLElement | undefined;
+ const action = controls?.lastElementChild;
+ if (!action) {
+ throw new Error('More action was not found.');
+ }
+
+ return action as HTMLElement;
+}
+
function getOnlyEditor(testBed: ReturnType<typeof createTreeTestBed>) {
const editors = Array.from(testBed.editorService.getAllEditor().values());
if (editors.length !== 1) {
@@ -535,6 +557,20 @@ describe('ThreadCommentTree', () => {
container = undefined;
});
+ it('extends the panel scroller to the card edges while preserving content padding', () => {
+ const testBed = createTreeTestBed();
+ addRootComment(testBed.threadCommentModel, createComment({ id: 'root-thread', ref: 'A1' }));
+
+ const rendered = renderDefaultTree(testBed.injector, 'root-thread');
+ root = rendered.root;
+ container = rendered.container;
+
+ const scroller = getTree(container, 'root-thread').children[1] as HTMLElement;
+
+ expect(scroller.className).toContain('-univer-mx-4');
+ expect(scroller.className).toContain('univer-px-4');
+ });
+
it('provides mirrored layout hooks for RTL comment rows', () => {
const testBed = createTreeTestBed();
addRootComment(testBed.threadCommentModel, createComment({ id: 'root-thread', ref: 'A1', dT: '2026/07/07 20:35' }));
@@ -560,6 +596,26 @@ describe('ThreadCommentTree', () => {
expect(avatar.className).toContain('rtl:univer-left-auto');
expect(avatar.className).toContain('rtl:univer-right-0');
expect(time?.getAttribute('dir')).toBe('ltr');
+ expect(time?.className).toContain('rtl:univer-text-right');
+ });
+
+ it('right-aligns the comment action menu in RTL', () => {
+ const testBed = createTreeTestBed();
+ const localeService = testBed.injector.get(LocaleService);
+ addRootComment(testBed.threadCommentModel, createComment({ id: 'root-thread', ref: 'A1' }));
+
+ const rendered = renderDefaultTree(testBed.injector, 'root-thread');
+ root = rendered.root;
+ container = rendered.container;
+
+ act(() => localeService.setDirection('rtl'));
+ act(() => getMoreAction(container!, 'root-thread').click());
+
+ const menu = document.body.querySelector('[data-slot="popover-content"] ul');
+
+ expect(menu).not.toBeNull();
+ expect(menu?.parentElement?.getAttribute('dir')).toBe('rtl');
+ expect(menu?.className).toContain('rtl:univer-text-right');
});
it('formats comment timestamps with dateKit intl using the current region', () => {
@@ -587,6 +643,22 @@ describe('ThreadCommentTree', () => {
expect(time?.textContent).not.toBe(rawDate);
});
+ it.each([LocaleType.AR_SA, LocaleType.FA_IR])('uses Latin digits for %s comment timestamps', (region) => {
+ const testBed = createTreeTestBed();
+ const rawDate = '2026/07/07 20:35';
+ testBed.injector.get(RegionService).setRegion(region);
+ addRootComment(testBed.threadCommentModel, createComment({ id: 'root-thread', ref: 'A1', dT: rawDate }));
+
+ const rendered = renderDefaultTree(testBed.injector, 'root-thread');
+ root = rendered.root;
+ container = rendered.container;
+
+ const dateText = getRootCommentItem(container, 'root-thread').querySelector('time')?.textContent ?? '';
+
+ expect(dateText).toMatch(/[0-9]/);
+ expect(dateText).not.toMatch(/[\u0660-\u0669\u06F0-\u06F9]/u);
+ });
+
it('does not render a timestamp for a new comment', () => {
const testBed = createTreeTestBed();