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.

feat(facade): univer-sheet change to workbook (#4460)

zhangwc4e9c3aa4556
diff --git a/packages/sheets-data-validation/src/facade/f-worksheet.ts b/packages/sheets-data-validation/src/facade/f-worksheet.ts
index 47ff94fc07..418a444f42 100644
--- a/packages/sheets-data-validation/src/facade/f-worksheet.ts
+++ b/packages/sheets-data-validation/src/facade/f-worksheet.ts
@@ -25,7 +25,7 @@ export interface IFWorksheetDataValidationMixin {
* Get all data validation rules in current sheet.
* @returns all data validation rules
* ```ts
- * const workbook = univerAPI.getActiveUniverSheet();
+ * const workbook = univerAPI.getActiveWorkbook();
* const worksheet = workbook.getWorksheet('sheet1');
* const dataValidations = worksheet.getDataValidations();
* ```
@@ -35,7 +35,7 @@ export interface IFWorksheetDataValidationMixin {
* Get data validation validator status for current sheet.
* @returns matrix of validator status
* ```ts
- * const workbook = univerAPI.getActiveUniverSheet();
+ * const workbook = univerAPI.getActiveWorkbook();
* const worksheet = workbook.getWorksheet('sheet1');
* const validatorStatus = worksheet.getValidatorStatus();
* ```
@@ -47,7 +47,7 @@ export interface IFWorksheetDataValidationMixin {
* @param ruleId - the rule id
* @returns data validation rule
* ```ts
- * const workbook = univerAPI.getActiveUniverSheet();
+ * const workbook = univerAPI.getActiveWorkbook();
* const worksheet = workbook.getWorksheet('sheet1');
* const dataValidation = worksheet.getDataValidation('ruleId');
* ```
diff --git a/packages/sheets-drawing-ui/src/facade/f-univer.ts b/packages/sheets-drawing-ui/src/facade/f-univer.ts
index 7212af7e54..a334d7dc33 100644
--- a/packages/sheets-drawing-ui/src/facade/f-univer.ts
+++ b/packages/sheets-drawing-ui/src/facade/f-univer.ts
@@ -87,7 +87,7 @@ export class FUniverDrawingMixin extends FUniver {
return;
}
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
if (workbook == null || params == null) {
return;
}
@@ -111,7 +111,7 @@ export class FUniverDrawingMixin extends FUniver {
return;
}
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
if (workbook == null || params == null) {
return;
}
@@ -129,7 +129,7 @@ export class FUniverDrawingMixin extends FUniver {
return;
}
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
if (workbook == null || params == null) {
return;
}
@@ -158,7 +158,7 @@ export class FUniverDrawingMixin extends FUniver {
return;
}
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
if (workbook == null || params == null) {
return;
}
@@ -176,7 +176,7 @@ export class FUniverDrawingMixin extends FUniver {
return;
}
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
if (workbook == null || params == null) {
return;
}
@@ -216,7 +216,7 @@ export class FUniverDrawingMixin extends FUniver {
return;
}
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
if (workbook == null || params == null) {
return;
}
@@ -242,7 +242,7 @@ export class FUniverDrawingMixin extends FUniver {
const drawingManagerService = this._injector.get(IDrawingManagerService);
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
if (workbook == null) {
return;
@@ -272,7 +272,7 @@ export class FUniverDrawingMixin extends FUniver {
return;
}
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
const drawingManagerService = this._injector.get(IDrawingManagerService);
if (workbook == null) {
diff --git a/packages/sheets-thread-comment/src/facade/f-thread-comment.ts b/packages/sheets-thread-comment/src/facade/f-thread-comment.ts
index e80c67c962..fbf74e87d3 100644
--- a/packages/sheets-thread-comment/src/facade/f-thread-comment.ts
+++ b/packages/sheets-thread-comment/src/facade/f-thread-comment.ts
@@ -59,7 +59,7 @@ export class FTheadCommentItem {
* @returns {string} The person id of the comment
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const personId = comment.personId;
@@ -74,7 +74,7 @@ export class FTheadCommentItem {
* @returns {string} The date time of the comment
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const dateTime = comment.dateTime;
@@ -89,7 +89,7 @@ export class FTheadCommentItem {
* @returns {RichTextValue} The content of the comment
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const content = comment.content;
@@ -104,7 +104,7 @@ export class FTheadCommentItem {
* @returns {string} The id of the comment
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const id = comment.id;
@@ -119,7 +119,7 @@ export class FTheadCommentItem {
* @returns {string} The thread id of the comment
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const threadId = comment.threadId;
@@ -134,7 +134,7 @@ export class FTheadCommentItem {
* @returns {FTheadCommentBuilder} The comment builder
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const newComment = comment.copy();
@@ -268,7 +268,7 @@ export class FThreadComment {
* @returns Whether the comment is a root comment
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const isRoot = comment.getIsRoot();
@@ -283,7 +283,7 @@ export class FThreadComment {
* @returns The comment data
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const commentData = comment.getCommentData();
@@ -299,7 +299,7 @@ export class FThreadComment {
* @returns the replies of the comment
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const replies = comment.getReplies();
@@ -317,7 +317,7 @@ export class FThreadComment {
* @returns The range of the comment
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const range = comment.getRange();
@@ -348,7 +348,7 @@ export class FThreadComment {
* @returns {RichTextValue} The rich text of the comment
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const richText = comment.getRichText();
@@ -364,7 +364,7 @@ export class FThreadComment {
* @returns {Promise<boolean>} success or not
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const success = await comment.deleteAsync();
@@ -402,7 +402,7 @@ export class FThreadComment {
* @returns success or not
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const success = await comment.updateAsync(univerAPI.newRichText().insertText('hello zhangsan'));
@@ -442,7 +442,7 @@ export class FThreadComment {
* @returns success or not
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
* const success = await comment.resolveAsync(true);
@@ -466,7 +466,7 @@ export class FThreadComment {
* @returns success or not
* @example
* ```ts
- * const comment = univerAPI.getActiveUniverSheet()
+ * const comment = univerAPI.getActiveWorkbook()
* .getSheetById(sheetId)
* .getCommentById(commentId);
*
diff --git a/packages/sheets-thread-comment/src/facade/f-worksheet.ts b/packages/sheets-thread-comment/src/facade/f-worksheet.ts
index 41e4d1df7c..e7db232928 100644
--- a/packages/sheets-thread-comment/src/facade/f-worksheet.ts
+++ b/packages/sheets-thread-comment/src/facade/f-worksheet.ts
@@ -27,7 +27,7 @@ export interface IFWorksheetCommentMixin {
* Get all comments in the current sheet
* @returns all comments in the current sheet
* ```ts
- * const workbook = univerAPI.getActiveUniverSheet();
+ * const workbook = univerAPI.getActiveWorkbook();
* const worksheet = workbook.getSheetById(sheetId);
* const comments = worksheet.getComments();
* ```
@@ -37,7 +37,7 @@ export interface IFWorksheetCommentMixin {
/**
* Clear all comments in the current sheet
* ```ts
- * const workbook = univerAPI.getActiveUniverSheet();
+ * const workbook = univerAPI.getActiveWorkbook();
* const worksheet = workbook.getSheetById(sheetId);
* await worksheet.clearComments();
* ```
@@ -48,7 +48,7 @@ export interface IFWorksheetCommentMixin {
* get comment by comment id
* @param {string} commentId comment id
* ```ts
- * const workbook = univerAPI.getActiveUniverSheet();
+ * const workbook = univerAPI.getActiveWorkbook();
* const worksheet = workbook.getSheetById(sheetId);
* const comment = worksheet.getCommentById(commentId);
* ```
diff --git a/packages/sheets-ui/src/facade/f-univer.ts b/packages/sheets-ui/src/facade/f-univer.ts
index 8074dbae13..7b3f5b141a 100644
--- a/packages/sheets-ui/src/facade/f-univer.ts
+++ b/packages/sheets-ui/src/facade/f-univer.ts
@@ -244,7 +244,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix
}
private _generateClipboardCopyParam(): IBeforeClipboardChangeParam | undefined {
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
const worksheet = workbook?.getActiveSheet();
const range = workbook?.getActiveRange();
if (!workbook || !worksheet || !range) {
@@ -299,7 +299,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix
return;
}
const { htmlContent, textContent } = params as ISheetPasteByShortKeyParams;
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
const worksheet = workbook?.getActiveSheet();
if (!workbook || !worksheet) {
return;
@@ -314,7 +314,7 @@ export class FUniverSheetsUIMixin extends FUniver implements IFUniverSheetsUIMix
}
private async _generateClipboardPasteParamAsync(): Promise<IBeforeClipboardPasteParam | undefined> {
- const workbook = this.getActiveUniverSheet();
+ const workbook = this.getActiveWorkbook();
const worksheet = workbook?.getActiveSheet();
if (!workbook || !worksheet) {
return;
diff --git a/packages/sheets/src/facade/f-univer.ts b/packages/sheets/src/facade/f-univer.ts
index 59b7eb2ebb..a724d1f1b2 100644
--- a/packages/sheets/src/facade/f-univer.ts
+++ b/packages/sheets/src/facade/f-univer.ts
@@ -25,37 +25,45 @@ import { FPermission } from './f-permission';
import { FWorkbook } from './f-workbook';
export interface IFUniverSheetsMixin {
+ /**
+ * @deprecated use `univerAPI.createWorkbook` instead.
+ */
+ createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;
+
/**
* Create a new spreadsheet and get the API handler of that spreadsheet.
- *
* @param {Partial<IWorkbookData>} data The snapshot of the spreadsheet.
* @returns {FWorkbook} FWorkbook API instance.
* @example
* ```ts
- * univerAPI.createUniverSheet({ id: 'Sheet1', name: 'Sheet1' });
+ * univerAPI.createWorkbook({ id: 'Sheet1', name: 'Sheet1' });
* ```
*/
- createUniverSheet(data: Partial<IWorkbookData>): FWorkbook;
+ createWorkbook(data: Partial<IWorkbookData>): FWorkbook;
+
/**
* Get the currently focused Univer spreadsheet.
* @returns {FWorkbook | null} The currently focused Univer spreadsheet.
* @example
* ```ts
- * univerAPI.getActiveUniverSheet();
+ * univerAPI.getActiveWorkbook();
* ```
*/
- getActiveUniverSheet(): FWorkbook | null;
+ getActiveWorkbook(): FWorkbook | null;
+
/**
- * @deprecated use `getActiveUniverSheet` as instead.
+ * @deprecated use `univerAPI.getActiveWorkbook` instead
*/
- getActiveWorkbook(): FWorkbook | null;
+ getActiveUniverSheet(): FWorkbook | null;
+
/**
* Get the spreadsheet API handler by the spreadsheet id.
- *
* @param {string} id The spreadsheet id.
* @returns {FWorkbook | null} The spreadsheet API instance.
*/
getUniverSheet(id: string): FWorkbook | null;
+
+ getWorkbook(id: string): FWorkbook | null;
/**
* Get the PermissionInstance.
* @deprecated This function is deprecated and will be removed in version 0.6.0. Please use the function with the same name on the `FWorkbook` instance instead.
@@ -70,7 +78,6 @@ export interface IFUniverSheetsMixin {
/**
* Create a new defined name builder.
* @returns {FDefinedNameBuilder} - The defined name builder.
- *
* @example
* ```ts
* univerAPI.newDefinedName();
@@ -250,7 +257,11 @@ export class FUniverSheetsMixin extends FUniver implements IFUniverSheetsMixin {
return this._injector.createInstance(FWorkbook, workbook);
};
- override getActiveUniverSheet(): FWorkbook | null {
+ override createWorkbook(data: Partial<IWorkbookData>): FWorkbook {
+ return this.createUniverSheet(data);
+ }
+
+ override getActiveWorkbook(): FWorkbook | null {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) {
return null;
@@ -259,8 +270,8 @@ export class FUniverSheetsMixin extends FUniver implements IFUniverSheetsMixin {
return this._injector.createInstance(FWorkbook, workbook);
}
- override getActiveWorkbook(): FWorkbook | null {
- return this.getActiveUniverSheet();
+ override getActiveUniverSheet(): FWorkbook | null {
+ return this.getActiveWorkbook();
}
override getUniverSheet(id: string): FWorkbook | null {
@@ -272,6 +283,10 @@ export class FUniverSheetsMixin extends FUniver implements IFUniverSheetsMixin {
return this._injector.createInstance(FWorkbook, workbook);
}
+ override getWorkbook(id: string): FWorkbook | null {
+ return this.getUniverSheet(id);
+ }
+
override getPermission(): FPermission {
return this._injector.createInstance(FPermission);
}