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: update row height & col width menu
wzhudevd2c9bdc9f58e
diff --git a/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts b/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.tsindex eba959926b..c9d8311d1e 100644--- a/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts@@ -10,7 +10,7 @@ export interface SetWorksheetRowHeightCommandParams {workbookId?: string;worksheetId?: string;rowIndex?: number;- value: number | number[];+ value: number | number[] | string | string[];}export const SetWorksheetRowHeightCommand: ICommand = {@@ -45,11 +45,12 @@ export const SetWorksheetRowHeightCommand: ICommand = {value = new Array(range.endRow - range.startRow + 1).fill(value);}+ value = value.map((v) => (typeof v === 'string' ? parseInt(v, 10) : v));const redoMutationParams: ISetWorksheetRowHeightMutationParams = {worksheetId,workbookId,rowIndex,- rowHeight: value,+ rowHeight: value as number[],};const undoMutationParams: ISetWorksheetRowHeightMutationParams = SetWorksheetRowHeightMutationFactory(accessor, redoMutationParams);const result = commandService.executeCommand(SetWorksheetRowHeightMutation.id, redoMutationParams);diff --git a/packages/base-sheets/src/Controller/RightMenuController.ts b/packages/base-sheets/src/Controller/RightMenuController.tsdeleted file mode 100644index cf5ae303a6..0000000000--- a/packages/base-sheets/src/Controller/RightMenuController.ts+++ /dev/null@@ -1,150 +0,0 @@-import { Inject, SkipSelf } from '@wendellhu/redi';-import { ICommandService, ICurrentUniverService, ObserverManager, UIObserver } from '@univerjs/core';-import { SelectionController } from './Selection/SelectionController';-import { SelectionModel } from '../Model/SelectionModel';-import { ISelectionManager } from '../Services/tokens';-import { SelectionManager } from './Selection';-import { HideColumnController } from './HideColumnController';-import { ClearSelectionContentCommand } from '../Commands/Commands/clear-selection-content.command';--/**- * @deprecated this should be removed after we complete refactoring UI system- */-export class RightMenuController {- constructor(- @SkipSelf() @Inject(ObserverManager) private readonly _globalObserverManager: ObserverManager,- @ISelectionManager private readonly _selectionManager: SelectionManager,- @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,- @Inject(HideColumnController) private readonly _hideColumnController: HideColumnController,- @ICommandService private readonly _commandService: ICommandService- ) {}-- listenEventManager() {- this._globalObserverManager.requiredObserver<UIObserver<string>>('onUIChangeObservable', 'core').add((msg: UIObserver<string>) => {- switch (msg.name) {- case 'insertRow':- this.insertRow();- break;- case 'insertColumn':- this.insertColumn();- break;- case 'deleteRow':- this.deleteRow();- break;- case 'deleteColumn':- this.deleteColumn();- break;- case 'hideColumn':- this.hideColumn();- break;- case 'moveTop':- this.deleteCellTop();- break;- case 'moveLeft':- this.deleteCellLeft();- break;- case 'clearContent':- this.clearContent();- break;- case 'setRowHeight':- this.setRowHeight(msg.value!);- break;- case 'setColumnWidth':- this.setColumnWidth(msg.value!);- break;- }- });- }-- insertRow = () => {- const selections = this._getSelections();- if (selections?.length === 1) {- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();- sheet?.insertRowBefore(selections[0].startRow, selections[0].endRow - selections[0].startRow + 1);- }- };-- deleteRow = () => {- const selections = this._getSelections();- if (selections?.length === 1) {- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();- sheet?.deleteRows(selections[0].startRow, selections[0].endRow - selections[0].startRow + 1);- }- };-- insertColumn = () => {- const selections = this._getSelections();- if (selections?.length === 1) {- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();- sheet.insertColumnBefore(selections[0].startColumn, selections[0].endColumn - selections[0].startColumn + 1);- }- };-- deleteColumn = () => {- const selections = this._getSelections();- if (selections?.length === 1) {- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();- sheet.deleteColumns(selections[0].startColumn, selections[0].endColumn - selections[0].startColumn + 1);- }- };-- hideColumn = () => {- const selections = this._getSelections();- if (selections?.length === 1) {- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();- this._hideColumnController.hideColumns(sheet.getSheetId(), selections[0].startColumn, selections[0].endColumn - selections[0].startColumn + 1);- }- };-- clearContent = () => {- // TODO: @wzhudev: should not call a command directly. Instead, it should invoke a method on XXXController and the controller would trigger a command.- // Only command should be resonsible for triggering commands.- this._commandService.executeCommand(ClearSelectionContentCommand.id);- };-- deleteCellLeft = () => {- const selections = this._getSelections();- if (selections?.length === 1) {- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();- sheet.getRange(selections[0]).deleteCells(0);- }- };-- deleteCellTop = () => {- const selections = this._getSelections();- if (selections?.length === 1) {- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();- sheet.getRange(selections[0]).deleteCells(1);- }- };-- setColumnWidth(width: string) {- const selections = this._getSelections();- if (selections?.length === 1) {- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();- sheet.setColumnWidth(selections[0].startColumn, selections[0].endColumn - selections[0].startColumn + 1, Number(width));- }- }-- setRowHeight(height: string) {- const selections = this._getSelections();- if (selections?.length === 1) {- const sheet = this._currentUniverService.getCurrentUniverSheetInstance()?.getWorkBook().getActiveSheet();- sheet.setRowHeights(selections[0].startRow, selections[0].endRow - selections[0].startRow + 1, Number(height));- }- }-- private _getSelections() {- const controls = this._selectionManager.getCurrentControls();- const selections = controls?.map((control: SelectionController) => {- const model: SelectionModel = control.model;- return {- startRow: model.startRow,- startColumn: model.startColumn,- endRow: model.endRow,- endColumn: model.endColumn,- };- });- return selections;- }-}diff --git a/packages/base-sheets/src/Controller/index.ts b/packages/base-sheets/src/Controller/index.tsindex feec45eb9a..092ec83edd 100644--- a/packages/base-sheets/src/Controller/index.ts+++ b/packages/base-sheets/src/Controller/index.ts@@ -2,7 +2,6 @@export * from './AntLineController';export * from './CellEditorController';export * from './CountBarController';-export * from './RightMenuController';export * from './Selection/index';export * from './SheetBarController';export * from './SheetContainerController';diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/SheetPlugin.tsindex 92a8173b9f..598523f54b 100644--- a/packages/base-sheets/src/SheetPlugin.ts+++ b/packages/base-sheets/src/SheetPlugin.ts@@ -5,7 +5,6 @@ import { Dependency, Inject, Injector } from '@wendellhu/redi';import { SheetPluginObserve, uninstall } from './Basics/Observer';import { CanvasView } from './View/CanvasView';import {- RightMenuController,SheetBarController,CellEditorController,SheetContainerController,@@ -38,10 +37,6 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {private _canvasEngine: Engine;- // TODO: @wzhudev these controllers should be removed finally after we completely refactored base-sheet plugin-- private _rightMenuController: RightMenuController;-private _editTooltipsController: EditTooltipsController;private _formulaBarController: FormulaBarController;@@ -116,7 +111,6 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {this._formulaBarController = this._injector.get(FormulaBarController);this._editTooltipsController = this._injector.get(EditTooltipsController);this._sheetBarController = this._injector.get(SheetBarController);- this._rightMenuController = this._injector.get(RightMenuController);this._countBarController = this._injector.get(CountBarController);this._hideColumnController = this._injector.get(HideColumnController);@@ -158,7 +152,6 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {// TODO: move these init to controllers not herethis._countBarController.listenEventManager();this._sheetBarController.listenEventManager();- this._rightMenuController.listenEventManager();}/** @deprecated move to DI system */@@ -175,7 +168,6 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {[FormulaBarController],[EditTooltipsController],[SheetBarController],- [RightMenuController],[CountBarController],// TODO@huwenzhao: this is a temporary solutiondiff --git a/packages/base-ui/src/Common/ComponentManager.ts b/packages/base-ui/src/Common/ComponentManager.tsindex dac4f336cb..a5ea699b87 100644--- a/packages/base-ui/src/Common/ComponentManager.ts+++ b/packages/base-ui/src/Common/ComponentManager.ts@@ -53,6 +53,7 @@ export interface ICustomComponent {name: string;props?: IKeyValue;}+export type ComponentList = Map<string, Function>;export class ComponentManager {diff --git a/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsxindex c0e8569a65..0ddd2108fe 100644--- a/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx+++ b/packages/base-ui/src/Components/CustomLabel/CustomLabel.tsx@@ -15,11 +15,16 @@ function getLocale(context: Partial<AppContextValues>, name: string) {}export interface INeoCustomLabelProps {- value: string | number | undefined;+ value?: string | number | undefined;selected?: boolean;onChange?(v: string | number): void;}+/**+ * The component to render toolbar item label and menu item label.+ * @param props+ * @returns+ */export function NeoCustomLabel(props: Pick<IMenuSelectorItem<unknown>, 'label' | 'icon' | 'display' | 'title'> & INeoCustomLabelProps): JSX.Element | null {const context = useContext(AppContext);const { display, value, title, icon, label, onChange, selected } = props;@@ -38,11 +43,11 @@ export function NeoCustomLabel(props: Pick<IMenuSelectorItem<unknown>, 'label' |}if (display === DisplayTypes.INPUT) {- // eslint-disable-next-line @typescript-eslint/no-explicit-anyreturn <Input onValueChange={(v) => onChange?.(v as unknown as string)} type="number" value={`${value}`} />;}if (display === DisplayTypes.ICON && icon) {+ // eslint-disable-next-line @typescript-eslint/no-explicit-anyconst LabelComponent = context.componentManager?.get(icon) as any;if (LabelComponent) {return <LabelComponent {...props} />;@@ -50,9 +55,12 @@ export function NeoCustomLabel(props: Pick<IMenuSelectorItem<unknown>, 'label' |}if (display === DisplayTypes.CUSTOM && label) {- const LabelComponent = context.componentManager?.get(label) as any;+ const labelName = typeof label === 'string' ? label : (label as ICustomComponent).name;+ const customProps = (label as ICustomComponent).props ?? {};+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ const LabelComponent = context.componentManager?.get(labelName) as any;if (LabelComponent) {- return <LabelComponent {...props} />;+ return <LabelComponent {...customProps} {...props} />;}}diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsxindex 5b3e31a641..5bcb80d6ff 100644--- a/packages/base-ui/src/Components/Menu/Menu.tsx+++ b/packages/base-ui/src/Components/Menu/Menu.tsx@@ -4,17 +4,7 @@ import { ICommandService, isRealNum } from '@univerjs/core';import { BaseMenuProps, BaseMenuItem, BaseMenuStyle } from '../../Interfaces';import { joinClassNames } from '../../Utils';import { AppContext } from '../../Common/AppContext';-import {- ICustomComponentOption,- IDisplayMenuItem,- IMenuButtonItem,- IMenuItem,- IMenuSelectorItem,- IValueOption,- MenuItemType,- isMenuButtonItem,- isValueOptions,-} from '../../services/menu/menu';+import { ICustomComponentOption, IDisplayMenuItem, IMenuButtonItem, IMenuItem, IMenuSelectorItem, IValueOption, MenuItemType, isValueOptions } from '../../services/menu/menu';import { CustomLabel, NeoCustomLabel } from '../CustomLabel/CustomLabel';import { IMenuService } from '../../services/menu/menu.service';@@ -284,17 +274,15 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {override componentDidMount(): void {const { menuItem } = this.props;- if (isMenuButtonItem(menuItem)) {- this.disabledSubscription = menuItem.disabled$?.subscribe((disabled) => {- this.setState({ disabled });- });- } else {- this.valueSubscription = menuItem.value$?.subscribe((value) => {- this.setState({ value });- });+ this.disabledSubscription = menuItem.disabled$?.subscribe((disabled) => {+ this.setState({ disabled });+ });- this.getSubMenus();- }+ this.valueSubscription = menuItem.value$?.subscribe((value) => {+ this.setState({ value });+ });++ this.getSubMenus();}override componentWillUnmount(): void {@@ -342,15 +330,37 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {}}+ // button type command should directly execute commandprivate renderButtonType(): ComponentChild {- const { menuItem, index } = this.props;- const { disabled } = this.state;+ const { menuItem, onClick } = this.props;+ const { disabled, value } = this.state;+ const { injector } = this.context;++ const commandService: ICommandService = injector.get(ICommandService);const item = menuItem as IDisplayMenuItem<IMenuButtonItem>;+ const { title, display, label } = item;++ console.log('debug, value', value, title);return (- <li className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')} onClick={(e) => this.handleClick(e, item, index)}>- {/* FIXME after translate title,use title for value display*/}- <NeoCustomLabel value={item.title} onChange={this.onChange}></NeoCustomLabel>+ <li+ className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')}+ disabled={disabled}+ onClick={() => {+ commandService.executeCommand(item.id);+ onClick();+ }}+ >+ <NeoCustomLabel+ display={display}+ value={value}+ title={title}+ label={label}+ onChange={(v) => {+ commandService.executeCommand(item.id, { value: v });+ onClick();+ }}+ ></NeoCustomLabel></li>);}diff --git a/packages/base-ui/src/services/menu/menu.ts b/packages/base-ui/src/services/menu/menu.tsindex d457002190..73f8750b06 100644--- a/packages/base-ui/src/services/menu/menu.ts+++ b/packages/base-ui/src/services/menu/menu.ts@@ -24,7 +24,7 @@ export const enum MenuItemType {SUBITEMS, // Multiple sub-menu items have different commands}-interface IMenuItemBase {+interface IMenuItemBase<V> {/** 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;@@ -32,37 +32,36 @@ interface IMenuItemBase {icon?: string;tooltip?: string;- /** @deprecated this type seems unnecessary */- type: MenuItemType;-/** In what menu should the item display. */positions: OneOrMany<MenuPosition | string>;+ /** @deprecated this type seems unnecessary */+ type: MenuItemType;+ /** Determines how the label of the selector should display. */+ display?: DisplayTypes;/*** Custom label component id.- *- * @deprecated this parameter would be removed after refactoring* */- label?: string;-- /** @deprecated this parameter would be removed after refactoring */- className?: string;-- /**- * If the menu is in a submenu, this property would be its parent menu item's id.- * @deprecated use positions instead- */- parentId?: string;+ label?:+ | string+ | {+ name: string;+ props?: Record<string, string | number>;+ };hidden$?: Observable<boolean>;disabled$?: Observable<boolean>;+ /** On observable value that should emit the value of the corresponding selection component. */+ value$?: Observable<V>;}-export interface IMenuButtonItem extends IMenuItemBase {+export interface IMenuButtonItem<V = undefined> extends IMenuItemBase<V> {type: MenuItemType.BUTTON;activated$?: Observable<boolean>;+ // TODO@wzhudev: I may deprecate this+ // eslint-disable-next-line @typescript-eslint/no-explicit-anyonClick?: (...arg: any) => void; // menu button click callback, does not trigger command. e.g. sheet bar rename}@@ -89,20 +88,17 @@ export interface ICustomComponentOption {export interface ICustomComponentProps<T> {value: T;- onValueChange: (v: T) => void;+ onChange: (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 {+export interface IMenuSelectorItem<V> extends IMenuItemBase<V> {type: MenuItemType.SELECTOR | MenuItemType.DROPDOWN | MenuItemType.SUBITEMS;- /** Determines how the label of the selector should display. */- display?: DisplayTypes;-- /** @deprecated this parameter would be removed after we complete refactoring */+ /** @deprecated this parameter would be removed after we complete refactoring, because they will be all NEO */selectType: SelectTypes;// selections 子菜单可以为三种类型@@ -111,9 +107,6 @@ export interface IMenuSelectorItem<V> extends IMenuItemBase {// 一个是其他 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 function isMenuSelectorItem<T>(v: IMenuItem): v is IMenuSelectorItem<T> {diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.tsindex 92ff913bad..1141a8f9c3 100644--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts@@ -7,27 +7,27 @@ 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 {- 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';+// 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[];@@ -124,25 +124,25 @@ export class ToolbarUIController extends Disposable {// in a single controller. I will do that layer.([- UndoMenuItemFactory,- RedoMenuItemFactory,- BoldMenuItemFactory,- ItalicMenuItemFactory,- UnderlineMenuItemFactory,- StrikeThroughMenuItemFactory,- FontFamilySelectorMenuItemFactory,- FontSizeSelectorMenuItemFactory,- ResetTextColorMenuItemFactory,- TextColorSelectorMenuItemFactory,- BackgroundColorSelectorMenuItemFactory,- ResetBackgroundColorMenuItemFactory,- CellBorderSelectorMenuItemFactory,- SetBorderColorMenuItemFactory,- SetBorderStyleMenuItemFactory,- HorizontalAlignMenuItemFactory,- VerticalAlignMenuItemFactory,- WrapTextMenuItemFactory,- TextRotateMenuItemFactory,+ // UndoMenuItemFactory,+ // RedoMenuItemFactory,+ // BoldMenuItemFactory,+ // ItalicMenuItemFactory,+ // UnderlineMenuItemFactory,+ // StrikeThroughMenuItemFactory,+ // FontFamilySelectorMenuItemFactory,+ // FontSizeSelectorMenuItemFactory,+ // ResetTextColorMenuItemFactory,+ // TextColorSelectorMenuItemFactory,+ // 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 01a4c97105..30b135d06d 100644--- a/packages/ui-plugin-sheets/src/Controller/menu.ts+++ b/packages/ui-plugin-sheets/src/Controller/menu.ts@@ -31,7 +31,7 @@ import {SetWorksheetRowShowCommand,SetWorksheetHideCommand,} from '@univerjs/base-sheets';-import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes, IDisplayMenuItem } from '@univerjs/base-ui';+import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes } from '@univerjs/base-ui';import {FontItalic,FontWeight,@@ -53,8 +53,6 @@ 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';-import styles from '../View/Toolbar/index.module.less';-export { SetBorderColorMenuItemFactory, SetBorderStyleMenuItemFactory } from './menu/border.menu';export function UndoMenuItemFactory(accessor: IAccessor): IMenuButtonItem {@@ -288,7 +286,6 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSeldisplay: DisplayTypes.FONT,positions: [MenuPosition.TOOLBAR],selections: FONT_FAMILY_CHILDREN,- className: styles.selectLabelString,disabled$: new Observable((subscriber) => {let editable = false;function update() {@@ -401,7 +398,6 @@ export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSeleselectType: SelectTypes.NEO,positions: [MenuPosition.TOOLBAR],display: DisplayTypes.COLOR,- className: styles.selectColorPickerParent,selections: [{id: SHEET_UI_PLUGIN_NAME + ColorPicker.name,@@ -444,7 +440,6 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMepositions: [MenuPosition.TOOLBAR],display: DisplayTypes.COLOR,icon: 'FillColorIcon',- className: styles.selectColorPickerParent,selections: [{id: SHEET_UI_PLUGIN_NAME + ColorPicker.name,@@ -478,7 +473,6 @@ export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelecticon: HORIZONTAL_ALIGN_CHILDREN[0].icon,positions: [MenuPosition.TOOLBAR],tooltip: 'toolbar.horizontalAlignMode.main',- className: styles.selectDoubleString,display: DisplayTypes.ICON,type: MenuItemType.SELECTOR,selectType: SelectTypes.NEO,@@ -504,7 +498,6 @@ export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectortitle: 'verticalAlignMode',icon: VERTICAL_ALIGN_CHILDREN[0].icon,tooltip: 'toolbar.verticalAlignMode.main',- className: styles.selectDoubleString,display: DisplayTypes.ICON,type: MenuItemType.SELECTOR,positions: [MenuPosition.TOOLBAR],@@ -640,12 +633,16 @@ export function RemoveColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {};}-export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonItem {+export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {+ const commandService = accessor.get(ICommandService);+ const selectionManager = accessor.get(ISelectionManager);+return {id: SetWorksheetRowHeightCommand.id,type: MenuItemType.BUTTON,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.rowHeight',+ display: DisplayTypes.CUSTOM,label: {name: RightMenuInput.name,props: {@@ -653,13 +650,35 @@ export function SetRowHeightMenuItemFactory(accessor: IAccessor): IMenuButtonItesuffix: 'px',},},+ value$: new Observable((subscriber) => {+ function update() {+ const range = selectionManager.getCurrentCell();+ const rowHeight = range?.getHeight();++ subscriber.next(rowHeight ?? 0);+ }++ const disposable = commandService.onCommandExecuted((c) => {+ const id = c.id;+ if (id === SetRangeStyleMutation.id || id === SetSelectionsOperation.id) {+ return update();+ }+ });++ update();+ return disposable.dispose;+ }),};}-export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem {+export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItem<number> {+ const commandService = accessor.get(ICommandService);+ const selectionManager = accessor.get(ISelectionManager);+return {id: SetWorksheetColWidthCommand.id,type: MenuItemType.BUTTON,+ display: DisplayTypes.CUSTOM,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.columnWidth',label: {@@ -669,6 +688,24 @@ export function SetColWidthMenuItemFactory(accessor: IAccessor): IMenuButtonItemsuffix: 'px',},},+ value$: new Observable((subscriber) => {+ function update() {+ const range = selectionManager.getCurrentCell();+ const rowHeight = range?.getWidth();++ subscriber.next(rowHeight ?? 0);+ }++ const disposable = commandService.onCommandExecuted((c) => {+ const id = c.id;+ if (id === SetRangeStyleMutation.id || id === SetSelectionsOperation.id) {+ return update();+ }+ });++ update();+ return disposable.dispose;+ }),};}@@ -730,8 +767,8 @@ export function RenameSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItemonClick: () => {// TODO@Dushusir 这里能监听到点击事件,但是无法触发到 this._sheetBar.reNameSheet(this._dataId);// 或许不应该通过这里的onClick直接更新UI?- console.info('rename=========')- }+ console.info('rename=========');+ },};}diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsxindex f7a0a79ce4..c62277fe3f 100644--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx@@ -1,36 +1,32 @@-import { CustomLabel, Input } from '@univerjs/base-ui';+import { CustomLabel, ICustomComponentProps, Input } from '@univerjs/base-ui';import { Component } from 'preact';-interface IProps {+interface IProps extends ICustomComponentProps<string> {prefix: string;suffix: string;onKeyUp?: (e: Event) => void;- onChange?: (e: Event) => void;}export class RightMenuInput extends Component<IProps> {- handleClick(e: Event) {- e.stopPropagation();- }-- handleKeyUp(e: Event) {- const { onKeyUp } = this.props;- onKeyUp?.(e);- }-- onChange(e: Event) {- const { onChange } = this.props;- onChange?.(e);- }+ private value = '';render() {- const { prefix, suffix } = this.props;+ const { prefix, suffix, value } = this.props;return (- <div>+ <div onClick={(e) => this.handleClick(e)}><CustomLabel label={prefix} />- <Input onPressEnter={this.handleKeyUp.bind(this)} type="number" placeholder="1" onClick={this.handleClick.bind(this)} onChange={this.onChange.bind(this)}></Input>+ <Input type="number" placeholder="1" value={value} onClick={(e) => e.stopPropagation()} onChange={this.onChange.bind(this)}></Input><CustomLabel label={suffix} /></div>);}++ private handleClick(e: Event) {+ e.stopPropagation();+ this.props.onChange?.(this.value);+ }++ private onChange(e: Event) {+ this.value = (e.target as HTMLInputElement).value;+ }}