|
1 | 1 | import { Logger } from '@ui5/webcomponents-react-base/lib/Logger'; |
2 | | -import { deprecationNotice } from '@ui5/webcomponents-react-base/lib/Utils'; |
3 | | -import { EventRegistry } from './EventRegistry'; |
| 2 | +import { MediaEventProvider } from './MediaEventProvider'; |
4 | 3 | import { supportMatchMediaListener } from './Support'; |
5 | 4 | import { changeRootCSSClass, getQuery, matchLegacyBySize } from './utils'; |
6 | 5 |
|
@@ -31,6 +30,8 @@ interface RangeSet { |
31 | 30 | listener?: () => void; |
32 | 31 | } |
33 | 32 |
|
| 33 | +const eventProvider = MediaEventProvider; |
| 34 | + |
34 | 35 | // private helpers |
35 | 36 | const initializedQuerySets: Record<string, RangeSet> = {}; |
36 | 37 |
|
@@ -93,7 +94,7 @@ const handleChange = (name: string): void => { |
93 | 94 | () => { |
94 | 95 | const mParams = checkQueries(name, false); |
95 | 96 | if (mParams) { |
96 | | - EventRegistry.fireEvent(`media_${name}`, mParams); |
| 97 | + eventProvider.fireEvent(`media_${name}`, mParams); |
97 | 98 | } |
98 | 99 | }, |
99 | 100 | supportMatchMediaListener() ? 0 : 100 |
@@ -190,8 +191,6 @@ export const initRangeSet = ( |
190 | 191 | } |
191 | 192 |
|
192 | 193 | if (hasRangeSet(oConfig.name)) { |
193 | | - // TODO v0.12.0 - Reactivate this line again once the Device Class is removed. |
194 | | - // Logger.info(`Range set ${oConfig.name} has already been initialized`, 'DEVICE.MEDIA'); |
195 | 194 | return; |
196 | 195 | } |
197 | 196 |
|
@@ -249,95 +248,15 @@ export const removeRangeSet = (rangeSetName: string): void => { |
249 | 248 | } |
250 | 249 |
|
251 | 250 | refreshCSSClasses(rangeSetName, '', true); |
252 | | - delete EventRegistry.mEventRegistry[`media_${rangeSetName}`]; |
| 251 | + // eslint-disable-next-line no-underscore-dangle |
| 252 | + delete eventProvider._eventRegistry[`media_${rangeSetName}`]; |
253 | 253 | delete initializedQuerySets[rangeSetName]; |
254 | 254 | }; |
255 | 255 |
|
256 | | -export const attachHandler = (fnFunction, oListener?, name: string = DEFAULT_RANGE_SET): void => { |
257 | | - EventRegistry.attachEvent(`media_${name}`, fnFunction, oListener); |
| 256 | +export const attachMediaHandler = (fnFunction, name: string = DEFAULT_RANGE_SET): void => { |
| 257 | + eventProvider.attachEvent(`media_${name}`, fnFunction); |
258 | 258 | }; |
259 | 259 |
|
260 | | -export const detachHandler = (fnFunction, oListener?, name: string = DEFAULT_RANGE_SET): void => { |
261 | | - EventRegistry.detachEvent(`media_${name}`, fnFunction, oListener); |
| 260 | +export const detachMediaHandler = (fnFunction, name: string = DEFAULT_RANGE_SET): void => { |
| 261 | + eventProvider.detachEvent(`media_${name}`, fnFunction); |
262 | 262 | }; |
263 | | - |
264 | | -export class MediaLegacy { |
265 | | - constructor() { |
266 | | - if (!initializedQuerySets[DEFAULT_RANGE_SET]) { |
267 | | - initRangeSet(); |
268 | | - } |
269 | | - if (!initializedQuerySets[RANGESETS.SAP_STANDARD_EXTENDED]) { |
270 | | - initRangeSet(RANGESETS.SAP_STANDARD_EXTENDED); |
271 | | - } |
272 | | - } |
273 | | - |
274 | | - // Public API |
275 | | - public RANGESETS = RANGESETS; |
276 | | - public predefinedRangeSets = DEFAULT_RANGESETS; |
277 | | - |
278 | | - public getCurrentRange(rangeSetName: string, width: number) { |
279 | | - deprecationNotice( |
280 | | - 'Device.media.getCurrentRange', |
281 | | - `Accessing 'Device.media.getCurrentRange' is deprecated and will be removed in the next major version. |
282 | | - Please use 'getCurrentRange' ('import { getCurrentRange } from '@ui5/webcomponents-react-base/lib/Media') instead.` |
283 | | - ); |
284 | | - return getCurrentRange(rangeSetName, width); |
285 | | - } |
286 | | - |
287 | | - public hasRangeSet(name) { |
288 | | - deprecationNotice( |
289 | | - 'Device.media.hasRangeSet', |
290 | | - `Accessing 'Device.media.hasRangeSet' is deprecated and will be removed in the next major version. |
291 | | - Please use 'hasRangeSet' ('import { hasRangeSet } from '@ui5/webcomponents-react-base/lib/Media') instead.` |
292 | | - ); |
293 | | - return hasRangeSet(name); |
294 | | - } |
295 | | - |
296 | | - public initRangeSet( |
297 | | - sName?: string, |
298 | | - aRangeBorders?: number[], |
299 | | - sUnit?: string, |
300 | | - aRangeNames?: string[], |
301 | | - bSuppressClasses?: boolean |
302 | | - ) { |
303 | | - deprecationNotice( |
304 | | - 'Device.media.initRangeSet', |
305 | | - `Accessing 'Device.media.initRangeSet' is deprecated and will be removed in the next major version. |
306 | | - Please use 'initRangeSet' ('import { initRangeSet } from '@ui5/webcomponents-react-base/lib/Media') instead.` |
307 | | - ); |
308 | | - return initRangeSet(sName, aRangeBorders, sUnit, aRangeNames, bSuppressClasses); |
309 | | - } |
310 | | - |
311 | | - public removeRangeSet(name) { |
312 | | - deprecationNotice( |
313 | | - 'Device.media.removeRangeSet', |
314 | | - `Accessing 'Device.media.removeRangeSet' is deprecated and will be removed in the next major version. |
315 | | - Please use 'removeRangeSet' ('import { removeRangeSet } from '@ui5/webcomponents-react-base/lib/Media') instead.` |
316 | | - ); |
317 | | - return removeRangeSet(name); |
318 | | - } |
319 | | - |
320 | | - public attachHandler(fnFunction, oListener?, name: string = DEFAULT_RANGE_SET) { |
321 | | - deprecationNotice( |
322 | | - 'Device.media.attachHandler', |
323 | | - `Accessing 'Device.media.attachHandler' is deprecated and will be removed in the next major version. |
324 | | - Please use 'attachHandler' ('import { attachHandler } from '@ui5/webcomponents-react-base/lib/Media') instead.` |
325 | | - ); |
326 | | - return attachHandler(fnFunction, oListener, name); |
327 | | - } |
328 | | - |
329 | | - public detachHandler(fnFunction, oListener?, name: string = DEFAULT_RANGE_SET) { |
330 | | - deprecationNotice( |
331 | | - 'Device.media.detachHandler', |
332 | | - `Accessing 'Device.media.detachHandler' is deprecated and will be removed in the next major version. |
333 | | - Please use 'detachHandler' ('import { detachHandler } from '@ui5/webcomponents-react-base/lib/Media') instead.` |
334 | | - ); |
335 | | - return detachHandler(fnFunction, oListener, name); |
336 | | - } |
337 | | - |
338 | | - // Private API |
339 | | - private static getRangeInfo = getRangeInfo; |
340 | | - private checkQueries = checkQueries; |
341 | | - private handleChange = handleChange; |
342 | | - matches = matches; |
343 | | -} |
0 commit comments