mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-12 17:08:14 +00:00
feat: 新增 onDetectingChange 事件监听, 可监听 hover 元素变化
This commit is contained in:
parent
2c0761fb6b
commit
0672f3b8cc
@ -1,6 +1,9 @@
|
||||
import { makeObservable, obx } from '@ali/lowcode-editor-core';
|
||||
import { EventEmitter } from 'events';
|
||||
import { Node, DocumentModel } from '../document';
|
||||
|
||||
const DETECTING_CHANGE_EVENT = 'detectingChange';
|
||||
|
||||
export class Detecting {
|
||||
@obx.ref private _enable = true;
|
||||
|
||||
@ -19,6 +22,8 @@ export class Detecting {
|
||||
|
||||
@obx.ref private _current: Node | null = null;
|
||||
|
||||
private emitter: EventEmitter = new EventEmitter();
|
||||
|
||||
constructor() {
|
||||
makeObservable(this);
|
||||
}
|
||||
@ -28,12 +33,16 @@ export class Detecting {
|
||||
}
|
||||
|
||||
capture(node: Node | null) {
|
||||
this._current = node;
|
||||
if (this._current !== node) {
|
||||
this._current = node;
|
||||
this.emitter.emit(DETECTING_CHANGE_EVENT, this.current);
|
||||
}
|
||||
}
|
||||
|
||||
release(node: Node) {
|
||||
if (this._current === node) {
|
||||
this._current = null;
|
||||
this.emitter.emit(DETECTING_CHANGE_EVENT, this.current);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,4 +51,11 @@ export class Detecting {
|
||||
this._current = null;
|
||||
}
|
||||
}
|
||||
|
||||
onDetectingChange(fn: () => void) {
|
||||
this.emitter.on(DETECTING_CHANGE_EVENT, fn);
|
||||
return () => {
|
||||
this.emitter.off(DETECTING_CHANGE_EVENT, fn);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user