import { Dialogic } from "dialogic" ; import m , { Component } from "mithril" ; type ComponentProps < T = unknown > = T & { show : ( ) => void ; hide : ( ) => void ; } ; export const Instance = < T = unknown > ( { attrs : componentAttrs , } ) => { let domElement ; const dispatchTransition = ( dispatchFn ) => { dispatchFn ( { detail : { identityOptions : componentAttrs . identityOptions , domElement , } , } ) ; } ; const onMount = ( ) => { dispatchTransition ( componentAttrs . onMount ) ; } ; const show = ( ) => { dispatchTransition ( componentAttrs . onShow ) ; } ; const hide = ( ) => { dispatchTransition ( componentAttrs . onHide ) ; } ; return { oncreate : ( vnode ) => { domElement = vnode . dom as HTMLElement ; onMount ( ) ; } , view : ( { attrs } ) => { const component = attrs . dialogicOptions . component as Component < ComponentProps < T > > ; if ( ! component ) { throw new Error ( "Component missing in dialogic options." ) ; } const passThroughOptions = attrs . passThroughOptions || ( { } as T ) ; return m ( "div" , { className : attrs . dialogicOptions . className } , m ( component , { ... passThroughOptions , show , hide , } ) ) ; } , } ; } ;