{ "version": 3, "sources": ["../../../../src/assets/mcui-js/marketo/form-modal-launcher.ts"], "sourcesContent": ["import { isNil, type Nil } from \"@mcwd/typescript-type-guards\";\r\nimport type { App as VueApp } from \"vue\";\r\nimport type { AppFormType } from \"./components/App-Form-Types.js\";\r\nimport { BaseFormLogger as logger } from \"./base-form-logger.js\";\r\nimport { FormExperienceSettingsObject } from \"./form-settings/form-experience/form-experience-settings.js\";\r\nimport type { GetInitializeFormParametersBySettingsKey } from \"./form-app-initializer.js\";\r\n\r\nconst { initializeForm } = await import(\"./form-app-initializer.js\");\r\n\r\n/** Id for the dynamically inserted modal wrapper */\r\nconst dynamicModalWrapperId = \"js-dynamic-modal-wrapper\";\r\n/** Selector for the dynamically inserted modal wrapper */\r\nconst dynamicWrapperSelector = `#${ dynamicModalWrapperId }`;\r\n\r\n/** FormSettingsKey values for form-experience settings that have 'canUseModal' === true */\r\nexport type ModalFormSettingsKey = (\r\n {\r\n [ K in keyof FormExperienceSettingsObject ]: \r\n [FormExperienceSettingsObject[ K ][\"canUseModal\"]] extends [true]\r\n ? K\r\n : never \r\n }\r\n)[keyof FormExperienceSettingsObject];\r\n\r\nexport const ModalFormSettingsKey = Object.keys(FormExperienceSettingsObject).filter(k => FormExperienceSettingsObject[ k ].canUseModal === true) as ModalFormSettingsKey[];\r\n\r\nfunction removeDynamicWrapper() {\r\n const dynamicWrapper: HTMLElement | Nil = document.body.querySelector(dynamicWrapperSelector);\r\n if (!isNil(dynamicWrapper)) {\r\n logger.debug(\"remove dynamic wrapper\");\r\n document.body.removeChild(dynamicWrapper);\r\n }\r\n}\r\n\r\n/** \r\n * Dynamically create an div element as a container for a form modal.\r\n * \r\n * The div itself is just a wrapper and is positioned off of the screen so it is not visible \r\n */\r\nfunction createDynamicWrapper() {\r\n removeDynamicWrapper();\r\n let dynamicWrapper: HTMLElement | Nil = document.querySelector(dynamicWrapperSelector);\r\n if (isNil(dynamicWrapper)) {\r\n dynamicWrapper = document.createElement('div');\r\n dynamicWrapper.id = dynamicModalWrapperId;\r\n dynamicWrapper.style.position = \"absolute\";\r\n dynamicWrapper.style.left = \"-10000px\";\r\n dynamicWrapper.style.top = \"auto\";\r\n dynamicWrapper.style.width = \"1px\";\r\n dynamicWrapper.style.height = \"1px\";\r\n dynamicWrapper.style.overflow = \"hidden\";\r\n dynamicWrapper.style.width = \"100px\";\r\n dynamicWrapper.style.height = \"100px\";\r\n dynamicWrapper.classList.add('eclipse-top-wrpr');\r\n document.body.appendChild(dynamicWrapper);\r\n dynamicWrapper = document.querySelector(dynamicWrapperSelector) as HTMLElement;\r\n }\r\n return dynamicWrapper;\r\n}\r\n\r\n/** \r\n * Receives the Vue App instance and component instance for the form that is currently displayed in the modal as parameters. \r\n * This function sets up an event handler on the component instance to unmount the app and remove the dynamic modal wrapper when the modal is closed.\r\n */\r\nfunction createWrapperCleanupHandlers(appInstance: VueApp, componentInstance: AppFormType) {\r\n const onEvent = componentInstance.onEvent;\r\n const offEvent = componentInstance.offEvent;\r\n const modalClosedHandler = () => {\r\n logger.debug(\"Calling modalClosedHandler\");\r\n offEvent(\"modalClosed\", modalClosedHandler);\r\n appInstance.unmount();\r\n removeDynamicWrapper();\r\n };\r\n logger.debug(\"Create onEvent\");\r\n onEvent(\"modalClosed\", modalClosedHandler);\r\n return { appInstance, componentInstance };\r\n}\r\n\r\n/** Export an object with two functions, `create` and `cleanup` that allow directly controlling creation and cleanup handler creation for the dynamic modal wrapper.\r\n * This object is exposed solely for export from the \"form-cta-modal-launcher\" file where it is re-exported as dynamicModalWrapper for legacy code.\r\n * We need to verify that the dynamicModalWrapper const exported from that file isn't used anywhere in legacy code or sitefinity database, then we can remove this and simply use the `launchModalForm` function instead.\r\n * @deprecated -- Cannot remove until we verify that this isn't used anywhere in legacy code or script blocks on the website \r\n */\r\nexport const DynamicModalWrapperManager = {\r\n create: createDynamicWrapper,\r\n cleanup: createWrapperCleanupHandlers\r\n} as const;\r\n\r\ntype DistributedOmit = \r\n T extends any\r\n ? Omit\r\n : never;\r\nexport async function launchModalForm<\r\n TFormSettingsKey extends Exclude\r\n> (\r\n options: DistributedOmit, \"rootContainer\">\r\n)\r\n{\r\n const rootContainer = createDynamicWrapper();\r\n logger.debug(`initializeForm<${ options?.formSettingsKey }>`);\r\n const fullArgs = { ...options, rootContainer } as GetInitializeFormParametersBySettingsKey;\r\n const { appInstance, componentInstance } = await initializeForm(fullArgs);\r\n createWrapperCleanupHandlers(appInstance, componentInstance);\r\n return { appInstance, componentInstance };\r\n}"], "mappings": "0GAOA,GAAM,CAAE,eAAAA,CAAe,EAAI,KAAM,QAAO,+BAA2B,EAG7DC,EAAwB,2BAExBC,EAAyB,IAAKD,CAAsB,GAY7CE,EAAuB,OAAO,KAAKC,CAA4B,EAAE,OAAOC,GAAKD,EAA8BC,CAAE,EAAE,cAAgB,EAAI,EAEhJ,SAASC,GAAuB,CAC9B,IAAMC,EAAoC,SAAS,KAAK,cAA2BL,CAAsB,EACpGM,EAAMD,CAAc,IACvBE,EAAO,MAAM,wBAAwB,EACrC,SAAS,KAAK,YAAYF,CAAc,EAE5C,CAOA,SAASG,GAAuB,CAC9BJ,EAAqB,EACrB,IAAIC,EAAoC,SAAS,cAA2BL,CAAsB,EAClG,OAAIM,EAAMD,CAAc,IACtBA,EAAiB,SAAS,cAAc,KAAK,EAC7CA,EAAe,GAAKN,EACpBM,EAAe,MAAM,SAAW,WAChCA,EAAe,MAAM,KAAO,WAC5BA,EAAe,MAAM,IAAM,OAC3BA,EAAe,MAAM,MAAQ,MAC7BA,EAAe,MAAM,OAAS,MAC9BA,EAAe,MAAM,SAAW,SAChCA,EAAe,MAAM,MAAQ,QAC7BA,EAAe,MAAM,OAAS,QAC9BA,EAAe,UAAU,IAAI,kBAAkB,EAC/C,SAAS,KAAK,YAAYA,CAAc,EACxCA,EAAiB,SAAS,cAA2BL,CAAsB,GAEtEK,CACT,CAMA,SAASI,EAA6BC,EAA8BC,EAAgC,CAClG,IAAMC,EAAUD,EAAkB,QAC5BE,EAAWF,EAAkB,SAC7BG,EAAqB,IAAM,CAC/BP,EAAO,MAAM,4BAA4B,EACzCM,EAAS,cAAeC,CAAkB,EAC1CJ,EAAY,QAAQ,EACpBN,EAAqB,CACvB,EACA,OAAAG,EAAO,MAAM,gBAAgB,EAC7BK,EAAQ,cAAeE,CAAkB,EAClC,CAAE,YAAAJ,EAAa,kBAAAC,CAAkB,CAC1C,CAOO,IAAMI,EAA6B,CACxC,OAAQP,EACR,QAASC,CACX,EAMA,eAAsBO,EAGpBC,EAEF,CACE,IAAMC,EAAgBV,EAAqB,EAC3CD,EAAO,MAAM,kBAAmBU,GAAS,eAAgB,GAAG,EAC5D,IAAME,EAAW,CAAE,GAAGF,EAAS,cAAAC,CAAc,EACvC,CAAE,YAAAR,EAAa,kBAAAC,CAAkB,EAAI,MAAMb,EAAiCqB,CAAQ,EAC1F,OAAAV,EAA6BC,EAAaC,CAAiB,EACpD,CAAE,YAAAD,EAAa,kBAAAC,CAAkB,CAC1C", "names": ["initializeForm", "dynamicModalWrapperId", "dynamicWrapperSelector", "ModalFormSettingsKey", "FormExperienceSettingsObject", "k", "removeDynamicWrapper", "dynamicWrapper", "isNil", "BaseFormLogger", "createDynamicWrapper", "createWrapperCleanupHandlers", "appInstance", "componentInstance", "onEvent", "offEvent", "modalClosedHandler", "DynamicModalWrapperManager", "launchModalForm", "options", "rootContainer", "fullArgs"] }