@payloadcms/ui 3.55.0-internal.92d1d86 → 3.55.0-internal.a030723
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/FieldSelect/reduceFieldOptions.js +1 -1
- package/dist/elements/FieldSelect/reduceFieldOptions.js.map +1 -1
- package/dist/elements/ListControls/index.d.ts.map +1 -1
- package/dist/elements/ListControls/index.js +78 -69
- package/dist/elements/ListControls/index.js.map +1 -1
- package/dist/elements/ListControls/index.scss +82 -2
- package/dist/elements/LivePreview/Window/index.d.ts.map +1 -1
- package/dist/elements/LivePreview/Window/index.js +64 -74
- package/dist/elements/LivePreview/Window/index.js.map +1 -1
- package/dist/elements/SearchBar/index.d.ts +3 -2
- package/dist/elements/SearchBar/index.d.ts.map +1 -1
- package/dist/elements/SearchBar/index.js +3 -2
- package/dist/elements/SearchBar/index.js.map +1 -1
- package/dist/elements/SearchBar/index.scss +7 -56
- package/dist/elements/SearchFilter/index.d.ts +33 -2
- package/dist/elements/SearchFilter/index.d.ts.map +1 -1
- package/dist/elements/SearchFilter/index.js +5 -7
- package/dist/elements/SearchFilter/index.js.map +1 -1
- package/dist/elements/Status/index.d.ts.map +1 -1
- package/dist/elements/Status/index.js +1 -1
- package/dist/elements/Status/index.js.map +1 -1
- package/dist/exports/client/index.js +24 -24
- package/dist/exports/client/index.js.map +4 -4
- package/dist/forms/RenderFields/index.d.ts.map +1 -1
- package/dist/forms/RenderFields/index.js +1 -1
- package/dist/forms/RenderFields/index.js.map +1 -1
- package/dist/forms/RowLabel/Context/index.d.ts.map +1 -1
- package/dist/forms/RowLabel/Context/index.js +31 -17
- package/dist/forms/RowLabel/Context/index.js.map +1 -1
- package/dist/providers/Auth/index.d.ts +1 -2
- package/dist/providers/Auth/index.d.ts.map +1 -1
- package/dist/providers/Auth/index.js +83 -74
- package/dist/providers/Auth/index.js.map +1 -1
- package/dist/providers/LivePreview/context.d.ts +2 -0
- package/dist/providers/LivePreview/context.d.ts.map +1 -1
- package/dist/providers/LivePreview/context.js +1 -0
- package/dist/providers/LivePreview/context.js.map +1 -1
- package/dist/providers/LivePreview/index.d.ts.map +1 -1
- package/dist/providers/LivePreview/index.js +12 -0
- package/dist/providers/LivePreview/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/views/BrowseByFolder/index.js +1 -1
- package/dist/views/BrowseByFolder/index.js.map +1 -1
- package/dist/views/CollectionFolder/index.js +1 -1
- package/dist/views/CollectionFolder/index.js.map +1 -1
- package/dist/views/Edit/Auth/index.d.ts.map +1 -1
- package/dist/views/Edit/Auth/index.js +1 -1
- package/dist/views/Edit/Auth/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/elements/SearchFilter/types.d.ts +0 -33
- package/dist/elements/SearchFilter/types.d.ts.map +0 -1
- package/dist/elements/SearchFilter/types.js +0 -2
- package/dist/elements/SearchFilter/types.js.map +0 -1
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
4
|
import { DndContext } from '@dnd-kit/core';
|
|
5
|
+
import { fieldSchemaToJSON } from 'payload/shared';
|
|
5
6
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
7
|
import { usePopupWindow } from '../../hooks/usePopupWindow.js';
|
|
7
8
|
import { useDocumentInfo } from '../../providers/DocumentInfo/index.js';
|
|
8
9
|
import { usePreferences } from '../../providers/Preferences/index.js';
|
|
10
|
+
import { useConfig } from '../Config/index.js';
|
|
9
11
|
import { customCollisionDetection } from './collisionDetection.js';
|
|
10
12
|
import { LivePreviewContext } from './context.js';
|
|
11
13
|
import { sizeReducer } from './sizeReducer.js';
|
|
@@ -56,6 +58,10 @@ export const LivePreviewProvider = ({
|
|
|
56
58
|
} = usePreferences();
|
|
57
59
|
const iframeRef = React.useRef(null);
|
|
58
60
|
const [iframeHasLoaded, setIframeHasLoaded] = useState(false);
|
|
61
|
+
const {
|
|
62
|
+
config,
|
|
63
|
+
getEntityConfig
|
|
64
|
+
} = useConfig();
|
|
59
65
|
const [zoom, setZoom] = useState(1);
|
|
60
66
|
const [position, setPosition] = useState({
|
|
61
67
|
x: 0,
|
|
@@ -69,7 +75,12 @@ export const LivePreviewProvider = ({
|
|
|
69
75
|
height: 0,
|
|
70
76
|
width: 0
|
|
71
77
|
});
|
|
78
|
+
const entityConfig = getEntityConfig({
|
|
79
|
+
collectionSlug,
|
|
80
|
+
globalSlug
|
|
81
|
+
});
|
|
72
82
|
const [breakpoint, setBreakpoint] = React.useState('responsive');
|
|
83
|
+
const [fieldSchemaJSON] = useState(() => fieldSchemaToJSON(entityConfig?.fields || [], config));
|
|
73
84
|
// The toolbar needs to freely drag and drop around the page
|
|
74
85
|
const handleDragEnd = ev => {
|
|
75
86
|
// only update position if the toolbar is completely within the preview area
|
|
@@ -158,6 +169,7 @@ export const LivePreviewProvider = ({
|
|
|
158
169
|
appIsReady,
|
|
159
170
|
breakpoint,
|
|
160
171
|
breakpoints,
|
|
172
|
+
fieldSchemaJSON,
|
|
161
173
|
iframeHasLoaded,
|
|
162
174
|
iframeRef,
|
|
163
175
|
isLivePreviewEnabled,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["DndContext","React","useCallback","useEffect","useMemo","useRef","useState","usePopupWindow","useDocumentInfo","usePreferences","customCollisionDetection","LivePreviewContext","sizeReducer","getAbsoluteUrl","url","URL","window","location","origin","href","LivePreviewProvider","breakpoints","incomingBreakpoints","children","isLivePreviewEnabled","isLivePreviewing","incomingIsLivePreviewing","incomingUrl","previewWindowType","setPreviewWindowType","setIsLivePreviewing","name","height","label","width","setURL","startsWith","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","listeningForMessages","setListeningForMessages","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","iframeHasLoaded","setIframeHasLoaded","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","measuredDeviceSize","setMeasuredDeviceSize","breakpoint","setBreakpoint","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","handleMessage","event","data","ready","addEventListener","removeEventListener","handleWindowChange","newPreviewWindowType","current","editViewType","_jsx","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"sources":["../../../src/providers/LivePreview/index.tsx"],"sourcesContent":["'use client'\nimport type { CollectionPreferences, LivePreviewConfig } from 'payload'\n\nimport { DndContext } from '@dnd-kit/core'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { customCollisionDetection } from './collisionDetection.js'\nimport { LivePreviewContext } from './context.js'\nimport { sizeReducer } from './sizeReducer.js'\n\nexport type LivePreviewProviderProps = {\n appIsReady?: boolean\n breakpoints?: LivePreviewConfig['breakpoints']\n children: React.ReactNode\n deviceSize?: {\n height: number\n width: number\n }\n isLivePreviewEnabled?: boolean\n isLivePreviewing: boolean\n url: string\n}\n\nconst getAbsoluteUrl = (url) => {\n try {\n return new URL(url, window.location.origin).href\n } catch {\n return url\n }\n}\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\n url: incomingUrl,\n}) => {\n const [previewWindowType, setPreviewWindowType] = useState<'iframe' | 'popup'>('iframe')\n const [isLivePreviewing, setIsLivePreviewing] = useState(incomingIsLivePreviewing)\n\n const breakpoints: LivePreviewConfig['breakpoints'] = useMemo(\n () => [\n ...(incomingBreakpoints || []),\n {\n name: 'responsive',\n height: '100%',\n label: 'Responsive',\n width: '100%',\n },\n ],\n [incomingBreakpoints],\n )\n\n const [url, setURL] = useState<string>('')\n\n // This needs to be done in a useEffect to prevent hydration issues\n // as the URL may not be absolute when passed in as a prop,\n // and getAbsoluteUrl requires the window object to be available\n useEffect(\n () =>\n setURL(\n incomingUrl?.startsWith('http://') || incomingUrl?.startsWith('https://')\n ? incomingUrl\n : getAbsoluteUrl(incomingUrl),\n ),\n [incomingUrl],\n )\n\n const { isPopupOpen, openPopupWindow, popupRef } = usePopupWindow({\n eventType: 'payload-live-preview',\n url,\n })\n\n const [appIsReady, setAppIsReady] = useState(false)\n const [listeningForMessages, setListeningForMessages] = useState(false)\n\n const { collectionSlug, globalSlug } = useDocumentInfo()\n\n const isFirstRender = useRef(true)\n\n const { setPreference } = usePreferences()\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null)\n\n const [iframeHasLoaded, setIframeHasLoaded] = useState(false)\n\n const [zoom, setZoom] = useState(1)\n\n const [position, setPosition] = useState({ x: 0, y: 0 })\n\n const [size, setSize] = React.useReducer(sizeReducer, { height: 0, width: 0 })\n\n const [measuredDeviceSize, setMeasuredDeviceSize] = useState({\n height: 0,\n width: 0,\n })\n\n const [breakpoint, setBreakpoint] =\n React.useState<LivePreviewConfig['breakpoints'][0]['name']>('responsive')\n\n // The toolbar needs to freely drag and drop around the page\n const handleDragEnd = (ev) => {\n // only update position if the toolbar is completely within the preview area\n // otherwise reset it back to the previous position\n // TODO: reset to the nearest edge of the preview area\n if (ev.over && ev.over.id === 'live-preview-area') {\n const newPos = {\n x: position.x + ev.delta.x,\n y: position.y + ev.delta.y,\n }\n\n setPosition(newPos)\n } else {\n // reset\n }\n }\n\n const setWidth = useCallback(\n (width) => {\n setSize({ type: 'width', value: width })\n },\n [setSize],\n )\n\n const setHeight = useCallback(\n (height) => {\n setSize({ type: 'height', value: height })\n },\n [setSize],\n )\n\n // explicitly set new width and height when as new breakpoints are selected\n // exclude `custom` breakpoint as it is handled by the `setWidth` and `setHeight` directly\n useEffect(() => {\n const foundBreakpoint = breakpoints?.find((bp) => bp.name === breakpoint)\n\n if (\n foundBreakpoint &&\n breakpoint !== 'responsive' &&\n breakpoint !== 'custom' &&\n typeof foundBreakpoint?.width === 'number' &&\n typeof foundBreakpoint?.height === 'number'\n ) {\n setSize({\n type: 'reset',\n value: {\n height: foundBreakpoint.height,\n width: foundBreakpoint.width,\n },\n })\n }\n }, [breakpoint, breakpoints])\n\n // Receive the `ready` message from the popup window\n // This indicates that the app is ready to receive `window.postMessage` events\n // This is also the only cross-origin way of detecting when a popup window has loaded\n // Unlike iframe elements which have an `onLoad` handler, there is no way to access `window.open` on popups\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n if (\n url?.startsWith(event.origin) &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-live-preview'\n ) {\n if (event.data.ready) {\n setAppIsReady(true)\n }\n }\n }\n\n window.addEventListener('message', handleMessage)\n\n setListeningForMessages(true)\n\n return () => {\n window.removeEventListener('message', handleMessage)\n }\n }, [url, listeningForMessages])\n\n const handleWindowChange = useCallback(\n (type: 'iframe' | 'popup') => {\n setAppIsReady(false)\n setPreviewWindowType(type)\n if (type === 'popup') {\n openPopupWindow()\n }\n },\n [openPopupWindow],\n )\n\n // when the user closes the popup window, switch back to the iframe\n // the `usePopupWindow` reports the `isPopupOpen` state for us to use here\n useEffect(() => {\n const newPreviewWindowType = isPopupOpen ? 'popup' : 'iframe'\n\n if (newPreviewWindowType !== previewWindowType) {\n handleWindowChange('iframe')\n }\n }, [previewWindowType, isPopupOpen, handleWindowChange])\n\n useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = false\n return\n }\n\n void setPreference<CollectionPreferences>(\n collectionSlug ? `collection-${collectionSlug}` : `global-${globalSlug}`,\n {\n editViewType: isLivePreviewing ? 'live-preview' : 'default',\n },\n true,\n )\n }, [isLivePreviewing, setPreference, collectionSlug, globalSlug])\n\n return (\n <LivePreviewContext\n value={{\n appIsReady,\n breakpoint,\n breakpoints,\n iframeHasLoaded,\n iframeRef,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n listeningForMessages,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIframeHasLoaded,\n setIsLivePreviewing,\n setMeasuredDeviceSize,\n setPreviewWindowType: handleWindowChange,\n setSize,\n setToolbarPosition: setPosition,\n setWidth,\n setZoom,\n size,\n toolbarPosition: position,\n url,\n zoom,\n }}\n >\n <DndContext collisionDetection={customCollisionDetection} onDragEnd={handleDragEnd}>\n {children}\n </DndContext>\n </LivePreviewContext>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,UAAU,QAAQ;AAC3B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAEzE,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,wBAAwB,QAAQ;AACzC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,WAAW,QAAQ;AAe5B,MAAMC,cAAA,GAAkBC,GAAA;EACtB,IAAI;IACF,OAAO,IAAIC,GAAA,CAAID,GAAA,EAAKE,MAAA,CAAOC,QAAQ,CAACC,MAAM,EAAEC,IAAI;EAClD,EAAE,MAAM;IACN,OAAOL,GAAA;EACT;AACF;AAEA,OAAO,MAAMM,mBAAA,GAA0DA,CAAC;EACtEC,WAAA,EAAaC,mBAAmB;EAChCC,QAAQ;EACRC,oBAAoB;EACpBC,gBAAA,EAAkBC,wBAAwB;EAC1CZ,GAAA,EAAKa;AAAW,CACjB;EACC,MAAM,CAACC,iBAAA,EAAmBC,oBAAA,CAAqB,GAAGvB,QAAA,CAA6B;EAC/E,MAAM,CAACmB,gBAAA,EAAkBK,mBAAA,CAAoB,GAAGxB,QAAA,CAASoB,wBAAA;EAEzD,MAAML,WAAA,GAAgDjB,OAAA,CACpD,MAAM,C,IACAkB,mBAAA,IAAuB,EAAE,GAC7B;IACES,IAAA,EAAM;IACNC,MAAA,EAAQ;IACRC,KAAA,EAAO;IACPC,KAAA,EAAO;EACT,EAC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,cAAA,EAAgBC,UAAA,CAAW;EAEhE,oBACE0C,IAAA,CAAC7E,kBAAA;IACC8D,KAAA,EAAO;MACLhC,UAAA;MACAsB,UAAA;MACA1C,WAAA;MACA6B,eAAA;MACAD,SAAA;MACAzB,oBAAA;MACAC,gBAAA;MACAY,WAAA;MACAM,oBAAA;MACAkB,kBAAA;MACAvB,eAAA;MACAC,QAAA;MACAX,iBAAA;MACAc,aAAA;MACAsB,aAAA;MACAU,SAAA;MACAvB,kBAAA;MACArB,mBAAA;MACAgC,qBAAA;MACAjC,oBAAA,EAAsBuD,kBAAA;MACtBzB,OAAA;MACA8B,kBAAA,EAAoBlC,WAAA;MACpBgB,QAAA;MACAlB,OAAA;MACAK,IAAA;MACAgC,eAAA,EAAiBpC,QAAA;MACjBxC,GAAA;MACAsC;IACF;cAEA,aAAAoC,IAAA,CAACxF,UAAA;MAAW2F,kBAAA,EAAoBjF,wBAAA;MAA0BkF,SAAA,EAAW3B,aAAA;gBAClE1C;;;AAIT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["DndContext","fieldSchemaToJSON","React","useCallback","useEffect","useMemo","useRef","useState","usePopupWindow","useDocumentInfo","usePreferences","useConfig","customCollisionDetection","LivePreviewContext","sizeReducer","getAbsoluteUrl","url","URL","window","location","origin","href","LivePreviewProvider","breakpoints","incomingBreakpoints","children","isLivePreviewEnabled","isLivePreviewing","incomingIsLivePreviewing","incomingUrl","previewWindowType","setPreviewWindowType","setIsLivePreviewing","name","height","label","width","setURL","startsWith","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","listeningForMessages","setListeningForMessages","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","iframeHasLoaded","setIframeHasLoaded","config","getEntityConfig","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","measuredDeviceSize","setMeasuredDeviceSize","entityConfig","breakpoint","setBreakpoint","fieldSchemaJSON","fields","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","handleMessage","event","data","ready","addEventListener","removeEventListener","handleWindowChange","newPreviewWindowType","current","editViewType","_jsx","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"sources":["../../../src/providers/LivePreview/index.tsx"],"sourcesContent":["'use client'\nimport type { CollectionPreferences, LivePreviewConfig } from 'payload'\n\nimport { DndContext } from '@dnd-kit/core'\nimport { fieldSchemaToJSON } from 'payload/shared'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { useConfig } from '../Config/index.js'\nimport { customCollisionDetection } from './collisionDetection.js'\nimport { LivePreviewContext } from './context.js'\nimport { sizeReducer } from './sizeReducer.js'\n\nexport type LivePreviewProviderProps = {\n appIsReady?: boolean\n breakpoints?: LivePreviewConfig['breakpoints']\n children: React.ReactNode\n deviceSize?: {\n height: number\n width: number\n }\n isLivePreviewEnabled?: boolean\n isLivePreviewing: boolean\n url: string\n}\n\nconst getAbsoluteUrl = (url) => {\n try {\n return new URL(url, window.location.origin).href\n } catch {\n return url\n }\n}\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\n url: incomingUrl,\n}) => {\n const [previewWindowType, setPreviewWindowType] = useState<'iframe' | 'popup'>('iframe')\n const [isLivePreviewing, setIsLivePreviewing] = useState(incomingIsLivePreviewing)\n\n const breakpoints: LivePreviewConfig['breakpoints'] = useMemo(\n () => [\n ...(incomingBreakpoints || []),\n {\n name: 'responsive',\n height: '100%',\n label: 'Responsive',\n width: '100%',\n },\n ],\n [incomingBreakpoints],\n )\n\n const [url, setURL] = useState<string>('')\n\n // This needs to be done in a useEffect to prevent hydration issues\n // as the URL may not be absolute when passed in as a prop,\n // and getAbsoluteUrl requires the window object to be available\n useEffect(\n () =>\n setURL(\n incomingUrl?.startsWith('http://') || incomingUrl?.startsWith('https://')\n ? incomingUrl\n : getAbsoluteUrl(incomingUrl),\n ),\n [incomingUrl],\n )\n\n const { isPopupOpen, openPopupWindow, popupRef } = usePopupWindow({\n eventType: 'payload-live-preview',\n url,\n })\n\n const [appIsReady, setAppIsReady] = useState(false)\n const [listeningForMessages, setListeningForMessages] = useState(false)\n\n const { collectionSlug, globalSlug } = useDocumentInfo()\n\n const isFirstRender = useRef(true)\n\n const { setPreference } = usePreferences()\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null)\n\n const [iframeHasLoaded, setIframeHasLoaded] = useState(false)\n\n const { config, getEntityConfig } = useConfig()\n\n const [zoom, setZoom] = useState(1)\n\n const [position, setPosition] = useState({ x: 0, y: 0 })\n\n const [size, setSize] = React.useReducer(sizeReducer, { height: 0, width: 0 })\n\n const [measuredDeviceSize, setMeasuredDeviceSize] = useState({\n height: 0,\n width: 0,\n })\n\n const entityConfig = getEntityConfig({ collectionSlug, globalSlug })\n\n const [breakpoint, setBreakpoint] =\n React.useState<LivePreviewConfig['breakpoints'][0]['name']>('responsive')\n\n const [fieldSchemaJSON] = useState(() => fieldSchemaToJSON(entityConfig?.fields || [], config))\n\n // The toolbar needs to freely drag and drop around the page\n const handleDragEnd = (ev) => {\n // only update position if the toolbar is completely within the preview area\n // otherwise reset it back to the previous position\n // TODO: reset to the nearest edge of the preview area\n if (ev.over && ev.over.id === 'live-preview-area') {\n const newPos = {\n x: position.x + ev.delta.x,\n y: position.y + ev.delta.y,\n }\n\n setPosition(newPos)\n } else {\n // reset\n }\n }\n\n const setWidth = useCallback(\n (width) => {\n setSize({ type: 'width', value: width })\n },\n [setSize],\n )\n\n const setHeight = useCallback(\n (height) => {\n setSize({ type: 'height', value: height })\n },\n [setSize],\n )\n\n // explicitly set new width and height when as new breakpoints are selected\n // exclude `custom` breakpoint as it is handled by the `setWidth` and `setHeight` directly\n useEffect(() => {\n const foundBreakpoint = breakpoints?.find((bp) => bp.name === breakpoint)\n\n if (\n foundBreakpoint &&\n breakpoint !== 'responsive' &&\n breakpoint !== 'custom' &&\n typeof foundBreakpoint?.width === 'number' &&\n typeof foundBreakpoint?.height === 'number'\n ) {\n setSize({\n type: 'reset',\n value: {\n height: foundBreakpoint.height,\n width: foundBreakpoint.width,\n },\n })\n }\n }, [breakpoint, breakpoints])\n\n // Receive the `ready` message from the popup window\n // This indicates that the app is ready to receive `window.postMessage` events\n // This is also the only cross-origin way of detecting when a popup window has loaded\n // Unlike iframe elements which have an `onLoad` handler, there is no way to access `window.open` on popups\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n if (\n url?.startsWith(event.origin) &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-live-preview'\n ) {\n if (event.data.ready) {\n setAppIsReady(true)\n }\n }\n }\n\n window.addEventListener('message', handleMessage)\n\n setListeningForMessages(true)\n\n return () => {\n window.removeEventListener('message', handleMessage)\n }\n }, [url, listeningForMessages])\n\n const handleWindowChange = useCallback(\n (type: 'iframe' | 'popup') => {\n setAppIsReady(false)\n setPreviewWindowType(type)\n if (type === 'popup') {\n openPopupWindow()\n }\n },\n [openPopupWindow],\n )\n\n // when the user closes the popup window, switch back to the iframe\n // the `usePopupWindow` reports the `isPopupOpen` state for us to use here\n useEffect(() => {\n const newPreviewWindowType = isPopupOpen ? 'popup' : 'iframe'\n\n if (newPreviewWindowType !== previewWindowType) {\n handleWindowChange('iframe')\n }\n }, [previewWindowType, isPopupOpen, handleWindowChange])\n\n useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = false\n return\n }\n\n void setPreference<CollectionPreferences>(\n collectionSlug ? `collection-${collectionSlug}` : `global-${globalSlug}`,\n {\n editViewType: isLivePreviewing ? 'live-preview' : 'default',\n },\n true,\n )\n }, [isLivePreviewing, setPreference, collectionSlug, globalSlug])\n\n return (\n <LivePreviewContext\n value={{\n appIsReady,\n breakpoint,\n breakpoints,\n fieldSchemaJSON,\n iframeHasLoaded,\n iframeRef,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n listeningForMessages,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIframeHasLoaded,\n setIsLivePreviewing,\n setMeasuredDeviceSize,\n setPreviewWindowType: handleWindowChange,\n setSize,\n setToolbarPosition: setPosition,\n setWidth,\n setZoom,\n size,\n toolbarPosition: position,\n url,\n zoom,\n }}\n >\n <DndContext collisionDetection={customCollisionDetection} onDragEnd={handleDragEnd}>\n {children}\n </DndContext>\n </LivePreviewContext>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,UAAU,QAAQ;AAC3B,SAASC,iBAAiB,QAAQ;AAClC,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAEzE,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,wBAAwB,QAAQ;AACzC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,WAAW,QAAQ;AAe5B,MAAMC,cAAA,GAAkBC,GAAA;EACtB,IAAI;IACF,OAAO,IAAIC,GAAA,CAAID,GAAA,EAAKE,MAAA,CAAOC,QAAQ,CAACC,MAAM,EAAEC,IAAI;EAClD,EAAE,MAAM;IACN,OAAOL,GAAA;EACT;AACF;AAEA,OAAO,MAAMM,mBAAA,GAA0DA,CAAC;EACtEC,WAAA,EAAaC,mBAAmB;EAChCC,QAAQ;EACRC,oBAAoB;EACpBC,gBAAA,EAAkBC,wBAAwB;EAC1CZ,GAAA,EAAKa;AAAW,CACjB;EACC,MAAM,CAACC,iBAAA,EAAmBC,oBAAA,CAAqB,GAAGxB,QAAA,CAA6B;EAC/E,MAAM,CAACoB,gBAAA,EAAkBK,mBAAA,CAAoB,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