From b16e6a3f9fc4b0962a8c997f1ec047e1659098bb Mon Sep 17 00:00:00 2001 From: Chintan Kavathia Date: Mon, 11 Nov 2024 18:13:01 +0530 Subject: [PATCH] refactor: remove useless utils BREAKING CHANGE: removed polyfill for `elementsFromPoint` since `elementsFromPoint` is now supported by all major browsers. --- projects/ngx-datatable/src/lib/events.ts | 8 ---- .../src/lib/utils/elm-from-point.ts | 45 ------------------- .../src/lib/utils/facade/browser.ts | 25 ----------- .../src/lib/utils/visibility-observer.ts | 24 ---------- projects/ngx-datatable/src/public-api.ts | 1 - 5 files changed, 103 deletions(-) delete mode 100644 projects/ngx-datatable/src/lib/events.ts delete mode 100644 projects/ngx-datatable/src/lib/utils/elm-from-point.ts delete mode 100644 projects/ngx-datatable/src/lib/utils/facade/browser.ts delete mode 100644 projects/ngx-datatable/src/lib/utils/visibility-observer.ts diff --git a/projects/ngx-datatable/src/lib/events.ts b/projects/ngx-datatable/src/lib/events.ts deleted file mode 100644 index 83664a030..000000000 --- a/projects/ngx-datatable/src/lib/events.ts +++ /dev/null @@ -1,8 +0,0 @@ -declare let global: any; - -export const MouseEvent = (((typeof window !== 'undefined' && window) as any) || (global as any)) - .MouseEvent as MouseEvent; -export const KeyboardEvent = (((typeof window !== 'undefined' && window) as any) || (global as any)) - .KeyboardEvent as KeyboardEvent; -export const Event = (((typeof window !== 'undefined' && window) as any) || (global as any)) - .Event as Event; diff --git a/projects/ngx-datatable/src/lib/utils/elm-from-point.ts b/projects/ngx-datatable/src/lib/utils/elm-from-point.ts deleted file mode 100644 index d86a08b67..000000000 --- a/projects/ngx-datatable/src/lib/utils/elm-from-point.ts +++ /dev/null @@ -1,45 +0,0 @@ -if (typeof document !== 'undefined' && !document.elementsFromPoint) { - document.elementsFromPoint = elementsFromPoint; -} - -/** - * Polyfill for `elementsFromPoint` - * - * https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint - * https://gist.github.com/iddan/54d5d9e58311b0495a91bf06de661380 - * https://gist.github.com/oslego/7265412 - */ -export function elementsFromPoint(x: number, y: number) { - const elements = []; - const previousPointerEvents = []; - let current: any; // TODO: window.getComputedStyle should be used with inferred type (Element) - let i; - let d; - - //if (document === undefined) return elements; - - // get all elements via elementFromPoint, and remove them from hit-testing in order - while ( - (current = document.elementFromPoint(x, y)) && - elements.indexOf(current) === -1 && - current != null - ) { - // push the element and its current style - elements.push(current); - previousPointerEvents.push({ - value: current.style.getPropertyValue('pointer-events'), - priority: current.style.getPropertyPriority('pointer-events') - }); - - // add "pointer-events: none", to get to the underlying element - current.style.setProperty('pointer-events', 'none', 'important'); - } - - // restore the previous pointer-events values - for (i = previousPointerEvents.length; (d = previousPointerEvents[--i]); ) { - elements[i].style.setProperty('pointer-events', d.value ? d.value : '', d.priority); - } - - // return our results - return elements; -} diff --git a/projects/ngx-datatable/src/lib/utils/facade/browser.ts b/projects/ngx-datatable/src/lib/utils/facade/browser.ts deleted file mode 100644 index e23b7f92c..000000000 --- a/projects/ngx-datatable/src/lib/utils/facade/browser.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -/** - * JS version of browser APIs. This library can only run in the browser. - */ -const win = (typeof window !== 'undefined' && window) || ({} as any); - -export { win as window }; -export const document = win.document; -export const location = win.location; -export const gc = win.gc ? () => win.gc() : (): any => null; -export const performance = win.performance ? win.performance : null; -export const Event = win.Event; -export const MouseEvent = win.MouseEvent; -export const KeyboardEvent = win.KeyboardEvent; -export const EventTarget = win.EventTarget; -export const History = win.History; -export const Location = win.Location; -export const EventListener = win.EventListener; diff --git a/projects/ngx-datatable/src/lib/utils/visibility-observer.ts b/projects/ngx-datatable/src/lib/utils/visibility-observer.ts deleted file mode 100644 index 773f3e7f7..000000000 --- a/projects/ngx-datatable/src/lib/utils/visibility-observer.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { NgZone } from '@angular/core'; - -export function checkVisibility(element: any, callback: any, zone: NgZone) { - let timeout: any; - - function check() { - // https://davidwalsh.name/offsetheight-visibility - const { offsetHeight, offsetWidth } = element; - - if (offsetHeight && offsetWidth) { - clearTimeout(timeout); - if (callback) { - zone.run(() => callback()); - } - } else { - clearTimeout(timeout); - zone.runOutsideAngular(() => { - timeout = setTimeout(() => check(), 50); - }); - } - } - - check(); -} diff --git a/projects/ngx-datatable/src/public-api.ts b/projects/ngx-datatable/src/public-api.ts index b96833789..876bb569f 100644 --- a/projects/ngx-datatable/src/public-api.ts +++ b/projects/ngx-datatable/src/public-api.ts @@ -58,5 +58,4 @@ export * from './lib/utils/throttle'; export * from './lib/utils/sort'; export * from './lib/utils/row-height-cache'; export * from './lib/utils/column-helper'; -export * from './lib/utils/elm-from-point'; export * from './lib/utils/tree';