Skip to content

Commit

Permalink
fix: add missing API(Google App has these)
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Dec 20, 2024
1 parent 3b875eb commit b933586
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/facade/f-univer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Univer } from '../univer';
import { FBase } from './f-base';
import { FBlob } from './f-blob';
import { FHooks } from './f-hooks';
import { FUser } from './f-user';

export class FUniver extends FBase {
/**
Expand Down Expand Up @@ -162,4 +163,8 @@ export class FUniver extends FBase {
newBlob(): FBlob {
return this._injector.createInstance(FBlob);
}

getUserManager(): FUser {
return this._injector.createInstance(FUser);
}
}
37 changes: 37 additions & 0 deletions packages/core/src/facade/f-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { IUser } from '../services/user-manager/user-manager.service';
import { Inject, Injector } from '../common/di';
import { UserManagerService } from '../services/user-manager/user-manager.service';
import { FBase } from './f-base';

export class FUser extends FBase {
constructor(
@Inject(Injector) protected readonly _injector: Injector,
@Inject(UserManagerService) private readonly _userManagerService: UserManagerService
) {
super();
}

/**
* get curr User
* univerAPI.getUserManager().getCurrUser()
*/
getCurrUser(): IUser {
return this._userManagerService.getCurrentUser();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class UserManagerService {
* @memberof UserManagerService
*/
public currentUser$ = this._currentUser$.asObservable();

getCurrentUser<T extends IUser>() {
return this._currentUser$.getValue() as T;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-thread-comment/src/facade/f-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import { ICommandService, type IDocumentBody, type Nullable, Tools, UserManagerService } from '@univerjs/core';
import { FRange } from '@univerjs/sheets/facade';
import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment';
import { FRange } from '@univerjs/sheets/facade';
import { AddCommentCommand, DeleteCommentTreeCommand, getDT } from '@univerjs/thread-comment';
import { FThreadComment } from './f-thread-comment';

Expand Down
16 changes: 15 additions & 1 deletion packages/sheets-thread-comment/src/facade/f-worksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
* limitations under the License.
*/

import { FWorksheet } from '@univerjs/sheets/facade';
import type { IDisposable } from '@univerjs/core';
import type { IAddCommentCommandParams } from '@univerjs/thread-comment';
import { ICommandService, ObjectMatrix } from '@univerjs/core';

Check failure on line 19 in packages/sheets-thread-comment/src/facade/f-worksheet.ts

View workflow job for this annotation

GitHub Actions / eslint

'ObjectMatrix' is defined but never used
import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment';
import { FWorksheet } from '@univerjs/sheets/facade';
import { AddCommentCommand } from '@univerjs/thread-comment';
import { FThreadComment } from './f-thread-comment';

export interface IFWorksheetCommentMixin {
Expand All @@ -32,6 +36,16 @@ export class FWorksheetCommentMixin extends FWorksheet implements IFWorksheetCom
const comments = sheetsTheadCommentModel.getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId());
return comments.map((comment) => this._injector.createInstance(FThreadComment, comment));
}

onCommented(callback: (params: IAddCommentCommandParams) => void): IDisposable {
const commandService = this._injector.get(ICommandService);
return commandService.onCommandExecuted((command) => {
if (command.id === AddCommentCommand.id) {
const params = command.params as IAddCommentCommandParams;
callback(params);
}
});
}
}

FWorksheet.extend(FWorksheetCommentMixin);
Expand Down
5 changes: 4 additions & 1 deletion packages/sheets/src/facade/f-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ export class FRange extends FBase {
}

// #region editing

setBackgroundColor(color: string): Promise<boolean> {
return this._commandService.executeCommand(SetStyleCommand.id, {
unitId: this._workbook.getUnitId(),
Expand All @@ -238,6 +237,10 @@ export class FRange extends FBase {
} as ISetStyleCommandParams<IColorStyle>);
}

setBackground(color: string): Promise<boolean> {
return this.setBackgroundColor(color);
}

/**
* The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.
* @param value
Expand Down
12 changes: 11 additions & 1 deletion packages/sheets/src/facade/f-worksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export class FWorksheet extends FBase {
}

/**
* Un hides the row in the given range.
* Unhides the row in the given range.
* @param row The range to unhide, if hidden.
* @returns This sheet, for chaining.
*/
Expand Down Expand Up @@ -1598,6 +1598,11 @@ export class FWorksheet extends FBase {
return this._worksheet.getLastColumnWithContent();
}

// same as Google App script
getLastColumn(): number {
return this._worksheet.getLastColumnWithContent();
}

/**
* Returns the position of the last row that has content.
* @returns {number} the last row of the sheet that contains content.
Expand All @@ -1613,6 +1618,11 @@ export class FWorksheet extends FBase {
return this._worksheet.getLastRowWithContent();
}

// same as Google App script
getLastRow(): number {
return this._worksheet.getLastRowWithContent();
}

/**
* Judge whether provided FWorksheet is equal to current.
* @param {FWorksheet} other the FWorksheet to compare with.
Expand Down

0 comments on commit b933586

Please sign in to comment.