(
delegate: FrameworkDelegate | undefined,
container: Element,
component?: ComponentRef,
cssClasses?: string[],
componentProps?: { [key: string]: any },
inline?: boolean
)
| 5 | // TODO(FW-2832): types |
| 6 | |
| 7 | export const attachComponent = async ( |
| 8 | delegate: FrameworkDelegate | undefined, |
| 9 | container: Element, |
| 10 | component?: ComponentRef, |
| 11 | cssClasses?: string[], |
| 12 | componentProps?: { [key: string]: any }, |
| 13 | inline?: boolean |
| 14 | ): Promise<HTMLElement> => { |
| 15 | if (delegate) { |
| 16 | return delegate.attachViewToDom(container, component, componentProps, cssClasses); |
| 17 | } |
| 18 | if (!inline && typeof component !== 'string' && !(component instanceof HTMLElement)) { |
| 19 | throw new Error('framework delegate is missing'); |
| 20 | } |
| 21 | |
| 22 | const el: any = typeof component === 'string' ? container.ownerDocument?.createElement(component) : component; |
| 23 | |
| 24 | if (cssClasses) { |
| 25 | cssClasses.forEach((c) => el.classList.add(c)); |
| 26 | } |
| 27 | if (componentProps) { |
| 28 | Object.assign(el, componentProps); |
| 29 | } |
| 30 | |
| 31 | container.appendChild(el); |
| 32 | |
| 33 | await new Promise((resolve) => componentOnReady(el, resolve)); |
| 34 | |
| 35 | return el; |
| 36 | }; |
| 37 | |
| 38 | export const detachComponent = (delegate: FrameworkDelegate | undefined, element: HTMLElement | undefined) => { |
| 39 | if (element) { |
no test coverage detected