Skip to content

Commit a56ddc1

Browse files
committed
Common core: fix ts issues
1 parent 8a6ce30 commit a56ddc1

File tree

11 files changed

+191
-161
lines changed

11 files changed

+191
-161
lines changed
Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
1-
export const hideCallback = (function() {
2-
let callbacks = [];
3-
return {
4-
add: function(callback) {
5-
if(!callbacks.includes(callback)) {
6-
callbacks.push(callback);
7-
}
8-
},
9-
remove: function(callback) {
10-
const indexOfCallback = callbacks.indexOf(callback);
11-
if(indexOfCallback !== -1) {
12-
callbacks.splice(indexOfCallback, 1);
13-
}
14-
},
15-
fire: function() {
16-
const callback = callbacks.pop();
17-
const result = !!callback;
18-
if(result) {
19-
callback();
20-
}
21-
return result;
22-
},
23-
hasCallback: function() {
24-
return callbacks.length > 0;
25-
}
26-
/// #DEBUG
27-
// eslint-disable-next-line comma-style
28-
, reset: function() {
29-
callbacks = [];
30-
}
31-
/// #ENDDEBUG
32-
};
33-
})();
1+
interface HideCallback {
2+
add: (callback: Function) => void;
3+
remove: (callback: Function) => void;
4+
fire: () => boolean;
5+
hasCallback: () => boolean;
6+
reset: () => void;
7+
}
8+
9+
// eslint-disable-next-line func-names
10+
export const hideCallback = (function (): HideCallback {
11+
let callbacks: Function[] = [];
12+
return {
13+
add(callback: Function): void {
14+
if (!callbacks.includes(callback)) {
15+
callbacks.push(callback);
16+
}
17+
},
18+
remove(callback: Function): void {
19+
const indexOfCallback = callbacks.indexOf(callback);
20+
if (indexOfCallback !== -1) {
21+
callbacks.splice(indexOfCallback, 1);
22+
}
23+
},
24+
fire(): boolean {
25+
const callback = callbacks.pop();
26+
const result = !!callback;
27+
if (result) {
28+
callback();
29+
}
30+
return result;
31+
},
32+
hasCallback(): boolean {
33+
return callbacks.length > 0;
34+
},
35+
/// #DEBUG
36+
37+
reset(): void {
38+
callbacks = [];
39+
},
40+
/// #ENDDEBUG
41+
};
42+
}());
43+
44+
export const fireCallback = (): boolean => hideCallback.fire();
Lines changed: 103 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,108 @@
1-
import { getWidth, setWidth } from '../../../../core/utils/size';
2-
import $ from '../../../../core/renderer';
3-
import { getWindow } from '../../../../core/utils/window';
4-
const window = getWindow();
5-
import eventsEngine from '../../events/core/events_engine';
6-
import { extend } from '../../../../core/utils/extend';
7-
import resizeCallbacks from '../../../../core/utils/resize_callbacks';
8-
import { styleProp } from '../../../../core/utils/style';
9-
10-
import devices from '../../../../__internal/core/m_devices';
11-
import domAdapter from '../../../../__internal/core/m_dom_adapter';
12-
import supportUtils from '../../../../__internal/core/utils/m_support';
13-
14-
export const initMobileViewport = function(options) {
15-
options = extend({}, options);
16-
let realDevice = devices.real();
17-
const allowZoom = options.allowZoom;
18-
const allowPan = options.allowPan;
19-
const allowSelection = ('allowSelection' in options) ? options.allowSelection : realDevice.platform === 'generic';
20-
21-
const metaSelector = 'meta[name=viewport]';
22-
if(!$(metaSelector).length) {
23-
$('<meta>').attr('name', 'viewport').appendTo('head');
24-
}
25-
26-
const metaVerbs = ['width=device-width'];
27-
const msTouchVerbs = [];
28-
29-
if(allowZoom) {
30-
msTouchVerbs.push('pinch-zoom');
31-
} else {
32-
metaVerbs.push('initial-scale=1.0', 'maximum-scale=1.0, user-scalable=no');
33-
}
34-
35-
if(allowPan) {
36-
msTouchVerbs.push('pan-x', 'pan-y');
37-
}
38-
39-
if(!allowPan && !allowZoom) {
40-
$('html, body').css({
41-
'msContentZooming': 'none',
42-
'msUserSelect': 'none',
43-
'overflow': 'hidden'
44-
});
45-
} else {
46-
$('html').css('msOverflowStyle', '-ms-autohiding-scrollbar');
47-
}
48-
49-
if(!allowSelection && supportUtils.supportProp('userSelect')) {
50-
$('.dx-viewport').css(styleProp('userSelect'), 'none');
51-
}
52-
53-
$(metaSelector).attr('content', metaVerbs.join());
54-
$('html').css('msTouchAction', msTouchVerbs.join(' ') || 'none');
55-
56-
realDevice = devices.real();
1+
import $ from '@js/core/renderer';
2+
import devices from '@ts/core/m_devices';
3+
import domAdapter from '@ts/core/m_dom_adapter';
4+
import { extend } from '@ts/core/utils/m_extend';
5+
import resizeCallbacks from '@ts/core/utils/m_resize_callbacks';
6+
import { getWidth, setWidth } from '@ts/core/utils/m_size';
7+
import { styleProp } from '@ts/core/utils/m_style';
8+
import supportUtils from '@ts/core/utils/m_support';
9+
import { getWindow } from '@ts/core/utils/m_window';
10+
import eventsEngine from '@ts/events/core/m_events_engine';
5711

58-
if(supportUtils.touch) {
59-
eventsEngine.off(domAdapter.getDocument(), '.dxInitMobileViewport');
60-
eventsEngine.on(domAdapter.getDocument(), 'dxpointermove.dxInitMobileViewport', function(e) {
61-
const count = e.pointers.length;
62-
const isTouchEvent = e.pointerType === 'touch';
63-
const zoomDisabled = !allowZoom && count > 1;
64-
const panDisabled = !allowPan && count === 1 && !e.isScrollingEvent;
12+
const window = getWindow();
6513

66-
if(isTouchEvent && (zoomDisabled || panDisabled)) {
67-
e.preventDefault();
68-
}
69-
});
14+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
15+
export const initMobileViewport = function (
16+
options: { allowZoom?: boolean; allowPan?: boolean; allowSelection?: boolean },
17+
): void {
18+
// eslint-disable-next-line no-param-reassign
19+
options = extend({}, options);
20+
let realDevice = devices.real();
21+
const { allowZoom } = options;
22+
const { allowPan } = options;
23+
const allowSelection = 'allowSelection' in options ? options.allowSelection : realDevice.platform === 'generic';
24+
25+
const metaSelector = 'meta[name=viewport]';
26+
if (!$(metaSelector).length) {
27+
// @ts-expect-error
28+
$('<meta>').attr('name', 'viewport').appendTo('head');
29+
}
30+
31+
const metaVerbs = ['width=device-width'];
32+
const msTouchVerbs = [];
33+
34+
if (allowZoom) {
35+
// @ts-expect-error
36+
msTouchVerbs.push('pinch-zoom');
37+
} else {
38+
metaVerbs.push('initial-scale=1.0', 'maximum-scale=1.0, user-scalable=no');
39+
}
40+
41+
if (allowPan) {
42+
// @ts-expect-error
43+
msTouchVerbs.push('pan-x', 'pan-y');
44+
}
45+
46+
if (!allowPan && !allowZoom) {
47+
$('html, body').css({
48+
msContentZooming: 'none',
49+
msUserSelect: 'none',
50+
overflow: 'hidden',
51+
});
52+
} else {
53+
$('html').css('msOverflowStyle', '-ms-autohiding-scrollbar');
54+
}
55+
56+
if (!allowSelection && supportUtils.supportProp('userSelect')) {
57+
$('.dx-viewport').css(styleProp('userSelect'), 'none');
58+
}
59+
60+
$(metaSelector).attr('content', metaVerbs.join());
61+
$('html').css('msTouchAction', msTouchVerbs.join(' ') || 'none');
62+
63+
realDevice = devices.real();
64+
65+
if (supportUtils.touch) {
66+
eventsEngine.off(domAdapter.getDocument(), '.dxInitMobileViewport');
67+
eventsEngine.on(domAdapter.getDocument(), 'dxpointermove.dxInitMobileViewport', (e) => {
68+
const count = e.pointers.length;
69+
const isTouchEvent = e.pointerType === 'touch';
70+
const zoomDisabled = !allowZoom && count > 1;
71+
const panDisabled = !allowPan && count === 1 && !e.isScrollingEvent;
72+
73+
if (isTouchEvent && (zoomDisabled || panDisabled)) {
74+
e.preventDefault();
75+
}
76+
});
77+
}
78+
79+
if (realDevice.ios) {
80+
// @ts-expect-error
81+
const isPhoneGap = domAdapter.getLocation().protocol === 'file:';
82+
83+
if (!isPhoneGap) {
84+
// NOTE: fix app size after device rotation in Safari when keyboard was shown
85+
resizeCallbacks.add(() => {
86+
const windowWidth = getWidth(window);
87+
setWidth($('body'), windowWidth);
88+
});
7089
}
71-
72-
if(realDevice.ios) {
73-
const isPhoneGap = (domAdapter.getLocation().protocol === 'file:');
74-
75-
if(!isPhoneGap) {
76-
// NOTE: fix app size after device rotation in Safari when keyboard was shown
77-
resizeCallbacks.add(function() {
78-
const windowWidth = getWidth(window);
79-
setWidth($('body'), windowWidth);
80-
});
90+
}
91+
92+
if (realDevice.android) {
93+
resizeCallbacks.add(() => {
94+
// eslint-disable-next-line no-restricted-globals
95+
setTimeout(() => {
96+
const activeElement = domAdapter.getActiveElement();
97+
98+
// @ts-expect-error
99+
if (activeElement.scrollIntoViewIfNeeded) {
100+
// @ts-expect-error
101+
activeElement.scrollIntoViewIfNeeded();
102+
} else {
103+
activeElement.scrollIntoView(false);
81104
}
82-
}
83-
84-
if(realDevice.android) {
85-
resizeCallbacks.add(function() {
86-
setTimeout(function() {
87-
const activeElement = domAdapter.getActiveElement();
88-
89-
activeElement.scrollIntoViewIfNeeded ?
90-
activeElement.scrollIntoViewIfNeeded() :
91-
activeElement.scrollIntoView(false);
92-
});
93-
});
94-
}
105+
});
106+
});
107+
}
95108
};

packages/devextreme/js/__internal/data/m_custom_store.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,25 @@ function runRawLoadWithKey(pendingDeferred, store, key) {
225225
});
226226
}
227227

228+
export function isGroupItem(item): boolean {
229+
if (item === undefined || item === null || typeof item !== 'object') {
230+
return false;
231+
}
232+
return 'key' in item && 'items' in item;
233+
}
234+
235+
export function isLoadResultObject(res): boolean {
236+
return !Array.isArray(res) && 'data' in res;
237+
}
238+
239+
export function isGroupItemsArray(res): boolean {
240+
return Array.isArray(res) && !!res.length && isGroupItem(res[0]);
241+
}
242+
243+
export function isItemsArray(res): boolean {
244+
return Array.isArray(res) && !isGroupItem(res[0]);
245+
}
246+
228247
// @ts-expect-error
229248
const CustomStore = Store.inherit({
230249
ctor(options) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import arrayQueryImpl from './array_query';
2-
import remoteQueryImpl from './remote_query';
1+
import arrayQueryImpl from './m_array_query';
2+
import remoteQueryImpl from './m_remote_query';
33

44
export const queryImpl = {
5-
array: arrayQueryImpl,
6-
remote: remoteQueryImpl
5+
array: arrayQueryImpl,
6+
remote: remoteQueryImpl,
77
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable prefer-destructuring */
2+
import eventsEngine from './m_events_engine';
3+
4+
export const on = eventsEngine.on;
5+
export const one = eventsEngine.one;
6+
export const off = eventsEngine.off;
7+
export const trigger = eventsEngine.trigger;
8+
9+
export const Event = eventsEngine.Event;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { hideCallback } from '../../../__internal/core/environment/hide_callback';
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { hideCallback } from './hide_callback';
1+
import { fireCallback } from '../../../__internal/core/environment/hide_callback';
22

3-
export default function() {
4-
return hideCallback.fire();
5-
}
3+
export default fireCallback;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { initMobileViewport } from '../../../../__internal/core/environment/init_mobile_viewport';
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import eventsEngine from './events/core/events_engine';
1+
export { on, one, off, trigger, Event } from '../../__internal/events/core/events';
22

33
/**
44
* @name events
55
*/
66

7-
8-
export const on = eventsEngine.on;
9-
10-
export const one = eventsEngine.one;
11-
export const off = eventsEngine.off;
12-
export const trigger = eventsEngine.trigger;
13-
147
/**
158
* @name events.Event
169
* @type function
@@ -21,5 +14,3 @@ export const trigger = eventsEngine.trigger;
2114
* @export Event
2215
* @hidden
2316
*/
24-
25-
export const Event = eventsEngine.Event;

packages/devextreme/js/common/data/custom_store.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
import CustomStore from '../../__internal/data/m_custom_store';
2-
3-
function isGroupItem(item) {
4-
if(item === undefined || item === null || typeof item !== 'object') {
5-
return false;
6-
}
7-
return 'key' in item && 'items' in item;
8-
}
9-
10-
function isLoadResultObject(res) {
11-
return !Array.isArray(res) && 'data' in res;
12-
}
13-
14-
function isGroupItemsArray(res) {
15-
return Array.isArray(res) && !!res.length && isGroupItem(res[0]);
16-
}
17-
18-
function isItemsArray(res) {
19-
return Array.isArray(res) && !isGroupItem(res[0]);
20-
}
1+
import CustomStore, {
2+
isLoadResultObject,
3+
isGroupItemsArray,
4+
isItemsArray,
5+
} from '../../__internal/data/m_custom_store';
216

227
export {
238
CustomStore,

0 commit comments

Comments
 (0)