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
refactor: add bold region command
wzhudevea6ed943501c
diff --git a/packages/base-sheets/src/Commands/Commands/set-border-command.ts b/packages/base-sheets/src/Commands/Commands/set-border-command.tsindex 2c542375ee..f8a9154db3 100644--- a/packages/base-sheets/src/Commands/Commands/set-border-command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-border-command.ts@@ -1,5 +1,6 @@import {BorderStyleTypes,+ BorderType,CommandType,IBorderStyleData,ICommand,@@ -38,10 +39,40 @@ function forEach(rangeData: IRangeData, action: (row: number, column: number) =>}}+export interface ISetBorderPositionCommandParams {+ value: BorderType;+}++export const SetBorderPositionCommand: ICommand<ISetBorderPositionCommandParams> = {+ id: 'sheet.command.set-border-position',+ type: CommandType.COMMAND,+ handler: async (accessor: IAccessor, params: ISetBorderPositionCommandParams) => true,+};++export interface ISetBorderStyleCommandParams {+ value: BorderStyleTypes;+}++export const SetBorderStyleCommand: ICommand = {+ id: 'sheet.command.set-border-style',+ type: CommandType.COMMAND,+ handler: async (accessor: IAccessor, params: ISetBorderStyleCommandParams) => true,+};++export interface ISetBorderColorCommandParams {+ value: string;+}++export const SetBorderColorCommand: ICommand<ISetBorderColorCommandParams> = {+ id: 'sheet.command.set-border-color',+ type: CommandType.COMMAND,+ handler: async (accessor: IAccessor, params: ISetBorderColorCommandParams) => true,+};+/*** The command to clear content in current selected ranges.*/-export const SetBorderCommand: ICommand = {+export const SetBorderCommand: ICommand<ISetBorderCommandParams> = {id: 'sheet.command.set-border',type: CommandType.COMMAND,// eslint-disable-next-line max-lines-per-functiondiff --git a/packages/base-sheets/src/Commands/Commands/set-style.command.ts b/packages/base-sheets/src/Commands/Commands/set-style.command.tsindex 289cddbd74..2d91e132be 100644--- a/packages/base-sheets/src/Commands/Commands/set-style.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-style.command.ts@@ -5,7 +5,6 @@ import {FontItalic,FontWeight,HorizontalAlign,- IBorderData,IColorStyle,ICommand,ICommandService,@@ -336,67 +335,6 @@ export const ResetBackgroundColorCommand: ICommand = {},};-export interface ISetCellBorderCommandParams {- value: IBorderData;-}--export const SetCellBorderCommand: ICommand<ISetCellBorderCommandParams> = {- type: CommandType.COMMAND,- id: 'sheet.command.set-cell-border',- handler: async (accessor, params) => {- if (!params) {- return false;- }-- const commandService = accessor.get(ICommandService);- const setStyleParams: ISetStyleParams<IBorderData> = {- style: {- type: 'bd',- value: params.value,- },- };-- return commandService.executeCommand(SetStyleCommand.id, setStyleParams);- },-};--export interface ISetCellBorderColorCommandParams {- value: string;-}--export const SetCellBorderColorCommand: ICommand<ISetCellBorderColorCommandParams> = {- type: CommandType.COMMAND,- id: 'sheet.command.set-cell-border-color',- handler: async (accessor, params) => {- if (!params) {- return false;- }-- const commandService = accessor.get(ICommandService);-- const currentCell = accessor.get(ISelectionManager).getCurrentCell();- if (!currentCell) {- return false;- }-- const currentBorder = currentCell.getBorder();- const newBorder = Tools.deepMerge(currentBorder, {- color: {- rgb: params.value,- },- });-- const setStyleParams: ISetStyleParams<IBorderData> = {- style: {- type: 'bd',- value: newBorder,- },- };-- return commandService.executeCommand(SetStyleCommand.id, setStyleParams);- },-};-export interface ISetVerticalTextAlignCommandParams {value: VerticalAlign;}diff --git a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts b/packages/base-sheets/src/Controller/BasicWorksheet.controller.tsindex b221dbd4c1..bece00cc3c 100644--- a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts+++ b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts@@ -12,7 +12,6 @@ import {ResetBackgroundColorCommand,ResetTextColorCommand,SetBackgroundColorCommand,- SetCellBorderCommand,SetStyleCommand,SetTextColorCommand,SetTextRotationCommand,@@ -45,6 +44,7 @@ import { DeleteRangeMoveTopCommand, IDeleteRangeMoveTopParams } from '../Commandimport { IInsertRangeMoveBottomParams, InsertRangeMoveBottomCommand } from '../Commands/Commands/insert-range-move-bottom.command';import { SetWorksheetOrderCommand } from '../Commands/Commands/set-worksheet-order.command';import { SetWorksheetOrderMutation } from '../Commands/Mutations/set-worksheet-order.mutation';+import { SetBorderColorCommand, SetBorderCommand, SetBorderPositionCommand, SetBorderStyleCommand } from '../Commands/Commands/set-border-command';export interface IStyleTypeValue<T> {type: keyof IStyleData;@@ -103,11 +103,15 @@ export class BasicWorksheetController extends Disposable implements IDisposableSetTextColorCommand,SetBackgroundColorCommand,- SetCellBorderCommand,SetTextWrapCommand,SetTextRotationCommand,ResetTextColorCommand,ResetBackgroundColorCommand,++ SetBorderCommand,+ SetBorderColorCommand,+ SetBorderStyleCommand,+ SetBorderPositionCommand,].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));}diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.tsindex ad0c36c5e4..188afbdd33 100644--- a/packages/base-sheets/src/index.ts+++ b/packages/base-sheets/src/index.ts@@ -5,6 +5,8 @@ export * from './Basics';export * from './View';export { ICanvasView, ISelectionManager } from './Services/tokens';+// #region commands+// mutationsexport { RemoveSheetMutation, RemoveSheetUndoMutationFactory } from './Commands/Mutations/remove-sheet.mutation';export { InsertSheetMutation, InsertSheetUndoMutationFactory } from './Commands/Mutations/insert-sheet.mutation';@@ -26,14 +28,12 @@ export {SetFontSizeCommand,SetTextColorCommand,SetBackgroundColorCommand,- SetCellBorderCommand,SetTextRotationCommand,SetHorizontalTextAlignCommand,SetTextWrapCommand,SetVerticalTextAlignCommand,ResetTextColorCommand,ResetBackgroundColorCommand,- SetCellBorderColorCommand,} from './Commands/Commands/set-style.command';export { InsertSheetCommand } from './Commands/Commands/insert-sheet.command';export { SetWorksheetActivateCommand } from './Commands/Commands/set-worksheet-activate.command';@@ -44,3 +44,15 @@ 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';+export {+ SetBorderColorCommand,+ SetBorderCommand,+ SetBorderPositionCommand,+ SetBorderStyleCommand,+ ISetBorderColorCommandParams,+ ISetBorderCommandParams,+ ISetBorderPositionCommandParams,+ ISetBorderStyleCommandParams,+} from './Commands/Commands/set-border-command';++// #endregiondiff --git a/packages/ui-plugin-sheets/src/Controller/menu.ts b/packages/ui-plugin-sheets/src/Controller/menu.tsindex 3be0d63b11..44db9dd88a 100644--- a/packages/ui-plugin-sheets/src/Controller/menu.ts+++ b/packages/ui-plugin-sheets/src/Controller/menu.ts@@ -18,14 +18,15 @@ import {SetFontSizeCommand,SetTextColorCommand,SetBackgroundColorCommand,- SetCellBorderCommand,+ SetBorderColorCommand,+ SetBorderPositionCommand,SetTextRotationCommand,SetTextWrapCommand,SetHorizontalTextAlignCommand,SetVerticalTextAlignCommand,ResetTextColorCommand,ResetBackgroundColorCommand,- SetCellBorderColorCommand,+ SetBorderStyleCommand,} from '@univerjs/base-sheets';import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes } from '@univerjs/base-ui';import { FontItalic, FontWeight, IBorderData, ICommandService, IPermissionService, IUndoRedoService, RedoCommand, UndoCommand } from '@univerjs/core';@@ -465,10 +466,10 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMeexport function SetBorderColorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<IBorderData | undefined> {return {- id: SetCellBorderColorCommand.id,+ id: SetBorderColorCommand.id,title: 'border',positions: [MenuPosition.TOOLBAR],- parentId: SetCellBorderCommand.id,+ parentId: SetBorderPositionCommand.id,display: DisplayTypes.COLOR,selectType: SelectTypes.NEO,type: MenuItemType.SELECTOR,@@ -480,13 +481,26 @@ export function SetBorderColorMenuItemFactory(accessor: IAccessor): IMenuSelecto};}+export function SetBorderStyleMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<IBorderData | undefined> {+ return {+ id: SetBorderStyleCommand.id,+ title: 'borderStyle',+ positions: [MenuPosition.TOOLBAR],+ parentId: SetBorderPositionCommand.id,+ display: DisplayTypes.COLOR,+ selectType: SelectTypes.NEO,+ type: MenuItemType.SELECTOR,+ selections: [],+ };+}+export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {const permissionService = accessor.get(IPermissionService);const commandService = accessor.get(ICommandService);const selectionManager = accessor.get(ISelectionManager);return {- id: SetCellBorderCommand.id,+ id: SetBorderPositionCommand.id,title: 'border',display: DisplayTypes.ICON,positions: [MenuPosition.TOOLBAR],