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.

Merge remote-tracking branch 'origin/dev' into wzhudev/refactor-toolbar

wzhudev2b825e45891e
diff --cc packages/base-sheets/src/index.ts
index da94a823f6,291bc2d336..ad0c36c5e4
--- a/packages/base-sheets/src/index.ts
+++ b/packages/base-sheets/src/index.ts
@@@ -29,19 -29,14 +29,18 @@@ export
SetCellBorderCommand,
SetTextRotationCommand,
SetHorizontalTextAlignCommand,
-- SetSpanCommand,
SetTextWrapCommand,
SetVerticalTextAlignCommand,
+ ResetTextColorCommand,
+ ResetBackgroundColorCommand,
+ SetCellBorderColorCommand,
} from './Commands/Commands/set-style.command';
export { InsertSheetCommand } from './Commands/Commands/insert-sheet.command';
- export { ClearSelectionContentCommand } from './Commands/Commands/clear-selection-content.command';
- export { InsertRowCommand, InsertColCommand } from './Commands/Commands/insert-row-col.command';
export { SetWorksheetActivateCommand } from './Commands/Commands/set-worksheet-activate.command';
export { SetWorksheetOrderCommand } from './Commands/Commands/set-worksheet-order.command';
export { SetWorksheetRowHeightCommand } from './Commands/Commands/set-worksheet-row-height.command';
export { SetWorksheetColWidthCommand } from './Commands/Commands/set-worksheet-col-width.command';
export { DeleteRangeCommand } from './Commands/Commands/delete-range.command';
export { RemoveRowCommand, RemoveColCommand } from './Commands/Commands/remove-row-col.command';
++export { InsertColCommand, InsertRowCommand, InsertColCommandParams, InsertRowCommandParams } from './Commands/Commands/insert-row-col.command';
++export { ClearSelectionContentCommand } from './Commands/Commands/clear-selection-content.command';
diff --cc packages/base-ui/src/Components/Menu/Menu.tsx
index 84dd4988a6,054b098cd3..036337e086
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@@ -1,23 -1,16 +1,23 @@@
import { Component, ComponentChild, createRef } from 'preact';
import { Subscription } from 'rxjs';
import { ICommandService } from '@univerjs/core';
- import { BaseMenuProps, BaseMenuItem, BaseMenuStyle } from '../../Interfaces';
--import { joinClassNames } from '../../Utils';
- import { CustomLabel, NeoCustomLabel } from '../CustomLabel';
-import { CustomLabel } from '../CustomLabel';
-
-import { BaseMenuProps, BaseMenuState, BaseMenuItem, BaseMenuStyle } from '../../Interfaces';
-
import styles from './index.module.less';
- import { IDisplayMenuItem, IMenuService } from '../../services/menu/menu.service';
-import { IDisplayMenuItem } from '../../services/menu/menu.service';
-import AppContext from '../../Common/AppContext';
+import { AppContext } from '../../Common/AppContext';
- import { ICustomComponentOption, IMenuItem, IValueOption, isValueOptions } from '../../services/menu/menu';
++import { ICustomComponentOption, IDisplayMenuItem, IMenuItem, IValueOption, isValueOptions } from '../../services/menu/menu';
++import { BaseMenuItem, BaseMenuProps, BaseMenuStyle } from '../../Interfaces/Menu';
++import { joinClassNames } from '../../Utils/util';
++import { CustomLabel, NeoCustomLabel } from '../CustomLabel/CustomLabel';
++import { IMenuService } from '../../services/menu/menu.service';
+
+export interface IBaseMenuState {
+ show: boolean;
+ posStyle: BaseMenuStyle;
+ menuItems: Array<IDisplayMenuItem<IMenuItem>>;
+}
+
+export class Menu extends Component<BaseMenuProps, IBaseMenuState> {
+ static override contextType = AppContext;
-export class Menu extends Component<BaseMenuProps, BaseMenuState> {
private _MenuRef = createRef<HTMLUListElement>();
private _refs: Menu[] = [];
@@@ -109,13 -92,25 +109,13 @@@
posStyle: style,
});
}
- // else {
- // if (curPosition.width > docPosition!.right) {
- // // 边界碰到univer-main-content右边界或者小于视口
- // style.right = '0';
- // style.left = 'auto';
- // } else {
- // style.left = '0';
- // style.right = 'auto';
- // }
- // if (curPosition.top >= docPosition.bottom) {
- // style.top = 'auto';
- // style.bottom = '100%';
- // }
- // }
};
+ // eslint-disable-next-line max-lines-per-function
render() {
- const { className = '', menuItems, style = '', menu, deep = 0 } = this.props;
- const { show, posStyle } = this.state;
+ const { context, props, state } = this;
+ const { className = '', style = '', menu, deep = 0, options, display } = props;
- const { show, posStyle, menuItems } = state;
++ const { posStyle, show, menuItems } = state;
return (
<ul className={joinClassNames(styles.colsMenu, className)} style={{ ...style, ...posStyle, display: show ? 'block' : 'none' }} ref={this._MenuRef}>
diff --cc packages/base-ui/src/Interfaces/Menu.ts
index b4a283e958,2880b2bdcb..e7d45b22db
--- a/packages/base-ui/src/Interfaces/Menu.ts
+++ b/packages/base-ui/src/Interfaces/Menu.ts
@@@ -1,7 -1,6 +1,7 @@@
import { ComponentChildren, JSX } from 'preact';
import { BaseComponent, JSXComponent } from '../BaseComponent';
- import { ICustomComponentOption, IValueOption } from '../services/menu/menu';
-import { IDisplayMenuItem, IMenuItem } from '../services/menu/menu.service';
++import { ICustomComponentOption, IMenuButtonItem, IValueOption } from '../services/menu/menu';
+import { DisplayTypes } from '../Components/Select/Select';
export interface BaseMenuItem {
className?: string;
@@@ -16,31 -15,27 +16,40 @@@
}
export interface BaseMenuProps {
- /** @deprecated this is legacy menu mechanism. Do not use it. Use `menuItems` instead. */
- menu?: BaseMenuItem[];
- menuItems?: IDisplayMenuItem[];
+ /** @deprecated */
onClick?: (...arg: any) => void;
+ /** @deprecated */
className?: string;
+ /** @deprecated */
style?: JSX.CSSProperties;
+ /** @deprecated */
parent?: any;
+ /** @deprecated */
dom?: HTMLElement;
+ /** @deprecated */
ref?: any;
+ /** @deprecated */
deep?: number;
+ /** @deprecated this is legacy menu mechanism. Do not use it. Use `menuItems` instead. */
+ menu?: BaseMenuItem[]; // TODO: should be renamed to `items`
+
+ // NOTE: options above are legacy. They are going to be removed after we complete refactoring.
+
+ display?: DisplayTypes;
+ menuId?: string;
+ options?: Array<IValueOption | ICustomComponentOption>;
+ onOptionSelect?: (option: IValueOption) => void;
}
-export interface TreeMenuItems extends IMenuItem {
++export interface TreeMenuItems extends IMenuButtonItem {
+ subMenuItems: TreeMenuItems[];
+ }
+
+ export type BaseMenuState = {
+ show: boolean;
+ posStyle: BaseMenuStyle;
+ };
+
export type BaseMenuStyle = {
left?: string;
right?: string;
diff --cc packages/base-ui/src/index.ts
index 10e9836668,f05aa731de..c040a6a5de
--- a/packages/base-ui/src/index.ts
+++ b/packages/base-ui/src/index.ts
@@@ -8,21 -8,9 +8,22 @@@ export * from './Components'
export * from './BaseComponent';
export * from './UIPlugin';
-export { IMenuService, IMenuItem, MenuPosition, DesktopMenuService, IDisplayMenuItem } from './services/menu/menu.service';
+export {
+ ICustomComponentProps,
+ ICustomComponentOption,
+ IMenuButtonItem,
+ IMenuItem,
+ IMenuSelectorItem,
+ IValueOption,
+ MenuItemType,
+ MenuPosition,
++ IDisplayMenuItem,
+ isCustomComponentOption,
+ isValueOptions,
+} from './services/menu/menu';
- export { IMenuService, DesktopMenuService, IDisplayMenuItem } from './services/menu/menu.service';
++export { IMenuService, DesktopMenuService } from './services/menu/menu.service';
export { KeyCode, MetaKeys } from './services/shortcut/keycode';
-export { IShortcutService, IShortcutItem, DesktopShortcutService } from './services/shortcut/shorcut.service';
+export { IShortcutService, IShortcutItem, DesktopShortcutService } from './services/shortcut/shortcut.service';
export { IPlatformService, DesktopPlatformService } from './services/platform/platform.service';
export { SharedController } from './controllers/shared-shortcut.controller';
diff --cc packages/base-ui/src/services/menu/menu.service.ts
index 55aeb95ee9,cc25c47797..974d0e7824
--- a/packages/base-ui/src/services/menu/menu.service.ts
+++ b/packages/base-ui/src/services/menu/menu.service.ts
@@@ -1,21 -1,66 +1,35 @@@
- import { createIdentifier, IDisposable } from '@wendellhu/redi';
-
++import { IDisposable, createIdentifier } from '@wendellhu/redi';
import { Disposable, toDisposable } from '@univerjs/core';
-
-import { createIdentifier, IDisposable } from '@wendellhu/redi';
-import { Observable } from 'rxjs';
-import { ComponentChildren } from 'preact';
-import { IShortcutService } from '../shortcut/shorcut.service';
-import { ICustomLabelType } from '../../Interfaces/CustomLabel';
+import { IShortcutService } from '../shortcut/shortcut.service';
- import { IMenuItem, MenuPosition } from './menu';
+ import { BaseSelectChildrenProps } from '../../Components/Select/Select';
+
-export type OneOrMany<T> = T | T[];
-
-export const enum MenuPosition {
- TOOLBAR,
- CONTEXT_MENU,
-}
++import { IDisplayMenuItem, IMenuItem, MenuPosition } from './menu';
- /**
- * @internal
- */
- export type IDisplayMenuItem<T extends IMenuItem> = T & {
- /** MenuService get responsible shortcut and display on the UI. */
- shortcut?: string;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ export interface IMenuItemState {
+ id: string;
+
+ disabled?: boolean;
+ hidden?: boolean;
+ checked?: boolean;
+ }
- /** Composed menu structure by the menu service. */
- subMenuItems?: Array<IDisplayMenuItem<IMenuItem>>; // TODO@wzhudev: related mechanism is not implemented yet
- };
+ // TODO@Dushusir remove CustomLabelProps and CustomLabel in rightMenuUIController after migrate new UI system
+
+ interface CustomLabelProps {
+ prefix?: string[] | string;
+ suffix?: string[] | string;
+ options?: BaseSelectChildrenProps[];
+ label?: string;
+ children?: CustomLabelProps[];
+ onKeyUp?: (e: Event) => void;
+ }
+
+ export interface CustomLabel {
+ name: string;
+ props?: CustomLabelProps;
+ }
-export interface IMenuItem {
- id: string;
- menu: OneOrMany<MenuPosition>;
- subMenus?: string[]; // submenu id list
- parentId?: string; // if it is submenu
- label?: string | ICustomLabelType | ComponentChildren;
-
- title: string;
- icon?: string;
- tooltip?: string;
- description?: string;
-
- hidden$?: Observable<boolean>;
- activated$?: Observable<boolean>;
- disabled$?: Observable<boolean>;
-}
-
-export interface IDisplayMenuItem extends IMenuItem {
- /** MenuService should get responsible shortcut and display on the UI. */
- shortcut?: string;
- subMenuItems?: IDisplayMenuItem[];
-}
-
export const IMenuService = createIdentifier<IMenuService>('univer.menu-service');
export interface IMenuService {
@@@ -80,21 -105,13 +94,22 @@@ export class DesktopMenuService extend
});
}
- getMenuItems(positions: MenuPosition): Array<IDisplayMenuItem<IMenuItem>> {
- getMenuItems(positions: MenuPosition): IDisplayMenuItem[] {
++ getMenuItems(positions: MenuPosition): Array<IDisplayMenuItem<any>> {
+ // TODO: @wzhudev: compose shortcut to returned menu items.
if (this._menuByPositions.has(positions)) {
- return [...this._menuByPositions.get(positions)!.values()].map((menu) => this.getDisplayMenuItems(menu));
+ return [...this._menuByPositions.get(positions)!.values()].filter((menu) => !menu.parentId).map((menu) => this.getDisplayMenuItems(menu));
+ }
+
+ return [] as Array<IDisplayMenuItem<any>>;
+ }
+
+ getSubMenuItems(parentId: string): Array<IDisplayMenuItem<IMenuItem>> {
+ const subMenuIds = this._menuByParentId.get(parentId);
+ if (!subMenuIds) {
+ return [];
}
- return [] as IDisplayMenuItem[];
+ return subMenuIds.map((id) => this.getDisplayMenuItems(this._menuItemMap.get(id)!));
}
getMenuItem(id: string): IMenuItem | null {
diff --cc packages/base-ui/src/services/menu/menu.ts
index 40019de590,0000000000..4c0e8b709c
mode 100644,000000..100644
--- a/packages/base-ui/src/services/menu/menu.ts
+++ b/packages/base-ui/src/services/menu/menu.ts
@@@ -1,104 -1,0 +1,108 @@@
+import { Observable } from 'rxjs';
+import { ComponentChildren } from 'preact';
+
+import { ICustomLabelType } from '../../Interfaces/CustomLabel';
+import { DisplayTypes, SelectTypes } from '../../Components/Select/Select';
+
+export type OneOrMany<T> = T | T[];
+
+export const enum MenuPosition {
+ VOID,
+ TOOLBAR,
+ CONTEXT_MENU,
+ TAB_CONTEXT_MENU,
+ ROW_HEADER_CONTEXT_MENU,
+ COL_HEADER_CONTEXT_MENU,
+}
+
+export const enum MenuItemType {
+ /** Button style menu item. */
+ BUTTON,
+ /** Menu item with submenus. Submenus could be other IMenuItem or an ID of a registered component. */
+ SELECTOR,
+ DROPDOWN,
+}
+
+interface IMenuItemBase {
+ /** ID of the menu item. Normally it should be the same as the ID of the command that it would invoke. */
+ id: string;
+ title: string;
+ description?: string;
+ icon?: string;
+ tooltip?: string;
+
+ /** @deprecated this type seems unnecessary */
+ type: MenuItemType;
+
+ /** In what menu should the item display. */
+ positions: OneOrMany<MenuPosition>;
+
+ /** @deprecated this parameter would be removed after refactoring */
+ label?: string | ICustomLabelType | ComponentChildren;
+
+ /** @deprecated this parameter would be removed after refactoring */
+ className?: string;
+
+ parentId?: string; // if it is submenu
+
+ hidden$?: Observable<boolean>;
+ disabled$?: Observable<boolean>;
+}
+
+export interface IMenuButtonItem extends IMenuItemBase {
+ type: MenuItemType.BUTTON;
+
+ activated$?: Observable<boolean>;
+}
+
+export interface IValueOption {
+ value: string | number;
+ label: string;
+ icon?: string;
+ tooltip?: string;
+ style?: object;
+ disabled?: boolean;
+}
+
+export function isValueOptions(v: IValueOption | ICustomComponentOption): v is IValueOption {
+ return typeof (v as IValueOption).value !== 'undefined';
+}
+
+export interface ICustomComponentOption {
+ id: string;
+}
+
+export interface ICustomComponentProps<T> {
+ value: T;
+ onValueChange: (v: T) => void;
+}
+
+export function isCustomComponentOption(v: IValueOption | ICustomComponentOption): v is ICustomComponentOption {
+ return typeof (v as ICustomComponentOption).id !== 'undefined';
+}
+
+export interface IMenuSelectorItem<V> extends IMenuItemBase {
+ type: MenuItemType.SELECTOR | MenuItemType.DROPDOWN;
+
+ /** Determines how the label of the selector should display. */
+ display?: DisplayTypes;
+
+ /** @deprecated this parameter would be removed after we complete refactoring */
+ selectType: SelectTypes;
+
+ // selections 子菜单可以为三种类型
+ // 一个是当前 menu 的 options,选中后直接使用其 value 触发 command
+ // 一个是一个特殊组件,比如 color picker,选中后直接使用其 value 触发 command
+ // 一个是其他 menu 的 id,直接渲染成其他的 menu
+ /** Options or IDs of registered components. */
+ selections?: Array<IValueOption | ICustomComponentOption>;
+
+ /** On observable value that should emit the value of the corresponding selection component. */
+ value$?: Observable<V>;
+}
+
+export type IMenuItem = IMenuButtonItem | IMenuSelectorItem<unknown>;
++
++export type IDisplayMenuItem<T extends IMenuItem> = T & {
++ shortcut?: string;
++};
diff --cc pnpm-lock.yaml
index 2adb9e6b22,a1db1e9dd3..cfd77ba241
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@@ -726,12 -717,9 +717,9 @@@ importers
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
devDependencies:
- '@preact/preset-vite':
- specifier: 2.0.0
'@testing-library/preact':
specifier: ^2.0.1
version: 2.0.1([email protected])
@@@ -784,12 -766,9 +766,9 @@@
specifier: workspace:^0.0.1
version: link:../core
'@wendellhu/redi':
- specifier: ^0.12.6
- version: 0.12.6
+ specifier: ^0.12.7
+ version: 0.12.7
devDependencies:
- '@preact/preset-vite':
- specifier: 2.0.0
'@testing-library/preact':
specifier: ^2.0.1
version: 2.0.1([email protected])