diff --git a/packages/checkbox/test/typings/checkbox.types.ts b/packages/checkbox/test/typings/checkbox.types.ts index 2d24cc8c9a..5da64b4388 100644 --- a/packages/checkbox/test/typings/checkbox.types.ts +++ b/packages/checkbox/test/typings/checkbox.types.ts @@ -1,8 +1,11 @@ -import { ActiveMixin } from '@vaadin/component-base/src/active-mixin.js'; -import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; -import { CheckedMixin } from '@vaadin/field-base/src/checked-mixin.js'; -import { DelegateFocusMixin } from '@vaadin/field-base/src/delegate-focus-mixin.js'; -import { SlotLabelMixin } from '@vaadin/field-base/src/slot-label-mixin.js'; +import { ActiveMixinClass } from '@vaadin/component-base/src/active-mixin.js'; +import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js'; +import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js'; +import { CheckedMixinClass } from '@vaadin/field-base/src/checked-mixin.js'; +import { DelegateFocusMixinClass } from '@vaadin/field-base/src/delegate-focus-mixin.js'; +import { LabelMixinClass } from '@vaadin/field-base/src/label-mixin.js'; import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; import '../../vaadin-checkbox.js'; import { CheckboxCheckedChangedEvent, CheckboxIndeterminateChangedEvent } from '../../vaadin-checkbox.js'; @@ -21,11 +24,14 @@ assertType(checkbox.name); assertType(checkbox.value); // Mixins -assertType(checkbox); -assertType(checkbox); -assertType(checkbox); -assertType(checkbox); -assertType(checkbox); +assertType(checkbox); +assertType(checkbox); +assertType(checkbox); +assertType(checkbox); +assertType(checkbox); +assertType(checkbox); +assertType(checkbox); +assertType(checkbox); assertType(checkbox); // Events diff --git a/packages/combo-box/package.json b/packages/combo-box/package.json index d7b772714b..0107e3f393 100644 --- a/packages/combo-box/package.json +++ b/packages/combo-box/package.json @@ -31,6 +31,7 @@ "polymer" ], "dependencies": { + "@open-wc/dedupe-mixin": "^1.3.0", "@polymer/iron-resizable-behavior": "^3.0.0", "@polymer/polymer": "^3.0.0", "@vaadin/component-base": "22.0.0-beta1", diff --git a/packages/combo-box/src/vaadin-combo-box-data-provider-mixin.d.ts b/packages/combo-box/src/vaadin-combo-box-data-provider-mixin.d.ts index 9265e52e3d..f8c9bbcdb8 100644 --- a/packages/combo-box/src/vaadin-combo-box-data-provider-mixin.d.ts +++ b/packages/combo-box/src/vaadin-combo-box-data-provider-mixin.d.ts @@ -3,6 +3,7 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; export type ComboBoxDataProviderCallback = (items: Array, size: number) => void; @@ -17,15 +18,11 @@ export type ComboBoxDataProvider = ( callback: ComboBoxDataProviderCallback ) => void; -declare function ComboBoxDataProviderMixin {}>( +export declare function ComboBoxDataProviderMixin>( base: T -): T & ComboBoxDataProviderMixinConstructor; +): T & Constructor>; -interface ComboBoxDataProviderMixinConstructor { - new (...args: any[]): ComboBoxDataProviderMixin; -} - -interface ComboBoxDataProviderMixin { +export declare class ComboBoxDataProviderMixinClass { /** * Number of items fetched at a time from the dataprovider. * @attr {number} page-size @@ -57,5 +54,3 @@ interface ComboBoxDataProviderMixin { */ clearCache(): void; } - -export { ComboBoxDataProviderMixin, ComboBoxDataProviderMixinConstructor }; diff --git a/packages/combo-box/src/vaadin-combo-box-light.d.ts b/packages/combo-box/src/vaadin-combo-box-light.d.ts index f04098cdbc..ace0172a57 100644 --- a/packages/combo-box/src/vaadin-combo-box-light.d.ts +++ b/packages/combo-box/src/vaadin-combo-box-light.d.ts @@ -4,8 +4,8 @@ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; -import { ComboBoxMixin } from './vaadin-combo-box-mixin.js'; -import { ComboBoxDataProviderMixin } from './vaadin-combo-box-data-provider-mixin.js'; +import { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-provider-mixin.js'; +import { ComboBoxMixinClass } from './vaadin-combo-box-mixin.js'; import { ComboBoxDefaultItem } from './vaadin-combo-box-mixin.js'; export { ComboBoxDataProvider, @@ -125,8 +125,8 @@ declare class ComboBoxLight extends HTMLElement { } interface ComboBoxLight - extends ComboBoxDataProviderMixin, - ComboBoxMixin, + extends ComboBoxDataProviderMixinClass, + ComboBoxMixinClass, ThemableMixin {} declare global { diff --git a/packages/combo-box/src/vaadin-combo-box-mixin.d.ts b/packages/combo-box/src/vaadin-combo-box-mixin.d.ts index df3d5a8d03..c684756835 100644 --- a/packages/combo-box/src/vaadin-combo-box-mixin.d.ts +++ b/packages/combo-box/src/vaadin-combo-box-mixin.d.ts @@ -3,9 +3,10 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js'; -import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js'; -import { InputMixin } from '@vaadin/field-base/src/input-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js'; +import { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js'; import { ComboBox } from './vaadin-combo-box.js'; export type ComboBoxDefaultItem = any; @@ -21,16 +22,22 @@ export type ComboBoxRenderer = ( model: ComboBoxItemModel ) => void; -declare function ComboBoxMixin {}>( +export declare function ComboBoxMixin>( base: T -): T & ComboBoxMixinConstructor; +): T & + Constructor> & + Constructor & + Constructor & + Constructor; -interface ComboBoxMixinConstructor { - new (...args: any[]): ComboBoxMixin; -} +export declare class ComboBoxMixinClass { + protected readonly _propertyForValue: string; + + protected _inputElementValue: string | undefined; -interface ComboBoxMixin extends DisabledMixin, InputMixin, KeyboardMixin { - readonly _propertyForValue: string; + protected _revertInputValue(): void; + + protected _getItemElements(): HTMLElement[]; /** * True if the dropdown is open, false otherwise. @@ -173,5 +180,3 @@ interface ComboBoxMixin extends DisabledMixin, InputMixin, KeyboardMixin */ checkValidity(): boolean; } - -export { ComboBoxMixin, ComboBoxMixinConstructor }; diff --git a/packages/combo-box/src/vaadin-combo-box.d.ts b/packages/combo-box/src/vaadin-combo-box.d.ts index d6c4ee60f9..29be14be55 100644 --- a/packages/combo-box/src/vaadin-combo-box.d.ts +++ b/packages/combo-box/src/vaadin-combo-box.d.ts @@ -3,12 +3,12 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; -import { InputControlMixin } from '@vaadin/field-base/src/input-control-mixin.js'; -import { PatternMixin } from '@vaadin/field-base/src/pattern-mixin.js'; +import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js'; +import { InputControlMixinClass } from '@vaadin/field-base/src/input-control-mixin.js'; +import { PatternMixinClass } from '@vaadin/field-base/src/pattern-mixin.js'; import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; -import { ComboBoxDataProviderMixin } from './vaadin-combo-box-data-provider-mixin.js'; -import { ComboBoxMixin } from './vaadin-combo-box-mixin.js'; +import { ComboBoxDataProviderMixinClass } from './vaadin-combo-box-data-provider-mixin.js'; +import { ComboBoxMixinClass } from './vaadin-combo-box-mixin.js'; import { ComboBoxDefaultItem } from './vaadin-combo-box-mixin.js'; export { ComboBoxDataProvider, @@ -220,12 +220,12 @@ declare class ComboBox extends HTMLElement { } interface ComboBox - extends ComboBoxDataProviderMixin, - ComboBoxMixin, - PatternMixin, - InputControlMixin, + extends ComboBoxDataProviderMixinClass, + ComboBoxMixinClass, + PatternMixinClass, + InputControlMixinClass, ThemableMixin, - ElementMixin {} + ElementMixinClass {} declare global { interface HTMLElementTagNameMap { diff --git a/packages/combo-box/test/typings/combo-box.types.ts b/packages/combo-box/test/typings/combo-box.types.ts index 2549fb3657..9da8074a1d 100644 --- a/packages/combo-box/test/typings/combo-box.types.ts +++ b/packages/combo-box/test/typings/combo-box.types.ts @@ -1,7 +1,7 @@ -import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; +import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js'; import { ThemableMixin } from '@vaadin/vaadin-themable-mixin'; -import { ComboBoxDataProviderMixin } from '../../src/vaadin-combo-box-data-provider-mixin'; -import { ComboBoxMixin } from '../../src/vaadin-combo-box-mixin'; +import { ComboBoxDataProviderMixinClass } from '../../src/vaadin-combo-box-data-provider-mixin'; +import { ComboBoxMixinClass } from '../../src/vaadin-combo-box-mixin'; import { ComboBoxFilterChangedEvent, ComboBoxInvalidChangedEvent, @@ -32,8 +32,9 @@ const genericComboBox = document.createElement('vaadin-combo-box'); const narrowedComboBox = genericComboBox as ComboBox; assertType(narrowedComboBox); -assertType(narrowedComboBox); -assertType>(narrowedComboBox); +assertType(narrowedComboBox); +assertType>(narrowedComboBox); +assertType>(narrowedComboBox); assertType(narrowedComboBox); narrowedComboBox.addEventListener('custom-value-set', (event) => { @@ -71,8 +72,8 @@ const genericComboBoxLightElement = document.createElement('vaadin-combo-box-lig assertType(genericComboBoxLightElement); const narrowedComboBoxLightElement = genericComboBoxLightElement as ComboBoxLight; -assertType>(narrowedComboBoxLightElement); -assertType>(narrowedComboBoxLightElement); +assertType>(narrowedComboBoxLightElement); +assertType>(narrowedComboBoxLightElement); assertType(narrowedComboBoxLightElement); narrowedComboBoxLightElement.addEventListener('custom-value-set', (event) => { diff --git a/packages/component-base/package.json b/packages/component-base/package.json index 9f4cb7a96b..e1f38cd05b 100644 --- a/packages/component-base/package.json +++ b/packages/component-base/package.json @@ -30,6 +30,7 @@ "web-component" ], "dependencies": { + "@open-wc/dedupe-mixin": "^1.3.0", "@polymer/polymer": "^3.0.0", "@vaadin/vaadin-development-mode-detector": "^2.0.0", "@vaadin/vaadin-usage-statistics": "^2.1.0", diff --git a/packages/component-base/src/active-mixin.d.ts b/packages/component-base/src/active-mixin.d.ts index 3ff4075b33..6868fd290a 100644 --- a/packages/component-base/src/active-mixin.d.ts +++ b/packages/component-base/src/active-mixin.d.ts @@ -3,8 +3,9 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { DisabledMixin } from './disabled-mixin.js'; -import { KeyboardMixin } from './keyboard-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from './disabled-mixin.js'; +import { KeyboardMixinClass } from './keyboard-mixin.js'; /** * A mixin to toggle the `active` attribute. @@ -15,12 +16,26 @@ import { KeyboardMixin } from './keyboard-mixin.js'; * The attribute is removed as soon as the element is deactivated * by the pointer or by releasing the activation key. */ -declare function ActiveMixin {}>(base: T): T & ActiveMixinConstructor; +export declare const ActiveMixin: >( + base: T +) => T & Constructor & Constructor & Constructor; -interface ActiveMixinConstructor { - new (...args: any[]): ActiveMixin; -} +export declare class ActiveMixinClass { + /** + * An array of activation keys. + * + * See possible values here: + * https://developer.mozilla.org/ru/docs/Web/API/KeyboardEvent/key/Key_Values + */ + protected readonly _activeKeys: string[]; -interface ActiveMixin extends DisabledMixin, KeyboardMixin {} + /** + * Override to define if the component needs to be activated. + */ + protected _shouldSetFocus(event: KeyboardEvent | MouseEvent): boolean; -export { ActiveMixinConstructor, ActiveMixin }; + /** + * Toggles the `active` attribute on the element. + */ + protected _setActive(active: boolean): void; +} diff --git a/packages/component-base/src/dir-mixin.d.ts b/packages/component-base/src/dir-mixin.d.ts index 056f0057b9..a8f583cbaa 100644 --- a/packages/component-base/src/dir-mixin.d.ts +++ b/packages/component-base/src/dir-mixin.d.ts @@ -3,22 +3,15 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * A mixin to handle `dir` attribute based on the one set on the `` element. */ -declare function DirMixin {}>(base: T): T & DirMixinConstructor; +export declare const DirMixin: >(base: T) => T & Constructor; -interface DirMixinConstructor { - new (...args: any[]): DirMixin; +export declare class DirMixinClass { + protected __getNormalizedScrollLeft(element: Element | null): number; - finalize(): void; + protected __setNormalizedScrollLeft(element: Element | null, scrollLeft: number): void; } - -interface DirMixin { - __getNormalizedScrollLeft(element: Element | null): number; - - __setNormalizedScrollLeft(element: Element | null, scrollLeft: number): void; -} - -export { DirMixin, DirMixinConstructor }; diff --git a/packages/component-base/src/disabled-mixin.d.ts b/packages/component-base/src/disabled-mixin.d.ts index 1806267108..cf567d7670 100644 --- a/packages/component-base/src/disabled-mixin.d.ts +++ b/packages/component-base/src/disabled-mixin.d.ts @@ -3,21 +3,20 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * A mixin to provide disabled property for field components. */ -declare function DisabledMixin {}>(base: T): T & DisabledMixinConstructor; +export declare const DisabledMixin: >( + base: T +) => Constructor & T; -interface DisabledMixinConstructor { - new (...args: any[]): DisabledMixin; -} - -interface DisabledMixin { +export declare class DisabledMixinClass { /** * If true, the user cannot interact with this element. */ disabled: boolean; -} -export { DisabledMixinConstructor, DisabledMixin }; + protected _disabledChanged(disabled: boolean, oldDisabled: boolean): void; +} diff --git a/packages/component-base/src/element-mixin.d.ts b/packages/component-base/src/element-mixin.d.ts index e588cb6ad6..a4b0806ecf 100644 --- a/packages/component-base/src/element-mixin.d.ts +++ b/packages/component-base/src/element-mixin.d.ts @@ -3,20 +3,24 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; import { ReactiveControllerHost } from 'lit'; import '../custom_typings/vaadin-usage-statistics.js'; import '../custom_typings/vaadin.js'; -import { DirMixin, DirMixinConstructor } from './dir-mixin.js'; +import { DirMixinClass } from './dir-mixin.js'; -declare function ElementMixin {}>( - base: T -): T & ElementMixinConstructor & DirMixinConstructor; - -interface ElementMixinConstructor { - new (...args: any[]): ElementMixin; - finalize(): void; -} +/** + * A mixin to provide common logic for Vaadin components. + */ +export declare function ElementMixin>( + superclass: T +): T & + Constructor & + Constructor & + Pick; -interface ElementMixin extends Pick, DirMixin {} +export declare class ElementMixinClass { + static version: string; -export { ElementMixin, ElementMixinConstructor }; + protected static finalize(): void; +} diff --git a/packages/component-base/src/focus-mixin.d.ts b/packages/component-base/src/focus-mixin.d.ts index 83ca683f9d..d793a2448b 100644 --- a/packages/component-base/src/focus-mixin.d.ts +++ b/packages/component-base/src/focus-mixin.d.ts @@ -3,33 +3,28 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * A mixin to handle `focused` and `focus-ring` attributes based on focus. */ -declare function FocusMixin {}>(base: T): T & FocusMixinConstructor; +export declare const FocusMixin: >(base: T) => T & Constructor; -interface FocusMixinConstructor { - new (...args: any[]): FocusMixin; -} - -interface FocusMixin { - readonly _keyboardActive: boolean; +export declare class FocusMixinClass { + protected readonly _keyboardActive: boolean; /** * Override to change how focused and focus-ring attributes are set. */ - _setFocused(focused: boolean): void; + protected _setFocused(focused: boolean): void; /** * Override to define if the field receives focus based on the event. */ - _shouldSetFocus(event: FocusEvent): boolean; + protected _shouldSetFocus(event: FocusEvent): boolean; /** * Override to define if the field loses focus based on the event. */ - _shouldRemoveFocus(event: FocusEvent): boolean; + protected _shouldRemoveFocus(event: FocusEvent): boolean; } - -export { FocusMixinConstructor, FocusMixin }; diff --git a/packages/component-base/src/keyboard-mixin.d.ts b/packages/component-base/src/keyboard-mixin.d.ts index b2e889524c..c4d16747f3 100644 --- a/packages/component-base/src/keyboard-mixin.d.ts +++ b/packages/component-base/src/keyboard-mixin.d.ts @@ -3,30 +3,27 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * A mixin that manages keyboard handling. * The mixin subscribes to the keyboard events while an actual implementation * for the event handlers is left to the client (a component or another mixin). */ -declare function KeyboardMixin {}>(base: T): T & KeyboardMixinConstructor; +export declare const KeyboardMixin: >( + base: T +) => T & Constructor; -interface KeyboardMixinConstructor { - new (...args: any[]): KeyboardMixin; -} - -interface KeyboardMixin { +export declare class KeyboardMixinClass { /** * A handler for the `keydown` event. By default, it does nothing. * Override the method to implement your own behavior. */ - _onKeyDown(event: KeyboardEvent): void; + protected _onKeyDown(event: KeyboardEvent): void; /** * A handler for the `keyup` event. By default, it does nothing. * Override the method to implement your own behavior. */ - _onKeyUp(event: KeyboardEvent): void; + protected _onKeyUp(event: KeyboardEvent): void; } - -export { KeyboardMixinConstructor, KeyboardMixin }; diff --git a/packages/component-base/src/slot-mixin.d.ts b/packages/component-base/src/slot-mixin.d.ts index c00e94bd33..a39824fb6f 100644 --- a/packages/component-base/src/slot-mixin.d.ts +++ b/packages/component-base/src/slot-mixin.d.ts @@ -3,21 +3,16 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * A mixin to provide content for named slots defined by component. */ -declare function SlotMixin {}>(base: T): T & SlotMixinConstructor; +export declare const SlotMixin: >(base: T) => T & Constructor; -interface SlotMixinConstructor { - new (...args: any[]): SlotMixin; -} - -interface SlotMixin { +export declare class SlotMixinClass { /** * List of named slots to initialize. */ - readonly slots: Record HTMLElement>; + protected readonly slots: Record HTMLElement>; } - -export { SlotMixinConstructor, SlotMixin }; diff --git a/packages/component-base/src/tabindex-mixin.d.ts b/packages/component-base/src/tabindex-mixin.d.ts index a13e14356f..889cd90fdb 100644 --- a/packages/component-base/src/tabindex-mixin.d.ts +++ b/packages/component-base/src/tabindex-mixin.d.ts @@ -3,27 +3,31 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { DisabledMixin } from './disabled-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from './disabled-mixin.js'; /** - * A mixin to provide the `tabindex` attribute. + * A mixin to toggle the `tabindex` attribute. * * By default, the attribute is set to 0 that makes the element focusable. * * The attribute is set to -1 whenever the user disables the element * and restored with the last known value once the element is enabled. */ -declare function TabindexMixin {}>(base: T): T & TabindexMixinConstructor; +export declare const TabindexMixin: >( + base: T +) => T & Constructor & Constructor; -interface TabindexMixinConstructor { - new (...args: any[]): TabindexMixin; -} - -interface TabindexMixin extends DisabledMixin { +export declare class TabindexMixinClass { /** * Indicates whether the element can be focused and where it participates in sequential keyboard navigation. */ tabindex: number | undefined | null; -} -export { TabindexMixinConstructor, TabindexMixin }; + /** + * When the user has changed tabindex while the element is disabled, + * the observer reverts tabindex to -1 and rather saves the new tabindex value to apply it later. + * The new value will be applied as soon as the element becomes enabled. + */ + protected _tabindexChanged(tabindex: number | undefined | null): void; +} diff --git a/packages/component-base/src/tabindex-mixin.js b/packages/component-base/src/tabindex-mixin.js index 5d7a79d604..86a7d5582f 100644 --- a/packages/component-base/src/tabindex-mixin.js +++ b/packages/component-base/src/tabindex-mixin.js @@ -6,7 +6,7 @@ import { DisabledMixin } from './disabled-mixin.js'; /** - * A mixin to provide the `tabindex` attribute. + * A mixin to toggle the `tabindex` attribute. * * By default, the attribute is set to 0 that makes the element focusable. * diff --git a/packages/date-picker/package.json b/packages/date-picker/package.json index 0624f5f09f..31c78cb736 100644 --- a/packages/date-picker/package.json +++ b/packages/date-picker/package.json @@ -31,6 +31,7 @@ "web-component" ], "dependencies": { + "@open-wc/dedupe-mixin": "^1.3.0", "@polymer/iron-a11y-announcer": "^3.0.0", "@polymer/iron-a11y-keys-behavior": "^3.0.0", "@polymer/iron-media-query": "^3.0.0", diff --git a/packages/date-picker/src/vaadin-date-picker-mixin.d.ts b/packages/date-picker/src/vaadin-date-picker-mixin.d.ts index 961a07010c..b2073e5ead 100644 --- a/packages/date-picker/src/vaadin-date-picker-mixin.d.ts +++ b/packages/date-picker/src/vaadin-date-picker-mixin.d.ts @@ -3,9 +3,12 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js'; -import { InputMixin } from '@vaadin/field-base/src/input-mixin.js'; -import { DelegateFocusMixin } from '@vaadin/field-base/src/delegate-focus-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js'; +import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js'; +import { DelegateFocusMixinClass } from '@vaadin/field-base/src/delegate-focus-mixin.js'; +import { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js'; export interface DatePickerDate { day: number; @@ -28,15 +31,19 @@ export interface DatePickerI18n { formatTitle: (monthName: string, fullYear: number) => string; } -declare function DatePickerMixin {}>(base: T): T & DatePickerMixinConstructor; - -interface DatePickerMixinConstructor { - new (...args: any[]): DatePickerMixin; -} - -interface DatePickerMixin extends DelegateFocusMixin, InputMixin, KeyboardMixin { +export declare function DatePickerMixin>( + base: T +): T & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor; + +export declare class DatePickerMixinClass { /** - * The value for this element. + * Selected date. * * Supported date formats: * - ISO 8601 `"YYYY-MM-DD"` (default) @@ -194,5 +201,3 @@ interface DatePickerMixin extends DelegateFocusMixin, InputMixin, KeyboardMixin */ checkValidity(): boolean; } - -export { DatePickerMixinConstructor, DatePickerMixin }; diff --git a/packages/date-picker/src/vaadin-date-picker-mixin.js b/packages/date-picker/src/vaadin-date-picker-mixin.js index e63f9dd239..1e20a8b12b 100644 --- a/packages/date-picker/src/vaadin-date-picker-mixin.js +++ b/packages/date-picker/src/vaadin-date-picker-mixin.js @@ -33,7 +33,7 @@ export const DatePickerMixin = (subclass) => _focusedDate: Date, /** - * The value for this element. + * Selected date. * * Supported date formats: * - ISO 8601 `"YYYY-MM-DD"` (default) diff --git a/packages/date-picker/src/vaadin-date-picker.d.ts b/packages/date-picker/src/vaadin-date-picker.d.ts index d571562b20..7af94c751d 100644 --- a/packages/date-picker/src/vaadin-date-picker.d.ts +++ b/packages/date-picker/src/vaadin-date-picker.d.ts @@ -125,7 +125,7 @@ export interface DatePickerEventMap extends HTMLElementEventMap, DatePickerCusto * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes. * @fires {CustomEvent} value-changed - Fired when the `value` property changes. */ -declare class DatePicker extends HTMLElement { +declare class DatePicker extends DatePickerMixin(InputControlMixin(ThemableMixin(ElementMixin(HTMLElement)))) { addEventListener( type: K, listener: (this: DatePicker, ev: DatePickerEventMap[K]) => void, @@ -139,8 +139,6 @@ declare class DatePicker extends HTMLElement { ): void; } -interface DatePicker extends DatePickerMixin, ElementMixin, InputControlMixin, ThemableMixin {} - declare global { interface HTMLElementTagNameMap { 'vaadin-date-picker': DatePicker; diff --git a/packages/date-picker/test/typings/date-picker.types.ts b/packages/date-picker/test/typings/date-picker.types.ts index 24cb0761a3..ec3d3a2ef6 100644 --- a/packages/date-picker/test/typings/date-picker.types.ts +++ b/packages/date-picker/test/typings/date-picker.types.ts @@ -1,4 +1,14 @@ -import { ThemableMixin } from '@vaadin/vaadin-themable-mixin'; +import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js'; +import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js'; +import { DelegateFocusMixinClass } from '@vaadin/field-base/src/delegate-focus-mixin.js'; +import { LabelMixinClass } from '@vaadin/field-base/src/label-mixin.js'; +import { InputConstraintsMixinClass } from '@vaadin/field-base/src/input-constraints-mixin.js'; +import { InputControlMixinClass } from '@vaadin/field-base/src/input-control-mixin.js'; +import { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js'; +import { ValidateMixinClass } from '@vaadin/field-base/src/validate-mixin.js'; +import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; import '../../vaadin-date-picker.js'; import { DatePicker, @@ -12,6 +22,7 @@ import { DatePickerLightOpenedChangedEvent, DatePickerLightValueChangedEvent } from '../../vaadin-date-picker-light.js'; +import { DatePickerMixinClass } from '../../src/vaadin-date-picker-mixin.js'; const assertType = (actual: TExpected) => actual; @@ -35,6 +46,7 @@ datePicker.addEventListener('value-changed', (event) => { assertType(event.detail.value); }); +// DatePicker properties assertType<() => boolean>(datePicker.checkValidity); assertType<() => boolean>(datePicker.validate); assertType<() => void>(datePicker.close); @@ -45,7 +57,7 @@ assertType(datePicker.showWeekNumbers); assertType(datePicker.autoOpenDisabled); assertType(datePicker.opened); assertType(datePicker.invalid); -assertType(datePicker.focusElement); +assertType(datePicker.focusElement); assertType(datePicker.disabled); assertType(datePicker.clearButtonVisible); assertType(datePicker.errorMessage); @@ -58,6 +70,20 @@ assertType(datePicker.required); assertType(datePicker.name); assertType(datePicker.initialPosition); +// DatePicker mixins +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); +assertType(datePicker); + /* DatePickerLight */ const datePickerLight = document.createElement('vaadin-date-picker-light'); @@ -79,6 +105,7 @@ datePickerLight.addEventListener('value-changed', (event) => { assertType(event.detail.value); }); +// DatePickerLight properties assertType<() => boolean>(datePickerLight.checkValidity); assertType<() => boolean>(datePickerLight.validate); assertType<() => void>(datePickerLight.close); @@ -88,7 +115,16 @@ assertType(datePickerLight.min); assertType(datePickerLight.showWeekNumbers); assertType(datePickerLight.autoOpenDisabled); assertType(datePickerLight.opened); -assertType(datePickerLight.focusElement); +assertType(datePickerLight.focusElement); assertType(datePickerLight.disabled); assertType(datePickerLight.value); assertType(datePickerLight.initialPosition); + +// DatePickerLight mixins +assertType(datePickerLight); +assertType(datePickerLight); +assertType(datePickerLight); +assertType(datePickerLight); +assertType(datePickerLight); +assertType(datePickerLight); +assertType(datePickerLight); diff --git a/packages/field-base/package.json b/packages/field-base/package.json index 912c99f981..737a2983a4 100644 --- a/packages/field-base/package.json +++ b/packages/field-base/package.json @@ -29,6 +29,7 @@ "web-component" ], "dependencies": { + "@open-wc/dedupe-mixin": "^1.3.0", "@polymer/polymer": "^3.0.0", "@vaadin/component-base": "22.0.0-beta1", "lit": "^2.0.0" diff --git a/packages/field-base/src/checked-mixin.d.ts b/packages/field-base/src/checked-mixin.d.ts index 3a7118e121..0daf2bb33a 100644 --- a/packages/field-base/src/checked-mixin.d.ts +++ b/packages/field-base/src/checked-mixin.d.ts @@ -3,24 +3,27 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js'; -import { DelegateStateMixin } from './delegate-state-mixin.js'; -import { InputMixin } from './input-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { DelegateStateMixinClass } from './delegate-state-mixin.js'; +import { InputMixinClass } from './input-mixin.js'; /** * A mixin to manage the checked state. */ -declare function CheckedMixin {}>(base: T): T & CheckedMixinConstructor; +export declare function CheckedMixin>( + base: T +): T & + Constructor & + Constructor & + Constructor & + Constructor; -interface CheckedMixinConstructor { - new (...args: any[]): CheckedMixin; -} - -interface CheckedMixin extends DelegateStateMixin, DisabledMixin, InputMixin { +export declare class CheckedMixinClass { /** * True if the element is checked. */ checked: boolean; -} -export { CheckedMixinConstructor, CheckedMixin }; + protected _toggleChecked(checked: boolean): void; +} diff --git a/packages/field-base/src/delegate-focus-mixin.d.ts b/packages/field-base/src/delegate-focus-mixin.d.ts index 48920eaa70..3938e86c1d 100644 --- a/packages/field-base/src/delegate-focus-mixin.d.ts +++ b/packages/field-base/src/delegate-focus-mixin.d.ts @@ -3,19 +3,18 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js'; -import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js'; /** * A mixin to forward focus to an element in the light DOM. */ -declare function DelegateFocusMixin {}>(base: T): T & DelegateFocusMixinConstructor; +export declare function DelegateFocusMixin>( + base: T +): T & Constructor & Constructor & Constructor; -interface DelegateFocusMixinConstructor { - new (...args: any[]): DelegateFocusMixin; -} - -interface DelegateFocusMixin extends DisabledMixin, FocusMixin { +export declare class DelegateFocusMixinClass { /** * Specify that this control should have input focus when the page loads. */ @@ -28,7 +27,17 @@ interface DelegateFocusMixin extends DisabledMixin, FocusMixin { * Any component implementing this mixin is expected to provide it * by using `this._setFocusElement(input)` Polymer API. */ - readonly focusElement: Element | null | undefined; -} + readonly focusElement: HTMLElement | null | undefined; + + protected _addFocusListeners(element: HTMLElement): void; + + protected _removeFocusListeners(element: HTMLElement): void; -export { DelegateFocusMixinConstructor, DelegateFocusMixin }; + protected _focusElementChanged(element: HTMLElement, oldElement: HTMLElement): void; + + protected _onBlur(event: FocusEvent): void; + + protected _onFocus(event: FocusEvent): void; + + protected _setFocusElement(element: HTMLElement): void; +} diff --git a/packages/field-base/src/delegate-state-mixin.d.ts b/packages/field-base/src/delegate-state-mixin.d.ts index daaa978209..c45e6b1c9c 100644 --- a/packages/field-base/src/delegate-state-mixin.d.ts +++ b/packages/field-base/src/delegate-state-mixin.d.ts @@ -3,21 +3,18 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * A mixin to delegate properties and attributes to a target element. */ -declare function DelegateStateMixin {}>(base: T): T & DelegateStateMixinConstructor; +export declare function DelegateStateMixin>( + base: T +): T & Constructor; -interface DelegateStateMixinConstructor { - new (...args: any[]): DelegateStateMixin; -} - -interface DelegateStateMixin { +export declare class DelegateStateMixinClass { /** * A target element to which attributes and properties are delegated. */ stateTarget: HTMLElement | null; } - -export { DelegateStateMixinConstructor, DelegateStateMixin }; diff --git a/packages/field-base/src/field-mixin.d.ts b/packages/field-base/src/field-mixin.d.ts index bde7afd24f..c7082f3f6b 100644 --- a/packages/field-base/src/field-mixin.d.ts +++ b/packages/field-base/src/field-mixin.d.ts @@ -3,19 +3,23 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { LabelMixin } from './label-mixin.js'; -import { ValidateMixin } from './validate-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DelegateStateMixinClass } from './delegate-state-mixin.js'; +import { LabelMixinClass } from './label-mixin.js'; +import { ValidateMixinClass } from './validate-mixin.js'; /** * A mixin to provide common field logic: label, error message and helper text. */ -declare function FieldMixin {}>(base: T): T & FieldMixinConstructor; +export declare function FieldMixin>( + superclass: T +): T & + Constructor & + Constructor & + Constructor & + Constructor; -interface FieldMixinConstructor { - new (...args: any[]): FieldMixin; -} - -interface FieldMixin extends LabelMixin, ValidateMixin { +export declare class FieldMixinClass { /** * A target element to which ARIA attributes are set. */ @@ -34,6 +38,18 @@ interface FieldMixin extends LabelMixin, ValidateMixin { * @attr {string} error-message */ errorMessage: string; -} -export { FieldMixin, FieldMixinConstructor }; + protected readonly _ariaAttr: 'aria-labelledby' | 'aria-describedby'; + + protected _ariaTargetChanged(target: HTMLElement): void; + + protected readonly _errorNode: HTMLElement; + + protected readonly _helperNode?: HTMLElement; + + protected _helperTextChanged(helperText: string | null | undefined): void; + + protected _updateAriaAttribute(target: HTMLElement, invalid: boolean, helperId: string): void; + + protected _updateAriaRequiredAttribute(target: HTMLElement, required: boolean): void; +} diff --git a/packages/field-base/src/input-constraints-mixin.d.ts b/packages/field-base/src/input-constraints-mixin.d.ts index 532f721b09..dd4f30bff4 100644 --- a/packages/field-base/src/input-constraints-mixin.d.ts +++ b/packages/field-base/src/input-constraints-mixin.d.ts @@ -3,26 +3,27 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { DelegateStateMixin } from './delegate-state-mixin.js'; -import { InputMixin } from './input-mixin.js'; -import { ValidateMixin } from './validate-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { DelegateStateMixinClass } from './delegate-state-mixin.js'; +import { InputMixinClass } from './input-mixin.js'; +import { ValidateMixinClass } from './validate-mixin.js'; /** * A mixin to combine multiple input validation constraints. */ -declare function InputConstraintsMixin {}>( +export declare function InputConstraintsMixin>( base: T -): T & InputConstraintsMixinConstructor; +): T & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor; -interface InputConstraintsMixinConstructor { - new (...args: any[]): InputConstraintsMixin; -} - -interface InputConstraintsMixin extends DelegateStateMixin, InputMixin, ValidateMixin { +export declare class InputConstraintsMixinClass { /** * Returns true if the current input value satisfies all constraints (if any). */ checkValidity(): boolean; } - -export { InputConstraintsMixin, InputConstraintsMixinConstructor }; diff --git a/packages/field-base/src/input-control-mixin.d.ts b/packages/field-base/src/input-control-mixin.d.ts index dbfb4bafcc..6fcdcf99d3 100644 --- a/packages/field-base/src/input-control-mixin.d.ts +++ b/packages/field-base/src/input-control-mixin.d.ts @@ -3,20 +3,37 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js'; -import { FieldMixin } from './field-mixin.js'; -import { InputConstraintsMixin } from './input-constraints-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js'; +import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js'; +import { DelegateFocusMixinClass } from './delegate-focus-mixin.js'; +import { DelegateStateMixinClass } from './delegate-state-mixin.js'; +import { FieldMixinClass } from './field-mixin.js'; +import { InputConstraintsMixinClass } from './input-constraints-mixin.js'; +import { InputMixinClass } from './input-mixin.js'; +import { LabelMixinClass } from './label-mixin.js'; +import { ValidateMixinClass } from './validate-mixin.js'; /** * A mixin to provide shared logic for the editable form input controls. */ -declare function InputControlMixin {}>(base: T): T & InputControlMixinConstructor; +export declare function InputControlMixin>( + base: T +): T & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor; -interface InputControlMixinConstructor { - new (...args: any[]): InputControlMixin; -} - -interface InputControlMixin extends KeyboardMixin, InputConstraintsMixin, FieldMixin { +export declare class InputControlMixinClass { /** * If true, the input text gets fully selected when the field is focused using click or touch / tap. */ @@ -48,5 +65,3 @@ interface InputControlMixin extends KeyboardMixin, InputConstraintsMixin, FieldM */ title: string; } - -export { InputControlMixin, InputControlMixinConstructor }; diff --git a/packages/field-base/src/input-field-mixin.d.ts b/packages/field-base/src/input-field-mixin.d.ts index 1b0c9f348e..88021bf900 100644 --- a/packages/field-base/src/input-field-mixin.d.ts +++ b/packages/field-base/src/input-field-mixin.d.ts @@ -3,18 +3,39 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { InputControlMixin } from './input-control-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js'; +import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js'; +import { DelegateFocusMixinClass } from './delegate-focus-mixin.js'; +import { DelegateStateMixinClass } from './delegate-state-mixin.js'; +import { FieldMixinClass } from './field-mixin.js'; +import { InputConstraintsMixinClass } from './input-constraints-mixin.js'; +import { InputControlMixinClass } from './input-control-mixin.js'; +import { InputMixinClass } from './input-mixin.js'; +import { LabelMixinClass } from './label-mixin.js'; +import { ValidateMixinClass } from './validate-mixin.js'; /** * A mixin to provide logic for vaadin-text-field and related components. */ -declare function InputFieldMixin {}>(base: T): T & InputFieldMixinConstructor; +export declare function InputFieldMixin>( + base: T +): T & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor; -interface InputFieldMixinConstructor { - new (...args: any[]): InputFieldMixin; -} - -interface InputFieldMixin extends InputControlMixin { +export declare class InputFieldMixinClass { /** * Whether the value of the control can be automatically completed by the browser. * List of available options at: @@ -42,5 +63,3 @@ interface InputFieldMixin extends InputControlMixin { */ autocapitalize: 'on' | 'off' | 'none' | 'characters' | 'words' | 'sentences' | undefined; } - -export { InputFieldMixin, InputFieldMixinConstructor }; diff --git a/packages/field-base/src/input-mixin.d.ts b/packages/field-base/src/input-mixin.d.ts index 5ff5fe6777..c15b3db944 100644 --- a/packages/field-base/src/input-mixin.d.ts +++ b/packages/field-base/src/input-mixin.d.ts @@ -3,18 +3,15 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * A mixin to store the reference to an input element * and add input and change event listeners to it. */ -declare function InputMixin {}>(base: T): T & InputMixinConstructor; +export declare function InputMixin>(base: T): T & Constructor; -interface InputMixinConstructor { - new (...args: any[]): InputMixin; -} - -interface InputMixin { +export declare class InputMixinClass { /** * A reference to the input element controlled by the mixin. * Any component implementing this mixin is expected to provide it @@ -24,7 +21,7 @@ interface InputMixin { * However, the input element does not have to always be native : * as an example, accepts other components. */ - readonly inputElement: HTMLInputElement; + readonly inputElement: HTMLElement; /** * The value of the field. @@ -35,6 +32,22 @@ interface InputMixin { * Clear the value of the field. */ clear(): void; -} -export { InputMixin, InputMixinConstructor }; + protected _addInputListeners(input: HTMLElement): void; + + protected _removeInputListeners(input: HTMLElement): void; + + protected _forwardInputValue(input: HTMLElement): void; + + protected _inputElementChanged(input: HTMLElement, oldInput: HTMLElement): void; + + protected _onChange(event: void): void; + + protected _onInput(event: void): void; + + protected _setInputElement(input: HTMLElement): void; + + protected _toggleHasValue(value: boolean): void; + + protected _valueChanged(value?: string, oldValue?: string): void; +} diff --git a/packages/field-base/src/label-mixin.d.ts b/packages/field-base/src/label-mixin.d.ts index a574e2518c..510b6621de 100644 --- a/packages/field-base/src/label-mixin.d.ts +++ b/packages/field-base/src/label-mixin.d.ts @@ -3,22 +3,25 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { SlotMixin } from '@vaadin/component-base/src/slot-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { SlotMixinClass } from '@vaadin/component-base/src/slot-mixin.js'; /** * A mixin to provide label via corresponding property or named slot. */ -declare function LabelMixin {}>(base: T): T & LabelMixinConstructor; +export declare function LabelMixin>( + base: T +): T & Constructor & Constructor; -interface LabelMixinConstructor { - new (...args: any[]): LabelMixin; -} - -interface LabelMixin extends SlotMixin { +export declare class LabelMixinClass { /** * String used for a label element. */ label: string | null | undefined; -} -export { LabelMixinConstructor, LabelMixin }; + protected readonly _labelNode: HTMLLabelElement; + + protected _labelChanged(label: string | null | undefined): void; + + protected _toggleHasLabelAttribute(): void; +} diff --git a/packages/field-base/src/pattern-mixin.d.ts b/packages/field-base/src/pattern-mixin.d.ts index 3d9edc43b5..a64ad5f5e8 100644 --- a/packages/field-base/src/pattern-mixin.d.ts +++ b/packages/field-base/src/pattern-mixin.d.ts @@ -3,18 +3,27 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { InputConstraintsMixin } from './input-constraints-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { DelegateStateMixinClass } from './delegate-state-mixin.js'; +import { InputConstraintsMixinClass } from './input-constraints-mixin.js'; +import { InputMixinClass } from './input-mixin.js'; +import { ValidateMixinClass } from './validate-mixin.js'; /** * A mixin to provide `pattern` and `preventInvalidInput` properties. */ -declare function PatternMixin {}>(base: T): T & PatternMixinConstructor; +export declare function PatternMixin>( + base: T +): T & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor; -interface PatternMixinConstructor { - new (...args: any[]): PatternMixin; -} - -interface PatternMixin extends InputConstraintsMixin { +export declare class PatternMixinClass { /** * A regular expression that the value is checked against. * The pattern must match the entire value, not just some subset. @@ -28,5 +37,3 @@ interface PatternMixin extends InputConstraintsMixin { */ preventInvalidInput: boolean | null | undefined; } - -export { PatternMixin, PatternMixinConstructor }; diff --git a/packages/field-base/src/shadow-focus-mixin.d.ts b/packages/field-base/src/shadow-focus-mixin.d.ts index 429e4f44c5..6b75af4244 100644 --- a/packages/field-base/src/shadow-focus-mixin.d.ts +++ b/packages/field-base/src/shadow-focus-mixin.d.ts @@ -3,19 +3,21 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js'; -import { TabindexMixin } from '@vaadin/component-base/src/tabindex-mixin.js'; -import { DelegateFocusMixin } from './delegate-focus-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js'; +import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js'; +import { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js'; +import { DelegateFocusMixinClass } from './delegate-focus-mixin.js'; /** * A mixin to forward focus to an element in the shadow DOM. */ -declare function ShadowFocusMixin {}>(base: T): T & ShadowFocusMixinConstructor; - -interface ShadowFocusMixinConstructor { - new (...args: any[]): ShadowFocusMixin; -} - -interface ShadowFocusMixin extends KeyboardMixin, TabindexMixin, DelegateFocusMixin {} - -export { ShadowFocusMixinConstructor, ShadowFocusMixin }; +export declare function ShadowFocusMixin>( + base: T +): T & + Constructor & + Constructor & + Constructor & + Constructor & + Constructor; diff --git a/packages/field-base/src/slot-label-mixin.d.ts b/packages/field-base/src/slot-label-mixin.d.ts index 44ba7b953a..b4931df175 100644 --- a/packages/field-base/src/slot-label-mixin.d.ts +++ b/packages/field-base/src/slot-label-mixin.d.ts @@ -3,18 +3,13 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { LabelMixin } from './label-mixin.js'; -import { SlotTargetMixin } from './slot-target-mixin.js'; +import { Constructor } from '@open-wc/dedupe-mixin'; +import { LabelMixinClass } from './label-mixin.js'; +import { SlotTargetMixinClass } from './slot-target-mixin.js'; /** * A mixin to forward any content from the default slot to the label node. */ -declare function SlotLabelMixin {}>(base: T): T & SlotLabelMixinConstructor; - -interface SlotLabelMixinConstructor { - new (...args: any[]): SlotLabelMixin; -} - -interface SlotLabelMixin extends SlotTargetMixin, LabelMixin {} - -export { SlotLabelMixinConstructor, SlotLabelMixin }; +export declare function SlotLabelMixin>( + base: T +): T & Constructor & Constructor; diff --git a/packages/field-base/src/slot-styles-mixin.d.ts b/packages/field-base/src/slot-styles-mixin.d.ts index 6aa08a5566..fabf00f400 100644 --- a/packages/field-base/src/slot-styles-mixin.d.ts +++ b/packages/field-base/src/slot-styles-mixin.d.ts @@ -3,22 +3,19 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * Mixin to insert styles into the outer scope to handle slotted components. * This is useful e.g. to hide native `` controls. */ -declare function SlotStylesMixin {}>(base: T): T & SlotStylesMixinConstructor; +export declare function SlotStylesMixin>( + base: T +): T & Constructor; -interface SlotStylesMixinConstructor { - new (...args: any[]): SlotStylesMixin; -} - -interface SlotStylesMixin { +export declare class SlotStylesMixinClass { /** * List of styles to insert into root. */ - readonly slotStyles: string[]; + protected readonly slotStyles: string[]; } - -export { SlotStylesMixinConstructor, SlotStylesMixin }; diff --git a/packages/field-base/src/slot-target-mixin.d.ts b/packages/field-base/src/slot-target-mixin.d.ts index 19888618e9..7a42edd047 100644 --- a/packages/field-base/src/slot-target-mixin.d.ts +++ b/packages/field-base/src/slot-target-mixin.d.ts @@ -3,30 +3,23 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * A mixin to copy the content from a source slot to a target element. */ -declare function SlotTargetMixin {}>(base: T): T & SlotTargetMixinConstructor; +export declare function SlotTargetMixin>( + base: T +): T & Constructor; -interface SlotTargetMixinConstructor { - new (...args: any[]): SlotTargetMixin; -} - -interface SlotTargetMixin { +export declare class SlotTargetMixinClass { /** * A reference to the source slot from which the content is copied to the target element. - * - * @protected */ - _sourceSlot: HTMLSlotElement; + protected readonly _sourceSlot: HTMLSlotElement; /** * A reference to the target element to which the content is copied from the source slot. - * - * @protected */ - _slotTarget: HTMLElement; + protected readonly _slotTarget: HTMLElement; } - -export { SlotTargetMixinConstructor, SlotTargetMixin }; diff --git a/packages/field-base/src/validate-mixin.d.ts b/packages/field-base/src/validate-mixin.d.ts index f9f9794049..de4599757b 100644 --- a/packages/field-base/src/validate-mixin.d.ts +++ b/packages/field-base/src/validate-mixin.d.ts @@ -3,17 +3,14 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ +import { Constructor } from '@open-wc/dedupe-mixin'; /** * A mixin to provide required state and validation logic. */ -declare function ValidateMixin {}>(base: T): T & ValidateMixinConstructor; +export declare function ValidateMixin>(base: T): T & Constructor; -interface ValidateMixinConstructor { - new (...args: any[]): ValidateMixin; -} - -interface ValidateMixin { +export declare class ValidateMixinClass { /** * Set to true when the field is invalid. */ @@ -34,5 +31,3 @@ interface ValidateMixin { */ checkValidity(): boolean; } - -export { ValidateMixinConstructor, ValidateMixin }; diff --git a/packages/grid/src/vaadin-grid.d.ts b/packages/grid/src/vaadin-grid.d.ts index 9ebe83fe13..871079603f 100644 --- a/packages/grid/src/vaadin-grid.d.ts +++ b/packages/grid/src/vaadin-grid.d.ts @@ -3,7 +3,7 @@ * Copyright (c) 2021 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ -import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; +import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js'; import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; import { ActiveItemMixin } from './vaadin-grid-active-item-mixin.js'; import { ArrayDataProviderMixin } from './vaadin-grid-array-data-provider-mixin.js'; @@ -397,7 +397,7 @@ declare class Grid extends HTMLElement { } interface Grid - extends ElementMixin, + extends ElementMixinClass, ThemableMixin, ActiveItemMixin, ArrayDataProviderMixin, diff --git a/packages/grid/test/typings/grid.types.ts b/packages/grid/test/typings/grid.types.ts index f295870bef..df3f0b1d58 100644 --- a/packages/grid/test/typings/grid.types.ts +++ b/packages/grid/test/typings/grid.types.ts @@ -1,4 +1,4 @@ -import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; +import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js'; import { ThemableMixin } from '@vaadin/vaadin-themable-mixin'; import { ActiveItemMixin } from '../../src/vaadin-grid-active-item-mixin'; import { ArrayDataProviderMixin } from '../../src/vaadin-grid-array-data-provider-mixin'; @@ -59,7 +59,7 @@ const genericGrid = document.createElement('vaadin-grid'); assertType(genericGrid); const narrowedGrid = genericGrid as Grid; -assertType(narrowedGrid); +assertType(narrowedGrid); assertType(narrowedGrid); assertType>(narrowedGrid); assertType>(narrowedGrid); diff --git a/packages/radio-group/test/typings/radio-button.types.ts b/packages/radio-group/test/typings/radio-button.types.ts index dcc6938159..825c4d1a7d 100644 --- a/packages/radio-group/test/typings/radio-button.types.ts +++ b/packages/radio-group/test/typings/radio-button.types.ts @@ -1,8 +1,11 @@ -import { ActiveMixin } from '@vaadin/component-base/src/active-mixin.js'; -import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js'; -import { CheckedMixin } from '@vaadin/field-base/src/checked-mixin.js'; -import { DelegateFocusMixin } from '@vaadin/field-base/src/delegate-focus-mixin.js'; -import { SlotLabelMixin } from '@vaadin/field-base/src/slot-label-mixin.js'; +import { ActiveMixinClass } from '@vaadin/component-base/src/active-mixin.js'; +import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js'; +import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js'; +import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js'; +import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js'; +import { CheckedMixinClass } from '@vaadin/field-base/src/checked-mixin.js'; +import { DelegateFocusMixinClass } from '@vaadin/field-base/src/delegate-focus-mixin.js'; +import { LabelMixinClass } from '@vaadin/field-base/src/label-mixin.js'; import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; import '../../vaadin-radio-button.js'; import '../../vaadin-radio-group.js'; @@ -22,11 +25,14 @@ assertType(radio.name); assertType(radio.value); // Radio mixins -assertType(radio); -assertType(radio); -assertType(radio); -assertType(radio); -assertType(radio); +assertType(radio); +assertType(radio); +assertType(radio); +assertType(radio); +assertType(radio); +assertType(radio); +assertType(radio); +assertType(radio); assertType(radio); // Radio events diff --git a/yarn.lock b/yarn.lock index 5be5297e83..7cbdd36c01 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1273,6 +1273,11 @@ "@octokit/webhooks-types" "4.7.0" aggregate-error "^3.1.0" +"@open-wc/dedupe-mixin@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@open-wc/dedupe-mixin/-/dedupe-mixin-1.3.0.tgz#0df5d438285fc3482838786ee81895318f0ff778" + integrity sha512-UfdK1MPnR6T7f3svzzYBfu3qBkkZ/KsPhcpc3JYhsUY4hbpwNF9wEQtD4Z+/mRqMTJrKg++YSxIxE0FBhY3RIw== + "@open-wc/semantic-dom-diff@^0.19.5-next.1": version "0.19.5-next.2" resolved "https://registry.yarnpkg.com/@open-wc/semantic-dom-diff/-/semantic-dom-diff-0.19.5-next.2.tgz#272acd6935a75e8fc5a287aff50c3b588b17004e"