-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rochmar Nicolas (DevExpress)
committed
Jul 24, 2024
1 parent
b59ae36
commit 0fe72ce
Showing
66 changed files
with
3,399 additions
and
3,338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
288 changes: 143 additions & 145 deletions
288
packages/devextreme/js/__internal/events/core/m_emitter.feedback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,181 +1,179 @@ | ||
import Class from '../../core/class'; | ||
import { noop, ensureDefined } from '../../core/utils/common'; | ||
import { contains } from '../../core/utils/dom'; | ||
import devices from '../../core/devices'; | ||
import { isMouseEvent } from '../utils/index'; | ||
import pointerEvents from '../pointer'; | ||
import Emitter from './emitter'; | ||
import registerEmitter from './emitter_registrator'; | ||
import Class from '@js/core/class'; | ||
import devices from '@js/core/devices'; | ||
import { ensureDefined, noop } from '@js/core/utils/common'; | ||
import { contains } from '@js/core/utils/dom'; | ||
import Emitter from '@js/events/core/emitter'; | ||
import registerEmitter from '@js/events/core/emitter_registrator'; | ||
import pointerEvents from '@js/events/pointer'; | ||
import { isMouseEvent } from '@js/events/utils/index'; | ||
|
||
const ACTIVE_EVENT_NAME = 'dxactive'; | ||
const INACTIVE_EVENT_NAME = 'dxinactive'; | ||
|
||
const ACTIVE_TIMEOUT = 30; | ||
const INACTIVE_TIMEOUT = 400; | ||
|
||
|
||
const FeedbackEvent = Class.inherit({ | ||
|
||
ctor: function(timeout, fire) { | ||
this._timeout = timeout; | ||
this._fire = fire; | ||
}, | ||
ctor(timeout, fire) { | ||
this._timeout = timeout; | ||
this._fire = fire; | ||
}, | ||
|
||
start: function() { | ||
const that = this; | ||
start() { | ||
const that = this; | ||
|
||
this._schedule(function() { | ||
that.force(); | ||
}); | ||
}, | ||
this._schedule(() => { | ||
that.force(); | ||
}); | ||
}, | ||
|
||
_schedule: function(fn) { | ||
this.stop(); | ||
this._timer = setTimeout(fn, this._timeout); | ||
}, | ||
_schedule(fn) { | ||
this.stop(); | ||
this._timer = setTimeout(fn, this._timeout); | ||
}, | ||
|
||
stop: function() { | ||
clearTimeout(this._timer); | ||
}, | ||
stop() { | ||
clearTimeout(this._timer); | ||
}, | ||
|
||
force: function() { | ||
if(this._fired) { | ||
return; | ||
} | ||
force() { | ||
if (this._fired) { | ||
return; | ||
} | ||
|
||
this.stop(); | ||
this._fire(); | ||
this._fired = true; | ||
}, | ||
this.stop(); | ||
this._fire(); | ||
this._fired = true; | ||
}, | ||
|
||
fired: function() { | ||
return this._fired; | ||
} | ||
fired() { | ||
return this._fired; | ||
}, | ||
|
||
}); | ||
|
||
|
||
let activeFeedback; | ||
|
||
const FeedbackEmitter = Emitter.inherit({ | ||
|
||
ctor: function() { | ||
this.callBase.apply(this, arguments); | ||
|
||
this._active = new FeedbackEvent(0, noop); | ||
this._inactive = new FeedbackEvent(0, noop); | ||
}, | ||
|
||
configure: function(data, eventName) { | ||
switch(eventName) { | ||
case ACTIVE_EVENT_NAME: | ||
data.activeTimeout = data.timeout; | ||
break; | ||
case INACTIVE_EVENT_NAME: | ||
data.inactiveTimeout = data.timeout; | ||
break; | ||
} | ||
|
||
this.callBase(data); | ||
}, | ||
|
||
start: function(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: function(e) { | ||
const that = this; | ||
|
||
const eventTarget = this._getEmitterTarget(e); | ||
|
||
const mouseEvent = isMouseEvent(e); | ||
const isSimulator = devices.isSimulator(); | ||
const deferFeedback = isSimulator || !mouseEvent; | ||
|
||
const activeTimeout = ensureDefined(this.activeTimeout, ACTIVE_TIMEOUT); | ||
const inactiveTimeout = ensureDefined(this.inactiveTimeout, INACTIVE_TIMEOUT); | ||
|
||
this._active = new FeedbackEvent(deferFeedback ? activeTimeout : 0, function() { | ||
that._fireEvent(ACTIVE_EVENT_NAME, e, { target: eventTarget }); | ||
}); | ||
this._inactive = new FeedbackEvent(deferFeedback ? inactiveTimeout : 0, function() { | ||
that._fireEvent(INACTIVE_EVENT_NAME, e, { target: eventTarget }); | ||
activeFeedback = null; | ||
}); | ||
}, | ||
|
||
cancel: function(e) { | ||
this.end(e); | ||
}, | ||
|
||
end: function(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: function() { | ||
this._active.stop(); | ||
this._inactive.stop(); | ||
|
||
if(activeFeedback === this) { | ||
activeFeedback = null; | ||
} | ||
|
||
this.callBase(); | ||
}, | ||
|
||
lockInactive: function() { | ||
this._active.force(); | ||
this._inactive.stop(); | ||
activeFeedback = null; | ||
ctor() { | ||
this.callBase.apply(this, arguments); | ||
|
||
this._active = new FeedbackEvent(0, noop); | ||
this._inactive = new FeedbackEvent(0, noop); | ||
}, | ||
|
||
/* eslint-disable default-case */ | ||
configure(data, eventName) { | ||
switch (eventName) { | ||
case ACTIVE_EVENT_NAME: | ||
data.activeTimeout = data.timeout; | ||
break; | ||
case INACTIVE_EVENT_NAME: | ||
data.inactiveTimeout = data.timeout; | ||
break; | ||
} | ||
|
||
this.callBase(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 that = this; | ||
|
||
const eventTarget = this._getEmitterTarget(e); | ||
|
||
const mouseEvent = isMouseEvent(e); | ||
const isSimulator = devices.isSimulator(); | ||
const deferFeedback = isSimulator || !mouseEvent; | ||
|
||
return this._inactive.force.bind(this._inactive); | ||
const activeTimeout = ensureDefined(this.activeTimeout, ACTIVE_TIMEOUT); | ||
const inactiveTimeout = ensureDefined(this.inactiveTimeout, INACTIVE_TIMEOUT); | ||
|
||
this._active = new FeedbackEvent(deferFeedback ? activeTimeout : 0, () => { | ||
that._fireEvent(ACTIVE_EVENT_NAME, e, { target: eventTarget }); | ||
}); | ||
this._inactive = new FeedbackEvent(deferFeedback ? inactiveTimeout : 0, () => { | ||
that._fireEvent(INACTIVE_EVENT_NAME, 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; | ||
} | ||
|
||
this.callBase(); | ||
}, | ||
|
||
lockInactive() { | ||
this._active.force(); | ||
this._inactive.stop(); | ||
activeFeedback = null; | ||
this._cancel(); | ||
|
||
return this._inactive.force.bind(this._inactive); | ||
}, | ||
|
||
}); | ||
FeedbackEmitter.lock = function(deferred) { | ||
const lockInactive = activeFeedback ? activeFeedback.lockInactive() : noop; | ||
(FeedbackEmitter as any).lock = function (deferred) { | ||
const lockInactive = activeFeedback ? activeFeedback.lockInactive() : noop; | ||
|
||
deferred.done(lockInactive); | ||
deferred.done(lockInactive); | ||
}; | ||
|
||
|
||
registerEmitter({ | ||
emitter: FeedbackEmitter, | ||
events: [ | ||
ACTIVE_EVENT_NAME, | ||
INACTIVE_EVENT_NAME | ||
] | ||
emitter: FeedbackEmitter, | ||
events: [ | ||
ACTIVE_EVENT_NAME, | ||
INACTIVE_EVENT_NAME, | ||
], | ||
}); | ||
|
||
export const lock = FeedbackEmitter.lock; | ||
export const { lock } = (FeedbackEmitter as any); | ||
export { | ||
ACTIVE_EVENT_NAME as active, | ||
INACTIVE_EVENT_NAME as inactive | ||
ACTIVE_EVENT_NAME as active, | ||
INACTIVE_EVENT_NAME as inactive, | ||
}; |
Oops, something went wrong.