Skip to content

Commit 4f483c4

Browse files
committed
feat(SidebarTab): allow to define web component on first usage
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent ff2cffd commit 4f483c4

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

lib/sidebar/SidebarTab.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ export interface ISidebarContext {
3232
* @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components
3333
* @see https://vuejs.org/guide/extras/web-components#building-custom-elements-with-vue
3434
*/
35-
export interface SidebarComponent extends HTMLElement, ISidebarContext {
35+
export interface SidebarTabComponent extends ISidebarContext {
3636
/**
37-
* This method is called by the files app if the sidebar tab state changes.
38-
*
39-
* @param active - The new active state
37+
* The active state of the sidebar tab.
38+
* It will be set to true if this component is the currently active tab.
4039
*/
41-
setActive(active: boolean): Promise<void>
40+
active: boolean
4241
}
4342

43+
/**
44+
* The instance type of a sidebar tab web component.
45+
*/
46+
export type SidebarTabComponentInstance = SidebarTabComponent & HTMLElement
47+
4448
/**
4549
* Implementation of a custom sidebar tab within the files app.
4650
*/
@@ -82,6 +86,15 @@ export interface ISidebarTab {
8286
* @param context - The current context of the files app
8387
*/
8488
enabled: (context: ISidebarContext) => boolean
89+
90+
/**
91+
* Called when the sidebar tab is rendered the first time in the sidebar.
92+
* This should be used to register the web componen (`CustomElementRegistry.define()`).
93+
*
94+
* The sidebar itself will anyways wait for the component to be defined in the registry (`customElements.whenDefined()`).
95+
* But also will wait for the promise returned by this method to resolve before rendering the tab.
96+
*/
97+
onInit?: () => Promise<void>
8598
}
8699

87100
/**

0 commit comments

Comments
 (0)