import { ProjectPlugin, ProjectPluginStructure, UIDLPopupConfig } from '@teleporthq/teleport-types' import { POPUP_RUNTIME_SOURCE } from './popup-runtime-source' /** * The config as a JavaScript literal that is safe inside an inline `` } /** * Popups on the published site (`uidl.popups`, built by the editor from the * popup components the owner switched on). Each popup is already a component * instance at the end of every page; this ships the one script that decides * when to open it — see popup-runtime-source.ts. * * Inline in `_document`'s head rather than a public file, so it is there * before the first page view is evaluated (about 14 KB unminified, a few KB * once the page is compressed). Added in `runBefore` because `_document` * reads `customCode.head` during generation; put first, so a broken tag in the * owner's own head code cannot swallow it. * A project without popups is left exactly as it was. */ export class NextPopupsProjectPlugin implements ProjectPlugin { async runBefore(structure: ProjectPluginStructure): Promise { const { uidl } = structure const snippet = buildPopupsHeadSnippet(uidl.popups) if (snippet) { const customCode = uidl.globals.customCode ?? {} uidl.globals.customCode = { ...customCode, head: `${snippet}${customCode.head ?? ''}` } } return structure } async runAfter(structure: ProjectPluginStructure): Promise { return structure } }