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.

chore: wip

wzhudevd4b852fdffc4
diff --git a/packages/base-sheets/src/Commands/Commands/set-style.command.ts b/packages/base-sheets/src/Commands/Commands/set-style.command.ts
index 73d449e0e2..8386d1a6f5 100644
--- a/packages/base-sheets/src/Commands/Commands/set-style.command.ts
+++ b/packages/base-sheets/src/Commands/Commands/set-style.command.ts
@@ -391,7 +391,7 @@ export const SetTextWrapCommand: ICommand<ISetTextWrapCommandParams> = {
};
export interface ISetTextRotationCommandParams {
- rotation: ITextRotation;
+ value: ITextRotation;
}
export const SetTextRotationCommand: ICommand<ISetTextRotationCommandParams> = {
@@ -406,7 +406,7 @@ export const SetTextRotationCommand: ICommand<ISetTextRotationCommandParams> = {
const setStyleParams: ISetStyleParams<ITextRotation> = {
style: {
type: 'tr',
- value: params.rotation,
+ value: params.value,
},
};
diff --git a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
index de70c63bc3..ca562e400d 100644
--- a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
+++ b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts
@@ -7,7 +7,15 @@ import { SetWorksheetNameCommand } from '../Commands/Commands/set-worksheet-name
import { SetWorksheetNameMutation } from '../Commands/Mutations/set-worksheet-name.mutation';
import { SetWorksheetActivateCommand } from '../Commands/Commands/set-worksheet-activate.command';
import { SetWorksheetActivateMutation } from '../Commands/Mutations/set-worksheet-activate.mutation';
-import { ISetStyleParams, SetBackgroundColorCommand, SetCellBorderCommand, SetStyleCommand, SetTextColorCommand } from '../Commands/Commands/set-style.command';
+import {
+ ISetStyleParams,
+ SetBackgroundColorCommand,
+ SetCellBorderCommand,
+ SetStyleCommand,
+ SetTextColorCommand,
+ SetTextRotationCommand,
+ SetTextWrapCommand,
+} 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';
import { TrimWhitespaceCommand } from '../Commands/Commands/trim-whitespace.command';
@@ -94,6 +102,8 @@ export class BasicWorksheetController extends Disposable implements IDisposable
SetTextColorCommand,
SetBackgroundColorCommand,
SetCellBorderCommand,
+ SetTextWrapCommand,
+ SetTextRotationCommand,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
}
diff --git a/packages/core/src/Sheets/Domain/Range.ts b/packages/core/src/Sheets/Domain/Range.ts
index 784fdf7604..daf191040a 100644
--- a/packages/core/src/Sheets/Domain/Range.ts
+++ b/packages/core/src/Sheets/Domain/Range.ts
@@ -677,7 +677,7 @@ export class Range {
* Returns the text rotation settings for the top left cell of the range.
*/
// getTextRotation(): number {
- getTextRotation() {
+ getTextRotation(): number {
return this.getTextRotations()[0][0];
}
@@ -685,8 +685,8 @@ export class Range {
* Returns the text rotation settings for the cells in the range.
*/
// getTextRotations(): number[][] {
- getTextRotations() {
- return this._getStyles('tr');
+ getTextRotations(): number[][] {
+ return this._getStyles('tr') as any as number[][]; // FIXME@Dushusir: fix type
}
/**
diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
index 5f89aa41aa..82f6175eb7 100644
--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
@@ -6,19 +6,7 @@ import { ComponentChildren } from 'preact';
import { SheetToolbarConfig, SHEET_UI_PLUGIN_NAME } from '../Basics';
import { ColorSelect, LineBold, LineColor, Toolbar } from '../View';
-import {
- BackgroundColorSelectorMenuItemFactory,
- BoldMenuItemFactory,
- CellBorderSelectorMenuItemFactory,
- FontColorSelectorMenuItemFactory,
- FontFamilySelectorMenuItemFactory,
- FontSizeSelectorMenuItemFactory,
- ItalicMenuItemFactory,
- RedoMenuItemFactory,
- StrikeThroughMenuItemFactory,
- UnderlineMenuItemFactory,
- UndoMenuItemFactory,
-} from './menu';
+import { WrapTextMenuItemFactory } from './menu';
export interface BaseToolbarSelectProps extends BaseSelectProps {
children?: BaseSelectChildrenProps[];
@@ -114,17 +102,19 @@ export class ToolbarUIController extends Disposable {
// 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,
- FontColorSelectorMenuItemFactory,
- BackgroundColorSelectorMenuItemFactory,
- CellBorderSelectorMenuItemFactory,
+ // UndoMenuItemFactory,
+ // RedoMenuItemFactory,
+ // FontFamilySelectorMenuItemFactory,
+ // FontSizeSelectorMenuItemFactory,
+ // BoldMenuItemFactory,
+ // ItalicMenuItemFactory,
+ // UnderlineMenuItemFactory,
+ // StrikeThroughMenuItemFactory,
+ // FontColorSelectorMenuItemFactory,
+ // BackgroundColorSelectorMenuItemFactory,
+ // CellBorderSelectorMenuItemFactory,
+ WrapTextMenuItemFactory,
+ // TextRotateMenuItemFactory,
].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.ts
index eac84682b1..c9b7b533e9 100644
--- a/packages/ui-plugin-sheets/src/Controller/menu.ts
+++ b/packages/ui-plugin-sheets/src/Controller/menu.ts
@@ -19,6 +19,8 @@ import {
SetTextColorCommand,
SetBackgroundColorCommand,
SetCellBorderCommand,
+ SetTextRotationCommand,
+ SetTextWrapCommand,
} from '@univerjs/base-sheets';
import { ColorPicker, DisplayTypes, IMenuItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes } from '@univerjs/base-ui';
import { FontItalic, FontWeight, ICommandService, IPermissionService, IUndoRedoService, RedoCommand, UndoCommand } from '@univerjs/core';
@@ -26,7 +28,7 @@ import { IAccessor } from '@wendellhu/redi';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { RightMenuInput } from '../View';
-import { BORDER_LINE_CHILDREN, BORDER_SIZE_CHILDREN, FONT_FAMILY_CHILDREN, FONT_SIZE_CHILDREN } from '../View/Toolbar/Const';
+import { BORDER_LINE_CHILDREN, BORDER_SIZE_CHILDREN, FONT_FAMILY_CHILDREN, FONT_SIZE_CHILDREN, TEXT_ROTATE_CHILDREN, TEXT_WRAP_CHILDREN } from '../View/Toolbar/Const';
import { ColorSelect, LineBold, LineColor } from '../View/Common';
import { SHEET_UI_PLUGIN_NAME } from '../Basics/Const/PLUGIN_NAME';
@@ -540,9 +542,69 @@ export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuItem {
export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuItem {}
-export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuItem {}
+export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+
+ return {
+ id: SetTextWrapCommand.id,
+ title: 'textWrapMode',
+ label: {
+ name: 'textWrapMode',
+ props: undefined,
+ },
+ tooltip: 'toolbar.textWrapMode.main',
+ type: MenuItemType.SELECTOR,
+ selectType: SelectTypes.SINGLE,
+ menu: [MenuPosition.TOOLBAR],
+ selections: TEXT_WRAP_CHILDREN,
+ value$: new Observable((subscriber) => {
+ const dispose = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+ if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {
+ return;
+ }
+
+ const range = selectionManager.getCurrentCell();
+ const ws = range?.getWrapStrategy();
+
+ subscriber.next(ws);
+ });
+
+ return () => dispose.dispose();
+ }),
+ };
+}
-export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuItem {}
+// FIXME: set rotation would cause a bug
+export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
+ const permissionService = accessor.get(IPermissionService);
+ const commandService = accessor.get(ICommandService);
+ const selectionManager = accessor.get(ISelectionManager);
+
+ return {
+ id: SetTextRotationCommand.id,
+ title: 'textRotateMode',
+ tooltip: 'toolbar.textRotateMode.main',
+ type: MenuItemType.SELECTOR,
+ selectType: SelectTypes.SINGLE,
+ menu: [MenuPosition.TOOLBAR],
+ value$: new Observable<number>((subscriber) => {
+ commandService.onCommandExecuted((c) => {
+ const id = c.id;
+ if (id !== SetRangeStyleMutation.id && id !== SetSelectionsOperation.id) {
+ return;
+ }
+
+ const range = selectionManager.getCurrentCell();
+ const tr = range?.getTextRotation();
+
+ subscriber.next(tr);
+ });
+ }),
+ selections: TEXT_ROTATE_CHILDREN,
+ };
+}
export function NumberFormatMenuItemFactory(accessor: IAccessor): IMenuItem {}