Skip to content

Commit a169fc5

Browse files
DateBox (Base + Mask + Strategies), HTMLEditor: convert into ES6 class (DevExpress#29250) (DevExpress#29282)
1 parent 3b1ebe3 commit a169fc5

File tree

14 files changed

+897
-691
lines changed

14 files changed

+897
-691
lines changed

packages/devextreme/js/__internal/ui/date_box/m_date_box.base.ts

Lines changed: 232 additions & 190 deletions
Large diffs are not rendered by default.

packages/devextreme/js/__internal/ui/date_box/m_date_box.mask.ts

Lines changed: 169 additions & 136 deletions
Large diffs are not rendered by default.

packages/devextreme/js/__internal/ui/date_box/m_date_box.strategy.calendar.ts

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@ import DateBoxStrategy from './m_date_box.strategy';
1111

1212
const TODAY_BUTTON_CLASS = 'dx-button-today';
1313

14-
const CalendarStrategy = DateBoxStrategy.inherit({
14+
class CalendarStrategy extends DateBoxStrategy {
15+
_lastActionElement?: string;
1516

16-
NAME: 'Calendar',
17+
ctor(dateBox): void {
18+
super.ctor(dateBox);
19+
20+
this.NAME = 'Calendar';
21+
}
1722

1823
getDefaultOptions() {
19-
return extend(this.callBase(), {
24+
return {
25+
...super.getDefaultOptions(),
2026
todayButtonText: messageLocalization.format('dxCalendar-todayButtonText'),
21-
});
22-
},
27+
};
28+
}
2329

24-
supportedKeys() {
30+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
31+
supportedKeys(): Record<string, (e: KeyboardEvent) => boolean | void> {
2532
const homeEndHandler = function (e) {
2633
if (this.option('opened')) {
2734
e.preventDefault();
@@ -69,25 +76,27 @@ const CalendarStrategy = DateBoxStrategy.inherit({
6976
home: homeEndHandler,
7077
end: homeEndHandler,
7178
};
72-
},
79+
}
7380

7481
getDisplayFormat(displayFormat) {
7582
return displayFormat || 'shortdate';
76-
},
83+
}
7784

78-
_closeDropDownByEnter: () => true,
85+
_closeDropDownByEnter() {
86+
return true;
87+
}
7988

8089
_getWidgetName() {
8190
return Calendar;
82-
},
91+
}
8392

8493
_getContouredValue() {
8594
return this._widget._view.option('contouredDate');
86-
},
95+
}
8796

8897
getKeyboardListener() {
8998
return this._widget;
90-
},
99+
}
91100

92101
_getWidgetOptions() {
93102
const disabledDates = this.dateBox.option('disabledDates');
@@ -104,20 +113,20 @@ const CalendarStrategy = DateBoxStrategy.inherit({
104113
onContouredChanged: this._refreshActiveDescendant.bind(this),
105114
skipFocusCheck: true,
106115
});
107-
},
116+
}
108117

109118
_injectComponent(func) {
110119
const that = this;
111120
return function (params) {
112121
extend(params, { component: that.dateBox });
113122
return func(params);
114123
};
115-
},
124+
}
116125

117126
_refreshActiveDescendant(e) {
118127
this._lastActionElement = 'calendar';
119128
this.dateBox.setAria('activedescendant', e.actionValue);
120-
},
129+
}
121130

122131
_getTodayButtonConfig() {
123132
const buttonsLocation = this.dateBox.option('buttonsLocation');
@@ -137,13 +146,13 @@ const CalendarStrategy = DateBoxStrategy.inherit({
137146
stylingMode,
138147
},
139148
};
140-
},
149+
}
141150

142151
_isCalendarVisible() {
143152
const { calendarOptions } = this.dateBox.option();
144153

145154
return isEmptyObject(calendarOptions) || calendarOptions.visible !== false;
146-
},
155+
}
147156

148157
_getPopupToolbarItems(toolbarItems) {
149158
const useButtons = this.dateBox.option('applyValueMode') === 'useButtons';
@@ -159,14 +168,14 @@ const CalendarStrategy = DateBoxStrategy.inherit({
159168
}
160169

161170
return toolbarItems;
162-
},
171+
}
163172

164173
popupConfig(popupConfig) {
165174
return extend(true, popupConfig, {
166175
position: { collision: 'flipfit flip' },
167176
width: 'auto',
168177
});
169-
},
178+
}
170179

171180
_valueChangedHandler(e) {
172181
const { value } = e;
@@ -179,23 +188,24 @@ const CalendarStrategy = DateBoxStrategy.inherit({
179188
if (this.dateBox.option('applyValueMode') === 'instantly') {
180189
this.dateBoxValue(this.getValue(), e.event);
181190
}
182-
},
191+
}
183192

184-
_updateValue() {
193+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
194+
_updateValue(preventDefaultValue?: boolean) {
185195
if (!this._widget) {
186196
return;
187197
}
188198

189199
this._widget.option('value', this.dateBoxValue());
190-
},
200+
}
191201

192202
textChangedHandler() {
193203
this._lastActionElement = 'input';
194204

195205
if (this.dateBox.option('opened') && this._widget) {
196206
this._updateValue(true);
197207
}
198-
},
208+
}
199209

200210
_cellClickHandler(e) {
201211
const { dateBox } = this;
@@ -204,7 +214,7 @@ const CalendarStrategy = DateBoxStrategy.inherit({
204214
dateBox.option('opened', false);
205215
this.dateBoxValue(this.getValue(), e.event);
206216
}
207-
},
208-
});
217+
}
218+
}
209219

210220
export default CalendarStrategy;

packages/devextreme/js/__internal/ui/date_box/m_date_box.strategy.calendar_with_time.ts

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,64 @@ import dateUtils from '@js/core/utils/date';
44
import { extend } from '@js/core/utils/extend';
55
import { getWidth } from '@js/core/utils/size';
66
import { getWindow } from '@js/core/utils/window';
7-
import Box from '@js/ui/box';
7+
import TimeView from '@ts/ui/date_box/m_time_view';
8+
import Box from '@ts/ui/m_box';
89

910
import CalendarStrategy from './m_date_box.strategy.calendar';
1011
import uiDateUtils from './m_date_utils';
11-
import TimeView from './m_time_view';
1212

1313
const window = getWindow();
1414

1515
const SHRINK_VIEW_SCREEN_WIDTH = 573;
1616
const DATEBOX_ADAPTIVITY_MODE_CLASS = 'dx-datebox-adaptivity-mode';
1717
const DATEBOX_TIMEVIEW_SIDE_CLASS = 'dx-datebox-datetime-time-side';
1818

19-
const CalendarWithTimeStrategy = CalendarStrategy.inherit({
19+
class CalendarWithTimeStrategy extends CalendarStrategy {
20+
_timeView!: TimeView;
2021

21-
NAME: 'CalendarWithTime',
22+
_repaintTimer?: ReturnType<typeof setTimeout>;
23+
24+
_removeMinWidthTimer?: ReturnType<typeof setTimeout>;
25+
26+
_currentAdaptiveMode?: boolean;
27+
28+
_box?: Box;
29+
30+
ctor(dateBox): void {
31+
super.ctor(dateBox);
32+
33+
this.NAME = 'CalendarWithTime';
34+
}
2235

2336
getDefaultOptions() {
24-
return extend(this.callBase(), {
37+
return {
38+
...super.getDefaultOptions(),
2539
applyValueMode: 'useButtons',
2640
buttonsLocation: 'bottom after',
2741
'dropDownOptions.showTitle': false,
28-
});
29-
},
42+
};
43+
}
3044

3145
_closeDropDownByEnter() {
3246
return dateUtils.sameDate(this._getContouredValue(), this.widgetOption('value'));
33-
},
47+
}
3448

3549
getDisplayFormat(displayFormat) {
3650
return displayFormat || 'shortdateshorttime';
37-
},
51+
}
3852

3953
_is24HourFormat() {
4054
// @ts-expect-error
4155
return dateLocalization.is24HourFormat(this.getDisplayFormat(this.dateBox.option('displayFormat')));
42-
},
56+
}
4357

4458
_getContouredValue() {
45-
const viewDate = this.callBase();
59+
const viewDate = super._getContouredValue();
4660
return this._updateDateTime(viewDate);
47-
},
61+
}
4862

49-
_renderWidget() {
50-
this.callBase();
63+
_renderWidget(): void {
64+
super._renderWidget();
5165

5266
this._timeView = this.dateBox._createComponent($('<div>'), TimeView, {
5367
value: this.dateBoxValue(),
@@ -56,10 +70,10 @@ const CalendarWithTimeStrategy = CalendarStrategy.inherit({
5670
onValueChanged: this._valueChangedHandler.bind(this),
5771
stylingMode: this.dateBox.option('stylingMode'),
5872
});
59-
},
73+
}
6074

61-
renderOpenedState() {
62-
this.callBase();
75+
renderOpenedState(): void {
76+
super.renderOpenedState();
6377
const popup = this._getPopup();
6478

6579
if (popup) {
@@ -69,9 +83,9 @@ const CalendarWithTimeStrategy = CalendarStrategy.inherit({
6983
clearTimeout(this._repaintTimer);
7084

7185
this._repaintTimer = setTimeout(() => {
72-
this._getPopup() && this._getPopup().repaint();
86+
this._getPopup()?.repaint();
7387
}, 0);
74-
},
88+
}
7589

7690
isAdaptivityChanged() {
7791
const isAdaptiveMode = this._isShrinkView();
@@ -82,8 +96,8 @@ const CalendarWithTimeStrategy = CalendarStrategy.inherit({
8296
return currentAdaptiveMode !== undefined;
8397
}
8498

85-
return this.callBase();
86-
},
99+
return super.isAdaptivityChanged();
100+
}
87101

88102
_updateValue(preventDefaultValue) {
89103
let date = this.dateBoxValue();
@@ -93,21 +107,21 @@ const CalendarWithTimeStrategy = CalendarStrategy.inherit({
93107
uiDateUtils.normalizeTime(date);
94108
}
95109

96-
this.callBase();
110+
super._updateValue();
97111

98112
if (this._timeView) {
99113
date && this._timeView.option('value', date);
100114
this._timeView.option('use24HourFormat', this._is24HourFormat());
101115
}
102-
},
116+
}
103117

104118
_isSmallScreen() {
105119
return getWidth(window) <= SHRINK_VIEW_SCREEN_WIDTH;
106-
},
120+
}
107121

108-
_isShrinkView() {
122+
_isShrinkView(): boolean {
109123
return !this.dateBox.option('showAnalogClock') || (this.dateBox.option('adaptivityEnabled') && this._isSmallScreen());
110-
},
124+
}
111125

112126
_getBoxItems() {
113127
const items = [{
@@ -121,10 +135,10 @@ const CalendarWithTimeStrategy = CalendarStrategy.inherit({
121135
}
122136

123137
return items;
124-
},
138+
}
125139

126140
renderPopupContent() {
127-
this.callBase();
141+
super.renderPopupContent();
128142
this._currentAdaptiveMode = this._isShrinkView();
129143

130144
const $popupContent = this._getPopup().$content();
@@ -154,41 +168,42 @@ const CalendarWithTimeStrategy = CalendarStrategy.inherit({
154168
return $container;
155169
}.bind(this),
156170
});
157-
},
171+
}
158172

159173
popupConfig(popupConfig) {
160-
const calendarPopupConfig = this.callBase(popupConfig);
174+
const calendarPopupConfig = super.popupConfig(popupConfig);
161175
return extend(calendarPopupConfig, { width: 'auto' });
162-
},
176+
}
163177

164-
_preventFocusOnPopup(e) {
178+
_preventFocusOnPopup(e): void {
165179
if (!$(e.target).hasClass('dx-texteditor-input')) {
166-
this.callBase.apply(this, arguments);
180+
// @ts-expect-error ts-error
181+
super._preventFocusOnPopup.apply(this, arguments);
167182
if (!this.dateBox._hasFocusClass()) {
168183
this.dateBox.focus();
169184
}
170185
}
171-
},
186+
}
172187

173-
_updateDateTime(date) {
174-
const time = this._timeView.option('value');
188+
_updateDateTime(date): void {
189+
const { value: time } = this._timeView.option();
175190
date.setHours(time.getHours(), time.getMinutes(), time.getSeconds(), time.getMilliseconds());
176191

177192
return date;
178-
},
193+
}
179194

180195
getValue() {
181196
let date = this._widget.option('value') ?? this._widget.getContouredDate();
182197
date = date ? new Date(date) : new Date();
183198

184199
return this._updateDateTime(date);
185-
},
200+
}
186201

187-
dispose() {
202+
dispose(): void {
188203
clearTimeout(this._removeMinWidthTimer);
189204
clearTimeout(this._repaintTimer);
190-
this.callBase();
191-
},
192-
});
205+
super.dispose();
206+
}
207+
}
193208

194209
export default CalendarWithTimeStrategy;

0 commit comments

Comments
 (0)