Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move item and list-box extensions to separate files #5352

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/context-menu/src/vaadin-context-menu-item.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license
* Copyright (c) 2016 - 2023 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { Item } from '@vaadin/item/src/vaadin-item.js';

/**
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
*
* @protected
*/
declare class ContextMenuItem extends Item {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class isn't exported because it's considered internal. Also, its name collides with ContextMenuItem type.
Because of it, previously when located in the mixin file, it was named ContextMenuItemElement.

I think we can keep these two classes as "private" for now, because they don't enhance parent classes with any logic. Generally, such components as vaadin-select-item do not provide type definitions at all.

Copy link
Contributor

@vursen vursen Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, at least vaadin-context-menu-item is used by the Flow counterpart (it creates a virtual DOM tree of vaadin-context-menu-items which then are assigned via the items array), so it isn't entirely private, but types don't make much sense for Flow, I agree.


declare global {
interface HTMLElementTagNameMap {
'vaadin-context-menu-item': ContextMenuItem;
}
}
20 changes: 20 additions & 0 deletions packages/context-menu/src/vaadin-context-menu-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright (c) 2016 - 2023 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { Item } from '@vaadin/item/src/vaadin-item.js';

/**
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
*
* @extends Item
* @protected
*/
class ContextMenuItem extends Item {
static get is() {
return 'vaadin-context-menu-item';
}
}

customElements.define(ContextMenuItem.is, ContextMenuItem);
19 changes: 19 additions & 0 deletions packages/context-menu/src/vaadin-context-menu-list-box.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license
* Copyright (c) 2016 - 2023 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { ListBox } from '@vaadin/list-box/src/vaadin-list-box.js';

/**
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
*
* @protected
*/
declare class ContextMenuListBox extends ListBox {}

declare global {
interface HTMLElementTagNameMap {
'vaadin-context-menu-list-box': ContextMenuListBox;
}
}
20 changes: 20 additions & 0 deletions packages/context-menu/src/vaadin-context-menu-list-box.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright (c) 2016 - 2023 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { ListBox } from '@vaadin/list-box/src/vaadin-list-box.js';

/**
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
*
* @extends ListBox
* @protected
*/
class ContextMenuListBox extends ListBox {
static get is() {
return 'vaadin-context-menu-list-box';
}
}

customElements.define(ContextMenuListBox.is, ContextMenuListBox);
25 changes: 2 additions & 23 deletions packages/context-menu/src/vaadin-contextmenu-items-mixin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Copyright (c) 2016 - 2023 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import './vaadin-context-menu-item.js';
import './vaadin-context-menu-list-box.js';
import type { Constructor } from '@open-wc/dedupe-mixin';
import { Item } from '@vaadin/item/src/vaadin-item.js';
import { ListBox } from '@vaadin/list-box/src/vaadin-list-box.js';

export interface ContextMenuItem {
text?: string;
Expand All @@ -16,27 +16,6 @@ export interface ContextMenuItem {
children?: ContextMenuItem[];
}

/**
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
*
* @protected
*/
declare class ContextMenuItemElement extends Item {}

declare global {
interface HTMLElementTagNameMap {
'vaadin-context-menu-item': ContextMenuItemElement;
'vaadin-context-menu-list-box': ContextMenuListBox;
}
}

/**
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
*
* @protected
*/
declare class ContextMenuListBox extends ListBox {}

export declare function ItemsMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<ItemsMixinClass> & T;

export declare class ItemsMixinClass {
Expand Down
31 changes: 2 additions & 29 deletions packages/context-menu/src/vaadin-contextmenu-items-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,10 @@
* Copyright (c) 2016 - 2023 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import './vaadin-context-menu-item.js';
import './vaadin-context-menu-list-box.js';
import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
import { Item } from '@vaadin/item/src/vaadin-item.js';
import { ListBox } from '@vaadin/list-box/src/vaadin-list-box.js';

/**
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
*
* @extends Item
* @protected
*/
class ContextMenuItemElement extends Item {
static get is() {
return 'vaadin-context-menu-item';
}
}

customElements.define(ContextMenuItemElement.is, ContextMenuItemElement);

/**
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
*
* @extends ListBox
* @protected
*/
class ContextMenuListBox extends ListBox {
static get is() {
return 'vaadin-context-menu-list-box';
}
}

customElements.define(ContextMenuListBox.is, ContextMenuListBox);

/**
* @polymerMixin
Expand Down