Skip to content

Commit e5a32c3

Browse files
committed
Common core: fix ts issues
1 parent 8687ebb commit e5a32c3

File tree

11 files changed

+190
-161
lines changed

11 files changed

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

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)