import { initializeWysiwyg } from '@iteria-app/wysiwyg' import { addFrontendListeners } from './frontendListeners' import { WindowMessaging } from './messaging' import { DevWorkbench } from './workbench/Workbench' import { FrontendActions } from './messaging/actions' import { addElementHighlight } from './react-instrumentation/elementHighlight' import { BundleWorker } from './bundler' import { ReactInstrumentation } from './react-instrumentation' export const messagingService = new WindowMessaging(window) const bundler = new BundleWorker(messagingService) export const workbench = new DevWorkbench(messagingService) export const reactInstrumentation = new ReactInstrumentation(messagingService) export const frontendActions = new FrontendActions(messagingService) interface IteriaProps { fsPort?: number cwd?: string graphQLEndpoint?: string graphQLSecret?: string features?: { tippy?: boolean generator?: boolean addFields?: boolean translations?: boolean themeEditor?: boolean graphQLEndpoint?: boolean floatingButton?: boolean } env: { [key: string]: string } deploymentUrl?: string injectMode?: 'jamstack' | 'devServer' mode: 'production' | 'development' command: 'build' | 'serve' } export const devServer = async (props?: IteriaProps) => { const injectMode = props.injectMode ?? 'jamstack' workbench.setInjectionMode(injectMode) workbench.setMode(props.mode) workbench.setCommand(props.command) workbench.setEnv(props.env) if (props.fsPort) workbench.setPort(props.fsPort) if (props.graphQLEndpoint) workbench.setGraphQLEndpoint( props.graphQLEndpoint, props.graphQLSecret ?? '' ) if (props.cwd) workbench.setCwd(props.cwd) if (injectMode === 'jamstack') { addFrontendListeners(messagingService, injectMode, props?.features) // await reactInstrumentation.setResourceHtmlElements( // 'https://example-material-ui.vercel.app' // ) frontendActions.getProjectFromArchive( props?.deploymentUrl ?? window.location.origin ) initializeWysiwyg() } else { initializeWysiwyg() addFrontendListeners(messagingService, injectMode) await addElementHighlight(window, injectMode, props?.features) } }