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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat: refactor toolbar features
wzhudevc1f81b793153
diff --git a/packages/base-sheets/src/Commands/Commands/set-style.command.ts b/packages/base-sheets/src/Commands/Commands/set-style.command.tsindex 2d91e132be..1ce5801273 100644--- a/packages/base-sheets/src/Commands/Commands/set-style.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-style.command.ts@@ -408,7 +408,7 @@ export const SetTextWrapCommand: ICommand<ISetTextWrapCommandParams> = {};export interface ISetTextRotationCommandParams {- value: ITextRotation;+ value: number | string;}export const SetTextRotationCommand: ICommand<ISetTextRotationCommandParams> = {@@ -423,7 +423,9 @@ export const SetTextRotationCommand: ICommand<ISetTextRotationCommandParams> = {const setStyleParams: ISetStyleParams<ITextRotation> = {style: {type: 'tr',- value: params.value,+ value: {+ a: params.value as number,+ },},};diff --git a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts b/packages/base-sheets/src/Controller/BasicWorksheet.controller.tsindex 21d8e038c9..b0563e0c67 100644--- a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts+++ b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts@@ -12,10 +12,12 @@ import {ResetBackgroundColorCommand,ResetTextColorCommand,SetBackgroundColorCommand,+ SetHorizontalTextAlignCommand,SetStyleCommand,SetTextColorCommand,SetTextRotationCommand,SetTextWrapCommand,+ SetVerticalTextAlignCommand,} from '../Commands/Commands/set-style.command';import { SetRangeStyleMutation } from '../Commands/Mutations/set-range-styles.mutation';import { ISetRangeFormattedValueParams, SetRangeFormattedValueCommand } from '../Commands/Commands/set-range-formatted-value.command';@@ -107,6 +109,8 @@ export class BasicWorksheetController extends Disposable implements IDisposableSetTextRotationCommand,ResetTextColorCommand,ResetBackgroundColorCommand,+ SetHorizontalTextAlignCommand,+ SetVerticalTextAlignCommand,SetBorderCommand,SetBorderColorCommand,diff --git a/packages/base-sheets/src/Services/TODO.md b/packages/base-sheets/src/Services/TODO.mdnew file mode 100644index 0000000000..f7383b66c0--- /dev/null+++ b/packages/base-sheets/src/Services/TODO.md@@ -0,0 +1 @@+- [ ] maybe the status managers could be merged into a single status service?\ No newline at end of filediff --git a/packages/base-sheets/src/Services/align-style-manager.service.ts b/packages/base-sheets/src/Services/align-style-manager.service.tsnew file mode 100644index 0000000000..4aef5541a1--- /dev/null+++ b/packages/base-sheets/src/Services/align-style-manager.service.ts@@ -0,0 +1,21 @@+import { HorizontalAlign } from '@univerjs/core';+import { IDisposable } from '@wendellhu/redi';+import { BehaviorSubject } from 'rxjs';++export class AlignStyleManagerService implements IDisposable {+ private readonly _alignInfo = {+ horizontal: HorizontalAlign.LEFT,+ vertical: 'top',+ };++ private readonly _alignInfo$ = new BehaviorSubject(this._alignInfo);++ // eslint-disable-next-line @typescript-eslint/member-ordering+ readonly alignInfo$ = this._alignInfo$.asObservable();++ dispose(): void {+ this._alignInfo$.complete();+ }++ setHorizontalAlign(horizontal: HorizontalAlign): void {}+}diff --git a/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsxindex a9f5847828..b12601b35d 100644--- a/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx+++ b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx@@ -7,19 +7,21 @@ import { DisplayTypes } from '../Select';import styles from './CustomLabel.module.less';import { IMenuSelectorItem } from '../../services/menu/menu';+import { Item } from '../Item/Item';+import { Input } from '../Input/input';function getLocale(context: Partial<AppContextValues>, name: string) {return context.localeService?.t(name);}-export interface INeoCustomLabelProps<T> {- value: T;- onChange?(v: T): void;+export interface INeoCustomLabelProps {+ value: string | number;+ onChange?(v: string | number): void;}-export function NeoCustomLabel<T>(props: Pick<IMenuSelectorItem<unknown>, 'icon' | 'display' | 'title'> & INeoCustomLabelProps<T>): JSX.Element | null {+export function NeoCustomLabel(props: Pick<IMenuSelectorItem<unknown>, 'label' | 'icon' | 'display' | 'title'> & INeoCustomLabelProps): JSX.Element | null {const context = useContext(AppContext);- const { display, value, title, icon } = props;+ const { display, value, title, icon, label, onChange } = props;if (display === DisplayTypes.COLOR) {// eslint-disable-next-line @typescript-eslint/no-explicit-any@@ -35,15 +37,26 @@ export function NeoCustomLabel<T>(props: Pick<IMenuSelectorItem<unknown>, 'icon'}if (display === DisplayTypes.INPUT) {- // TODO: implement display input+ return <Input onValueChange={(v) => onChange?.(v as unknown as string)} type="number" value={`${value}`} />;}// if the render type is icon, then render value to icon- if (display === DisplayTypes.ICON) {- return <>{value}</>;+ if (display === DisplayTypes.ICON && icon) {+ const LabelComponent = context.componentManager?.get(icon) as any;+ if (LabelComponent) {+ return <LabelComponent {...props} />;+ }+ }++ if (display === DisplayTypes.CUSTOM && label) {+ const LabelComponent = context.componentManager?.get(label) as any;+ if (LabelComponent) {+ return <LabelComponent {...props} />;+ }}- return <>{value}</>;+ const LabelComponent = icon ? (context.componentManager?.get(icon) as any) : null;+ return <Item selected={false} label={title} suffix={LabelComponent ? <LabelComponent /> : null} disabled={false}></Item>;}/** @deprecated */@@ -68,6 +81,7 @@ export function CustomLabel(props: IBaseCustomLabelProps): JSX.Element | null {return label;}+ // other types of components and iconif (label) {const Label = context.componentManager?.get((label as ICustomComponent).name) as any;if (Label) {@@ -89,9 +103,6 @@ export interface IColorSelectProps {export class ColorSelect extends Component<IColorSelectProps> {render() {const { value, icon, title } = this.props;-- console.log('debug color select value', value);-return (<div className={styles.colorSelect}><div>{icon ? <CustomLabel label={{ name: icon }} /> : title}</div>diff --git a/packages/base-ui/src/Components/Input/input.tsx b/packages/base-ui/src/Components/Input/input.tsxindex 9fc0c883fc..69ba5de8d7 100644--- a/packages/base-ui/src/Components/Input/input.tsx+++ b/packages/base-ui/src/Components/Input/input.tsx@@ -61,10 +61,11 @@ export class Input extends Component<BaseInputProps, IState> {};handlePressEnter = (e: KeyboardEvent) => {- const { onPressEnter } = this.props;+ const { onPressEnter, onValueChange } = this.props;if (e.key === 'Enter') {onPressEnter?.(e);this.ref.current.blur();+ onValueChange?.(this.getValue());}};@@ -76,11 +77,13 @@ export class Input extends Component<BaseInputProps, IState> {onClick = (e: MouseEvent) => {const { onClick } = this.props;onClick?.(e);+ e.stopPropagation();};onBlur = (e: FocusEvent) => {- const { onBlur } = this.props;+ const { onBlur, onValueChange } = this.props;onBlur?.(e);+ onValueChange?.(this.getValue());};// get input valuediff --git a/packages/base-ui/src/Components/Item/Item.tsx b/packages/base-ui/src/Components/Item/Item.tsxindex 6c81007bf7..89ba2085ab 100644--- a/packages/base-ui/src/Components/Item/Item.tsx+++ b/packages/base-ui/src/Components/Item/Item.tsx@@ -11,27 +11,29 @@ export interface BaseItemProps extends BaseMenuItem {border?: boolean;}+// TODO@wzhudev: move this component to another proper position. Now used by NeoCustomLabel component.++/**+ * This render as a label of MenuItem.+ */export class Item extends Component<BaseItemProps> {render() {const { selected, label, suffix, disabled } = this.props;+return (<div className={joinClassNames(styles.selectItem, disabled ? styles.selectDisabledItem : '')}>- {selected ? (+ {selected && (<span className={styles.selectItemSelected}><Icon.CorrectIcon /></span>- ) : (- '')}<span className={styles.selectItemContent}><CustomLabel label={label} /></span>- {suffix ? (+ {suffix && (<span className={styles.selectItemSuffix}><CustomLabel label={suffix} /></span>- ) : (- '')}</div>);diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsxindex 748cdb8884..cf9fe66372 100644--- a/packages/base-ui/src/Components/Menu/Menu.tsx+++ b/packages/base-ui/src/Components/Menu/Menu.tsx@@ -189,7 +189,7 @@ export class Menu extends Component<BaseMenuProps, IBaseMenuState> {// TODO: handle if options is a custom component}}>- <NeoCustomLabel value={option.value} display={display} title={option.label} />+ <NeoCustomLabel value={option.value} display={display} title={option.label} icon={option.icon} /></li>);}@@ -363,7 +363,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {onMouseLeave={(e) => this.mouseLeave(e, index)}onClick={(e) => this.handleClick(e, item, index)}>- <NeoCustomLabel title={item.title} value={value} onChange={this.onChange} icon={item.icon} display={item.display}></NeoCustomLabel>+ <NeoCustomLabel title={item.title} value={value} onChange={this.onChange} icon={item.icon} display={item.display} label={item.label}></NeoCustomLabel>{item.shortcut && ` (${item.shortcut})`}{(menuItems.length > 0 || (item as IMenuSelectorItem<unknown>).selections?.length) && (<Menudiff --git a/packages/base-ui/src/Components/Select/Select.tsx b/packages/base-ui/src/Components/Select/Select.tsxindex 7591774de5..d697a90c1a 100644--- a/packages/base-ui/src/Components/Select/Select.tsx+++ b/packages/base-ui/src/Components/Select/Select.tsx@@ -12,12 +12,16 @@ import { Icon, IDisplayMenuItem, IMenuItem, IValueOption } from '../..'; // FIXM// TODO: these type definitions should be moved out of components to menu serviceexport enum SelectTypes {+ /** 单选 */SINGLE,/** dropdown with input */INPUT,COLOR,+ /** 两栏菜单,主按钮会跟着上次的选项发生变化 */DOUBLE,+ /** 显示一个固定的值 */FIX,+ /** 显示一个固定的值 */DOUBLEFIX,/** This should be the only type. The enum would be removed after we finish refactor. */@@ -38,6 +42,8 @@ export enum DisplayTypes {INPUT,FONT,++ CUSTOM,}export interface BaseSelectChildrenProps extends BaseItemProps {@@ -409,14 +415,24 @@ export class Select extends PureComponent<BaseSelectProps, IState> {onClick?.(option.value);};+ const iconToDisplay = options?.find((o) => o.value === value)?.icon ?? icon;return (<div className={`${styles.selectDouble}`}>- {/* TODO@wzhudev: we should compose options and builtin component here. They may have different onClick callback. */}- {/* TODO@wzhudev: should pass in a value to set the menu's selected status. */}- <Dropdown tooltip={tooltip} onClick={onClick} menu={{ menuId: id, options, onClick: onClickInner, onOptionSelect, display }} icon={<Icon.NextIcon />}>+ <Dropdown+ tooltip={tooltip}+ onClick={type === SelectTypes.NEO ? () => onClick?.(value) : onClick}+ menu={{+ menuId: id,+ options,+ onClick: onClickInner,+ onOptionSelect,+ display: display === DisplayTypes.ICON ? DisplayTypes.LABEL : display === DisplayTypes.INPUT ? DisplayTypes.LABEL : display,+ }}+ icon={<Icon.NextIcon />}+ >{/* TODO@wzhudev: change menu props of Dropdown. Dropdown shouldn't know how to create a menu. */}<div className={styles.selectLabel}>- <NeoCustomLabel icon={icon} display={display} title={title!} value={value} onChange={(v) => onClick?.(v)} />+ <NeoCustomLabel icon={iconToDisplay} display={display} title={title!} value={value} onChange={(v) => onClick?.(v)} /></div></Dropdown></div>diff --git a/packages/base-ui/src/Interfaces/Input.ts b/packages/base-ui/src/Interfaces/Input.tsindex 775bbdd170..5a34b012ef 100644--- a/packages/base-ui/src/Interfaces/Input.ts+++ b/packages/base-ui/src/Interfaces/Input.ts@@ -14,6 +14,7 @@ export interface BaseInputProps extends BaseComponentProps {onFocus?: (e: Event) => void;onBlur?: (e: FocusEvent) => void;onClick?: (e: MouseEvent) => void;+ onValueChange?: (value: string) => void;className?: string;readonly?: boolean;id?: string;diff --git a/packages/base-ui/src/services/menu/menu.ts b/packages/base-ui/src/services/menu/menu.tsindex 0d0eb9f788..fcb871ba71 100644--- a/packages/base-ui/src/services/menu/menu.ts+++ b/packages/base-ui/src/services/menu/menu.ts@@ -1,7 +1,5 @@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[];@@ -39,8 +37,12 @@ interface IMenuItemBase {/** In what menu should the item display. */positions: OneOrMany<MenuPosition>;- /** @deprecated this parameter would be removed after refactoring */- label?: string | ICustomLabelType | ComponentChildren;+ /**+ * Custom label component id.+ *+ * @deprecated this parameter would be removed after refactoring+ * */+ label?: string;/** @deprecated this parameter would be removed after refactoring */className?: string;@@ -119,3 +121,5 @@ export type IMenuItem = IMenuButtonItem | IMenuSelectorItem<unknown>;export type IDisplayMenuItem<T extends IMenuItem> = T & {shortcut?: string;};++export type IMenuItemFactory = (accessor: IAccessor) => IMenuItem;diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.tsindex 0c8884220d..7112c4a397 100644--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts@@ -3,11 +3,31 @@ import { ISelectionManager, SelectionManager } from '@univerjs/base-sheets';import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentManager, IMenuService, MenuPosition } from '@univerjs/base-ui';import { UIObserver, ICurrentUniverService, ObserverManager, Disposable } from '@univerjs/core';import { ComponentChildren } from 'preact';+import { IMenuItemFactory } from '@univerjs/base-ui/src/services/menu/menu';import { SheetToolbarConfig, SHEET_UI_PLUGIN_NAME } from '../Basics';import { ColorSelect, LineBold, LineColor, Toolbar } from '../View';-import { SetBorderColorMenuItemFactory } from './menu';-import { CellBorderSelectorMenuItemFactory, SetBorderStyleMenuItemFactory } from './menu/border.menu';+import {+ BackgroundColorSelectorMenuItemFactory,+ BoldMenuItemFactory,+ FontFamilySelectorMenuItemFactory,+ FontSizeSelectorMenuItemFactory,+ HorizontalAlignMenuItemFactory,+ ItalicMenuItemFactory,+ RedoMenuItemFactory,+ ResetBackgroundColorMenuItemFactory,+ ResetTextColorMenuItemFactory,+ SetBorderColorMenuItemFactory,+ SetBorderStyleMenuItemFactory,+ StrikeThroughMenuItemFactory,+ TextColorSelectorMenuItemFactory,+ TextRotateMenuItemFactory,+ UnderlineMenuItemFactory,+ UndoMenuItemFactory,+ VerticalAlignMenuItemFactory,+ WrapTextMenuItemFactory,+} from './menu';+import { CellBorderSelectorMenuItemFactory } from './menu/border.menu';export interface BaseToolbarSelectProps extends BaseSelectProps {children?: BaseSelectChildrenProps[];@@ -102,28 +122,29 @@ export class ToolbarUIController extends Disposable {private _initializeToolbar(): void {// TODO: @wzhudev: now we register menu items that only display in the toolbar here. In fact we should register all commands and menu items and shortcuts// in a single controller. I will do that layer.- [- // UndoMenuItemFactory,- // RedoMenuItemFactory,- // FontFamilySelectorMenuItemFactory,- // FontSizeSelectorMenuItemFactory,- // BoldMenuItemFactory,- // ItalicMenuItemFactory,- // UnderlineMenuItemFactory,- // StrikeThroughMenuItemFactory,- // TextColorSelectorMenuItemFactory,- // ResetTextColorMenuItemFactory,- // BackgroundColorSelectorMenuItemFactory,- // ResetBackgroundColorMenuItemFactory,- CellBorderSelectorMenuItemFactory,- SetBorderColorMenuItemFactory,- SetBorderStyleMenuItemFactory,- // SetBorderStyleMenuItemFactory,- // HorizontalAlignMenuItemFactory,- // VerticalAlignMenuItemFactory,- // WrapTextMenuItemFactory,- // TextRotateMenuItemFactory,- ].forEach((factory) => {+ (+ [+ UndoMenuItemFactory,+ RedoMenuItemFactory,+ FontFamilySelectorMenuItemFactory,+ FontSizeSelectorMenuItemFactory,+ BoldMenuItemFactory,+ ItalicMenuItemFactory,+ UnderlineMenuItemFactory,+ StrikeThroughMenuItemFactory,+ TextColorSelectorMenuItemFactory,+ ResetTextColorMenuItemFactory,+ BackgroundColorSelectorMenuItemFactory,+ ResetBackgroundColorMenuItemFactory,+ CellBorderSelectorMenuItemFactory,+ SetBorderColorMenuItemFactory,+ SetBorderStyleMenuItemFactory,+ HorizontalAlignMenuItemFactory,+ VerticalAlignMenuItemFactory,+ WrapTextMenuItemFactory,+ TextRotateMenuItemFactory,+ ] as IMenuItemFactory[]+ ).forEach((factory) => {this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));});}diff --git a/packages/ui-plugin-sheets/src/Controller/menu.ts b/packages/ui-plugin-sheets/src/Controller/menu.tsindex acb0eca163..ec7ac977ea 100644--- a/packages/ui-plugin-sheets/src/Controller/menu.ts+++ b/packages/ui-plugin-sheets/src/Controller/menu.ts@@ -31,12 +31,24 @@ import {SetWorksheetRowShowCommand,SetWorksheetHideCommand,} from '@univerjs/base-sheets';-import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes, IDisplayMenuItem, IValueOption, ICustomComponentOption } from '@univerjs/base-ui';-import { FontItalic, FontWeight, ICommandService, IPermissionService, IUndoRedoService, RedoCommand, UndoCommand } from '@univerjs/core';+import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes, IDisplayMenuItem } from '@univerjs/base-ui';+import {+ FontItalic,+ FontWeight,+ HorizontalAlign,+ ICommandService,+ IPermissionService,+ IUndoRedoService,+ RedoCommand,+ UndoCommand,+ VerticalAlign,+ WrapStrategy,+} from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';import { Observable } from 'rxjs';import { map } from 'rxjs/operators';+import { ISetHorizontalTextAlignCommandParams, ISetTextWrapCommandParams, ISetVerticalTextAlignCommandParams } from '@univerjs/base-sheets/src/Commands/Commands/set-style.command';import { RightMenuInput } from '../View';import { FONT_FAMILY_CHILDREN, FONT_SIZE_CHILDREN, HORIZONTAL_ALIGN_CHILDREN, TEXT_ROTATE_CHILDREN, TEXT_WRAP_CHILDREN, VERTICAL_ALIGN_CHILDREN } from '../View/Toolbar/Const';import { SHEET_UI_PLUGIN_NAME } from '../Basics/Const/PLUGIN_NAME';@@ -263,7 +275,6 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIt}export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {- // NOTE: we could get more font options from (a) font service, so user can provide their own fontsconst permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);const selectionManager = accessor.get(ISelectionManager);@@ -398,18 +409,15 @@ export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSele},],value$: new Observable<string>((subscriber) => {+ const defaultColor = '#000';const disposable = commandService.onCommandExecuted((c) => {- const id = c.id;- if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {- return;+ if (c.id === SetTextColorCommand.id) {+ const color = (c.params as { value: string }).value;+ subscriber.next(color ?? defaultColor);}-- const range = selectionManager.getCurrentCell();- const color = range?.getFontColor();-- subscriber.next(color ?? '');});+ subscriber.next(defaultColor);return disposable.dispose;}),};@@ -445,18 +453,15 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMe},],value$: new Observable<string>((subscriber) => {+ const defaultColor = '#fff';const disposable = commandService.onCommandExecuted((c) => {- const id = c.id;- if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {- return;+ if (c.id === SetBackgroundColorCommand.id) {+ const color = (c.params as { value: string }).value;+ subscriber.next(color ?? defaultColor);}-- const range = selectionManager.getCurrentCell();- const color = range?.getBackground();-- subscriber.next(color ?? '');});+ subscriber.next(defaultColor);return disposable.dispose;}),};@@ -468,103 +473,113 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMe// }// }-export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {+export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<HorizontalAlign> {return {id: SetHorizontalTextAlignCommand.id,title: 'horizontalAlignMode',+ icon: HORIZONTAL_ALIGN_CHILDREN[0].icon,positions: [MenuPosition.TOOLBAR],tooltip: 'toolbar.horizontalAlignMode.main',className: styles.selectDoubleString,- display: DisplayTypes.SUFFIX,+ display: DisplayTypes.ICON,type: MenuItemType.SELECTOR,- selectType: SelectTypes.DOUBLE,+ selectType: SelectTypes.NEO,selections: HORIZONTAL_ALIGN_CHILDREN,+ value$: new Observable<HorizontalAlign>((subscriber) => {+ const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {+ if (c.id === SetHorizontalTextAlignCommand.id) {+ const align = (c.params as ISetHorizontalTextAlignCommandParams).value;+ subscriber.next(align);+ }+ });++ subscriber.next(HorizontalAlign.LEFT);++ return disposable.dispose;+ }),};}-export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {+export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<VerticalAlign> {return {id: SetVerticalTextAlignCommand.id,title: 'verticalAlignMode',+ icon: VERTICAL_ALIGN_CHILDREN[0].icon,tooltip: 'toolbar.verticalAlignMode.main',className: styles.selectDoubleString,- display: DisplayTypes.SUFFIX,+ display: DisplayTypes.ICON,type: MenuItemType.SELECTOR,positions: [MenuPosition.TOOLBAR],- selectType: SelectTypes.DOUBLE,+ selectType: SelectTypes.NEO,selections: VERTICAL_ALIGN_CHILDREN,+ value$: new Observable<VerticalAlign>((subscriber) => {+ const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {+ if (c.id === SetVerticalTextAlignCommand.id) {+ const align = (c.params as ISetVerticalTextAlignCommandParams).value;+ subscriber.next(align);+ }+ });++ subscriber.next(VerticalAlign.TOP);++ return disposable.dispose;+ }),};}-export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {- const commandService = accessor.get(ICommandService);- const selectionManager = accessor.get(ISelectionManager);-+export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<WrapStrategy> {return {id: SetTextWrapCommand.id,title: 'textWrapMode',tooltip: 'toolbar.textWrapMode.main',+ icon: TEXT_WRAP_CHILDREN[0].icon,type: MenuItemType.SELECTOR,- selectType: SelectTypes.DOUBLE,+ selectType: SelectTypes.NEO,positions: [MenuPosition.TOOLBAR],selections: TEXT_WRAP_CHILDREN,- display: DisplayTypes.SUFFIX,+ display: DisplayTypes.ICON,value$: new Observable((subscriber) => {- const disposable = commandService.onCommandExecuted((c) => {- const id = c.id;- if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {- return;+ const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {+ if (c.id === SetTextWrapCommand.id) {+ const wrap = (c.params as ISetTextWrapCommandParams).value;+ subscriber.next(wrap ?? WrapStrategy.OVERFLOW);}-- const range = selectionManager.getCurrentCell();- const ws = range?.getWrapStrategy();-- subscriber.next(ws);});- return () => disposable.dispose();+ subscriber.next(WrapStrategy.OVERFLOW);++ return disposable.dispose;}),};}// FIXME: set rotation would cause a bug-export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {- const permissionService = accessor.get(IPermissionService);- const commandService = accessor.get(ICommandService);- const selectionManager = accessor.get(ISelectionManager);-+export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number | string> {return {id: SetTextRotationCommand.id,title: 'textRotateMode',tooltip: 'toolbar.textRotateMode.main',- display: DisplayTypes.SUFFIX,+ icon: TEXT_ROTATE_CHILDREN[0].icon,+ display: DisplayTypes.ICON,type: MenuItemType.SELECTOR,- selectType: SelectTypes.DOUBLE,+ selectType: SelectTypes.NEO,+ selections: TEXT_ROTATE_CHILDREN,positions: [MenuPosition.TOOLBAR],- value$: new Observable<number>((subscriber) => {- commandService.onCommandExecuted((c) => {- const id = c.id;- if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {- return;+ value$: new Observable<number | string>((subscriber) => {+ const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {+ if (c.id === SetTextRotationCommand.id) {+ const rotation = (c.params as { value: number | string }).value;+ subscriber.next(rotation ?? 0);}+ });- const range = selectionManager.getCurrentCell();- const tr = range?.getTextRotation();+ subscriber.next(0);- subscriber.next(tr);- });+ return disposable.dispose;}),- selections: TEXT_ROTATE_CHILDREN,};}-export function NumberFormatMenuItemFactory(accessor: IAccessor): IMenuItem {}--// NOTE: these menu icons should be registered by plugins not defined here.-// export function SearchReplaceMenuItemFactory(accessor: IAccessor): IMenuItem {}-// export function ImportMenuItemFactory(accessor: IAccessor): IMenuItem {}-// export function ImageMenuItemFactory(accessor: IAccessor): IMenuItem {}-// right menu in main containerexport function ClearSelectionMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {@@ -572,7 +587,7 @@ export function ClearSelectionMenuItemFactory(accessor: IAccessor): IMenuButtonItype: MenuItemType.BUTTON,title: 'rightClick.clearContent',positions: [MenuPosition.CONTEXT_MENU],- parentId: 'right-menu'+ parentId: 'right-menu',};}@@ -582,7 +597,7 @@ export function InsertRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {type: MenuItemType.BUTTON,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.insertRow',- parentId: 'right-menu'+ parentId: 'right-menu',};}@@ -592,7 +607,7 @@ export function InsertColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {type: MenuItemType.BUTTON,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.insertColumn',- parentId: 'right-menu'+ parentId: 'right-menu',};}@@ -602,7 +617,7 @@ export function RemoveRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {type: MenuItemType.BUTTON,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.deleteSelectedRow',- parentId: 'right-menu'+ parentId: 'right-menu',};}@@ -612,7 +627,7 @@ export function HideRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {type: MenuItemType.BUTTON,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.hideSelectedRow',- parentId: 'right-menu'+ parentId: 'right-menu',};}@@ -622,7 +637,7 @@ export function ShowRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {type: MenuItemType.BUTTON,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.showHideRow',- parentId: 'right-menu'+ parentId: 'right-menu',};}@@ -632,7 +647,7 @@ export function RemoveColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {type: MenuItemType.BUTTON,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.deleteSelectedColumn',- parentId: 'right-menu'+ parentId: 'right-menu',};}@@ -649,7 +664,7 @@ export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonItesuffix: 'px',},},- parentId: 'right-menu'+ parentId: 'right-menu',};}@@ -714,7 +729,7 @@ export function DeleteSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItemexport function CopySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {// TODO@Dushusir use real command id- id: "CopySheetCommand.id",+ id: 'CopySheetCommand.id',type: MenuItemType.BUTTON,positions: [MenuPosition.SHEET_BAR],title: 'sheetConfig.copy',@@ -726,22 +741,22 @@ export function CopySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {// No need to trigger command after clicking,maybe no need Command id?export function RenameSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- id: "RenameSheetCommand.id",+ id: 'RenameSheetCommand.id',type: MenuItemType.BUTTON,positions: [MenuPosition.SHEET_BAR],title: 'sheetConfig.rename',parentId: 'sheet-bar-right-menu',- onClick:()=>{+ onClick: () => {// TODO@Dushusir 这里能监听到点击事件,但是无法触发到 this._sheetBar.reNameSheet(this._dataId);- console.info('rename=========')- }+ console.info('rename=========');+ },};}// TODO@Dushusir add commandexport function ChangeColorSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {return {- id: "ChangeColorSheetCommand.id",+ id: 'ChangeColorSheetCommand.id',title: 'sheetConfig.changeColor',positions: [MenuPosition.SHEET_BAR],display: DisplayTypes.COLOR,@@ -769,7 +784,7 @@ export function HideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {// TODO@Dushusir use show worksheet commandexport function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- id: "SetWorksheetHideCommand.id",+ id: 'SetWorksheetHideCommand.id',type: MenuItemType.BUTTON,positions: [MenuPosition.SHEET_BAR],title: 'sheetConfig.unhide',diff --git a/packages/ui-plugin-sheets/src/Controller/menu/border.menu.ts b/packages/ui-plugin-sheets/src/Controller/menu/border.menu.tsindex c35a18d5d6..d6f6cf2612 100644--- a/packages/ui-plugin-sheets/src/Controller/menu/border.menu.ts+++ b/packages/ui-plugin-sheets/src/Controller/menu/border.menu.ts@@ -5,7 +5,133 @@ import { IAccessor } from '@wendellhu/redi';import { map } from 'rxjs/operators';import { SHEET_UI_PLUGIN_NAME } from '../../Basics/Const/PLUGIN_NAME';-import { BORDER_LINE_CHILDREN, BORDER_SIZE_CHILDREN } from '../../View/Toolbar/Const';+import { LineBold } from '../../View';++export const BORDER_LINE_CHILDREN = [+ {+ label: 'borderLine.borderTop',+ icon: 'TopBorderIcon',+ value: 'top',+ },+ {+ label: 'borderLine.borderBottom',+ icon: 'BottomBorderIcon',+ value: 'bottom',+ },+ {+ label: 'borderLine.borderLeft',+ icon: 'LeftBorderIcon',+ value: 'left',+ },+ {+ label: 'borderLine.borderRight',+ icon: 'RightBorderIcon',+ value: 'right',+ },+ {+ label: 'borderLine.borderNone',+ icon: 'NoneBorderIcon',+ value: 'none',+ },+ {+ label: 'borderLine.borderAll',+ icon: 'FullBorderIcon',+ value: 'all',+ },+ {+ label: 'borderLine.borderOutside',+ icon: 'OuterBorderIcon',+ value: 'outside',+ },+ {+ label: 'borderLine.borderInside',+ icon: 'InnerBorderIcon',+ value: 'inside',+ },+ {+ label: 'borderLine.borderHorizontal',+ icon: 'StripingBorderIcon',+ value: 'horizontal',+ },+ {+ label: 'borderLine.borderVertical',+ icon: 'VerticalBorderIcon',+ value: 'vertical',+ },+];++export const BORDER_SIZE_CHILDREN = [+ {+ label: 'borderLine.borderNone',+ value: BorderStyleTypes.NONE,+ },+ {+ label: {+ name: 'BorderThin',+ },+ value: BorderStyleTypes.THIN,+ },+ {+ label: {+ name: 'BorderHair',+ },+ value: BorderStyleTypes.HAIR,+ },+ {+ label: {+ name: 'BorderDotted',+ },+ value: BorderStyleTypes.DOTTED,+ },+ {+ label: {+ name: 'BorderDashed',+ },+ value: BorderStyleTypes.DASHED,+ },+ {+ label: {+ name: 'BorderDashDot',+ },+ value: BorderStyleTypes.DOTTED,+ },+ {+ label: {+ name: 'BorderDashDotDot',+ },+ value: BorderStyleTypes.DASH_DOT_DOT,+ },+ {+ label: {+ name: 'BorderMedium',+ },+ value: BorderStyleTypes.MEDIUM,+ },+ {+ label: {+ name: 'BorderMediumDashed',+ },+ value: BorderStyleTypes.MEDIUM_DASHED,+ },+ {+ label: {+ name: 'BorderMediumDashDot',+ },+ value: BorderStyleTypes.MEDIUM_DASH_DOT,+ },+ {+ label: {+ name: 'BorderMediumDashDotDot',+ },+ value: BorderStyleTypes.MEDIUM_DASH_DOT_DOT,+ },+ {+ label: {+ name: 'BorderThick',+ },+ value: BorderStyleTypes.THICK,+ },+];export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {const permissionService = accessor.get(IPermissionService);@@ -15,6 +141,7 @@ export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSelreturn {id: SetBorderPositionCommand.id,title: 'border',+ icon: 'FullBorderIcon',display: DisplayTypes.ICON,positions: [MenuPosition.TOOLBAR],type: MenuItemType.DROPDOWN,@@ -54,9 +181,10 @@ export function SetBorderStyleMenuItemFactory(accessor: IAccessor): IMenuSelectoreturn {id: SetBorderStyleCommand.id,title: 'borderStyle',+ label: SHEET_UI_PLUGIN_NAME + LineBold.name,positions: [MenuPosition.TOOLBAR],parentId: SetBorderPositionCommand.id,- display: DisplayTypes.LABEL,+ display: DisplayTypes.CUSTOM,selectType: SelectTypes.NEO,type: MenuItemType.SELECTOR,selections: [...BORDER_SIZE_CHILDREN],diff --git a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsxindex df156665dd..6b2c95bbdf 100644--- a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx+++ b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx@@ -7,10 +7,12 @@ interface IState {interface IProps extends BaseComponentProps {label: string;- img: string;+ value: string;}export class LineBold extends Component<IProps, IState> {+ static readonly componentName = 'bold';+static override contextType = AppContext;constructor(props: IProps) {@@ -30,7 +32,7 @@ export class LineBold extends Component<IProps, IState> {override componentWillReceiveProps(props: IProps) {this.setState({- img: props.img,+ img: props.value,});}@@ -57,7 +59,7 @@ export class LineBold extends Component<IProps, IState> {<div style={{ paddingBottom: '3px', width: '100%', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}><span className={'base-sheets-line-bold'} style={{ position: 'relative' }}><CustomLabel label={label} />- <div style={{ width: '100%', height: 0, position: 'absolute', left: 0, bottom: '14px' }}>{img.length ? this.getImg(img) : ''}</div>+ <div style={{ width: '100%', height: 0, position: 'absolute', left: 0, bottom: '14px' }}>{img && this.getImg(img)}</div></span><Icon.RightIcon /></div>diff --git a/packages/ui-plugin-sheets/src/View/Toolbar/Const.ts b/packages/ui-plugin-sheets/src/View/Toolbar/Const.tsindex 1e6b62a0d3..1e63ef2f3e 100644--- a/packages/ui-plugin-sheets/src/View/Toolbar/Const.ts+++ b/packages/ui-plugin-sheets/src/View/Toolbar/Const.ts@@ -1,4 +1,4 @@-import { BorderStyleTypes } from '@univerjs/core';+import { HorizontalAlign, VerticalAlign, WrapStrategy } from '@univerjs/core';export const FONT_SIZE_CHILDREN = [{@@ -148,155 +148,6 @@ export const FONT_FAMILY_CHILDREN = [},];-export const BORDER_LINE_CHILDREN = [- {- label: 'borderLine.borderTop',- icon: 'TopBorderIcon',- suffix: {- name: 'TopBorderIcon',- },- value: 'top',- },- {- label: 'borderLine.borderBottom',- suffix: {- name: 'BottomBorderIcon',- },- value: 'bottom',- },- {- label: 'borderLine.borderLeft',- suffix: {- name: 'LeftBorderIcon',- },- value: 'left',- },- {- label: 'borderLine.borderRight',- suffix: {- name: 'RightBorderIcon',- },- value: 'right',- border: true,- },- {- label: 'borderLine.borderNone',- suffix: {- name: 'NoneBorderIcon',- },- value: 'none',- },- {- label: 'borderLine.borderAll',- suffix: {- name: 'FullBorderIcon',- },- value: 'all',- selected: true,- },- {- label: 'borderLine.borderOutside',- suffix: {- name: 'OuterBorderIcon',- },- value: 'outside',- },- {- label: 'borderLine.borderInside',- suffix: {- name: 'InnerBorderIcon',- },- value: 'inside',- },- {- label: 'borderLine.borderHorizontal',- suffix: {- name: 'StripingBorderIcon',- },- value: 'horizontal',- },- {- label: 'borderLine.borderVertical',- suffix: {- name: 'VerticalBorderIcon',- },- value: 'vertical',- },-];--export const BORDER_SIZE_CHILDREN = [- {- label: 'borderLine.borderNone',- value: BorderStyleTypes.NONE,- },- {- label: {- name: 'BorderThin',- },- value: BorderStyleTypes.THIN,- },- {- label: {- name: 'BorderHair',- },- value: BorderStyleTypes.HAIR,- },- {- label: {- name: 'BorderDotted',- },- value: BorderStyleTypes.DOTTED,- },- {- label: {- name: 'BorderDashed',- },- value: BorderStyleTypes.DASHED,- },- {- label: {- name: 'BorderDashDot',- },- value: BorderStyleTypes.DOTTED,- },- {- label: {- name: 'BorderDashDotDot',- },- value: BorderStyleTypes.DASH_DOT_DOT,- },- {- label: {- name: 'BorderMedium',- },- value: BorderStyleTypes.MEDIUM,- },- {- label: {- name: 'BorderMediumDashed',- },- value: BorderStyleTypes.MEDIUM_DASHED,- },- {- label: {- name: 'BorderMediumDashDot',- },- value: BorderStyleTypes.MEDIUM_DASH_DOT,- },- {- label: {- name: 'BorderMediumDashDotDot',- },- value: BorderStyleTypes.MEDIUM_DASH_DOT_DOT,- },- {- label: {- name: 'BorderThick',- },- value: BorderStyleTypes.THICK,- },-];-export const MERGE_CHILDREN = [{label: 'merge.all',@@ -319,117 +170,86 @@ export const MERGE_CHILDREN = [export const HORIZONTAL_ALIGN_CHILDREN = [{label: 'align.left',- suffix: {- name: 'LeftAlignIcon',- },- value: 1,+ icon: 'LeftAlignIcon',+ value: HorizontalAlign.LEFT,},{label: 'align.center',- selected: true,- suffix: {- name: 'CenterAlignIcon',- },- value: 2,+ icon: 'CenterAlignIcon',+ value: HorizontalAlign.CENTER,},{label: 'align.right',- suffix: {- name: 'RightAlignIcon',- },- value: 3,+ icon: 'RightAlignIcon',+ value: HorizontalAlign.RIGHT,},];export const VERTICAL_ALIGN_CHILDREN = [{label: 'align.top',- suffix: {- name: 'TopVerticalIcon',- },- value: 1,+ icon: 'TopVerticalIcon',+ value: VerticalAlign.TOP,},{label: 'align.middle',- suffix: {- name: 'CenterVerticalIcon',- },- value: 2,+ icon: 'CenterVerticalIcon',+ value: VerticalAlign.MIDDLE,},{label: 'align.bottom',- suffix: {- name: 'BottomVerticalIcon',- },- value: 3,+ icon: 'BottomVerticalIcon',+ value: VerticalAlign.BOTTOM,},];export const TEXT_WRAP_CHILDREN = [{label: 'textWrap.overflow',- suffix: {- name: 'OverflowIcon',- },- value: 1,+ icon: 'OverflowIcon',+ value: WrapStrategy.OVERFLOW,},{label: 'textWrap.wrap',- suffix: {- name: 'BrIcon',- },- value: 3,+ icon: 'BrIcon',+ value: WrapStrategy.WRAP,},{label: 'textWrap.clip',- suffix: {- name: 'CutIcon',- },- value: 2,+ icon: 'CutIcon',+ value: WrapStrategy.CLIP,},];export const TEXT_ROTATE_CHILDREN = [{label: 'textRotate.none',- suffix: {- name: 'TextRotateIcon',- },+ icon: 'TextRotateIcon',value: 0,},{label: 'textRotate.angleUp',- suffix: {- name: 'TextRotateAngleUpIcon',- },+ icon: 'TextRotateAngleUpIcon',value: -45,},{label: 'textRotate.angleDown',- suffix: {- name: 'TextRotateAngleDownIcon',- },+ icon: 'TextRotateAngleDownIcon',value: 45,},{label: 'textRotate.vertical',- suffix: {- name: 'TextRotateVerticalIcon',- },+ icon: 'TextRotateVerticalIcon',value: 'v',},{label: 'textRotate.rotationUp',- suffix: {- name: 'TextRotateRotationUpIcon',- },+ icon: 'TextRotateRotationUpIcon',value: -90,},{label: 'textRotate.rotationDown',- suffix: {- name: 'TextRotateRotationDownIcon',- },+ icon: 'TextRotateRotationDownIcon',value: 90,},];diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex cfd77ba241..ea44a29ba8 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -768,6 +768,9 @@ importers:'@wendellhu/redi':specifier: ^0.12.7version: 0.12.7+ rxjs:+ specifier: ^7.8.1+ version: 7.8.1devDependencies:'@testing-library/preact':specifier: ^2.0.1