devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
152 lines (151 loc) • 4.36 kB
JavaScript
/**
* DevExtreme (esm/__internal/events/core/emitter.feedback.js)
* Version: 26.1.6
* Build date: Fri Oct 16 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import pointerEvents from "../../../common/core/events/pointer";
import {
isMouseEvent
} from "../../../common/core/events/utils/index";
import {
ensureDefined,
noop
} from "../../../core/utils/common";
import {
contains
} from "../../../core/utils/dom";
import devices from "../../core/devices";
import Emitter from "../../events/core/emitter";
import registerEmitter from "../../events/core/emitter_registrator";
const ACTIVE_EVENT_NAME = "dxactive";
const INACTIVE_EVENT_NAME = "dxinactive";
const ACTIVE_TIMEOUT = 30;
const INACTIVE_TIMEOUT = 400;
class FeedbackEvent {
constructor(timeout, fire) {
this._fired = false;
this._timeout = timeout;
this._fire = fire
}
start() {
this._schedule(() => {
this.force()
})
}
_schedule(fn) {
this.stop();
this._timer = setTimeout(fn, this._timeout)
}
stop() {
clearTimeout(this._timer)
}
force() {
if (this._fired) {
return
}
this.stop();
this._fire();
this._fired = true
}
fired() {
return this._fired
}
}
let activeFeedback = null;
class FeedbackEmitter extends Emitter {
constructor(element) {
super(element);
this._active = new FeedbackEvent(0, noop);
this._inactive = new FeedbackEvent(0, noop)
}
configure(data, eventName) {
switch (eventName) {
case "dxactive":
data.activeTimeout = data.timeout;
break;
case "dxinactive":
data.inactiveTimeout = data.timeout
}
super.configure(data)
}
start(e) {
if (activeFeedback) {
const activeChildExists = contains(this.getElement().get(0), activeFeedback.getElement().get(0));
const childJustActivated = !activeFeedback._active.fired();
if (activeChildExists && childJustActivated) {
this._cancel();
return
}
activeFeedback._inactive.force()
}
activeFeedback = this;
this._initEvents(e);
this._active.start()
}
_initEvents(e) {
const eventTarget = this._getEmitterTarget(e);
const mouseEvent = isMouseEvent(e);
const isSimulator = devices.isSimulator();
const deferFeedback = isSimulator || !mouseEvent;
const activeTimeout = ensureDefined(this.activeTimeout, 30);
const inactiveTimeout = ensureDefined(this.inactiveTimeout, 400);
this._active = new FeedbackEvent(deferFeedback ? activeTimeout : 0, () => {
this._fireEvent("dxactive", e, {
target: eventTarget
})
});
this._inactive = new FeedbackEvent(deferFeedback ? inactiveTimeout : 0, () => {
this._fireEvent("dxinactive", e, {
target: eventTarget
});
activeFeedback = null
})
}
cancel(e) {
this.end(e)
}
end(e) {
const skipTimers = e.type !== pointerEvents.up;
if (skipTimers) {
this._active.stop()
} else {
this._active.force()
}
this._inactive.start();
if (skipTimers) {
this._inactive.force()
}
}
dispose() {
this._active.stop();
this._inactive.stop();
if (activeFeedback === this) {
activeFeedback = null
}
super.dispose()
}
lockInactive() {
this._active.force();
this._inactive.stop();
activeFeedback = null;
this._cancel();
return this._inactive.force.bind(this._inactive)
}
static lock(deferred) {
const lockInactive = activeFeedback ? activeFeedback.lockInactive() : noop;
deferred.done(lockInactive)
}
}
registerEmitter({
emitter: FeedbackEmitter,
events: ["dxactive", "dxinactive"]
});
export const {
lock: lock
} = FeedbackEmitter;
export {
ACTIVE_EVENT_NAME as active, INACTIVE_EVENT_NAME as inactive
};