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.

fix(ui): fix close ui plugin config and focus capturing (#2086)

Wenzhao Hu4a360f7edb7c
diff --git a/packages/ui/src/render-unit/.gitkeep b/packages/ui/src/render-unit/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/packages/ui/src/services/layout/layout.service.ts b/packages/ui/src/services/layout/layout.service.ts
index 34434ca03f..42bf60d975 100644
--- a/packages/ui/src/services/layout/layout.service.ts
+++ b/packages/ui/src/services/layout/layout.service.ts
@@ -23,7 +23,14 @@ import { IEditorService } from '../editor/editor.service';
type FocusHandlerFn = (unitId: string) => void;
export const FOCUSING_UNIVER = 'FOCUSING_UNIVER';
-const collectionOfCnForFocusableEle = ['univer-app-layout', 'univer-toolbar-btn', 'univer-menu-item', 'univer-button', 'univer-sheet-bar-btn'];
+const givingBackFocusElements = [
+ 'univer-app-layout',
+ 'univer-toolbar-btn',
+ 'univer-menu-item',
+ 'univer-button',
+ 'univer-sheet-bar-btn',
+ 'univer-render-canvas',
+];
export interface ILayoutService {
readonly isFocused: boolean;
@@ -148,8 +155,8 @@ export class DesktopLayoutService extends Disposable implements ILayoutService {
this.disposeWithMe(
fromEvent(window, 'focusin').subscribe((event) => {
const target = event.target as HTMLElement;
- if (collectionOfCnForFocusableEle.some((item) => target.classList.contains(item))) {
- this._editorBlurListener();
+ if (givingBackFocusElements.some((item) => target.classList.contains(item))) {
+ this._blurEditor();
queueMicrotask(() => this.focus());
return;
}
@@ -173,9 +180,9 @@ export class DesktopLayoutService extends Disposable implements ILayoutService {
);
}
- private _editorBlurListener() {
+ private _blurEditor() {
const focusEditor = this._editorService.getFocusEditor();
- if (focusEditor && focusEditor.isSheetEditor() !== true) {
+ if (focusEditor?.isSheetEditor() !== true) {
this._editorService.blur();
}
}
diff --git a/packages/ui/src/ui-plugin.ts b/packages/ui/src/ui-plugin.ts
index c07407e8b7..e23d79cbea 100644
--- a/packages/ui/src/ui-plugin.ts
+++ b/packages/ui/src/ui-plugin.ts
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-import type { IContextService } from '@univerjs/core';
-import { IConfigService, ILocalStorageService, LocaleService, Plugin } from '@univerjs/core';
+import { IContextService, ILocalStorageService, LocaleService, Plugin } from '@univerjs/core';
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
@@ -73,7 +72,7 @@ export class UniverUIPlugin extends Plugin {
constructor(
private _config: Partial<IUniverUIConfig> = {},
- @IConfigService private readonly _contextService: IContextService,
+ @IContextService private readonly _contextService: IContextService,
@Inject(Injector) protected readonly _injector: Injector,
@Inject(LocaleService) private readonly _localeService: LocaleService
) {