Skip to content

Commit 6eff737

Browse files
committed
feat(hotkey): Add mount method to Hotkey class
1 parent dbd9382 commit 6eff737

File tree

6 files changed

+36
-14
lines changed

6 files changed

+36
-14
lines changed

docs/docs/api/hotkey.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ bind(
3232
- [IPublicTypeHotkeyCallback](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/hotkey-callback.ts)
3333
- [IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
3434

35+
### mount
36+
37+
给指定窗口绑定快捷键
38+
39+
```typescript
40+
/**
41+
* 给指定窗口绑定快捷键
42+
* @param window 窗口的 window 对象
43+
*/
44+
mount(window: Window): IPublicTypeDisposable;
45+
46+
```
47+
3548

3649
## 使用示例
3750
### 基础示例

packages/designer/src/project/project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface IProject extends Omit<IBaseApiProject<
6868

6969
onCurrentDocumentChange(fn: (doc: IDocumentModel) => void): () => void;
7070

71-
onSimulatorReady(fn: (args: any) => void): () => void;
71+
onSimulatorReady(fn: (simulator: ISimulatorHost) => void): () => void;
7272

7373
onRendererReady(fn: () => void): () => void;
7474

packages/editor-core/src/command.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { IPublicApiCommand, IPublicEnumTransitionType, IPublicModelPluginContext, IPublicTypeCommand, IPublicTypeCommandHandlerArgs, IPublicTypeListCommand } from '@alilc/lowcode-types';
22
import { checkPropTypes } from '@alilc/lowcode-utils';
3-
export interface ICommand extends Omit<IPublicApiCommand, 'registerCommand' | 'batchExecuteCommand'> {
4-
registerCommand(command: IPublicTypeCommand, options?: {
5-
commandScope?: string;
6-
}): void;
7-
8-
batchExecuteCommand(commands: { name: string; args: IPublicTypeCommandHandlerArgs }[], pluginContext?: IPublicModelPluginContext): void;
9-
}
3+
export interface ICommand extends Command {}
104

115
export interface ICommandOptions {
126
commandScope?: string;
137
}
148

15-
export class Command implements ICommand {
9+
export class Command implements Omit<IPublicApiCommand, 'registerCommand' | 'batchExecuteCommand'> {
1610
private commands: Map<string, IPublicTypeCommand> = new Map();
1711
private commandErrors: Function[] = [];
1812

packages/editor-core/src/hotkey.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isEqual } from 'lodash';
22
import { globalContext } from './di';
3-
import { IPublicTypeHotkeyCallback, IPublicTypeHotkeyCallbackConfig, IPublicTypeHotkeyCallbacks, IPublicApiHotkey } from '@alilc/lowcode-types';
3+
import { IPublicTypeHotkeyCallback, IPublicTypeHotkeyCallbackConfig, IPublicTypeHotkeyCallbacks, IPublicApiHotkey, IPublicTypeDisposable } from '@alilc/lowcode-types';
44

55
interface KeyMap {
66
[key: number]: string;
@@ -339,11 +339,10 @@ function fireCallback(callback: IPublicTypeHotkeyCallback, e: KeyboardEvent, com
339339
}
340340
}
341341

342-
export interface IHotKey extends Omit<IPublicApiHotkey, 'bind' | 'callbacks'> {
343-
activate(activate: boolean): void;
342+
export interface IHotKey extends Hotkey {
344343
}
345344

346-
export class Hotkey implements IHotKey {
345+
export class Hotkey implements Omit<IPublicApiHotkey, 'bind' | 'callbacks'> {
347346
callBacks: IPublicTypeHotkeyCallbacks = {};
348347

349348
private directMap: HotkeyDirectMap = {};
@@ -368,7 +367,7 @@ export class Hotkey implements IHotKey {
368367
this.isActivate = activate;
369368
}
370369

371-
mount(window: Window) {
370+
mount(window: Window): IPublicTypeDisposable {
372371
const { document } = window;
373372
const handleKeyEvent = this.handleKeyEvent.bind(this);
374373
document.addEventListener('keypress', handleKeyEvent, false);
@@ -542,6 +541,8 @@ export class Hotkey implements IHotKey {
542541
}
543542

544543
private handleKeyEvent(e: KeyboardEvent): void {
544+
console.log(e);
545+
// debugger;
545546
if (!this.isActivate) {
546547
return;
547548
}

packages/shell/src/api/hotkey.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ export class Hotkey implements IPublicApiHotkey {
5050
this[hotkeySymbol].unbind(combos, callback, action);
5151
};
5252
}
53+
54+
/**
55+
* 给指定窗口绑定快捷键
56+
* @param window 窗口的 window 对象
57+
*/
58+
mount(window: Window) {
59+
return this[hotkeySymbol].mount(window);
60+
}
5361
}

packages/types/src/shell/api/hotkey.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@ export interface IPublicApiHotkey {
2222
callback: IPublicTypeHotkeyCallback,
2323
action?: string,
2424
): IPublicTypeDisposable;
25+
26+
/**
27+
* 给指定窗口绑定快捷键
28+
* @param window 窗口的 window 对象
29+
*/
30+
mount(window: Window): IPublicTypeDisposable;
2531
}

0 commit comments

Comments
 (0)