{"version":3,"file":"index.js","names":["c","_c","reduceFieldsToValues","React","useEffect","useAllFormFields","useDocumentEvents","useDocumentInfo","useLivePreviewContext","useLocale","ShimmerEffect","DeviceContainer","IFrame","LivePreviewToolbar","baseClass","LivePreviewWindow","props","$","appIsReady","breakpoint","iframeRef","isLivePreviewing","loadedURL","popupRef","previewWindowType","url","locale","mostRecentUpdate","formState","id","collectionSlug","globalSlug","t0","values","message","type","data","externallyUpdatedRelationship","code","current","postMessage","contentWindow","t1","t2","message_0","t3","t4","t5","t6","filter","Boolean","t7","join","t8","_jsx","className","children","_jsxs","height"],"sources":["../../../../src/elements/LivePreview/Window/index.tsx"],"sourcesContent":["'use client'\n\nimport type { EditViewProps } from 'payload'\n\nimport { reduceFieldsToValues } from 'payload/shared'\nimport React, { useEffect } from 'react'\n\nimport { useAllFormFields } from '../../../forms/Form/context.js'\nimport { useDocumentEvents } from '../../../providers/DocumentEvents/index.js'\nimport { useDocumentInfo } from '../../../providers/DocumentInfo/index.js'\nimport { useLivePreviewContext } from '../../../providers/LivePreview/context.js'\nimport { useLocale } from '../../../providers/Locale/index.js'\nimport { ShimmerEffect } from '../../ShimmerEffect/index.js'\nimport { DeviceContainer } from '../Device/index.js'\nimport { IFrame } from '../IFrame/index.js'\nimport { LivePreviewToolbar } from '../Toolbar/index.js'\nimport './index.scss'\n\nconst baseClass = 'live-preview-window'\n\nexport const LivePreviewWindow: React.FC = (props) => {\n const {\n appIsReady,\n breakpoint,\n iframeRef,\n isLivePreviewing,\n loadedURL,\n popupRef,\n previewWindowType,\n url,\n } = useLivePreviewContext()\n\n const locale = useLocale()\n\n const { mostRecentUpdate } = useDocumentEvents()\n\n const [formState] = useAllFormFields()\n const { id, collectionSlug, globalSlug } = useDocumentInfo()\n\n /**\n * For client-side apps, send data through `window.postMessage`\n * The preview could either be an iframe embedded on the page\n * Or it could be a separate popup window\n * We need to transmit data to both accordingly\n */\n useEffect(() => {\n if (!isLivePreviewing || !appIsReady) {\n return\n }\n\n // For performance, do not reduce fields to values until after the iframe or popup has loaded\n if (formState) {\n const values = reduceFieldsToValues(formState, true)\n\n if (!values.id) {\n values.id = id\n }\n\n const message = {\n type: 'payload-live-preview',\n collectionSlug,\n data: values,\n externallyUpdatedRelationship: mostRecentUpdate,\n globalSlug,\n locale: locale.code,\n }\n\n // Post message to external popup window\n if (previewWindowType === 'popup' && popupRef.current) {\n popupRef.current.postMessage(message, url)\n }\n\n // Post message to embedded iframe\n if (previewWindowType === 'iframe' && iframeRef.current) {\n iframeRef.current.contentWindow?.postMessage(message, url)\n }\n }\n }, [\n formState,\n url,\n collectionSlug,\n globalSlug,\n id,\n previewWindowType,\n popupRef,\n appIsReady,\n iframeRef,\n mostRecentUpdate,\n locale,\n isLivePreviewing,\n loadedURL,\n ])\n\n /**\n * To support SSR, we transmit a `window.postMessage` event without a payload\n * This is because the event will ultimately trigger a server-side roundtrip\n * i.e., save, save draft, autosave, etc. will fire `router.refresh()`\n */\n useEffect(() => {\n if (!isLivePreviewing || !appIsReady) {\n return\n }\n\n const message = {\n type: 'payload-document-event',\n }\n\n // Post message to external popup window\n if (previewWindowType === 'popup' && popupRef.current) {\n popupRef.current.postMessage(message, url)\n }\n\n // Post message to embedded iframe\n if (previewWindowType === 'iframe' && iframeRef.current) {\n iframeRef.current.contentWindow?.postMessage(message, url)\n }\n }, [mostRecentUpdate, iframeRef, popupRef, previewWindowType, url, isLivePreviewing, appIsReady])\n\n if (previewWindowType !== 'iframe') {\n return null\n }\n\n return (\n \n
\n \n
\n {url ?