123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import hotkeys from "hotkeys-js";
- import { ModuleControl } from "queenjs";
- import { EditorModule } from "../../module";
- type IHotKeyItem = {
- hotKey: string;
- action: (this: EditorModule, key: string) => void;
- };
- export class HotKeyCtrl extends ModuleControl<EditorModule> {
-
- hotKeys = this.defineHotKeys([
-
- {
- hotKey: "esc",
- action() {
- this.actions.pickComp("");
- },
- },
-
- {
- hotKey: "ctrl+up",
- action() {
- this.actions.pickParentComp(this.store.currCompId);
- },
- },
- {
- hotKey: "ctrl+c",
- action() {
- this.actions.ctrlc();
- },
- },{
- hotKey: "ctrl+g",
- action() {
- this.actions.toogleGroup();
- },
- },
- {
- hotKey: "ctrl+v",
- action() {
- this.actions.ctrlv();
- },
- },
-
- {
- hotKey: "Backspace,del",
- action() {
- this.actions.removeComp(this.store.currCompId);
- },
- },
- {
- hotKey: "q,w,a,s,d,e",
- action(key) {
-
-
- this.actions.handleImageHotKey(key);
- },
- },
-
- {
- hotKey: "ctrl+z",
- action() {
- if (!this.controls.historyCtrl.state.enable) return;
- this.controls.historyCtrl.history.undo();
- },
- },
-
- {
- hotKey: "ctrl+shift+z",
- action() {
- if (!this.controls.historyCtrl.state.enable) return;
-
- this.controls.historyCtrl.history.redo();
- },
- },
- {
- hotKey: "up,down,left,right",
- action(key) {
- console.log("move key down", key);
- this.actions.handleSelectMoving(key);
- },
- },
- ]);
- init() {
- const { module, hotKeys } = this;
- hotkeys(
- hotKeys.map((d) => d.hotKey).join(","),
- module.moduleName,
- function (event, handler) {
- event.preventDefault();
- const hotAct = hotKeys.find((d) =>
- d.hotKey.split(",").includes(handler.key)
- );
- hotAct?.action.call(module, handler.key);
- }
- );
- hotkeys.setScope(module.moduleName);
- }
- destroy() {
- hotkeys.deleteScope(this.module.moduleName);
- }
- defineHotKeys<T extends IHotKeyItem[]>(hotKeys: T) {
- return hotKeys;
- }
- }
|