Skip to content

Commit 86d282f

Browse files
Introduce reusable Interaction, PointerInteraction event types for mouse, pointer, touch, and keyboard native events (DevExpress#31240)
1 parent e350c7a commit 86d282f

File tree

109 files changed

+440
-349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+440
-349
lines changed

packages/devextreme/js/__internal/core/widget/widget.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import { extend } from '@js/core/utils/extend';
1717
import { each } from '@js/core/utils/iterator';
1818
import { isDefined, isPlainObject } from '@js/core/utils/type';
1919
import { compare as compareVersions } from '@js/core/utils/version';
20-
import type { DxEvent } from '@js/events';
20+
import type {
21+
DxEvent,
22+
PointerInteractionEvent,
23+
} from '@js/events';
2124
import type { WidgetOptions } from '@js/ui/widget/ui.widget';
2225
import { focusable as focusableSelector } from '@ts/core/utils/m_selectors';
2326
import type { DOMComponentProperties } from '@ts/core/widget/dom_component';
@@ -525,7 +528,7 @@ class Widget<
525528
$element: dxElementWrapper,
526529
value: boolean,
527530
// eslint-disable-next-line @typescript-eslint/no-unused-vars
528-
event?: DxEvent<PointerEvent | MouseEvent | TouchEvent>,
531+
event?: DxEvent<PointerInteractionEvent>,
529532
): void {
530533
this.option('isActive', value);
531534
$element.toggleClass(ACTIVE_STATE_CLASS, value);

packages/devextreme/js/__internal/ui/chat/messagebox.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { NativeEventInfo } from '@js/common/core/events';
22
import messageLocalization from '@js/common/core/localization/message';
33
import devices from '@js/core/devices';
44
import $, { type dxElementWrapper } from '@js/core/renderer';
5+
import type { InteractionEvent } from '@js/events';
56
import type { ClickEvent, Properties as ButtonProperties } from '@js/ui/button';
67
import Button from '@js/ui/button';
78
import type { DOMComponentProperties } from '@ts/core/widget/dom_component';
@@ -21,7 +22,7 @@ export const TYPING_END_DELAY = 2000;
2122
const ESCAPE_KEY = 'escape';
2223

2324
export type MessageEnteredEvent =
24-
NativeEventInfo<MessageBox, KeyboardEvent | PointerEvent | MouseEvent | TouchEvent> &
25+
NativeEventInfo<MessageBox, InteractionEvent> &
2526
{ text?: string };
2627

2728
export type TypingStartEvent = NativeEventInfo<MessageBox, UIEvent & { target: HTMLInputElement }>;

packages/devextreme/js/__internal/ui/collection/collection_widget.base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { isDefined, isFunction, isPlainObject } from '@js/core/utils/type';
2828
import type { DataSourceOptions } from '@js/data/data_source';
2929
import type {
3030
Cancelable, DxEvent,
31+
PointerInteractionEvent,
3132
} from '@js/events';
3233
import type {
3334
CollectionWidgetItem as CollectionWidgetItemProperties,
@@ -116,7 +117,7 @@ export interface PostprocessRenderItemInfo<TItem> {
116117
itemIndex: number;
117118
}
118119

119-
export type InkRippleEvent = DxEvent<PointerEvent | MouseEvent | TouchEvent>;
120+
export type InkRippleEvent = DxEvent<PointerInteractionEvent>;
120121
export type Constructor<T> = new (...args: unknown[]) => T;
121122

122123
export interface CollectionWidgetBaseProperties<

packages/devextreme/js/__internal/ui/context_menu/menu_base.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { asyncNoop, noop } from '@js/core/utils/common';
66
import type { DeferredObj } from '@js/core/utils/deferred';
77
import { each } from '@js/core/utils/iterator';
88
import { isDefined, isObject, isPlainObject } from '@js/core/utils/type';
9-
import type { DxEvent, ItemInfo, NativeEventInfo } from '@js/events';
9+
import type {
10+
DxEvent, ItemInfo, NativeEventInfo, PointerInteractionEvent,
11+
} from '@js/events';
1012
import type { dxMenuBaseOptions } from '@js/ui/context_menu/ui.menu_base';
1113
import type dxMenuBase from '@js/ui/context_menu/ui.menu_base';
1214
import type {
@@ -51,10 +53,10 @@ const ITEM_URL_CLASS = 'dx-item-url';
5153
const DX_MENU_ITEM_DATA_KEY = 'dxMenuItemDataKey';
5254

5355
type ItemClickEvent<TComponent, TItem> =
54-
NativeEventInfo<TComponent, MouseEvent | PointerEvent | TouchEvent>
56+
NativeEventInfo<TComponent, PointerInteractionEvent>
5557
& ItemInfo<TItem>;
5658
export type HoverEvent = DxEvent<MouseEvent | PointerEvent>;
57-
export type ClickEvent = DxEvent<MouseEvent | PointerEvent | TouchEvent>;
59+
export type ClickEvent = DxEvent<PointerInteractionEvent>;
5860
export type ItemClickActionArguments<
5961
TComponent extends dxMenuBase<MenuBaseProperties> = dxMenuBase<MenuBaseProperties>,
6062
TItem extends dxMenuBaseItem = dxMenuBaseItem,

packages/devextreme/js/__internal/ui/drawer/drawer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import { Deferred, when } from '@js/core/utils/deferred';
1212
import { getBoundingRect } from '@js/core/utils/position';
1313
import { isDefined, isFunction } from '@js/core/utils/type';
1414
import { hasWindow } from '@js/core/utils/window';
15-
import type { DxEvent } from '@js/events';
15+
import type {
16+
DxEvent,
17+
PointerInteractionEvent,
18+
} from '@js/events';
1619
import type { PanelLocation, Properties } from '@js/ui/drawer';
1720
import type { OptionChanged } from '@ts/core/widget/types';
1821
import Widget from '@ts/core/widget/widget';
@@ -138,7 +141,7 @@ class Drawer extends Widget<DrawerProperties> {
138141
super._initTemplates();
139142
}
140143

141-
_viewContentWrapperClickHandler(e: DxEvent<MouseEvent | PointerEvent | TouchEvent>): void {
144+
_viewContentWrapperClickHandler(e: DxEvent<PointerInteractionEvent>): void {
142145
const { opened, shading } = this.option();
143146
let { closeOnOutsideClick } = this.option();
144147

packages/devextreme/js/__internal/ui/drop_down_editor/m_drop_down_editor.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ import { each } from '@js/core/utils/iterator';
2424
import { getDefaultAlignment } from '@js/core/utils/position';
2525
import { isDefined } from '@js/core/utils/type';
2626
import { hasWindow } from '@js/core/utils/window';
27-
import type { DxEvent, EventInfo } from '@js/events';
27+
import type {
28+
DxEvent,
29+
EventInfo,
30+
PointerInteractionEvent,
31+
} from '@js/events';
2832
import type { Options as Properties } from '@js/ui/drop_down_editor/ui.drop_down_editor';
2933
import type { Properties as PopupProperties } from '@js/ui/popup';
3034
import Popup from '@js/ui/popup/ui.popup';
@@ -54,8 +58,6 @@ const OVERLAY_CONTENT_LABEL = 'Dropdown';
5458

5559
const isIOs = devices.current().platform === 'ios';
5660

57-
type HideOnOutsideClickEvent = DxEvent<MouseEvent | PointerEvent | TouchEvent>;
58-
5961
export const DROP_DOWN_EDITOR_DEPRECATED_OPTIONS = {
6062
fieldTemplate: {
6163
since: '25.2',
@@ -863,7 +865,7 @@ class DropDownEditor<
863865
shading: false,
864866
hideOnParentScroll: true,
865867
hideOnOutsideClick: (
866-
e: DxEvent<MouseEvent | PointerEvent | TouchEvent>,
868+
e: DxEvent<PointerInteractionEvent>,
867869
): boolean => this._closeOutsideDropDownHandler(e),
868870
animation: {
869871
show: {
@@ -987,7 +989,7 @@ class DropDownEditor<
987989
return positionSide;
988990
}
989991

990-
_closeOutsideDropDownHandler(event: HideOnOutsideClickEvent): boolean {
992+
_closeOutsideDropDownHandler(event: DxEvent<PointerInteractionEvent>): boolean {
991993
const { target } = event;
992994

993995
const $target = $(target);

packages/devextreme/js/__internal/ui/form/form.layout_manager.utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import type { FunctionTemplate } from '@js/core/templates/function_template';
88
import { extend } from '@js/core/utils/extend';
99
import { captionize } from '@js/core/utils/inflector';
1010
import { isDefined, isFunction } from '@js/core/utils/type';
11-
import type { DxEvent } from '@js/events';
11+
import type {
12+
DxEvent,
13+
PointerInteractionEvent,
14+
} from '@js/events';
1215
import type {
1316
FormItemComponent, FormLabelMode, LabelLocation, SimpleItem,
1417
} from '@js/ui/form';
@@ -253,7 +256,7 @@ function getDropDownEditorOptions(
253256
// Do not overwrite boolean hideOnOutsideClick
254257
if (openOnFieldClick && isFunction(initialHideOnOutsideClick)) {
255258
const hideOnOutsideClick = (
256-
e: DxEvent<MouseEvent | PointerEvent | TouchEvent>,
259+
e: DxEvent<PointerInteractionEvent>,
257260
): boolean => {
258261
const $target = $(e.target);
259262
const $label = $parent.find(`label[for="${editorInputId}"]`);

packages/devextreme/js/__internal/ui/list/list.base.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ import { getHeight, getOuterHeight, setHeight } from '@js/core/utils/size';
2323
import { isDefined, isPlainObject } from '@js/core/utils/type';
2424
import { hasWindow } from '@js/core/utils/window';
2525
import type { DataSourceLike } from '@js/data/data_source';
26-
import type { DxEvent, NativeEventInfo } from '@js/events';
26+
import type {
27+
DxEvent,
28+
InteractionEvent,
29+
NativeEventInfo,
30+
PointerInteractionEvent,
31+
} from '@js/events';
2732
import type { Properties as ButtonProperties } from '@js/ui/button';
2833
import Button from '@js/ui/button';
2934
import type {
@@ -869,16 +874,16 @@ export class ListBase extends CollectionWidget<ListBaseProperties, Item> {
869874
$element,
870875
eventNameClick,
871876
headerSelector,
872-
(e: DxEvent<MouseEvent | PointerEvent | TouchEvent>): void => {
877+
(e: DxEvent<PointerInteractionEvent>): void => {
873878
this._processGroupCollapse(e);
874879
},
875880
);
876881
}
877882
}
878883

879-
_processGroupCollapse(e: DxEvent<MouseEvent | PointerEvent | TouchEvent | KeyboardEvent>): void {
884+
_processGroupCollapse(e: DxEvent<InteractionEvent>): void {
880885
const actionCallback = (
881-
evt: NativeEventInfo<MouseEvent | PointerEvent | TouchEvent | KeyboardEvent>,
886+
evt: NativeEventInfo<InteractionEvent>,
882887
): void => {
883888
const { focusStateEnabled } = this.option();
884889
const $group = $(evt.event?.currentTarget).parent();

packages/devextreme/js/__internal/ui/list/list.edit.decorator.context.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import messageLocalization from '@js/common/core/localization/message';
33
import type { dxElementWrapper } from '@js/core/renderer';
44
import $ from '@js/core/renderer';
55
import { getOuterHeight, getOuterWidth } from '@js/core/utils/size';
6-
import type { DxEvent } from '@js/events';
6+
import type {
7+
DxEvent,
8+
PointerInteractionEvent,
9+
} from '@js/events';
710
import type { ItemClickEvent } from '@js/ui/list';
811
import type dxOverlay from '@js/ui/overlay';
912
import { ListBase } from '@ts/ui/list/list.base';
@@ -34,7 +37,7 @@ class EditDecoratorContext extends EditDecorator {
3437
shading: false,
3538
deferRendering: true,
3639
hideOnParentScroll: true,
37-
hideOnOutsideClick: (e: DxEvent<MouseEvent | PointerEvent | TouchEvent>): boolean => !$(e.target).closest(`.${CONTEXTMENU_CLASS}`).length,
40+
hideOnOutsideClick: (e: DxEvent<PointerInteractionEvent>): boolean => !$(e.target).closest(`.${CONTEXTMENU_CLASS}`).length,
3841
animation: {
3942
show: {
4043
type: 'slide',

packages/devextreme/js/__internal/ui/list/list.edit.decorator.reorder.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { isMouseEvent } from '@js/common/core/events/utils';
55
import type { dxElementWrapper } from '@js/core/renderer';
66
import $ from '@js/core/renderer';
77
import { getWidth, setWidth } from '@js/core/utils/size';
8-
import type { Cancelable, DxEvent } from '@js/events';
8+
import type {
9+
Cancelable,
10+
DxEvent,
11+
PointerInteractionEvent,
12+
} from '@js/events';
913
import type {
1014
DragChangeEvent,
1115
DragStartEvent,
@@ -114,15 +118,15 @@ class EditDecoratorReorder extends EditDecorator {
114118
eventsEngine.on(
115119
$handle,
116120
pointerEvents.down,
117-
(e: DxEvent<PointerEvent | MouseEvent | TouchEvent>): void => {
121+
(e: DxEvent<PointerInteractionEvent>): void => {
118122
this._lockedDrag = !isMouseEvent(e);
119123
},
120124
);
121125
eventsEngine.on(
122126
$handle,
123127
holdEvent.name,
124128
{ timeout: 30 },
125-
(e: DxEvent<PointerEvent | MouseEvent | TouchEvent> & Cancelable): void => {
129+
(e: DxEvent<PointerInteractionEvent> & Cancelable): void => {
126130
e.cancel = true;
127131
this._lockedDrag = false;
128132
},

0 commit comments

Comments
 (0)