Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): add more facade #4291

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/sheets-ui/src/facade/f-sheet-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import type { ICellCustomRender, IDisposable, Nullable } from '@univerjs/core';
import type { IDragCellPosition, IEditorBridgeServiceVisibleParam, IHoverCellPosition } from '@univerjs/sheets-ui';
import { ICommandService, InterceptorEffectEnum, toDisposable } from '@univerjs/core';
import { InterceptCellContentPriority, INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';
import { FSheetHooks } from '@univerjs/sheets/facade';
import { DragManagerService, HoverManagerService, SetCellEditVisibleOperation } from '@univerjs/sheets-ui';
import { FSheetHooks } from '@univerjs/sheets/facade';

export interface IFSheetHooksUIMixin {
/**
Expand Down Expand Up @@ -129,5 +129,5 @@ export class FSheetHooksUIMixin extends FSheetHooks implements IFSheetHooksUIMix
FSheetHooks.extend(FSheetHooksUIMixin);
declare module '@univerjs/sheets/facade' {
// eslint-disable-next-line ts/naming-convention
interface FSheetHooks extends IFSheetHooksUIMixin {}
interface FSheetHooks extends IFSheetHooksUIMixin { }
}
17 changes: 15 additions & 2 deletions packages/sheets/src/facade/f-univer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import type { IWorkbookData, Workbook } from '@univerjs/core';
import { FUniver, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import type { IDisposable, IWorkbookData, Workbook } from '@univerjs/core';
import { FUniver, IUniverInstanceService, toDisposable, UniverInstanceType } from '@univerjs/core';
import { FPermission } from './f-permission';
import { FWorkbook } from './f-workbook';

Expand Down Expand Up @@ -47,6 +47,10 @@ export interface IFUniverSheetsMixin {
* @returns {FPermission} - The PermissionInstance.
*/
getPermission(): FPermission;
/**
* Register a callback that will be triggered when a Univer Sheet is created.
*/
onUniverSheetCreated(callback: (workbook: FWorkbook) => void): IDisposable;
}

export class FUniverSheetsMixin extends FUniver implements IFUniverSheetsMixin {
Expand Down Expand Up @@ -77,6 +81,15 @@ export class FUniverSheetsMixin extends FUniver implements IFUniverSheetsMixin {
override getPermission(): FPermission {
return this._injector.createInstance(FPermission);
}

override onUniverSheetCreated(callback: (workbook: FWorkbook) => void): IDisposable {
const subscription = this._univerInstanceService.getTypeOfUnitAdded$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
const fworkbook = this._injector.createInstance(FWorkbook, workbook);
callback(fworkbook);
});

return toDisposable(subscription);
}
}

FUniver.extend(FUniverSheetsMixin);
Expand Down
17 changes: 16 additions & 1 deletion packages/ui/src/controllers/ui/ui.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,26 @@ import { createIdentifier } from '@univerjs/core';
export interface IWorkbenchOptions {
container?: string | HTMLElement;

/**
* If Univer should make the header bar visible.
*/
header?: boolean;

/**
* If Univer should make the toolbar bar visible.
*/
toolbar?: boolean;

/**
* If Univer should make the footer bar visible.
*/
footer?: boolean;

/**
* If Univer should make the context menu usable.
*/
contextMenu?: boolean;
}

export interface IUIController {}
export interface IUIController { }
export const IUIController = createIdentifier<IUIController>('univer.ui.ui-controller');
42 changes: 40 additions & 2 deletions packages/ui/src/facade/f-univer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,38 @@
*/

import type { IDisposable } from '@univerjs/core';
import type { IMessageOptions } from '@univerjs/design';
import type { IDialogPartMethodOptions, ISidebarMethodOptions } from '@univerjs/ui';
import { FUniver } from '@univerjs/core';
import { ComponentManager, CopyCommand, IDialogService, ISidebarService, PasteCommand } from '@univerjs/ui';
import { ComponentManager, CopyCommand, IDialogService, IMessageService, ISidebarService, PasteCommand } from '@univerjs/ui';

export interface IFUniverUIMixin {
/**
* Copy the current selected content of the currently focused unit into your system clipboard.
*/
copy(): Promise<boolean>;

/**
* Paste into the current selected position of the currently focused unit from your system clipboard.
*/
paste(): Promise<boolean>;

/**
* Open a sidebar.
*
* @deprecated Please use `openSidebar` instead.
* @param params the sidebar options
* @returns the disposable object
*/
openSiderbar(params: ISidebarMethodOptions): IDisposable;
/**
* Open a sidebar.
*
* @deprecated Please use `openSidebar` instead.
* @param params the sidebar options
* @returns the disposable object
*/
openSidebar(params: ISidebarMethodOptions): IDisposable;

/**
* Open a dialog.
Expand All @@ -43,6 +60,18 @@ export interface IFUniverUIMixin {
* @returns The component manager
*/
getComponentManager(): ComponentManager;

/**
* Show a message.
*
* @example
* ```ts
* const message = univerAPI.showMessage({ key: 'my-message', content: 'Warning', duration: 0 });
*
* someAction().then(() => message.dispose());
* ```
*/
wzhudev marked this conversation as resolved.
Show resolved Hide resolved
showMessage(options: IMessageOptions): IDisposable;
}

export class FUniverUIMixin extends FUniver implements IFUniverUIMixin {
Expand All @@ -59,6 +88,10 @@ export class FUniverUIMixin extends FUniver implements IFUniverUIMixin {
return sideBarService.open(params);
}

override openSidebar(params: ISidebarMethodOptions): IDisposable {
return this.openSiderbar(params);
}

override openDialog(dialog: IDialogPartMethodOptions): IDisposable {
const dialogService = this._injector.get(IDialogService);
const disposable = dialogService.open({
Expand All @@ -73,10 +106,15 @@ export class FUniverUIMixin extends FUniver implements IFUniverUIMixin {
override getComponentManager(): ComponentManager {
return this._injector.get(ComponentManager);
}

override showMessage(options: IMessageOptions): IDisposable {
const messageService = this._injector.get(IMessageService);
return messageService.show(options);
}
}

FUniver.extend(FUniverUIMixin);
declare module '@univerjs/core' {
// eslint-disable-next-line ts/naming-convention
interface FUniver extends IFUniverUIMixin {}
interface FUniver extends IFUniverUIMixin { }
}
Loading