Skip to content

Commit

Permalink
feat(esl-popup): update imports, move separate window helpers, remove…
Browse files Browse the repository at this point in the history
… unnecessary code
  • Loading branch information
dshovchko committed Jul 28, 2021
1 parent a4d25f9 commit f198295
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 118 deletions.
4 changes: 2 additions & 2 deletions src/modules/esl-popup/core/calcPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface ElementRect extends ObjectRect {
cy: number;
}

export interface IntersetionRatioRect {
export interface IntersectionRatioRect {
top?: number;
left?: number;
right?: number;
Expand All @@ -39,7 +39,7 @@ export interface IntersetionRatioRect {
export interface PopupPositionConfig {
position: PositionType;
behavior: string;
intersectionRatio: IntersetionRatioRect,
intersectionRatio: IntersectionRatioRect,
element: DOMRect;
inner: ElementRect;
outer: ObjectRect;
Expand Down
41 changes: 6 additions & 35 deletions src/modules/esl-popup/core/esl-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {bind} from '../../esl-utils/decorators/bind';
import {prop} from '../../esl-utils/decorators/prop';
import {rafDecorator} from '../../esl-utils/async/raf';
import {ESLToggleable} from '../../esl-toggleable/core';

import {listScrollParents} from './listScrollParents';
import {getListScrollParents} from '../../esl-utils/dom/scroll';
import {getWindowRect} from '../../esl-utils/dom/window';
import {calcPopupPosition, resizeRect} from './calcPosition';

import type {ToggleableActionParams} from '../../esl-toggleable/core';
import type {PositionType, IntersetionRatioRect} from './calcPosition';
import type {PositionType, IntersectionRatioRect} from './calcPosition';

const INTERSECTION_LIMIT_FOR_ADJACENT_AXIS = 0.7;

Expand Down Expand Up @@ -39,7 +39,7 @@ export class ESLPopup extends ESLToggleable {
protected _offsetWindow: number;
protected _deferredUpdatePosition = rafDecorator(() => this._updatePosition());
protected _activatorObserver: ActivatorObserver;
protected _intersectionRatio: IntersetionRatioRect = {};
protected _intersectionRatio: IntersectionRatioRect = {};

@attr({defaultValue: 'top'}) public position: PositionType;
@attr({defaultValue: 'fit'}) public behavior: string;
Expand Down Expand Up @@ -82,35 +82,6 @@ export class ESLPopup extends ESLToggleable {
return ['top', 'bottom'].includes(this.position);
}

// TODO: move to utilities
protected get _windowWidth() {
// return document.documentElement.clientWidth || document.body.clientWidth;
return window.innerWidth || document.documentElement.clientWidth;
}

protected get _windowHeight() {
return window.innerHeight || document.documentElement.clientHeight;
}

protected get _windowBottom() {
return window.pageYOffset + this._windowHeight;
}

protected get _windowRight() {
return window.pageXOffset + this._windowWidth;
}

protected get _windowRect() {
return {
top: window.pageYOffset + this._offsetWindow,
left: window.pageXOffset + this._offsetWindow,
right: this._windowRight - this._offsetWindow,
bottom: this._windowBottom - this._offsetWindow,
height: this._windowHeight,
width: this._windowWidth
};
}

public onShow(params: PopupActionParams) {
super.onShow(params);

Expand Down Expand Up @@ -172,7 +143,7 @@ export class ESLPopup extends ESLToggleable {
}

protected _addActivatorObserver(target: HTMLElement) {
const scrollParents = listScrollParents(target);
const scrollParents = getListScrollParents(target);

const unsubscribers = scrollParents.map(($root) => {
const options = {passive: true} as EventListenerOptions;
Expand Down Expand Up @@ -238,7 +209,7 @@ export class ESLPopup extends ESLToggleable {
element: popupRect,
trigger,
inner: resizeRect(trigger, innerMargin),
outer: resizeRect(this._windowRect, -this._offsetWindow)
outer: resizeRect(getWindowRect(), -this._offsetWindow)
};

const {left, top, arrow} = calcPopupPosition(config);
Expand Down
5 changes: 0 additions & 5 deletions src/modules/esl-popup/core/getComputedStyle.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/modules/esl-popup/core/getDocumentElement.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/modules/esl-popup/core/getNodeName.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/modules/esl-popup/core/getParentNode.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/modules/esl-popup/core/getScrollParent.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/modules/esl-popup/core/getWindow.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/modules/esl-popup/core/isScrollParent.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/modules/esl-popup/core/listScrollParents.ts

This file was deleted.

0 comments on commit f198295

Please sign in to comment.