Skip to content

Commit

Permalink
refactor(ui): replace fromDocumentEvent with fromGlobalEvent (#1916)
Browse files Browse the repository at this point in the history
* refactor(ui): replace fromDocumentEvent with fromGlobalEvent

* chore: fix lockfile
  • Loading branch information
jikkai authored Apr 15, 2024
1 parent d4f67f8 commit a717c32
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/data-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
},
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/protocol": "^0.1.14",
"@univerjs/sheets": "workspace:*",
"@wendellhu/redi": "0.13.0",
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "^0.1.17",
"dayjs": "^1.11.10"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/facade/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"@univerjs/engine-render": "workspace:*",
"@univerjs/network": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
Expand All @@ -82,6 +81,7 @@
"@univerjs/network": "workspace:*",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/sheets-conditional-formatting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/protocol": "^0.1.14",
"@univerjs/sheets": "workspace:*",
"@wendellhu/redi": "0.13.0",
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/protocol": "^0.1.17",
"dayjs": "^1.11.10"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons-svg": "^0.1.43",
"@univerjs/icons-svg": "^0.1.44",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@wendellhu/redi": "^0.13.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/common/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import { toDisposable } from '@univerjs/core';
import type { IDisposable } from '@wendellhu/redi';

export function fromDocumentEvent<K extends keyof DocumentEventMap>(
export function fromGlobalEvent<K extends keyof WindowEventMap>(
type: K,
listener: (this: Document, ev: DocumentEventMap[K]) => any,
listener: (this: Window, ev: WindowEventMap[K]) => any,
options?: boolean | AddEventListenerOptions
): IDisposable {
document.addEventListener(type, listener, options);
return toDisposable(() => document.removeEventListener(type, listener, options));
window.addEventListener(type, listener, options);
return toDisposable(() => window.removeEventListener(type, listener, options));
}

export function fromEvent<K extends keyof HTMLElementEventMap>(
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/src/services/shortcut/shortcut.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { createIdentifier, Optional } from '@wendellhu/redi';
import type { Observable } from 'rxjs';
import { Subject } from 'rxjs';

import { fromDocumentEvent } from '../../common/lifecycle';
import { fromGlobalEvent } from '../../common/lifecycle';
import { ILayoutService } from '../layout/layout.service';
import { IPlatformService } from '../platform/platform.service';
import { KeyCodeToChar, MetaKeys } from './keycode';
Expand Down Expand Up @@ -89,8 +89,10 @@ export class DesktopShortcutService extends Disposable implements IShortcutServi

// Register native keydown event handler to trigger shortcuts.
this.disposeWithMe(
fromDocumentEvent('keydown', (e: KeyboardEvent) => {
fromGlobalEvent('keydown', (e: KeyboardEvent) => {
this._resolveKeyboardEvent(e);
}, {
capture: true,
})
);
}
Expand Down
34 changes: 13 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a717c32

Please sign in to comment.