Skip to content

Commit

Permalink
Fix no-unsafe-call & fix component typing
Browse files Browse the repository at this point in the history
  • Loading branch information
mkszepp committed Feb 16, 2025
1 parent 2adcfac commit 2baf4e6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
3 changes: 0 additions & 3 deletions ember-basic-dropdown/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ export default ts.config(
parserOptions: parserOptions.esm.ts,
},
extends: [...ts.configs.recommendedTypeChecked, ember.configs.gts],
rules: {
'@typescript-eslint/no-unsafe-call': 'off',
},
},
{
files: ['src/**/*'],
Expand Down
26 changes: 20 additions & 6 deletions ember-basic-dropdown/src/components/basic-dropdown-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,17 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
}

window.addEventListener('resize', this.runloopAwareRepositionBound);
window.addEventListener('orientationchange', this.runloopAwareRepositionBound);
window.addEventListener(
'orientationchange',
this.runloopAwareRepositionBound,
);

if (this.isTouchDevice) {
document.addEventListener('touchstart', this.touchStartHandlerBound, true);
document.addEventListener(
'touchstart',
this.touchStartHandlerBound,
true,
);
document.addEventListener('touchend', this.handleRootMouseDown, true);

if (rootElement) {
Expand Down Expand Up @@ -376,7 +383,11 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
this._contentWormhole.getRootNode() instanceof ShadowRoot
) {
const rootElement = this._contentWormhole.getRootNode() as HTMLElement;
rootElement.addEventListener('touchmove', this.touchMoveHandlerBound, true);
rootElement.addEventListener(
'touchmove',
this.touchMoveHandlerBound,
true,
);
}
}

Expand All @@ -390,7 +401,11 @@ export default class BasicDropdownContent extends Component<BasicDropdownContent
this._contentWormhole.getRootNode() instanceof ShadowRoot
) {
const rootElement = this._contentWormhole.getRootNode() as HTMLElement;
rootElement.removeEventListener('touchmove', this.touchMoveHandlerBound, true);
rootElement.removeEventListener(
'touchmove',
this.touchMoveHandlerBound,
true,
);
}
}

Expand Down Expand Up @@ -577,8 +592,7 @@ function closestContent(el: Element): Element | null {
return el;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
function waitForAnimations(element: Element, callback: Function): void {
function waitForAnimations(element: Element, callback: () => void): void {
window.requestAnimationFrame(function () {
const computedStyle = window.getComputedStyle(element);
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class BasicDropdownWormholeComponent extends Component<BasicDropd
get getDestinationId(): string {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const config = getOwner(this).resolveRegistration('config:environment') as {
'ember-basic-dropdown'?: {
destination?: string;
Expand Down
25 changes: 13 additions & 12 deletions ember-basic-dropdown/src/components/basic-dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ export interface BasicDropdownArgs {
rootEventType?: TRootEventType;
preventScroll?: boolean;
matchTriggerWidth?: boolean;
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
onInit?: Function;
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
registerAPI?: Function;
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
onOpen?: Function;
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
onClose?: Function;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
triggerComponent?: string | ComponentLike<any> | undefined;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
contentComponent?: string | ComponentLike<any> | undefined;
onInit?: (dropdown: Dropdown) => void;
registerAPI?: (dropdown: Dropdown | null) => void;
onOpen?: (dropdown: Dropdown, e?: Event) => boolean | void;
onClose?: (dropdown: Dropdown, e?: Event) => boolean | void;
triggerComponent?:
| string
| ComponentLike<BasicDropdownTriggerSignature>
| undefined;
contentComponent?:
| string
| ComponentLike<BasicDropdownContentSignature>
| undefined;
calculatePosition?: CalculatePosition;
}

Expand Down Expand Up @@ -394,6 +394,7 @@ export default class BasicDropdown extends Component<BasicDropdownSignature> {
_getDestinationId(): string {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const config = getOwner(this).resolveRegistration('config:environment') as {
environment: string;
APP: {
Expand Down
15 changes: 12 additions & 3 deletions ember-basic-dropdown/src/modifiers/basic-dropdown-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,18 @@ function cleanup(instance: DropdownTriggerModifier) {
}

triggerElement.removeEventListener('click', instance.handleMouseEventBound);
triggerElement.removeEventListener('mousedown', instance.handleMouseEventBound);
triggerElement.removeEventListener(
'mousedown',
instance.handleMouseEventBound,
);
triggerElement.removeEventListener('keydown', instance.handleKeyDownBound);
triggerElement.removeEventListener('touchstart', instance.handleTouchStartBound);
triggerElement.removeEventListener('touchend', instance.handleTouchEndBound);
triggerElement.removeEventListener(
'touchstart',
instance.handleTouchStartBound,
);
triggerElement.removeEventListener(
'touchend',
instance.handleTouchEndBound,
);
}
}

0 comments on commit 2baf4e6

Please sign in to comment.