Skip to content

Commit

Permalink
Widget: remove excess typing file
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeniyKiyashko committed Dec 24, 2024
1 parent b26f849 commit 31c1226
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 103 deletions.
9 changes: 5 additions & 4 deletions packages/devextreme/js/__internal/core/widget/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class Component<

_createActionByOption(
optionName: string,
config: Record<string, unknown>,
config?: Record<string, unknown>,
): (event?: Record<string, unknown>) => void {
// eslint-disable-next-line @typescript-eslint/init-declarations
let action;
Expand Down Expand Up @@ -406,15 +406,16 @@ export class Component<
actionFunc = this.option(optionName);
}

if (!action && !actionFunc && !config.beforeExecute
&& !config.afterExecute && !this._eventsStrategy.hasEvent(eventName)) {
if (!action && !actionFunc && !config?.beforeExecute
&& !config?.afterExecute && !this._eventsStrategy.hasEvent(eventName)) {
return;
}

if (!action) {
// @ts-expect-error
const { beforeExecute } = config;
// @ts-expect-error
config.beforeExecute = (...props): void => {
// @ts-expect-error
// eslint-disable-next-line max-len
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain, @typescript-eslint/no-unused-expressions
beforeExecute && beforeExecute.apply(this, props);
Expand Down
2 changes: 1 addition & 1 deletion packages/devextreme/js/__internal/core/widget/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Widget<

private readonly _activeStateUnit!: string;

private _keyboardListenerId?: string | null;
public _keyboardListenerId?: string | null;

private _isReady?: boolean;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { DefaultOptionsRule } from '@js/core/options/utils';
import $ from '@js/core/renderer';
import type { ButtonStyle, ButtonType, ClickEvent } from '@js/ui/button';
import Button from '@js/ui/button';
import { isFluent, isMaterial } from '@js/ui/themes';
import type { WidgetOptions } from '@js/ui/widget/ui.widget';

import Widget from '../widget';
import Widget from '@ts/core/widget/widget';

const CALENDAR_NAVIGATOR_CLASS = 'dx-calendar-navigator';
const CALENDAR_NAVIGATOR_PREVIOUS_MONTH_CLASS = 'dx-calendar-navigator-previous-month';
Expand All @@ -24,9 +24,9 @@ export interface NavigatorOptions extends WidgetOptions<Navigator> {
}

class Navigator extends Widget<NavigatorOptions> {
_clickAction?: any;
_clickAction?: ((event: { direction: number; event: ClickEvent }) => void) | null;

_captionClickAction?: any;
_captionClickAction?: ((event: { event: ClickEvent }) => void) | null;

_prevButton!: Button;

Expand All @@ -45,7 +45,7 @@ class Navigator extends Widget<NavigatorOptions> {
};
}

_defaultOptionsRules(): Record<string, unknown>[] {
_defaultOptionsRules(): DefaultOptionsRule<NavigatorOptions>[] {
return super._defaultOptionsRules().concat([
{
device() {
Expand Down Expand Up @@ -103,10 +103,9 @@ class Navigator extends Widget<NavigatorOptions> {
{
focusStateEnabled,
icon: rtlEnabled ? 'chevronright' : 'chevronleft',
onClick: (e) => { this._clickAction({ direction: -direction, event: e }); },
onClick: (e) => { this._clickAction?.({ direction: -direction, event: e }); },
type,
stylingMode,
// @ts-expect-error
integrationOptions: {},
},
);
Expand All @@ -121,10 +120,9 @@ class Navigator extends Widget<NavigatorOptions> {
{
focusStateEnabled,
icon: rtlEnabled ? 'chevronleft' : 'chevronright',
onClick: (e) => { this._clickAction({ direction, event: e }); },
onClick: (e) => { this._clickAction?.({ direction, event: e }); },
type,
stylingMode,
// @ts-expect-error
integrationOptions: {},
},
);
Expand All @@ -138,7 +136,7 @@ class Navigator extends Widget<NavigatorOptions> {
Button,
{
focusStateEnabled,
onClick: (e) => { this._captionClickAction({ event: e }); },
onClick: (e) => { this._captionClickAction?.({ event: e }); },
type,
stylingMode,
template: (_, content) => {
Expand All @@ -152,19 +150,22 @@ class Navigator extends Widget<NavigatorOptions> {
.append($('<span>').addClass(BUTTON_TEXT_CLASS).text(captionText));
});
},
// @ts-expect-error
integrationOptions: {},
},
);

const $caption = this._caption.$element();

// @ts-expect-error
this.$element().append($prevButton, $caption, $nextButton);
this.$element()
.append($prevButton)
.append($caption)
.append($nextButton);
}

_renderCaption(): void {
this._caption?.option('text', this.option('text'));
const { text } = this.option();

this._caption?.option('text', text);
}

toggleButton(
Expand Down
3 changes: 1 addition & 2 deletions packages/devextreme/js/__internal/ui/collection/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type { DataSource } from '@js/common/data';
import type { dxElementWrapper } from '@js/core/renderer';
import type { CollectionWidgetOptions, ItemLike } from '@js/ui/collection/ui.collection_widget.base';
import CollectionWidget from '@js/ui/collection/ui.collection_widget.base';

import Widget from '../widget';
import Widget from '@ts/core/widget/widget';

export interface TypedCollectionWidgetOptions<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class ContextMenu extends MenuBase {
return super._defaultOptionsRules().concat([{
device: () => !hasWindow(),
options: {
// @ts-expect-error
animation: null,
},
}]);
Expand All @@ -143,7 +144,7 @@ class ContextMenu extends MenuBase {
});
}

_initActions() {
_initActions(): void {
this._actions = {};

each(ACTIONS, (index, action) => {
Expand Down Expand Up @@ -348,14 +349,14 @@ class ContextMenu extends MenuBase {

_initMarkup(): void {
this.$element()
// @ts-expect-error
.addClass(DX_HAS_CONTEXT_MENU_CLASS);

super._initMarkup();
}

_render(): void {
super._render();
// @ts-expect-error
this._renderVisibility(this.option('visible'));
this._addWidgetClass();
}
Expand Down Expand Up @@ -464,7 +465,6 @@ class ContextMenu extends MenuBase {
}

const eventName = addNamespace(showEvent, this.NAME);
// @ts-expect-error
let contextMenuAction = this._createAction((e) => {
// @ts-expect-error
const delay = this.getShowDelay(this.option('showEvent'));
Expand All @@ -480,7 +480,7 @@ class ContextMenu extends MenuBase {
const handler = (e) => contextMenuAction({ event: e, target: $(e.currentTarget) });
// @ts-expect-error
contextMenuAction = this._createAction(contextMenuAction);

// @ts-expect-error
if (isRenderer(target) || target.nodeType || isWindow(target)) {
this._showContextMenuEventHandler = undefined;
eventsEngine.on(target, eventName, handler);
Expand Down Expand Up @@ -571,7 +571,7 @@ class ContextMenu extends MenuBase {
onHidden: this._overlayHiddenActionHandler.bind(this),
visualContainer: window,
};

// @ts-expect-error
return overlayOptions;
}

Expand Down Expand Up @@ -614,7 +614,7 @@ class ContextMenu extends MenuBase {
const $activeItemContainer = this._getActiveItemsContainer(e.target);
const $itemContainers = this._getItemsContainers();
const $clickedItem = this._searchActiveItem(e.target);
// @ts-expect-error

const $rootItem = this.$element().parents(`.${DX_MENU_ITEM_CLASS}`);
const isRootItemClicked = $clickedItem[0] === $rootItem[0] && $clickedItem.length && $rootItem.length;
const isInnerOverlayClicked = this._isIncludeOverlay($activeItemContainer, $itemContainers) && $clickedItem.length;
Expand Down Expand Up @@ -803,7 +803,6 @@ class ContextMenu extends MenuBase {

if (animation) {
if (isPlainObject(animation.to)) {
// @ts-expect-error
animation.to.position = submenuPosition;
}
this._animate($submenu, animation);
Expand Down Expand Up @@ -1006,6 +1005,7 @@ class ContextMenu extends MenuBase {
this._overlay.$content().addClass(this._widgetClass());
this._renderFocusState();
this._attachHoverEvents();
// @ts-expect-error
this._attachClickEvent();
this._renderItems(this._dataAdapter.getRootNodes());
}
Expand Down Expand Up @@ -1147,7 +1147,6 @@ class ContextMenu extends MenuBase {
}
}

// @ts-expect-error
registerComponent('dxContextMenu', ContextMenu);

export default ContextMenu;
17 changes: 10 additions & 7 deletions packages/devextreme/js/__internal/ui/context_menu/m_menu_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ const DX_MENU_ITEM_CAPTION_URL_CLASS = `${DX_MENU_ITEM_CAPTION_CLASS}-with-url`;
const DX_ICON_WITH_URL_CLASS = 'dx-icon-with-url';
const ITEM_URL_CLASS = 'dx-item-url';

// @ts-expect-error
export type Properties = dxMenuBaseOptions<MenuBase, Item>;

class MenuBase extends HierarchicalCollectionWidget<Properties> {
static ItemClass = MenuItem;

_editStrategy?: MenuBaseEditStrategy;

_activeStateUnit?: string;

hasIcons?: boolean;

_inkRipple?: {
Expand Down Expand Up @@ -139,11 +138,14 @@ class MenuBase extends HierarchicalCollectionWidget<Properties> {
});
}

_isSelectionEnabled() {
return this.option('selectionMode') === SINGLE_SELECTION_MODE;
_isSelectionEnabled(): boolean {
const { selectionMode } = this.option();

return selectionMode === SINGLE_SELECTION_MODE;
}

_init() {
_init(): void {
// @ts-expect-error
this._activeStateUnit = `.${ITEM_CLASS}`;
super._init();
this._renderSelectedItem();
Expand Down Expand Up @@ -285,7 +287,7 @@ class MenuBase extends HierarchicalCollectionWidget<Properties> {
_getShowSubmenuMode() {
const defaultValue = 'onClick';
let optionValue = this.option('showSubmenuMode');

// @ts-expect-error
optionValue = isObject(optionValue) ? optionValue.name : optionValue;

return this._isDesktopDevice() ? optionValue : defaultValue;
Expand Down Expand Up @@ -318,7 +320,7 @@ class MenuBase extends HierarchicalCollectionWidget<Properties> {
if (!$itemElement || this._isItemDisabled($itemElement)) return;

e.stopPropagation();

// @ts-expect-error
if (this._getShowSubmenuMode() === 'onHover') {
clearTimeout(this._showSubmenusTimeout);
this._showSubmenusTimeout = setTimeout(this._showSubmenu.bind(this, $itemElement), this._getSubmenuDelay('show'));
Expand Down Expand Up @@ -557,6 +559,7 @@ class MenuBase extends HierarchicalCollectionWidget<Properties> {
const itemClickActionHandler = this._createAction(this._updateSubmenuVisibilityOnClick.bind(this));
this._itemDXEventHandler(e, 'onItemClick', {}, {
beforeExecute: this._itemClick,
// @ts-expect-error
afterExecute: itemClickActionHandler.bind(this),
});
e._skipHandling = true;
Expand Down
7 changes: 0 additions & 7 deletions packages/devextreme/js/__internal/ui/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import type ValidationMessage from '@js/ui/validation_message';

import Widget from './widget';

// interface AriaOptions {
// role: string;
// // eslint-disable-next-line spellcheck/spell-checker
// roledescription: string;
// label: string;
// }

declare class ExtendedEditor<TProperties> extends Widget<TProperties> {
public _validationMessage?: ValidationMessage;

Expand Down
Loading

0 comments on commit 31c1226

Please sign in to comment.