Skip to content

Commit 5951a31

Browse files
marker-daomarker dao ®
andauthored
PopupDrag: Improve typing and refactor (DevExpress#33832)
Co-authored-by: marker dao ® <youdontknow@marker-dao.eth>
1 parent 162a9da commit 5951a31

6 files changed

Lines changed: 140 additions & 78 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ export type PositioningEvent<
146146

147147
interface VisualPositionChangedEvent<
148148
TPosition = OverlayProperties['position'],
149-
> extends PositioningEvent<TPosition> {
149+
> extends Omit<PositioningEvent<TPosition>, 'event'> {
150150
readonly previousPosition: OverlayProperties['position'];
151+
readonly event?: DxEvent<PointerInteractionEvent | KeyboardEvent>;
151152
}
152153

153154
export interface OverlayActions<

packages/devextreme/js/__internal/ui/overlay/overlay_position_controller.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ import type {
1414
DxEvent,
1515
PointerInteractionEvent,
1616
} from '@js/events';
17+
import windowUtils from '@ts/core/utils/m_window';
1718
import swatch from '@ts/core/utils/swatch_container';
1819
import type {
1920
OverlayActions,
2021
OverlayProperties,
2122
} from '@ts/ui/overlay/overlay';
2223

23-
import windowUtils from '../../core/utils/m_window';
24-
2524
export type OverlayPositionAlignment = | 'top center'
2625
| 'bottom center'
2726
| 'right center'
@@ -240,7 +239,7 @@ export class OverlayPositionController<
240239
this.restorePositionOnNextRender(shouldRestorePosition);
241240
}
242241

243-
detectVisualPositionChange(event?: DxEvent<PointerInteractionEvent>): void {
242+
detectVisualPositionChange(event?: DxEvent<PointerInteractionEvent | KeyboardEvent>): void {
244243
this._updateVisualPositionValue();
245244
this._raisePositionedEvents(event);
246245
}
@@ -313,7 +312,7 @@ export class OverlayPositionController<
313312
this.detectVisualPositionChange();
314313
}
315314

316-
_raisePositionedEvents(event?: DxEvent<PointerInteractionEvent>): void {
315+
_raisePositionedEvents(event?: DxEvent<PointerInteractionEvent | KeyboardEvent>): void {
317316
const previousPosition = this._previousVisualPosition;
318317
const newPosition = this._visualPosition;
319318

packages/devextreme/js/__internal/ui/popup/m_popup.full.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import Popup from '@js/ui/popup/ui.popup';
55

66
import type { PopupProperties } from './m_popup';
77

8+
const TOOLBAR_WIDGET_NAME = 'dxToolbar';
9+
810
export default class PopupFull extends Popup {
911
_getDefaultOptions(): PopupProperties {
1012
return {
@@ -15,11 +17,12 @@ export default class PopupFull extends Popup {
1517

1618
// eslint-disable-next-line class-methods-use-this
1719
_getToolbarName(): string {
18-
return 'dxToolbar';
20+
return TOOLBAR_WIDGET_NAME;
1921
}
2022
}
2123

22-
PopupFull.defaultOptions = function (rule) {
24+
// eslint-disable-next-line func-names
25+
PopupFull.defaultOptions = function (rule): void {
2326
Popup.defaultOptions(rule);
2427
};
2528

packages/devextreme/js/__internal/ui/popup/m_popup.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ import type {
5454
ControllerProperties,
5555
} from '@ts/ui/overlay/overlay_position_controller';
5656
import * as zIndexPool from '@ts/ui/overlay/z_index';
57-
import type { ToolbarBaseProperties } from '@ts/ui/toolbar/toolbar.base';
58-
59-
import PopupDrag from './m_popup_drag';
60-
import type { OverflowManager } from './m_popup_overflow_manager';
61-
import { createBodyOverflowManager } from './m_popup_overflow_manager';
57+
import type { PopupDragConfig } from '@ts/ui/popup/m_popup_drag';
58+
import PopupDrag from '@ts/ui/popup/m_popup_drag';
59+
import type { OverflowManager } from '@ts/ui/popup/m_popup_overflow_manager';
60+
import { createBodyOverflowManager } from '@ts/ui/popup/m_popup_overflow_manager';
6261
import type {
6362
PopupControllerProperties,
6463
PopupPositionControllerConstructor,
65-
} from './popup_position_controller';
66-
import { PopupPositionController } from './popup_position_controller';
64+
} from '@ts/ui/popup/popup_position_controller';
65+
import { PopupPositionController } from '@ts/ui/popup/popup_position_controller';
66+
import type { ToolbarBaseProperties } from '@ts/ui/toolbar/toolbar.base';
6767

6868
// STYLE popup
6969

@@ -97,7 +97,7 @@ const BUTTON_TEXT_MODE = 'text';
9797
const BUTTON_CONTAINED_MODE = 'contained';
9898
const BUTTON_OUTLINED_MODE = 'outlined';
9999

100-
const TOOLBAR_NAME_BASE = 'dxToolbarBase';
100+
const TOOLBAR_BASE_WIDGET_NAME = 'dxToolbarBase';
101101

102102
const HEIGHT_STRATEGIES = {
103103
static: '',
@@ -208,7 +208,7 @@ class Popup<
208208

209209
_resizable!: Resizable;
210210

211-
_drag?: PopupDrag;
211+
_drag?: PopupDrag<PopupPositionController>;
212212

213213
_renderedDimensions?: {
214214
width: number;
@@ -959,7 +959,7 @@ class Popup<
959959

960960
// eslint-disable-next-line class-methods-use-this
961961
_getToolbarName(): string {
962-
return TOOLBAR_NAME_BASE;
962+
return TOOLBAR_BASE_WIDGET_NAME;
963963
}
964964

965965
_toggleDisabledState(value: boolean): void {
@@ -1119,7 +1119,7 @@ class Popup<
11191119
return;
11201120
}
11211121

1122-
const config = {
1122+
const config: PopupDragConfig<PopupPositionController> = {
11231123
dragEnabled,
11241124
handle: $dragTarget.get(0),
11251125
draggableElement: this._$content?.get(0),
@@ -1129,7 +1129,7 @@ class Popup<
11291129
if (this._drag) {
11301130
this._drag.init(config);
11311131
} else {
1132-
this._drag = new PopupDrag(config);
1132+
this._drag = new PopupDrag<PopupPositionController>(config);
11331133
}
11341134

11351135
this.$overlayContent().toggleClass(POPUP_DRAGGABLE_CLASS, dragEnabled);

0 commit comments

Comments
 (0)