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.

refactor(ui): replace fromDocumentEvent with fromGlobalEvent (#1916)

白熱a717c32d5314
diff --git a/packages/data-validation/package.json b/packages/data-validation/package.json
index c713340c80..8369ed0453 100644
--- a/packages/data-validation/package.json
+++ b/packages/data-validation/package.json
@@ -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": {
diff --git a/packages/facade/package.json b/packages/facade/package.json
index e1418ebf2b..06b9c67c8f 100644
--- a/packages/facade/package.json
+++ b/packages/facade/package.json
@@ -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:*",
@@ -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:*",
diff --git a/packages/sheets-conditional-formatting/package.json b/packages/sheets-conditional-formatting/package.json
index 09ef20e597..d65e4b64b6 100644
--- a/packages/sheets-conditional-formatting/package.json
+++ b/packages/sheets-conditional-formatting/package.json
@@ -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",
diff --git a/packages/ui/src/common/lifecycle.ts b/packages/ui/src/common/lifecycle.ts
index 95c60ecc3e..6dd7134cd5 100644
--- a/packages/ui/src/common/lifecycle.ts
+++ b/packages/ui/src/common/lifecycle.ts
@@ -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>(
diff --git a/packages/ui/src/services/shortcut/shortcut.service.ts b/packages/ui/src/services/shortcut/shortcut.service.ts
index a538e14e76..f26fc7c6c1 100644
--- a/packages/ui/src/services/shortcut/shortcut.service.ts
+++ b/packages/ui/src/services/shortcut/shortcut.service.ts
@@ -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';
@@ -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,
})
);
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 9ddab65b06..c6f7d73267 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -357,8 +357,8 @@ importers:
packages/data-validation:
dependencies:
'@univerjs/protocol':
- specifier: ^0.1.14
- version: 0.1.14(@grpc/[email protected])([email protected])
+ specifier: ^0.1.17
+ version: 0.1.17(@grpc/[email protected])([email protected])
dayjs:
specifier: ^1.11.10
version: 1.11.10
@@ -645,10 +645,6 @@ importers:
version: 1.4.0(@types/[email protected])([email protected])
packages/facade:
- dependencies:
- '@univerjs/sheets-conditional-formatting':
- specifier: workspace:*
- version: link:../sheets-conditional-formatting
devDependencies:
'@univerjs/core':
specifier: workspace:*
@@ -671,6 +667,9 @@ importers:
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
+ '@univerjs/sheets-conditional-formatting':
+ specifier: workspace:*
+ version: link:../sheets-conditional-formatting
'@univerjs/sheets-formula':
specifier: workspace:*
version: link:../sheets-formula
@@ -839,8 +838,8 @@ importers:
packages/sheets-conditional-formatting:
dependencies:
'@univerjs/protocol':
- specifier: ^0.1.14
- version: 0.1.14(@grpc/[email protected])([email protected])
+ specifier: ^0.1.17
+ version: 0.1.17(@grpc/[email protected])([email protected])
dayjs:
specifier: ^1.11.10
version: 1.11.10
@@ -855,8 +854,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons-svg':
- specifier: ^0.1.43
- version: 0.1.43
+ specifier: ^0.1.44
+ version: 0.1.44
'@univerjs/shared':
specifier: workspace:*
version: link:../../common/shared
@@ -5935,6 +5934,10 @@ packages:
resolution: {integrity: sha512-QIHvXOczbNq26Cisio8vpkQuaK8zKVwDO3diCSw17PYA2ZDn6d2umwbfP/Ptwt6aYW4kCNlJGAX2wSTUrL1MvA==}
dev: true
+ /@univerjs/[email protected]:
+ resolution: {integrity: sha512-2n/WnFGcRYxkiFa85te2hs57VLM+8WZ4aZvdJlXB+2AT61KuA0crt5uDUUNv9BXYVi3jtLxh3fF/pJb4DJyK6Q==}
+ dev: true
+
resolution: {integrity: sha512-emPPhk9aNGIl/wF/z+9KLAq5EG/zmUoSwj2UaHHssnM/mv96Ieob4MpkhTfrVtvtiAUI2zZpUXrbsRX3PShrXg==}
peerDependencies:
@@ -5945,17 +5948,6 @@ packages:
react-dom: 18.2.0([email protected])
dev: false
- resolution: {integrity: sha512-f4BmBCDJ3WKVj5MIiB8S0PLnzVu0xHUpC8g4YCT4Ac2P/29UV0KfRPj2CqYQJOwsym6jLJTSHIvr9BhRGEgIWQ==}
- engines: {node: '>=16.0.0', npm: '>=8.0.0'}
- peerDependencies:
- '@grpc/grpc-js': ^1.9.14
- rxjs: '>=7.0.0'
- dependencies:
- '@grpc/grpc-js': 1.10.4
- rxjs: 7.8.1
- dev: false
-
resolution: {integrity: sha512-V7THIzlOroiTPwXPS57q1IfOLK9Be+oH6mSRH5XAsYEywNqRVwUlMIe1TTu4GWKhJpfjTMwihkcDeVZfA1+C4A==}
engines: {node: '>=16.0.0', npm: '>=8.0.0'}