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(facade): add sheet facade functions (#4494)
zhangwab3c71286549
diff --git a/packages/core/src/facade/f-enum.ts b/packages/core/src/facade/f-enum.tsindex ed5b2137df..61ae769107 100644--- a/packages/core/src/facade/f-enum.ts+++ b/packages/core/src/facade/f-enum.ts@@ -17,12 +17,27 @@import { UniverInstanceType } from '../common/unit';import { CommandType } from '../services/command/command.service';import { LifecycleStages } from '../services/lifecycle/lifecycle';-import { BaselineOffset, BooleanNumber, HorizontalAlign, TextDecoration, TextDirection, VerticalAlign } from '../types/enum';+import { BaselineOffset, BooleanNumber, BorderStyleTypes, BorderType, HorizontalAlign, TextDecoration, TextDirection, VerticalAlign } from '../types/enum';+import { AutoFillSeries } from '../types/enum/auto-fill-series';+import { ColorType } from '../types/enum/color-type';+import { CommonHideTypes } from '../types/enum/common-hide-types';+import { CopyPasteType } from '../types/enum/copy-paste-type';import { DataValidationErrorStyle } from '../types/enum/data-validation-error-style';import { DataValidationOperator } from '../types/enum/data-validation-operator';import { DataValidationRenderMode } from '../types/enum/data-validation-render-mode';import { DataValidationStatus } from '../types/enum/data-validation-status';import { DataValidationType } from '../types/enum/data-validation-type';+import { DeleteDirection } from '../types/enum/delete-direction';+import { DeveloperMetadataVisibility } from '../types/enum/developer-metadata-visibility';+import { Dimension } from '../types/enum/dimension';+import { Direction } from '../types/enum/direction';+import { InterpolationPointType } from '../types/enum/interpolation-point-type';+import { LocaleType } from '../types/enum/locale-type';+import { MentionType } from '../types/enum/mention-type';+import { ProtectionType } from '../types/enum/protection-type';+import { RelativeDate } from '../types/enum/relative-date';+import { SheetTypes } from '../types/enum/sheet-types';+import { ThemeColorType } from '../types/enum/theme-color-type';export class FEnum {static _instance: FEnum | null;@@ -157,4 +172,123 @@ export class FEnum {get VerticalAlign() {return VerticalAlign;}++ /**+ * Different border types+ */+ get BorderType() {+ return BorderType;+ }++ /**+ * Different border style types+ */+ get BorderStyleTypes() {+ return BorderStyleTypes;+ }++ /**+ * Auto fill series types+ */+ get AutoFillSeries() {+ return AutoFillSeries;+ }++ /**+ * Color types+ */+ get ColorType() {+ return ColorType;+ }++ /**+ * Common hide types+ */+ get CommonHideTypes() {+ return CommonHideTypes;+ }++ /**+ * Copy paste types+ */+ get CopyPasteType() {+ return CopyPasteType;+ }++ /**+ * Delete direction types+ */+ get DeleteDirection() {+ return DeleteDirection;+ }++ /**+ * Developer metadata visibility types+ */+ get DeveloperMetadataVisibility() {+ return DeveloperMetadataVisibility;+ }++ /**+ * Dimension types+ */+ get Dimension() {+ return Dimension;+ }++ /**+ * Direction types+ */+ get Direction() {+ return Direction;+ }++ /**+ * Interpolation point types+ */+ get InterpolationPointType() {+ return InterpolationPointType;+ }++ /**+ * Locale types+ */+ get LocaleType() {+ return LocaleType;+ }++ /**+ * Mention types+ */+ get MentionType() {+ return MentionType;+ }++ /**+ * Protection types+ */+ get ProtectionType() {+ return ProtectionType;+ }++ /**+ * Relative date types+ */+ get RelativeDate() {+ return RelativeDate;+ }++ /**+ * Sheet types+ */+ get SheetTypes() {+ return SheetTypes;+ }++ /**+ * Theme color types+ */+ get ThemeColorType() {+ return ThemeColorType;+ }}diff --git a/packages/facade/src/apis/__tests__/create-test-bed.ts b/packages/facade/src/apis/__tests__/create-test-bed.tsindex 4e263d26c0..7be978962c 100644--- a/packages/facade/src/apis/__tests__/create-test-bed.ts+++ b/packages/facade/src/apis/__tests__/create-test-bed.ts@@ -18,7 +18,8 @@import type { Dependency, IWorkbookData, Nullable, UnitModel } from '@univerjs/core';import type { IRender } from '@univerjs/engine-render';-import type { IDragCellPosition } from '@univerjs/sheets-ui';+import type { ICellPosWithEvent, IHoverCellPosition, IHoverRichTextInfo, IHoverRichTextPosition } from '@univerjs/sheets-ui';+import type { IHoverHeaderPosition } from '@univerjs/sheets-ui/services/hover-manager.service.js';import {ILogService,Inject,@@ -180,10 +181,24 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?:injector.add([IDefinedNamesService, { useClass: DefinedNamesService }]);// Create a mock HoverManagerService with currentCell$const mockHoverManagerService = {- currentCell$: new Subject<Nullable<IDragCellPosition>>().asObservable(),- currentPosition$: new Subject<Nullable<IDragCellPosition>>().asObservable(),- currentClickedCell$: new Subject<Nullable<IDragCellPosition>>().asObservable(),- endCell$: new Subject<Nullable<IDragCellPosition>>().asObservable(),+ currentCell$: new Subject<Nullable<IHoverCellPosition>>().asObservable(),+ currentRichText$: new Subject<Nullable<IHoverRichTextPosition>>().asObservable(),+ currentClickedCell$: new Subject<IHoverRichTextInfo>().asObservable(),+ currentDbClickedCell$: new Subject<IHoverRichTextInfo>().asObservable(),+ currentCellPosWithEvent$: new Subject<Nullable<ICellPosWithEvent>>().asObservable(),+ currentPointerDownCell$: new Subject<ICellPosWithEvent>().asObservable(),+ currentPointerUpCell$: new Subject<ICellPosWithEvent>().asObservable(),+ currentPosition$: new Subject<Nullable<IHoverCellPosition>>().asObservable(),+ currentHoveredRowHeader$: new Subject<Nullable<IHoverHeaderPosition>>().asObservable(),+ currentHoveredColHeader$: new Subject<Nullable<IHoverHeaderPosition>>().asObservable(),+ currentRowHeaderClick$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentColHeaderClick$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentRowHeaderDbClick$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentColHeaderDbClick$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentRowHeaderPointerDown$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentColHeaderPointerDown$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentRowHeaderPointerUp$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentColHeaderPointerUp$: new Subject<IHoverHeaderPosition>().asObservable(),};injector.add([HoverManagerService, { useValue: mockHoverManagerService as unknown as HoverManagerService }]);injector.add([DragManagerService, { useValue: mockHoverManagerService as unknown as DragManagerService }]);diff --git a/packages/sheets-ui/src/facade/__tests__/f-sheet-hooks.spec.ts b/packages/sheets-ui/src/facade/__tests__/f-sheet-hooks.spec.tsindex 07258a2695..1776e51972 100644--- a/packages/sheets-ui/src/facade/__tests__/f-sheet-hooks.spec.ts+++ b/packages/sheets-ui/src/facade/__tests__/f-sheet-hooks.spec.ts@@ -17,7 +17,7 @@import type { ICellData, Injector, IStyleData, Nullable, Workbook } from '@univerjs/core';import type { IDragCellPosition } from '../../services/drag-manager.service';import type { IEditorBridgeServiceVisibleParam } from '../../services/editor-bridge.service';-import type { IHoverCellPosition } from '../../services/hover-manager.service';+import type { ICellPosWithEvent, IHoverCellPosition, IHoverHeaderPosition, IHoverRichTextInfo, IHoverRichTextPosition } from '../../services/hover-manager.service';import { ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import { DocSelectionManagerService } from '@univerjs/docs';@@ -93,7 +93,24 @@ describe('Test FSheetHooks', () => {dragEndCell$ = new Subject<Nullable<IDragCellPosition>>();// Create a mock HoverManagerService with currentCell$- mockHoverManagerService = {++ const mockHoverManagerService = {+ currentRichText$: new Subject<Nullable<IHoverRichTextPosition>>().asObservable(),+ currentClickedCell$: new Subject<IHoverRichTextInfo>().asObservable(),+ currentDbClickedCell$: new Subject<IHoverRichTextInfo>().asObservable(),+ currentCellPosWithEvent$: new Subject<Nullable<ICellPosWithEvent>>().asObservable(),+ currentPointerDownCell$: new Subject<ICellPosWithEvent>().asObservable(),+ currentPointerUpCell$: new Subject<ICellPosWithEvent>().asObservable(),+ currentHoveredRowHeader$: new Subject<Nullable<IHoverHeaderPosition>>().asObservable(),+ currentHoveredColHeader$: new Subject<Nullable<IHoverHeaderPosition>>().asObservable(),+ currentRowHeaderClick$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentColHeaderClick$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentRowHeaderDbClick$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentColHeaderDbClick$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentRowHeaderPointerDown$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentColHeaderPointerDown$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentRowHeaderPointerUp$: new Subject<IHoverHeaderPosition>().asObservable(),+ currentColHeaderPointerUp$: new Subject<IHoverHeaderPosition>().asObservable(),currentCell$: hoverCurrentCell$.asObservable(),currentPosition$: hoverCurrentPosition$.asObservable(),};diff --git a/packages/sheets-ui/src/facade/f-univer.ts b/packages/sheets-ui/src/facade/f-univer.tsindex 335d968d60..8ff1df9944 100644--- a/packages/sheets-ui/src/facade/f-univer.ts+++ b/packages/sheets-ui/src/facade/f-univer.ts@@ -269,7 +269,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixif (!hoverManagerService) return;disposable.add(hoverManagerService.currentClickedCell$- ?.pipe(filter((cell) => !!cell))+ .pipe(filter((cell) => !!cell)).subscribe((cell) => {if (!this._eventListend(this.Event.CellClicked)) return;const baseParams = this.getSheetTarget(cell.location.unitId, cell.location.subUnitId);@@ -284,7 +284,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix);disposable.add(- hoverManagerService.currentRichText$?.pipe(filter((cell) => !!cell))+ hoverManagerService.currentRichText$.pipe(filter((cell) => !!cell)).subscribe((cell) => {if (!this._eventListend(this.Event.CellHover)) return;const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);@@ -299,7 +299,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix);disposable.add(- hoverManagerService.currentPointerDownCell$?.pipe(filter((cell) => !!cell))+ hoverManagerService.currentPointerDownCell$.pipe(filter((cell) => !!cell)).subscribe((cell) => {if (!this._eventListend(this.Event.CellPointerDown)) return;const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);@@ -314,7 +314,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix);disposable.add(- hoverManagerService.currentPointerUpCell$?.pipe(filter((cell) => !!cell))+ hoverManagerService.currentPointerUpCell$.pipe(filter((cell) => !!cell)).subscribe((cell) => {if (!this._eventListend(this.Event.CellPointerUp)) return;const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);@@ -329,7 +329,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix);disposable.add(- hoverManagerService.currentCellPosWithEvent$?.pipe(filter((cell) => !!cell))+ hoverManagerService.currentCellPosWithEvent$.pipe(filter((cell) => !!cell)).subscribe((cell) => {if (!this._eventListend(this.Event.CellPointerMove)) return;const baseParams = this.getSheetTarget(cell.unitId, cell.subUnitId);@@ -345,7 +345,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixdisposable.add(dragManagerService.currentCell$- ?.pipe(filter((cell) => !!cell))+ .pipe(filter((cell) => !!cell)).subscribe((cell) => {if (!this._eventListend(this.Event.DragOver)) return;const baseParams = this.getSheetTarget(cell.location.unitId, cell.location.subUnitId);@@ -360,8 +360,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix);disposable.add(- dragManagerService.endCell$- ?.pipe(filter((cell) => !!cell))+ dragManagerService.endCell$?.pipe(filter((cell) => !!cell)).subscribe((cell) => {if (!this._eventListend(this.Event.Drop)) return;const baseParams = this.getSheetTarget(cell.location.unitId, cell.location.subUnitId);@@ -378,7 +377,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix// Row Header Eventsdisposable.add(hoverManagerService.currentRowHeaderClick$- ?.pipe(filter((header) => !!header))+ .pipe(filter((header) => !!header)).subscribe((header) => {if (!this._eventListend(this.Event.RowHeaderClick)) return;const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);@@ -392,7 +391,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixdisposable.add(hoverManagerService.currentRowHeaderPointerDown$- ?.pipe(filter((header) => !!header))+ .pipe(filter((header) => !!header)).subscribe((header) => {if (!this._eventListend(this.Event.RowHeaderPointerDown)) return;const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);@@ -406,7 +405,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixdisposable.add(hoverManagerService.currentRowHeaderPointerUp$- ?.pipe(filter((header) => !!header))+ .pipe(filter((header) => !!header)).subscribe((header) => {if (!this._eventListend(this.Event.RowHeaderPointerUp)) return;const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);@@ -420,7 +419,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixdisposable.add(hoverManagerService.currentHoveredRowHeader$- ?.pipe(filter((header) => !!header))+ .pipe(filter((header) => !!header)).subscribe((header) => {if (!this._eventListend(this.Event.RowHeaderHover)) return;const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);@@ -435,7 +434,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix// Column Header Eventsdisposable.add(hoverManagerService.currentColHeaderClick$- ?.pipe(filter((header) => !!header))+ .pipe(filter((header) => !!header)).subscribe((header) => {if (!this._eventListend(this.Event.ColumnHeaderClick)) return;const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);@@ -449,7 +448,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixdisposable.add(hoverManagerService.currentColHeaderPointerDown$- ?.pipe(filter((header) => !!header))+ .pipe(filter((header) => !!header)).subscribe((header) => {if (!this._eventListend(this.Event.ColumnHeaderPointerDown)) return;const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);@@ -463,7 +462,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixdisposable.add(hoverManagerService.currentColHeaderPointerUp$- ?.pipe(filter((header) => !!header))+ .pipe(filter((header) => !!header)).subscribe((header) => {if (!this._eventListend(this.Event.ColumnHeaderPointerUp)) return;const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);@@ -477,7 +476,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMixdisposable.add(hoverManagerService.currentHoveredColHeader$- ?.pipe(filter((header) => !!header))+ .pipe(filter((header) => !!header)).subscribe((header) => {if (!this._eventListend(this.Event.ColumnHeaderHover)) return;const baseParams = this.getSheetTarget(header.unitId, header.subUnitId);diff --git a/packages/sheets/src/commands/commands/set-border-command.ts b/packages/sheets/src/commands/commands/set-border-command.tsindex 5384a4b88b..0a08583839 100644--- a/packages/sheets/src/commands/commands/set-border-command.ts+++ b/packages/sheets/src/commands/commands/set-border-command.ts@@ -536,7 +536,7 @@ export const SetBorderCommand: ICommand = {id: 'sheet.command.set-border',type: CommandType.COMMAND,- handler: async (accessor: IAccessor, params?: ISetBorderCommandParams) => {+ handler: (accessor: IAccessor, params?: ISetBorderCommandParams) => {const commandService = accessor.get(ICommandService);const undoRedoService = accessor.get(IUndoRedoService);const univerInstanceService = accessor.get(IUniverInstanceService);@@ -591,41 +591,41 @@ export const SetBorderCommand: ICommand = {export const SetBorderPositionCommand: ICommand<ISetBorderPositionCommandParams> = {id: 'sheet.command.set-border-position',type: CommandType.COMMAND,- handler: async (accessor: IAccessor, params: ISetBorderPositionCommandParams) => {+ handler: (accessor: IAccessor, params: ISetBorderPositionCommandParams) => {if (!params.value) return false;const commandService = accessor.get(ICommandService);const borderManager = accessor.get(BorderStyleManagerService);borderManager.setType(params.value);- return commandService.executeCommand(SetBorderCommand.id);+ return commandService.syncExecuteCommand(SetBorderCommand.id);},};export const SetBorderStyleCommand: ICommand = {id: 'sheet.command.set-border-style',type: CommandType.COMMAND,- handler: async (accessor: IAccessor, params: ISetBorderStyleCommandParams) => {+ handler: (accessor: IAccessor, params: ISetBorderStyleCommandParams) => {const commandService = accessor.get(ICommandService);const borderManager = accessor.get(BorderStyleManagerService);borderManager.setStyle(params.value);- return commandService.executeCommand(SetBorderCommand.id);+ return commandService.syncExecuteCommand(SetBorderCommand.id);},};export const SetBorderColorCommand: ICommand<ISetBorderColorCommandParams> = {id: 'sheet.command.set-border-color',type: CommandType.COMMAND,- handler: async (accessor: IAccessor, params: ISetBorderColorCommandParams) => {+ handler: (accessor: IAccessor, params: ISetBorderColorCommandParams) => {const commandService = accessor.get(ICommandService);const borderManager = accessor.get(BorderStyleManagerService);borderManager.setColor(params.value);- return commandService.executeCommand(SetBorderCommand.id);+ return commandService.syncExecuteCommand(SetBorderCommand.id);},};export const SetBorderBasicCommand: ICommand<ISetBorderBasicCommandParams> = {id: 'sheet.command.set-border-basic',type: CommandType.COMMAND,- handler: async (accessor: IAccessor, params: ISetBorderBasicCommandParams) => {+ handler: (accessor: IAccessor, params: ISetBorderBasicCommandParams) => {const { unitId, subUnitId, value } = params;const { type, color, style } = value;@@ -636,7 +636,7 @@ export const SetBorderBasicCommand: ICommand<ISetBorderBasicCommandParams> = {if (color) borderManager.setColor(color);borderManager.setStyle(style);- return commandService.executeCommand(SetBorderCommand.id, {+ return commandService.syncExecuteCommand(SetBorderCommand.id, {unitId,subUnitId,});diff --git a/packages/sheets/src/facade/f-defined-name.ts b/packages/sheets/src/facade/f-defined-name.tsindex 75b59a8b1b..7412984536 100644--- a/packages/sheets/src/facade/f-defined-name.ts+++ b/packages/sheets/src/facade/f-defined-name.ts@@ -23,7 +23,7 @@ import { RangeProtectionRuleModel, RemoveDefinedNameCommand, SCOPE_WORKBOOK_VALU* Get defined name field name* @param {string} unitId - unit id* @param {LocaleService} localeService - locale service- * @param {DefinedNamesService} definedNamesService - defined names service+ * @param {IDefinedNamesService} definedNamesService - defined names service* @returns {string} field name*/function getDefinedNameFieldName(unitId: string, localeService: LocaleService, definedNamesService: IDefinedNamesService): string {diff --git a/packages/sheets/src/facade/f-event.ts b/packages/sheets/src/facade/f-event.tsindex 3539d53ed1..e18933e638 100644--- a/packages/sheets/src/facade/f-event.ts+++ b/packages/sheets/src/facade/f-event.ts@@ -134,7 +134,7 @@ export interface IFSheetEventMixin {get SheetNameChanged(): 'SheetNameChanged';/*** Event fired before a sheet name is changed- * @see {@link IBeforeSheetNameChange}+ * @see {@link IBeforeSheetNameChangeEvent}* @example* ```ts* univerAPI.addEvent(univerAPI.Event.BeforeSheetNameChange, (params) => {@@ -158,7 +158,7 @@ export interface IFSheetEventMixin {get SheetTabColorChanged(): 'SheetTabColorChanged';/*** Event fired before a sheet tab color is changed- * @see {@link IBeforeSheetTabColorChange}+ * @see {@link IBeforeSheetTabColorChangeEvent}* @example* ```ts* univerAPI.addEvent(univerAPI.Event.BeforeSheetTabColorChange, (params) => {@@ -182,7 +182,7 @@ export interface IFSheetEventMixin {get SheetHideChanged(): 'SheetHideChanged';/*** Event fired before a sheet is hidden- * @see {@link IBeforeSheetHideChange}+ * @see {@link IBeforeSheetHideChangeEvent}* @example* ```ts* univerAPI.addEvent(univerAPI.Event.BeforeSheetHideChange, (params) => {diff --git a/packages/sheets/src/facade/f-range.ts b/packages/sheets/src/facade/f-range.tsindex 1647de65a7..187a4a9843 100644--- a/packages/sheets/src/facade/f-range.ts+++ b/packages/sheets/src/facade/f-range.ts@@ -14,12 +14,12 @@* limitations under the License.*/-import type { CellValue, CustomData, ICellData, IColorStyle, IDocumentData, IObjectMatrixPrimitiveType, IRange, IStyleData, ITextDecoration, Nullable, Workbook, Worksheet } from '@univerjs/core';-import type { ISetHorizontalTextAlignCommandParams, ISetRangeValuesCommandParams, ISetStyleCommandParams, ISetTextWrapCommandParams, ISetVerticalTextAlignCommandParams, IStyleTypeValue, SplitDelimiterEnum } from '@univerjs/sheets';+import type { BorderStyleTypes, BorderType, CellValue, CustomData, ICellData, IColorStyle, IDocumentData, IObjectMatrixPrimitiveType, IRange, IStyleData, ITextDecoration, Nullable, Workbook, Worksheet } from '@univerjs/core';+import type { ISetBorderBasicCommandParams, ISetHorizontalTextAlignCommandParams, ISetRangeValuesCommandParams, ISetStyleCommandParams, ISetTextWrapCommandParams, ISetVerticalTextAlignCommandParams, IStyleTypeValue, SplitDelimiterEnum } from '@univerjs/sheets';import type { FHorizontalAlignment, FVerticalAlignment } from './utils';-import { BooleanNumber, Dimension, FBaseInitialable, ICommandService, Inject, Injector, Rectangle, RichTextValue, WrapStrategy } from '@univerjs/core';+import { BooleanNumber, Dimension, FBaseInitialable, ICommandService, Inject, Injector, Rectangle, RichTextValue, TextStyleValue, WrapStrategy } from '@univerjs/core';import { FormulaDataModel, serializeRange, serializeRangeWithSheet } from '@univerjs/engine-formula';-import { addMergeCellsUtil, DeleteWorksheetRangeThemeStyleCommand, getAddMergeMutationRangeByType, RemoveWorksheetMergeCommand, SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorksheetRangeThemeStyleCommand, SheetRangeThemeService, SplitTextToColumnsCommand } from '@univerjs/sheets';+import { addMergeCellsUtil, DeleteWorksheetRangeThemeStyleCommand, getAddMergeMutationRangeByType, RemoveWorksheetMergeCommand, SetBorderBasicCommand, SetHorizontalTextAlignCommand, SetRangeValuesCommand, SetStyleCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorksheetRangeThemeStyleCommand, SheetRangeThemeService, SplitTextToColumnsCommand } from '@univerjs/sheets';import { FWorkbook } from './f-workbook';import { covertCellValue, covertCellValues, transformCoreHorizontalAlignment, transformCoreVerticalAlignment, transformFacadeHorizontalAlignment, transformFacadeVerticalAlignment } from './utils';@@ -197,6 +197,44 @@ export class FRange extends FBaseInitialable {return null;}+ /**+ * Return first cell style in this range+ * @returns {TextStyleValue | null} The cell style+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getCellStyle()+ * ```+ */+ getCellStyle(): TextStyleValue | null {+ const data = this.getCellStyleData();+ return data ? TextStyleValue.create(data) : null;+ }++ /**+ * Returns the cell styles for the cells in the range.+ * @returns {Array<Array<TextStyleValue | null>>} A two-dimensional array of cell styles.+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .getCellStyles()+ * ```+ */+ getCellStyles(): Array<Array<TextStyleValue | null>> {+ const cells = this.getCellDatas();+ const styles = this._workbook.getStyles();+ return cells.map((row) => row.map((cell) => {+ if (!cell) return null;+ const style = styles.getStyleByCell(cell);+ return style ? TextStyleValue.create(style) : null;+ }));+ }++ // eslint-disable-next-line jsdoc/require-returns/*** @deprecated use `getValueAndRichTextValue` instead. This api can't return rich text value.*/@@ -204,6 +242,7 @@ export class FRange extends FBaseInitialable {return this._worksheet.getCell(this._range.startRow, this._range.startColumn)?.v ?? null;}+ // eslint-disable-next-line jsdoc/require-returns/*** @deprecated use `getValueAndRichTextValues` instead. This api can't return rich text value.*/@@ -263,6 +302,7 @@ export class FRange extends FBaseInitialable {return range;}+ // eslint-disable-next-line jsdoc/require-returns/*** @deprecated use `getCellDatas` instead.*/@@ -493,6 +533,33 @@ export class FRange extends FBaseInitialable {return dataGrid.map((row) => row.map((data) => data?.custom ?? null));}+ /**+ * Sets basic border properties for the current range.+ * @param {BorderType} type The type of border to apply+ * @param {BorderStyleTypes} style The border style+ * @param {string} [color] Optional border color in CSS notation+ * @returns {FRange} This range, for chaining+ * @example+ * ```ts+ * univerAPI.getActiveWorkbook()+ * .getActiveSheet()+ * .getActiveRange()+ * .setBorder(BorderType.ALL, BorderStyleType.THIN, '#ff0000');+ * ```+ */+ setBorder(type: BorderType, style: BorderStyleTypes, color?: string): FRange {+ this._commandService.syncExecuteCommand(SetBorderBasicCommand.id, {+ unitId: this._workbook.getUnitId(),+ subUnitId: this._worksheet.getSheetId(),+ value: {+ type,+ style,+ color,+ },+ } as ISetBorderBasicCommandParams);+ return this;+ }+// #region editing/**@@ -1270,7 +1337,6 @@ export class FRange extends FBaseInitialable {* // A | B | C* // 1 | 2 | 3* // 1 | 2 | 3- ** @example Show how to split text to columns with custom delimiter* // A1:A3 has following values:* // A | B | Cdiff --git a/packages/sheets/src/facade/f-workbook.ts b/packages/sheets/src/facade/f-workbook.tsindex 4db338666c..b05039c19a 100644--- a/packages/sheets/src/facade/f-workbook.ts+++ b/packages/sheets/src/facade/f-workbook.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { CommandListener, CustomData, ICommandInfo, IDisposable, IEventParamConfig, IRange, IWorkbookData, LocaleType, Registry, Workbook } from '@univerjs/core';+import type { CommandListener, CustomData, ICommandInfo, IDisposable, IRange, IWorkbookData, LocaleType, Workbook } from '@univerjs/core';import type { ISetDefinedNameMutationParam } from '@univerjs/engine-formula';import type { ISetSelectionsOperationParams, ISheetCommandSharedParams, RangeThemeStyle } from '@univerjs/sheets';import type { FontLine as _FontLine } from './f-range';@@ -60,26 +60,6 @@ export class FWorkbook extends FBaseInitialable {return this._workbook;}- private _eventRegistry: Map<string, Registry<(param: any) => void>> = new Map();-- /**- * Fire an event, used in internal only.- * @param event {string} key of event- * @param params {any} params of event- * @returns {boolean} should cancel- * @example- * ```ts- * this.fireEvent(univerAPI.event.UnitCreated, params);- * ```- */- protected fireEvent<T extends keyof IEventParamConfig>(event: T, params: IEventParamConfig[T]): boolean | undefined {- this._eventRegistry.get(event)?.getData().forEach((callback) => {- callback(params);- });-- return params.cancel;- }-/*** Get the id of the workbook.* @returns {string} The id of the workbook.@@ -111,6 +91,7 @@ export class FWorkbook extends FBaseInitialable {/*** Set the name of the workbook.* @param {string} name The new name of the workbook.+ * @returns {void}* @example* ```ts* // The code below sets the name of the workbook@@ -139,7 +120,7 @@ export class FWorkbook extends FBaseInitialable {/*** @deprecated use 'save' instead.- * @returns {*} {IWorkbookData} Workbook snapshot data+ * @returns {IWorkbookData} Workbook snapshot data* @memberof FWorkbook* @example* ```ts@@ -186,10 +167,10 @@ export class FWorkbook extends FBaseInitialable {/*** Create a new worksheet and returns a handle to it.- * @param name Name of the new sheet- * @param rows How may rows would the new sheet have- * @param column How many columns would the new sheet have- * @returns The new created sheet+ * @param {string} name Name of the new sheet+ * @param {number} rows How many rows would the new sheet have+ * @param {number} column How many columns would the new sheet have+ * @returns {FWorksheet} The new created sheet* @example* ```ts* // The code below creates a new sheet@@ -225,8 +206,8 @@ export class FWorkbook extends FBaseInitialable {/*** Get a worksheet by sheet id.- * @param sheetId The id of the sheet to get.- * @returns The worksheet with given sheet id+ * @param {string} sheetId The id of the sheet to get.+ * @returns {FWorksheet | null} The worksheet with given sheet id* @example* ```ts* // The code below gets a worksheet by sheet id@@ -245,8 +226,8 @@ export class FWorkbook extends FBaseInitialable {/*** Get a worksheet by sheet name.- * @param name The name of the sheet to get.- * @returns The worksheet with given sheet name+ * @param {string} name The name of the sheet to get.+ * @returns {FWorksheet | null} The worksheet with given sheet name* @example* ```ts* // The code below gets a worksheet by sheet name@@ -265,8 +246,8 @@ export class FWorkbook extends FBaseInitialable {/*** Sets the given worksheet to be the active worksheet in the workbook.- * @param sheet The worksheet to set as the active worksheet.- * @returns The active worksheet+ * @param {FWorksheet | string} sheet The worksheet to set as the active worksheet.+ * @returns {FWorksheet} The active worksheet* @example* ```ts* // The code below sets the given worksheet to be the active worksheet@@ -275,20 +256,20 @@ export class FWorkbook extends FBaseInitialable {* activeSpreadsheet.setActiveSheet(sheet);* ```*/- setActiveSheet(sheet: FWorksheet): FWorksheet {+ setActiveSheet(sheet: FWorksheet | string): FWorksheet {this._commandService.syncExecuteCommand(SetWorksheetActiveOperation.id, {unitId: this.id,- subUnitId: sheet.getSheetId(),+ subUnitId: typeof sheet === 'string' ? sheet : sheet.getSheetId(),});- return sheet;+ return typeof sheet === 'string' ? this.getSheetBySheetId(sheet)! : sheet;}/*** Inserts a new worksheet into the workbook.* Using a default sheet name. The new sheet becomes the active sheet- * @param sheetName - (optional) The name of the new sheet- * @returns The new sheet+ * @param {string} [sheetName] The name of the new sheet+ * @returns {FWorksheet} The new sheet* @example* ```ts* // The code below inserts a new sheet into the workbook@@ -324,7 +305,7 @@ export class FWorkbook extends FBaseInitialable {/*** Deletes the specified worksheet.- * @param sheet The worksheet to delete.+ * @param {FWorksheet | string} sheet The worksheet to delete.* @returns {boolean} True if the worksheet was deleted, false otherwise.* @example* ```ts@@ -334,9 +315,9 @@ export class FWorkbook extends FBaseInitialable {* activeSpreadsheet.deleteSheet(sheet);* ```*/- deleteSheet(sheet: FWorksheet): boolean {+ deleteSheet(sheet: FWorksheet | string): boolean {const unitId = this.id;- const subUnitId = sheet.getSheetId();+ const subUnitId = typeof sheet === 'string' ? sheet : sheet.getSheetId();return this._commandService.syncExecuteCommand(RemoveSheetCommand.id, {unitId,subUnitId,@@ -362,7 +343,7 @@ export class FWorkbook extends FBaseInitialable {/*** Redo the last undone action.- * @returns A promise that resolves to true if the redo was successful, false otherwise.+ * @returns {FWorkbook} A promise that resolves to true if the redo was successful, false otherwise.* @example* ```ts* // The code below redoes the last undone action@@ -385,7 +366,7 @@ export class FWorkbook extends FBaseInitialable {/*** Register a callback that will be triggered before invoking a command targeting the Univer sheet.* @param {onBeforeCommandExecuteCallback} callback the callback.- * @returns A function to dispose the listening.+ * @returns {IDisposable} A function to dispose the listening.* @example* ```ts* // The code below registers a callback that will be triggered before invoking a command targeting the Univer sheet@@ -414,7 +395,7 @@ export class FWorkbook extends FBaseInitialable {/*** Register a callback that will be triggered when a command is invoked targeting the Univer sheet.* @param {onCommandExecutedCallback} callback the callback.- * @returns A function to dispose the listening.+ * @returns {IDisposable} A function to dispose the listening.* @example* ```ts* // The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheet@@ -442,7 +423,7 @@ export class FWorkbook extends FBaseInitialable {/*** Register a callback that will be triggered when the selection changes.* @param {onSelectionChangeCallback} callback The callback.- * @returns A function to dispose the listening+ * @returns {IDisposable} A function to dispose the listening*/onSelectionChange(callback: (selections: IRange[]) => void): IDisposable {return toDisposable(@@ -479,7 +460,7 @@ export class FWorkbook extends FBaseInitialable {/*** Sets the selection region for active sheet.- * @param range The range to set as the active selection.+ * @param {FRange} range The range to set as the active selection.* @returns {FWorkbook} FWorkbook instance*/setActiveRange(range: FRange): FWorkbook {@@ -511,7 +492,7 @@ export class FWorkbook extends FBaseInitialable {/*** Returns the selected range in the active sheet, or null if there is no active range.- * @returns the active range+ * @returns {FRange | null} The active range*/// could sheet have no active range ?getActiveRange(): FRange | null {@@ -566,7 +547,6 @@ export class FWorkbook extends FBaseInitialable {* @returns {FWorksheet} The duplicated worksheet* @example* ```ts- * // The code below duplicates the active sheet* const activeSpreadsheet = univerAPI.getActiveWorkbook();* activeSpreadsheet.duplicateActiveSheet();* ```@@ -578,7 +558,7 @@ export class FWorkbook extends FBaseInitialable {/*** Get the number of sheets in the workbook.- * @returns The number of sheets in the workbook+ * @returns {number} The number of sheets in the workbook* @example* ```ts* // The code below gets the number of sheets in the workbook@@ -778,6 +758,7 @@ export class FWorkbook extends FBaseInitialable {/*** Insert a defined name by builder param.* @param {ISetDefinedNameMutationParam} param The param to insert the defined name+ * @returns {void}* @example* ```ts* // The code below inserts a defined name by builder param@@ -795,6 +776,7 @@ export class FWorkbook extends FBaseInitialable {/*** Update the defined name with the given name.* @param {ISetDefinedNameMutationParam} param The param to insert the defined name+ * @returns {void}* @example* ```ts* // The code below updates the defined name with the given name@@ -825,7 +807,8 @@ export class FWorkbook extends FBaseInitialable {/*** Register a custom range theme style.- * @param rangeThemeStyle+ * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register+ * @returns {void}* @example* ```ts* // import {RangeThemeStyle} from '@univerjs/sheets';@@ -848,7 +831,8 @@ export class FWorkbook extends FBaseInitialable {/*** Unregister a custom range theme style.- * @param themeName+ * @param {string} themeName The name of the theme to unregister+ * @returns {void}* @example* ```ts* const fWorkbook = univerAPI.getActiveWorkbook();