require host in open/toggle method

This commit is contained in:
Mads Rasmussen
2024-04-28 14:02:37 +02:00
parent d84d1fc55d
commit 341ca9dd21
2 changed files with 20 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
import type { UmbOpenContextMenuArgs } from './types.js';
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
@@ -16,21 +17,24 @@ export class UmbSectionSidebarContext extends UmbContextBase<UmbSectionSidebarCo
#headline = new UmbStringState<undefined>(undefined);
headline = this.#headline.asObservable();
#contextElement: HTMLElement | undefined = undefined;
constructor(host: UmbControllerHost) {
super(host, UMB_SECTION_SIDEBAR_CONTEXT);
}
toggleContextMenu(entityType: string, unique: string | null | undefined, headline: string | undefined) {
this.openContextMenu(entityType, unique, headline);
toggleContextMenu(host: HTMLElement, args: UmbOpenContextMenuArgs) {
this.openContextMenu(host, args);
}
// TODO: we wont get notified about tree item name changes because we don't have a subscription
// we need to figure out how we best can handle this when we only know the entity and unique id
openContextMenu(entityType: string, unique: string | null | undefined, headline: string | undefined) {
this.#entityType.setValue(entityType);
this.#unique.setValue(unique);
this.#headline.setValue(headline);
openContextMenu(host: HTMLElement, args: UmbOpenContextMenuArgs) {
this.#entityType.setValue(args.entityType);
this.#unique.setValue(args.unique);
this.#headline.setValue(args.headline);
this.#contextMenuIsOpen.setValue(true);
this.#contextElement = host;
}
closeContextMenu() {
@@ -38,6 +42,11 @@ export class UmbSectionSidebarContext extends UmbContextBase<UmbSectionSidebarCo
this.#entityType.setValue(undefined);
this.#unique.setValue(undefined);
this.#headline.setValue(undefined);
this.#contextElement = undefined;
}
get contextElement() {
return this.#contextElement;
}
}

View File

@@ -0,0 +1,5 @@
export interface UmbOpenContextMenuArgs {
entityType: string;
unique: string | null | undefined;
headline: string | undefined;
}