import shorten from 'shorten-uuid' import { // createElement, ReactElement, } from 'react' // import ErrorBoundary from '../adaptor/jsx/ErrorBoundary' // import ErrorView from '../adaptor/jsx/ErrorView' import { Context, Options } from '../types' import { Emitter } from '../emitter' const { encode } = shorten() export function generateElement( context: Context, emitter: Emitter, { id, zoom, }: Options ) { const onMounted = () => emitter.emit('mounted') const { window, document, body, } = context const target = document.createElement('div') body.setAttribute('class', `bcse-container bcse-${encode(id)}`) body.appendChild(target) if (zoom) { body.style.zoom = `${zoom}` } return { uses: { element: () => target, }, mount(element: HTMLElement) { target.innerHTML = '' if (element) { target.appendChild(element) onMounted() } }, mountJsx(jsx: ReactElement) { if (jsx) { window.ReactDOM.render( // createElement( // ErrorBoundary, // { // fallback: ErrorView, // onReset() { // emitter.emit('resetErrorBoundary') // }, // }, jsx, // ), target ) onMounted() } }, mountVue(vue) { if (vue) { vue.$mount(target) onMounted() } }, _mount(element: HTMLElement): void { element.innerHTML = '' element.appendChild(body) }, } }