@payloadcms/ui 3.68.0-internal.35482da → 3.68.0-internal.4c88018

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.
Files changed (59) hide show
  1. package/dist/elements/AnimateHeight/usePatchAnimateHeight.js +1 -2
  2. package/dist/elements/AnimateHeight/usePatchAnimateHeight.js.map +1 -1
  3. package/dist/elements/DraggableSortable/DraggableSortableItem/index.d.ts.map +1 -1
  4. package/dist/elements/DraggableSortable/DraggableSortableItem/index.js +2 -1
  5. package/dist/elements/DraggableSortable/DraggableSortableItem/index.js.map +1 -1
  6. package/dist/elements/DraggableSortable/index.d.ts.map +1 -1
  7. package/dist/elements/DraggableSortable/index.js +15 -12
  8. package/dist/elements/DraggableSortable/index.js.map +1 -1
  9. package/dist/elements/DraggableSortable/useDraggableSortable/index.d.ts.map +1 -1
  10. package/dist/elements/DraggableSortable/useDraggableSortable/index.js +2 -1
  11. package/dist/elements/DraggableSortable/useDraggableSortable/index.js.map +1 -1
  12. package/dist/elements/Link/index.d.ts.map +1 -1
  13. package/dist/elements/ListDrawer/DrawerContent.js +1 -2
  14. package/dist/elements/ListDrawer/DrawerContent.js.map +1 -1
  15. package/dist/elements/Thumbnail/createThumbnail.js +4 -8
  16. package/dist/elements/Thumbnail/createThumbnail.js.map +1 -1
  17. package/dist/elements/WhereBuilder/Condition/Relationship/index.js +1 -2
  18. package/dist/elements/WhereBuilder/Condition/Relationship/index.js.map +1 -1
  19. package/dist/elements/WhereBuilder/index.js +1 -2
  20. package/dist/elements/WhereBuilder/index.js.map +1 -1
  21. package/dist/exports/client/{CodeEditor-QOURTFMT.js → CodeEditor-YX3DTLLV.js} +2 -2
  22. package/dist/exports/client/{DatePicker-VMLA35FO.js → DatePicker-KHWHHBGL.js} +2 -2
  23. package/dist/exports/client/chunk-AIZM2QMN.js +27 -0
  24. package/dist/exports/client/chunk-AIZM2QMN.js.map +7 -0
  25. package/dist/exports/client/chunk-KF6HIYPT.js +29 -0
  26. package/dist/exports/client/{chunk-7V3NHDV6.js.map → chunk-KF6HIYPT.js.map} +4 -4
  27. package/dist/exports/client/index.js +12 -12
  28. package/dist/exports/client/index.js.map +4 -4
  29. package/dist/exports/shared/index.js +1 -1
  30. package/dist/exports/shared/index.js.map +1 -1
  31. package/dist/fields/Checkbox/Input.d.ts.map +1 -1
  32. package/dist/fields/Checkbox/Input.js +1 -0
  33. package/dist/fields/Checkbox/Input.js.map +1 -1
  34. package/dist/forms/Form/index.js +3 -6
  35. package/dist/forms/Form/index.js.map +1 -1
  36. package/dist/forms/Form/mergeServerFormState.js +1 -2
  37. package/dist/forms/Form/mergeServerFormState.js.map +1 -1
  38. package/dist/hooks/useQueue.js +2 -4
  39. package/dist/hooks/useQueue.js.map +1 -1
  40. package/dist/providers/DocumentInfo/index.js +1 -2
  41. package/dist/providers/DocumentInfo/index.js.map +1 -1
  42. package/dist/providers/LivePreview/index.d.ts.map +1 -1
  43. package/dist/providers/LivePreview/index.js +4 -1
  44. package/dist/providers/LivePreview/index.js.map +1 -1
  45. package/dist/providers/Root/index.d.ts.map +1 -1
  46. package/dist/providers/Root/index.js.map +1 -1
  47. package/dist/providers/ServerFunctions/index.js +8 -16
  48. package/dist/providers/ServerFunctions/index.js.map +1 -1
  49. package/dist/providers/TableColumns/buildColumnState/index.js +1 -2
  50. package/dist/providers/TableColumns/buildColumnState/index.js.map +1 -1
  51. package/dist/styles.css +1 -1
  52. package/dist/views/Edit/index.js +1 -2
  53. package/dist/views/Edit/index.js.map +1 -1
  54. package/package.json +11 -12
  55. package/dist/exports/client/chunk-53XJ3K67.js +0 -27
  56. package/dist/exports/client/chunk-53XJ3K67.js.map +0 -7
  57. package/dist/exports/client/chunk-7V3NHDV6.js +0 -29
  58. /package/dist/exports/client/{CodeEditor-QOURTFMT.js.map → CodeEditor-YX3DTLLV.js.map} +0 -0
  59. /package/dist/exports/client/{DatePicker-VMLA35FO.js.map → DatePicker-KHWHHBGL.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["DndContext","React","useCallback","useEffect","useMemo","useRef","useState","usePopupWindow","useDocumentInfo","usePreferences","formatAbsoluteURL","customCollisionDetection","LivePreviewContext","sizeReducer","LivePreviewProvider","breakpoints","incomingBreakpoints","children","isLivePreviewEnabled","isLivePreviewing","incomingIsLivePreviewing","isPreviewEnabled","previewURL","previewURLFromProps","typeofLivePreviewURL","url","urlFromProps","previewWindowType","setPreviewWindowType","setIsLivePreviewing","name","height","label","width","setURL","setPreviewURL","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","listeningForMessages","setListeningForMessages","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","loadedURL","setLoadedURL","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","measuredDeviceSize","setMeasuredDeviceSize","breakpoint","setBreakpoint","setLivePreviewURL","_incomingURL","incomingURL","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","handleMessage","event","startsWith","origin","data","ready","window","addEventListener","removeEventListener","handleWindowChange","newPreviewWindowType","current","editViewType","_jsx","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"sources":["../../../src/providers/LivePreview/index.tsx"],"sourcesContent":["'use client'\nimport type { CollectionPreferences, LivePreviewConfig, LivePreviewURLType } from 'payload'\n\nimport { DndContext } from '@dnd-kit/core'\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { LivePreviewContextType } from './context.js'\n\nimport { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { formatAbsoluteURL } from '../../utilities/formatAbsoluteURL.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 /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n isPreviewEnabled?: boolean\n /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n previewURL?: string\n} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\n isPreviewEnabled,\n previewURL: previewURLFromProps,\n typeofLivePreviewURL,\n url: urlFromProps,\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 const [previewURL, setPreviewURL] = useState<string>(previewURLFromProps)\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 [loadedURL, setLoadedURL] = useState<string>()\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 /**\n * A \"middleware\" callback fn that does some additional work before `setURL`.\n * This is what we provide through context, bc it:\n * - ensures the URL is absolute\n * - resets `appIsReady` to `false` while the new URL is loading\n */\n const setLivePreviewURL = useCallback<LivePreviewContextType['setURL']>(\n (_incomingURL) => {\n let incomingURL: LivePreviewURLType\n\n if (typeof _incomingURL === 'string') {\n incomingURL = formatAbsoluteURL(_incomingURL)\n }\n\n if (!incomingURL) {\n setIsLivePreviewing(false)\n }\n\n if (incomingURL !== url) {\n setAppIsReady(false)\n setURL(incomingURL)\n }\n },\n [url],\n )\n\n /**\n * `url` needs to be relative to the window, which cannot be done on initial render.\n */\n useEffect(() => {\n if (typeof urlFromProps === 'string') {\n setURL(formatAbsoluteURL(urlFromProps))\n }\n }, [urlFromProps])\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 /**\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 */\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 iframeRef,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n isPreviewEnabled,\n listeningForMessages,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewURL,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\n setPreviewURL,\n setPreviewWindowType: handleWindowChange,\n setSize,\n setToolbarPosition: setPosition,\n setURL: setLivePreviewURL,\n setWidth,\n setZoom,\n size,\n toolbarPosition: position,\n typeofLivePreviewURL,\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;AAIzE,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,wBAAwB,QAAQ;AACzC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,WAAW,QAAQ;AAsB5B,OAAO,MAAMC,mBAAA,GAA0DA,CAAC;EACtEC,WAAA,EAAaC,mBAAmB;EAChCC,QAAQ;EACRC,oBAAoB;EACpBC,gBAAA,EAAkBC,wBAAwB;EAC1CC,gBAAgB;EAChBC,UAAA,EAAYC,mBAAmB;EAC/BC,oBAAoB;EACpBC,GAAA,EAAKC;AAAY,CAClB;EACC,MAAM,CAACC,iBAAA,EAAmBC,oBAAA,CAAqB,GAAGtB,QAAA,CAA6B;EAC/E,MAAM,CAACa,gBAAA,EAAkBU,mBAAA,CAAoB,GAAGvB,QAAA,CAASc,wBAAA;EAEzD,MAAML,WAAA,GAAgDX,OAAA,CACpD,MAAM,C,IACAY,mBAAA,IAAuB,EAAE,GAC7B;IACEc,IAAA,EAAM;IACNC,MAAA,EAAQ;IACRC,KAAA,EAAO;IACPC,KAAA,EAAO;EACT,EACD,EACD,CAACjB,mBAAA,CAAoB;EAGvB,MAAM,CAACS,GAAA,EAAKS,MAAA,CAAO,GAAG5B,QAAA,CAAiB;EACvC,MAAM,CAACgB,UAAA,EAAYa,aAAA,CAAc,GAAG7B,QAAA,CAAiBiB,mBAAA;EAErD,MAAM;IAA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B;IACF;IAEA,KAAK5C,aAAA,CACHH,cAAA,GAAiB,cAAcA,cAAA,EAAgB,GAAG,UAAUC,UAAA,EAAY,EACxE;MACE+C,YAAA,EAAczE,gBAAA,GAAmB,iBAAiB;IACpD,GACA;EAEJ,GAAG,CAACA,gBAAA,EAAkB4B,aAAA,EAAeH,cAAA,EAAgBC,UAAA,CAAW;EAEhE,oBACEgD,IAAA,CAACjF,kBAAA;IACC+D,KAAA,EAAO;MACLnC,UAAA;MACAsB,UAAA;MACA/C,WAAA;MACAiC,SAAA;MACA9B,oBAAA;MACAC,gBAAA;MACAiB,WAAA;MACAf,gBAAA;MACAqB,oBAAA;MACAO,SAAA;MACAW,kBAAA;MACAvB,eAAA;MACAC,QAAA;MACAhB,UAAA;MACAK,iBAAA;MACAc,aAAA;MACAsB,aAAA;MACAa,SAAA;MACA/C,mBAAA;MACAqB,YAAA;MACAW,qBAAA;MACA1B,aAAA;MACAP,oBAAA,EAAsB6D,kBAAA;MACtB/B,OAAA;MACAoC,kBAAA,EAAoBxC,WAAA;MACpBpB,MAAA,EAAQ8B,iBAAA;MACRS,QAAA;MACArB,OAAA;MACAK,IAAA;MACAsC,eAAA,EAAiB1C,QAAA;MACjB7B,oBAAA;MACAC,GAAA;MACA0B;IACF;cAEA,aAAA0C,IAAA,CAAC7F,UAAA;MAAWgG,kBAAA,EAAoBrF,wBAAA;MAA0BsF,SAAA,EAAW9B,aAAA;gBAClElD;;;AAIT","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["DndContext","React","useCallback","useEffect","useId","useMemo","useRef","useState","usePopupWindow","useDocumentInfo","usePreferences","formatAbsoluteURL","customCollisionDetection","LivePreviewContext","sizeReducer","LivePreviewProvider","breakpoints","incomingBreakpoints","children","isLivePreviewEnabled","isLivePreviewing","incomingIsLivePreviewing","isPreviewEnabled","previewURL","previewURLFromProps","typeofLivePreviewURL","url","urlFromProps","previewWindowType","setPreviewWindowType","setIsLivePreviewing","name","height","label","width","setURL","setPreviewURL","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","listeningForMessages","setListeningForMessages","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","loadedURL","setLoadedURL","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","measuredDeviceSize","setMeasuredDeviceSize","breakpoint","setBreakpoint","setLivePreviewURL","_incomingURL","incomingURL","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","handleMessage","event","startsWith","origin","data","ready","window","addEventListener","removeEventListener","handleWindowChange","newPreviewWindowType","current","editViewType","dndContextID","_jsx","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"sources":["../../../src/providers/LivePreview/index.tsx"],"sourcesContent":["'use client'\nimport type { CollectionPreferences, LivePreviewConfig, LivePreviewURLType } from 'payload'\n\nimport { DndContext } from '@dnd-kit/core'\nimport React, { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\n\nimport type { LivePreviewContextType } from './context.js'\n\nimport { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { formatAbsoluteURL } from '../../utilities/formatAbsoluteURL.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 /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n isPreviewEnabled?: boolean\n /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n previewURL?: string\n} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\n isPreviewEnabled,\n previewURL: previewURLFromProps,\n typeofLivePreviewURL,\n url: urlFromProps,\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 const [previewURL, setPreviewURL] = useState<string>(previewURLFromProps)\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 [loadedURL, setLoadedURL] = useState<string>()\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 /**\n * A \"middleware\" callback fn that does some additional work before `setURL`.\n * This is what we provide through context, bc it:\n * - ensures the URL is absolute\n * - resets `appIsReady` to `false` while the new URL is loading\n */\n const setLivePreviewURL = useCallback<LivePreviewContextType['setURL']>(\n (_incomingURL) => {\n let incomingURL: LivePreviewURLType\n\n if (typeof _incomingURL === 'string') {\n incomingURL = formatAbsoluteURL(_incomingURL)\n }\n\n if (!incomingURL) {\n setIsLivePreviewing(false)\n }\n\n if (incomingURL !== url) {\n setAppIsReady(false)\n setURL(incomingURL)\n }\n },\n [url],\n )\n\n /**\n * `url` needs to be relative to the window, which cannot be done on initial render.\n */\n useEffect(() => {\n if (typeof urlFromProps === 'string') {\n setURL(formatAbsoluteURL(urlFromProps))\n }\n }, [urlFromProps])\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 /**\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 */\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 const dndContextID = useId()\n\n return (\n <LivePreviewContext\n value={{\n appIsReady,\n breakpoint,\n breakpoints,\n iframeRef,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n isPreviewEnabled,\n listeningForMessages,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewURL,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\n setPreviewURL,\n setPreviewWindowType: handleWindowChange,\n setSize,\n setToolbarPosition: setPosition,\n setURL: setLivePreviewURL,\n setWidth,\n setZoom,\n size,\n toolbarPosition: position,\n typeofLivePreviewURL,\n url,\n zoom,\n }}\n >\n <DndContext\n collisionDetection={customCollisionDetection}\n // Provide stable ID to fix hydration issues: https://github.com/clauderic/dnd-kit/issues/926\n id={dndContextID}\n onDragEnd={handleDragEnd}\n >\n {children}\n </DndContext>\n </LivePreviewContext>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,UAAU,QAAQ;A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AA,CAAW;EAEhE,MAAMgD,YAAA,GAAe1F,KAAA;EAErB,oBACE2F,IAAA,CAAClF,kBAAA;IACC+D,KAAA,EAAO;MACLnC,UAAA;MACAsB,UAAA;MACA/C,WAAA;MACAiC,SAAA;MACA9B,oBAAA;MACAC,gBAAA;MACAiB,WAAA;MACAf,gBAAA;MACAqB,oBAAA;MACAO,SAAA;MACAW,kBAAA;MACAvB,eAAA;MACAC,QAAA;MACAhB,UAAA;MACAK,iBAAA;MACAc,aAAA;MACAsB,aAAA;MACAa,SAAA;MACA/C,mBAAA;MACAqB,YAAA;MACAW,qBAAA;MACA1B,aAAA;MACAP,oBAAA,EAAsB6D,kBAAA;MACtB/B,OAAA;MACAqC,kBAAA,EAAoBzC,WAAA;MACpBpB,MAAA,EAAQ8B,iBAAA;MACRS,QAAA;MACArB,OAAA;MACAK,IAAA;MACAuC,eAAA,EAAiB3C,QAAA;MACjB7B,oBAAA;MACAC,GAAA;MACA0B;IACF;cAEA,aAAA2C,IAAA,CAAC/F,UAAA;MACCkG,kBAAA,EAAoBtF,wBAAA;MACpB;MACA2D,EAAA,EAAIuB,YAAA;MACJK,SAAA,EAAW/B,aAAA;gBAEVlD;;;AAIT","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Root/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACjF,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,MAAM,EACN,oBAAoB,EACpB,oBAAoB,EACpB,SAAS,EACV,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAyB9C,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IAClC,QAAQ,C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K,CAAC,SAAS,CAAA;IAClC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;IAC7B,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAA;IAC3C,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAA;IACtD,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAA;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IAChC,QAAQ,CAAC,WAAW,EAAE,oBAAoB,CAAA;IAC1C,QAAQ,CAAC,cAAc,EAAE,oBAAoB,CAAA;IAC7C,QAAQ,CAAC,0BAA0B,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACrE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,cAAc,CAAC,CAAA;IACjD,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAyFxC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","DndContext","pointerWithin","ModalContainer","ModalProvider","ScrollInfoProvider","React","CloseModalOnRouteChange","LoadingOverlayProvider","NavProvider","StayLoggedInModal","StepNavProvider","ClickOutsideProvider","WindowInfoProvider","AuthProvider","ClientFunctionProvider","ConfigProvider","DocumentEventsProvider","LocaleProvider","ParamsProvider","PreferencesProvider","RouteCache","RouteTransitionProvider","SearchParamsProvider","ServerFunctionsProvider","ThemeProvider","ToastContainer","TranslationProvider","UploadHandlersProvider","RootProvider","t0","$","children","config","dateFNSKey","fallbackLang","isNavOpen","languageCode","languageOptions","locale","permissions","serverFunction","switchLanguageServerAction","theme","translations","user","dndContextID","useId","t1","_jsxs","_jsx","cachingEnabled","process","env","NEXT_PUBLIC_ENABLE_ROUTER_CACHE_REFRESH","language","breakpoints","l","m","s","xs","classPrefix","transTime","zIndex","initialIsOpen","collisionDetection","id"],"sources":["../../../src/providers/Root/index.tsx"],"sourcesContent":["'use client'\nimport type { I18nClient, I18nOptions, Language } from '@payloadcms/translations'\nimport type {\n ClientConfig,\n LanguageOptions,\n Locale,\n SanitizedPermissions,\n ServerFunctionClient,\n TypedUser,\n} from 'payload'\n\nimport { DndContext, pointerWithin } from '@dnd-kit/core'\nimport { ModalContainer, ModalProvider } from '@faceless-ui/modal'\nimport { ScrollInfoProvider } from '@faceless-ui/scroll-info'\nimport React from 'react'\n\nimport type { Theme } from '../Theme/index.js'\n\nimport { CloseModalOnRouteChange } from '../../elements/CloseModalOnRouteChange/index.js'\nimport { LoadingOverlayProvider } from '../../elements/LoadingOverlay/index.js'\nimport { NavProvider } from '../../elements/Nav/context.js'\nimport { StayLoggedInModal } from '../../elements/StayLoggedIn/index.js'\nimport { StepNavProvider } from '../../elements/StepNav/index.js'\nimport { ClickOutsideProvider } from '../../providers/ClickOutside/index.js'\nimport { WindowInfoProvider } from '../../providers/WindowInfo/index.js'\nimport { AuthProvider } from '../Auth/index.js'\nimport { ClientFunctionProvider } from '../ClientFunction/index.js'\nimport { ConfigProvider } from '../Config/index.js'\nimport { DocumentEventsProvider } from '../DocumentEvents/index.js'\nimport { LocaleProvider } from '../Locale/index.js'\nimport { ParamsProvider } from '../Params/index.js'\nimport { PreferencesProvider } from '../Preferences/index.js'\nimport { RouteCache } from '../RouteCache/index.js'\nimport { RouteTransitionProvider } from '../RouteTransition/index.js'\nimport { SearchParamsProvider } from '../SearchParams/index.js'\nimport { ServerFunctionsProvider } from '../ServerFunctions/index.js'\nimport { ThemeProvider } from '../Theme/index.js'\nimport { ToastContainer } from '../ToastContainer/index.js'\nimport { TranslationProvider } from '../Translation/index.js'\nimport { UploadHandlersProvider } from '../UploadHandlers/index.js'\n\ntype Props = {\n readonly children: React.ReactNode\n readonly config: ClientConfig\n readonly dateFNSKey: Language['dateFNSKey']\n readonly fallbackLang: I18nOptions['fallbackLanguage']\n readonly isNavOpen?: boolean\n readonly languageCode: string\n readonly languageOptions: LanguageOptions\n readonly locale?: Locale['code']\n readonly permissions: SanitizedPermissions\n readonly serverFunction: ServerFunctionClient\n readonly switchLanguageServerAction?: (lang: string) => Promise<void>\n readonly theme: Theme\n readonly translations: I18nClient['translations']\n readonly user: null | TypedUser\n}\n\nexport const RootProvider: React.FC<Props> = ({\n children,\n config,\n dateFNSKey,\n fallbackLang,\n isNavOpen,\n languageCode,\n languageOptions,\n locale,\n permissions,\n serverFunction,\n switchLanguageServerAction,\n theme,\n translations,\n user,\n}) => {\n const dndContextID = React.useId()\n\n return (\n <ClickOutsideProvider>\n <ServerFunctionsProvider serverFunction={serverFunction}>\n <RouteTransitionProvider>\n <RouteCache\n cachingEnabled={process.env.NEXT_PUBLIC_ENABLE_ROUTER_CACHE_REFRESH === 'true'}\n >\n <ConfigProvider config={config}>\n <ClientFunctionProvider>\n <TranslationProvider\n dateFNSKey={dateFNSKey}\n fallbackLang={fallbackLang}\n language={languageCode}\n languageOptions={languageOptions}\n switchLanguageServerAction={switchLanguageServerAction}\n translations={translations}\n >\n <WindowInfoProvider\n breakpoints={{\n l: '(max-width: 1440px)',\n m: '(max-width: 1024px)',\n s: '(max-width: 768px)',\n xs: '(max-width: 400px)',\n }}\n >\n <ScrollInfoProvider>\n <SearchParamsProvider>\n <ModalProvider classPrefix=\"payload\" transTime={0} zIndex=\"var(--z-modal)\">\n <CloseModalOnRouteChange />\n <AuthProvider permissions={permissions} user={user}>\n <PreferencesProvider>\n <ThemeProvider theme={theme}>\n <ParamsProvider>\n <LocaleProvider locale={locale}>\n <StepNavProvider>\n <LoadingOverlayProvider>\n <DocumentEventsProvider>\n <NavProvider initialIsOpen={isNavOpen}>\n <UploadHandlersProvider>\n <DndContext\n collisionDetection={pointerWithin}\n id={dndContextID}\n >\n {children}\n </DndContext>\n </UploadHandlersProvider>\n </NavProvider>\n </DocumentEventsProvider>\n </LoadingOverlayProvider>\n </StepNavProvider>\n </LocaleProvider>\n </ParamsProvider>\n </ThemeProvider>\n </PreferencesProvider>\n <ModalContainer />\n <StayLoggedInModal />\n </AuthProvider>\n </ModalProvider>\n </SearchParamsProvider>\n </ScrollInfoProvider>\n </WindowInfoProvider>\n </TranslationProvider>\n </ClientFunctionProvider>\n </ConfigProvider>\n </RouteCache>\n </RouteTransitionProvider>\n </ServerFunctionsProvider>\n <ToastContainer config={config} />\n </ClickOutsideProvider>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAWA,SAASC,UAAU,EAAEC,aAAa,QAAQ;AAC1C,SAASC,cAAc,EAAEC,aAAa,QAAQ;AAC9C,SAASC,kBAAkB,QAAQ;AACnC,OAAOC,KAAA,MAAW;AAIlB,SAASC,uBAAuB,QAAQ;AACxC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,WAAW,QAAQ;AAC5B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,eAAe,QAAQ;AAChC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,cAAc,QAAQ;AAC/B,SAASC,sBAAsB,QAAQ;AACvC,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,uBAAuB,QAAQ;AACxC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,aAAa,QAAQ;AAC9B,SAASC,cAAc,QAAQ;AAC/B,SAASC,mBAAmB,QAAQ;AACpC,SAASC,sBAAsB,QAAQ;AAmBvC,OAAO,MAAM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
1
+ {"version":3,"file":"index.js","names":["c","_c","DndContext","pointerWithin","ModalContainer","ModalProvider","ScrollInfoProvider","React","CloseModalOnRouteChange","LoadingOverlayProvider","NavProvider","StayLoggedInModal","StepNavProvider","ClickOutsideProvider","WindowInfoProvider","AuthProvider","ClientFunctionProvider","ConfigProvider","DocumentEventsProvider","LocaleProvider","ParamsProvider","PreferencesProvider","RouteCache","RouteTransitionProvider","SearchParamsProvider","ServerFunctionsProvider","ThemeProvider","ToastContainer","TranslationProvider","UploadHandlersProvider","RootProvider","t0","$","children","config","dateFNSKey","fallbackLang","isNavOpen","languageCode","languageOptions","locale","permissions","serverFunction","switchLanguageServerAction","theme","translations","user","dndContextID","useId","t1","_jsxs","_jsx","cachingEnabled","process","env","NEXT_PUBLIC_ENABLE_ROUTER_CACHE_REFRESH","language","breakpoints","l","m","s","xs","classPrefix","transTime","zIndex","initialIsOpen","collisionDetection","id"],"sources":["../../../src/providers/Root/index.tsx"],"sourcesContent":["'use client'\nimport type { I18nClient, I18nOptions, Language } from '@payloadcms/translations'\nimport type {\n ClientConfig,\n LanguageOptions,\n Locale,\n SanitizedPermissions,\n ServerFunctionClient,\n TypedUser,\n} from 'payload'\n\nimport { DndContext, pointerWithin } from '@dnd-kit/core'\nimport { ModalContainer, ModalProvider } from '@faceless-ui/modal'\nimport { ScrollInfoProvider } from '@faceless-ui/scroll-info'\nimport React from 'react'\n\nimport type { Theme } from '../Theme/index.js'\n\nimport { CloseModalOnRouteChange } from '../../elements/CloseModalOnRouteChange/index.js'\nimport { LoadingOverlayProvider } from '../../elements/LoadingOverlay/index.js'\nimport { NavProvider } from '../../elements/Nav/context.js'\nimport { StayLoggedInModal } from '../../elements/StayLoggedIn/index.js'\nimport { StepNavProvider } from '../../elements/StepNav/index.js'\nimport { ClickOutsideProvider } from '../../providers/ClickOutside/index.js'\nimport { WindowInfoProvider } from '../../providers/WindowInfo/index.js'\nimport { AuthProvider } from '../Auth/index.js'\nimport { ClientFunctionProvider } from '../ClientFunction/index.js'\nimport { ConfigProvider } from '../Config/index.js'\nimport { DocumentEventsProvider } from '../DocumentEvents/index.js'\nimport { LocaleProvider } from '../Locale/index.js'\nimport { ParamsProvider } from '../Params/index.js'\nimport { PreferencesProvider } from '../Preferences/index.js'\nimport { RouteCache } from '../RouteCache/index.js'\nimport { RouteTransitionProvider } from '../RouteTransition/index.js'\nimport { SearchParamsProvider } from '../SearchParams/index.js'\nimport { ServerFunctionsProvider } from '../ServerFunctions/index.js'\nimport { ThemeProvider } from '../Theme/index.js'\nimport { ToastContainer } from '../ToastContainer/index.js'\nimport { TranslationProvider } from '../Translation/index.js'\nimport { UploadHandlersProvider } from '../UploadHandlers/index.js'\n\ntype Props = {\n readonly children: React.ReactNode\n readonly config: ClientConfig\n readonly dateFNSKey: Language['dateFNSKey']\n readonly fallbackLang: I18nOptions['fallbackLanguage']\n readonly isNavOpen?: boolean\n readonly languageCode: string\n readonly languageOptions: LanguageOptions\n readonly locale?: Locale['code']\n readonly permissions: SanitizedPermissions\n readonly serverFunction: ServerFunctionClient\n readonly switchLanguageServerAction?: (lang: string) => Promise<void>\n readonly theme: Theme\n readonly translations: I18nClient['translations']\n readonly user: null | TypedUser\n}\n\nexport const RootProvider: React.FC<Props> = ({\n children,\n config,\n dateFNSKey,\n fallbackLang,\n isNavOpen,\n languageCode,\n languageOptions,\n locale,\n permissions,\n serverFunction,\n switchLanguageServerAction,\n theme,\n translations,\n user,\n}) => {\n const dndContextID = React.useId()\n\n return (\n <ClickOutsideProvider>\n <ServerFunctionsProvider serverFunction={serverFunction}>\n <RouteTransitionProvider>\n <RouteCache\n cachingEnabled={process.env.NEXT_PUBLIC_ENABLE_ROUTER_CACHE_REFRESH === 'true'}\n >\n <ConfigProvider config={config}>\n <ClientFunctionProvider>\n <TranslationProvider\n dateFNSKey={dateFNSKey}\n fallbackLang={fallbackLang}\n language={languageCode}\n languageOptions={languageOptions}\n switchLanguageServerAction={switchLanguageServerAction}\n translations={translations}\n >\n <WindowInfoProvider\n breakpoints={{\n l: '(max-width: 1440px)',\n m: '(max-width: 1024px)',\n s: '(max-width: 768px)',\n xs: '(max-width: 400px)',\n }}\n >\n <ScrollInfoProvider>\n <SearchParamsProvider>\n <ModalProvider classPrefix=\"payload\" transTime={0} zIndex=\"var(--z-modal)\">\n <CloseModalOnRouteChange />\n <AuthProvider permissions={permissions} user={user}>\n <PreferencesProvider>\n <ThemeProvider theme={theme}>\n <ParamsProvider>\n <LocaleProvider locale={locale}>\n <StepNavProvider>\n <LoadingOverlayProvider>\n <DocumentEventsProvider>\n <NavProvider initialIsOpen={isNavOpen}>\n <UploadHandlersProvider>\n <DndContext\n collisionDetection={pointerWithin}\n // Provide stable ID to fix hydration issues: https://github.com/clauderic/dnd-kit/issues/926\n id={dndContextID}\n >\n {children}\n </DndContext>\n </UploadHandlersProvider>\n </NavProvider>\n </DocumentEventsProvider>\n </LoadingOverlayProvider>\n </StepNavProvider>\n </LocaleProvider>\n </ParamsProvider>\n </ThemeProvider>\n </PreferencesProvider>\n <ModalContainer />\n <StayLoggedInModal />\n </AuthProvider>\n </ModalProvider>\n </SearchParamsProvider>\n </ScrollInfoProvider>\n </WindowInfoProvider>\n </TranslationProvider>\n </ClientFunctionProvider>\n </ConfigProvider>\n </RouteCache>\n </RouteTransitionProvider>\n </ServerFunctionsProvider>\n <ToastContainer config={config} />\n </ClickOutsideProvider>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAWA,SAASC,UAAU,EAAEC,aAAa,QAAQ;AAC1C,SAASC,cAAc,EAAEC,aAAa,QAAQ;AAC9C,SAASC,kBAAkB,QAAQ;AACnC,OAAOC,KAAA,MAAW;AAIlB,SAASC,uBAAuB,QAAQ;AACxC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,WAAW,QAAQ;AAC5B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,eAAe,QAAQ;AAChC,SAASC,oBAAoB,QAAQ;AACrC,SAASC,kBAAkB,QAA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EACEkB,IAAA,CAAAzC,WAAA;4CAAAuD,aAAA,EAA4B5B,SAAA;4CAAAJ,QAAA,EAC1BkB,IAAA,CAAAtB,sBAAA;8CAAAI,QAAA,EACEkB,IAAA,CAAAjD,UAAA;gDAAAgE,kBAAA,EAAA/D,aAAA;gDAAAgE,EAAA,EAGMpB,YAAA;gDAAAd;8CAAA,C;;;;;;;;;gCAaxBkB,IAAA,CAAA/C,cAAA,IAAC,GACD+C,IAAA,CAAAxC,iBAAA,IAAC;0BAAA,C;;;;;;;;;;UAYvBwC,IAAA,CAAAxB,cAAA;QAAAO;MAAA,C;;;;;;;;;;;;;;;;;;;;;SAnEFe,E;CAsEJ","ignoreList":[]}
@@ -38,8 +38,7 @@ export const ServerFunctionsProvider = ({
38
38
  }
39
39
  }
40
40
  } catch (_err) {
41
- console.error(_err) // eslint-disable-line no-console
42
- ;
41
+ console.error(_err); // eslint-disable-line no-console
43
42
  }
44
43
  let error = `Error scheduling ${rest.type}`;
45
44
  if (rest.doc) {
@@ -69,8 +68,7 @@ export const ServerFunctionsProvider = ({
69
68
  }
70
69
  }
71
70
  } catch (_err) {
72
- console.error(_err) // eslint-disable-line no-console
73
- ;
71
+ console.error(_err); // eslint-disable-line no-console
74
72
  }
75
73
  return {
76
74
  state: null
@@ -96,8 +94,7 @@ export const ServerFunctionsProvider = ({
96
94
  }
97
95
  }
98
96
  } catch (_err) {
99
- console.error(_err) // eslint-disable-line no-console
100
- ;
97
+ console.error(_err); // eslint-disable-line no-console
101
98
  }
102
99
  // return { state: args.formState }
103
100
  }, [serverFunction]);
@@ -117,8 +114,7 @@ export const ServerFunctionsProvider = ({
117
114
  // TODO: infer this type when `strictNullChecks` is enabled
118
115
  return result;
119
116
  } catch (_err) {
120
- console.error(_err) // eslint-disable-line no-console
121
- ;
117
+ console.error(_err); // eslint-disable-line no-console
122
118
  }
123
119
  }, [serverFunction]);
124
120
  const copyDataFromLocale = useCallback(async args => {
@@ -135,8 +131,7 @@ export const ServerFunctionsProvider = ({
135
131
  return result;
136
132
  }
137
133
  } catch (_err) {
138
- console.error(_err) // eslint-disable-line no-console
139
- ;
134
+ console.error(_err); // eslint-disable-line no-console
140
135
  }
141
136
  }, [serverFunction]);
142
137
  const getFolderResultsComponentAndData = useCallback(async args => {
@@ -153,8 +148,7 @@ export const ServerFunctionsProvider = ({
153
148
  return result;
154
149
  }
155
150
  } catch (_err) {
156
- console.error(_err) // eslint-disable-line no-console
157
- ;
151
+ console.error(_err); // eslint-disable-line no-console
158
152
  }
159
153
  }, [serverFunction]);
160
154
  const _internal_renderField = useCallback(async args => {
@@ -165,8 +159,7 @@ export const ServerFunctionsProvider = ({
165
159
  });
166
160
  return result;
167
161
  } catch (_err) {
168
- console.error(_err) // eslint-disable-line no-console
169
- ;
162
+ console.error(_err); // eslint-disable-line no-console
170
163
  }
171
164
  }, [serverFunction]);
172
165
  const slugify = useCallback(async args => {
@@ -184,8 +177,7 @@ export const ServerFunctionsProvider = ({
184
177
  // TODO: infer this type when `strictNullChecks` is enabled
185
178
  return result;
186
179
  } catch (_err) {
187
- console.error(_err) // eslint-disable-line no-console
188
- ;
180
+ console.error(_err); // eslint-disable-line no-console
189
181
  }
190
182
  }, [serverFunction]);
191
183
  return /*#__PURE__*/_jsx(ServerFunctionsContext, {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["React","createContext","useCallback","ServerFunctionsContext","undefined","useServerFunctions","context","use","Error","ServerFunctionsProvider","children","serverFunction","getDocumentSlots","args","name","schedulePublish","signal","remoteSignal","rest","aborted","result","_err","console","error","type","doc","value","relationTo","getFormState","fallbackLocale","state","getTableState","renderDocument","copyDataFromLocale","getFolderResultsComponentAndData","_internal_renderField","slugify","_jsx"],"sources":["../../../src/providers/ServerFunctions/index.tsx"],"sourcesContent":["import type {\n AdminViewServerPropsOnly,\n BuildFormStateArgs,\n BuildTableStateArgs,\n Data,\n DocumentPreferences,\n DocumentSlots,\n FormState,\n GetFolderResultsComponentAndDataArgs,\n Locale,\n Params,\n RenderDocumentVersionsProperties,\n ServerFunction,\n ServerFunctionClient,\n SlugifyServerFunctionArgs,\n} from 'payload'\nimport type { Slugify } from 'payload/shared'\n\nimport React, { createContext, useCallback } from 'react'\n\nimport type {\n RenderFieldServerFnArgs,\n RenderFieldServerFnReturnType,\n} from '../../forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js'\nimport type { buildFormStateHandler } from '../../utilities/buildFormState.js'\nimport type { buildTableStateHandler } from '../../utilities/buildTableState.js'\nimport type { CopyDataFromLocaleArgs } from '../../utilities/copyDataFromLocale.js'\nimport type { getFolderResultsComponentAndDataHandler } from '../../utilities/getFolderResultsComponentAndData.js'\nimport type {\n schedulePublishHandler,\n SchedulePublishHandlerArgs,\n} from '../../utilities/schedulePublishHandler.js'\n\ntype GetFormStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildFormStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildFormStateHandler>\n\ntype SchedulePublishClient = (\n args: {\n signal?: AbortSignal\n } & Omit<SchedulePublishHandlerArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof schedulePublishHandler>\n\ntype GetTableStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildTableStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildTableStateHandler>\n\ntype SlugifyClient = (\n args: {\n signal?: AbortSignal\n } & Omit<SlugifyServerFunctionArgs, 'clientConfig' | 'req'>,\n) => ReturnType<Slugify>\n\nexport type RenderDocumentResult = {\n data: any\n Document: React.ReactNode\n preferences: DocumentPreferences\n}\n\ntype RenderDocumentBaseArgs = {\n collectionSlug: string\n disableActions?: boolean\n docID: number | string\n drawerSlug?: string\n initialData?: Data\n initialState?: FormState\n locale?: Locale\n overrideEntityVisibility?: boolean\n paramsOverride?: AdminViewServerPropsOnly['params']\n redirectAfterCreate?: boolean\n redirectAfterDelete: boolean\n redirectAfterDuplicate: boolean\n redirectAfterRestore?: boolean\n searchParams?: Params\n /**\n * Properties specific to the versions view\n */\n versions?: RenderDocumentVersionsProperties\n}\n\nexport type RenderDocumentServerFunction = ServerFunction<\n RenderDocumentBaseArgs,\n Promise<RenderDocumentResult>\n>\n\ntype RenderDocumentServerFunctionHookFn = (\n // No req or importMap - those are augmented by handleServerFunctions\n args: {\n signal?: AbortSignal\n } & RenderDocumentBaseArgs,\n) => Promise<RenderDocumentResult>\n\ntype CopyDataFromLocaleClient = (\n args: {\n signal?: AbortSignal\n } & Omit<CopyDataFromLocaleArgs, 'req'>,\n) => Promise<{ data: Data }>\n\ntype GetDocumentSlots = (args: {\n collectionSlug: string\n id?: number | string\n signal?: AbortSignal\n}) => Promise<DocumentSlots>\n\ntype GetFolderResultsComponentAndDataClient = (\n args: {\n signal?: AbortSignal\n } & Omit<GetFolderResultsComponentAndDataArgs, 'req'>,\n) => ReturnType<typeof getFolderResultsComponentAndDataHandler>\n\ntype RenderFieldClient = (args: RenderFieldServerFnArgs) => Promise<RenderFieldServerFnReturnType>\n\nexport type ServerFunctionsContextType = {\n _internal_renderField: RenderFieldClient\n copyDataFromLocale: CopyDataFromLocaleClient\n getDocumentSlots: GetDocumentSlots\n getFolderResultsComponentAndData: GetFolderResultsComponentAndDataClient\n getFormState: GetFormStateClient\n getTableState: GetTableStateClient\n renderDocument: RenderDocumentServerFunctionHookFn\n schedulePublish: SchedulePublishClient\n serverFunction: ServerFunctionClient\n slugify: SlugifyClient\n}\n\nexport const ServerFunctionsContext = createContext<ServerFunctionsContextType | undefined>(\n undefined,\n)\n\nexport const useServerFunctions = () => {\n const context = React.use(ServerFunctionsContext)\n if (context === undefined) {\n throw new Error('useServerFunctions must be used within a ServerFunctionsProvider')\n }\n return context\n}\n\nexport const ServerFunctionsProvider: React.FC<{\n children: React.ReactNode\n serverFunction: ServerFunctionClient\n}> = ({ children, serverFunction }) => {\n if (!serverFunction) {\n throw new Error('ServerFunctionsProvider requires a serverFunction prop')\n }\n\n const getDocumentSlots = useCallback<GetDocumentSlots>(\n async (args) =>\n await serverFunction({\n name: 'render-document-slots',\n args,\n }),\n [serverFunction],\n )\n\n const schedulePublish = useCallback<SchedulePublishClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'schedule-publish',\n args: { ...rest },\n })) as Awaited<ReturnType<typeof schedulePublishHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n let error = `Error scheduling ${rest.type}`\n\n if (rest.doc) {\n error += ` for document with ID ${rest.doc.value} in collection ${rest.doc.relationTo}`\n }\n\n return { error }\n },\n [serverFunction],\n )\n\n const getFormState = useCallback<GetFormStateClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'form-state',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof buildFormStateHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n return { state: null }\n },\n [serverFunction],\n )\n\n const getTableState = useCallback<GetTableStateClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'table-state',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof buildTableStateHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n // return { state: args.formState }\n },\n [serverFunction],\n )\n\n const renderDocument = useCallback<RenderDocumentServerFunctionHookFn>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n try {\n const result = (await serverFunction({\n name: 'render-document',\n args: {\n fallbackLocale: false,\n ...rest,\n } as Parameters<RenderDocumentServerFunctionHookFn>[0],\n })) as Awaited<ReturnType<RenderDocumentServerFunctionHookFn>> // TODO: infer this type when `strictNullChecks` is enabled\n\n return result\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const copyDataFromLocale = useCallback<CopyDataFromLocaleClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'copy-data-from-locale',\n args: rest,\n })) as { data: Data }\n\n if (!remoteSignal?.aborted) {\n return result\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const getFolderResultsComponentAndData = useCallback<GetFolderResultsComponentAndDataClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'get-folder-results-component-and-data',\n args: rest,\n })) as Awaited<ReturnType<typeof getFolderResultsComponentAndDataHandler>>\n\n if (!remoteSignal?.aborted) {\n return result\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const _internal_renderField = useCallback<RenderFieldClient>(\n async (args) => {\n try {\n const result = (await serverFunction({\n name: 'render-field',\n args,\n })) as RenderFieldServerFnReturnType\n\n return result\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const slugify = useCallback<SlugifyClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'slugify',\n args: { ...rest },\n })) as Awaited<ReturnType<Slugify>> // TODO: infer this type when `strictNullChecks` is enabled\n\n return result\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n return (\n <ServerFunctionsContext\n value={{\n _internal_renderField,\n copyDataFromLocale,\n getDocumentSlots,\n getFolderResultsComponentAndData,\n getFormState,\n getTableState,\n renderDocument,\n schedulePublish,\n serverFun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M;MAAA;IACtB;EACF,GACA,CAACV,cAAA,CAAe;EAGlB,MAAMwB,qBAAA,GAAwBjC,WAAA,CAC5B,MAAOW,IAAA;IACL,IAAI;MACF,MAAMO,MAAA,GAAU,MAAMT,cAAA,CAAe;QACnCG,IAAA,EAAM;QACND;MACF;MAEA,OAAOO,MAAA;IACT,EAAE,OAAOC,IAAA,EAAM;MACbC,OAAA,CAAQC,KAAK,CAACF,IAAA,EAAM;MAAA;IACtB;EACF,GACA,CAACV,cAAA,CAAe;EAGlB,MAAMyB,OAAA,GAAUlC,WAAA,CACd,MAAOW,IAAA;IACL,MAAM;MAAEG,MAAA,EAAQC,YAAY;MAAE,GAAGC;IAAA,CAAM,GAAGL,IAAA,IAAQ,CAAC;IAEnD,IAAI;MACF,MAAMO,MAAA,GAAU,MAAMT,cAAA,CAAe;QACnCG,IAAA,EAAM;QACND,IAAA,EAAM;UAAE,GAAGK;QAAK;MAClB;MAAoC;MAEpC,OAAOE,MAAA;IACT,EAAE,OAAOC,IAAA,EAAM;MACbC,OAAA,CAAQC,KAAK,CAACF,IAAA,EAAM;MAAA;IACtB;EACF,GACA,CAACV,cAAA,CAAe;EAGlB,oBACE0B,IAAA,CAAClC,sBAAA;IACCuB,KAAA,EAAO;MACLS,qBAAA;MACAF,kBAAA;MACArB,gBAAA;MACAsB,gCAAA;MACAN,YAAA;MACAG,aAAA;MACAC,cAAA;MACAjB,eAAA;MACAJ,cAAA;MACAyB;IACF;cAEC1B;;AAGP","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["React","createContext","useCallback","ServerFunctionsContext","undefined","useServerFunctions","context","use","Error","ServerFunctionsProvider","children","serverFunction","getDocumentSlots","args","name","schedulePublish","signal","remoteSignal","rest","aborted","result","_err","console","error","type","doc","value","relationTo","getFormState","fallbackLocale","state","getTableState","renderDocument","copyDataFromLocale","getFolderResultsComponentAndData","_internal_renderField","slugify","_jsx"],"sources":["../../../src/providers/ServerFunctions/index.tsx"],"sourcesContent":["import type {\n AdminViewServerPropsOnly,\n BuildFormStateArgs,\n BuildTableStateArgs,\n Data,\n DocumentPreferences,\n DocumentSlots,\n FormState,\n GetFolderResultsComponentAndDataArgs,\n Locale,\n Params,\n RenderDocumentVersionsProperties,\n ServerFunction,\n ServerFunctionClient,\n SlugifyServerFunctionArgs,\n} from 'payload'\nimport type { Slugify } from 'payload/shared'\n\nimport React, { createContext, useCallback } from 'react'\n\nimport type {\n RenderFieldServerFnArgs,\n RenderFieldServerFnReturnType,\n} from '../../forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js'\nimport type { buildFormStateHandler } from '../../utilities/buildFormState.js'\nimport type { buildTableStateHandler } from '../../utilities/buildTableState.js'\nimport type { CopyDataFromLocaleArgs } from '../../utilities/copyDataFromLocale.js'\nimport type { getFolderResultsComponentAndDataHandler } from '../../utilities/getFolderResultsComponentAndData.js'\nimport type {\n schedulePublishHandler,\n SchedulePublishHandlerArgs,\n} from '../../utilities/schedulePublishHandler.js'\n\ntype GetFormStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildFormStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildFormStateHandler>\n\ntype SchedulePublishClient = (\n args: {\n signal?: AbortSignal\n } & Omit<SchedulePublishHandlerArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof schedulePublishHandler>\n\ntype GetTableStateClient = (\n args: {\n signal?: AbortSignal\n } & Omit<BuildTableStateArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof buildTableStateHandler>\n\ntype SlugifyClient = (\n args: {\n signal?: AbortSignal\n } & Omit<SlugifyServerFunctionArgs, 'clientConfig' | 'req'>,\n) => ReturnType<Slugify>\n\nexport type RenderDocumentResult = {\n data: any\n Document: React.ReactNode\n preferences: DocumentPreferences\n}\n\ntype RenderDocumentBaseArgs = {\n collectionSlug: string\n disableActions?: boolean\n docID: number | string\n drawerSlug?: string\n initialData?: Data\n initialState?: FormState\n locale?: Locale\n overrideEntityVisibility?: boolean\n paramsOverride?: AdminViewServerPropsOnly['params']\n redirectAfterCreate?: boolean\n redirectAfterDelete: boolean\n redirectAfterDuplicate: boolean\n redirectAfterRestore?: boolean\n searchParams?: Params\n /**\n * Properties specific to the versions view\n */\n versions?: RenderDocumentVersionsProperties\n}\n\nexport type RenderDocumentServerFunction = ServerFunction<\n RenderDocumentBaseArgs,\n Promise<RenderDocumentResult>\n>\n\ntype RenderDocumentServerFunctionHookFn = (\n // No req or importMap - those are augmented by handleServerFunctions\n args: {\n signal?: AbortSignal\n } & RenderDocumentBaseArgs,\n) => Promise<RenderDocumentResult>\n\ntype CopyDataFromLocaleClient = (\n args: {\n signal?: AbortSignal\n } & Omit<CopyDataFromLocaleArgs, 'req'>,\n) => Promise<{ data: Data }>\n\ntype GetDocumentSlots = (args: {\n collectionSlug: string\n id?: number | string\n signal?: AbortSignal\n}) => Promise<DocumentSlots>\n\ntype GetFolderResultsComponentAndDataClient = (\n args: {\n signal?: AbortSignal\n } & Omit<GetFolderResultsComponentAndDataArgs, 'req'>,\n) => ReturnType<typeof getFolderResultsComponentAndDataHandler>\n\ntype RenderFieldClient = (args: RenderFieldServerFnArgs) => Promise<RenderFieldServerFnReturnType>\n\nexport type ServerFunctionsContextType = {\n _internal_renderField: RenderFieldClient\n copyDataFromLocale: CopyDataFromLocaleClient\n getDocumentSlots: GetDocumentSlots\n getFolderResultsComponentAndData: GetFolderResultsComponentAndDataClient\n getFormState: GetFormStateClient\n getTableState: GetTableStateClient\n renderDocument: RenderDocumentServerFunctionHookFn\n schedulePublish: SchedulePublishClient\n serverFunction: ServerFunctionClient\n slugify: SlugifyClient\n}\n\nexport const ServerFunctionsContext = createContext<ServerFunctionsContextType | undefined>(\n undefined,\n)\n\nexport const useServerFunctions = () => {\n const context = React.use(ServerFunctionsContext)\n if (context === undefined) {\n throw new Error('useServerFunctions must be used within a ServerFunctionsProvider')\n }\n return context\n}\n\nexport const ServerFunctionsProvider: React.FC<{\n children: React.ReactNode\n serverFunction: ServerFunctionClient\n}> = ({ children, serverFunction }) => {\n if (!serverFunction) {\n throw new Error('ServerFunctionsProvider requires a serverFunction prop')\n }\n\n const getDocumentSlots = useCallback<GetDocumentSlots>(\n async (args) =>\n await serverFunction({\n name: 'render-document-slots',\n args,\n }),\n [serverFunction],\n )\n\n const schedulePublish = useCallback<SchedulePublishClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'schedule-publish',\n args: { ...rest },\n })) as Awaited<ReturnType<typeof schedulePublishHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n let error = `Error scheduling ${rest.type}`\n\n if (rest.doc) {\n error += ` for document with ID ${rest.doc.value} in collection ${rest.doc.relationTo}`\n }\n\n return { error }\n },\n [serverFunction],\n )\n\n const getFormState = useCallback<GetFormStateClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'form-state',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof buildFormStateHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n return { state: null }\n },\n [serverFunction],\n )\n\n const getTableState = useCallback<GetTableStateClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n if (!remoteSignal?.aborted) {\n const result = (await serverFunction({\n name: 'table-state',\n args: { fallbackLocale: false, ...rest },\n })) as Awaited<ReturnType<typeof buildTableStateHandler>> // TODO: infer this type when `strictNullChecks` is enabled\n\n if (!remoteSignal?.aborted) {\n return result\n }\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n\n // return { state: args.formState }\n },\n [serverFunction],\n )\n\n const renderDocument = useCallback<RenderDocumentServerFunctionHookFn>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n try {\n const result = (await serverFunction({\n name: 'render-document',\n args: {\n fallbackLocale: false,\n ...rest,\n } as Parameters<RenderDocumentServerFunctionHookFn>[0],\n })) as Awaited<ReturnType<RenderDocumentServerFunctionHookFn>> // TODO: infer this type when `strictNullChecks` is enabled\n\n return result\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const copyDataFromLocale = useCallback<CopyDataFromLocaleClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'copy-data-from-locale',\n args: rest,\n })) as { data: Data }\n\n if (!remoteSignal?.aborted) {\n return result\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const getFolderResultsComponentAndData = useCallback<GetFolderResultsComponentAndDataClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'get-folder-results-component-and-data',\n args: rest,\n })) as Awaited<ReturnType<typeof getFolderResultsComponentAndDataHandler>>\n\n if (!remoteSignal?.aborted) {\n return result\n }\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const _internal_renderField = useCallback<RenderFieldClient>(\n async (args) => {\n try {\n const result = (await serverFunction({\n name: 'render-field',\n args,\n })) as RenderFieldServerFnReturnType\n\n return result\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n const slugify = useCallback<SlugifyClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args || {}\n\n try {\n const result = (await serverFunction({\n name: 'slugify',\n args: { ...rest },\n })) as Awaited<ReturnType<Slugify>> // TODO: infer this type when `strictNullChecks` is enabled\n\n return result\n } catch (_err) {\n console.error(_err) // eslint-disable-line no-console\n }\n },\n [serverFunction],\n )\n\n return (\n <ServerFunctionsContext\n value={{\n _internal_renderField,\n copyDataFromLocale,\n getDocumentSlots,\n getFolderResultsComponentAndData,\n getFormState,\n getTableState,\n renderDocument,\n schedulePublish,\n serverFunction,\n slugify,\n }}\n >\n {children}\n </ServerFunctionsContext>\n )\n}\n"],"mappings":";AAkBA,OAAOA,KAAA,IAASC,aAAa,EAAEC,WAAW,QAAQ;AA+GlD,OAAO,MAAMC,sBAAA,gBAAyBF,aAAA,CACpCG,SAAA;AAGF,OAAO,MAAMC,kBAAA,GAAqBA,CAAA;EAChC,MAAMC,OAAA,GAAUN,KAAA,CAAMO,GAAG,CAACJ,sBAAA;EAC1B,IAAIG,OAAA,KAAYF,SAAA,EAAW;IACzB,MAAM,IAAII,KAAA,CAAM;EAClB;EACA,OAAOF,OAAA;AACT;AAEA,OAAO,MAAMG,uBAAA,GAGRA,CAAC;EAAEC,QAAQ;EAAEC;AAAc,CAAE;EAChC,IAAI,CAACA,cAAA,EAAgB;IACnB,MAAM,IAAIH,KAAA,CAAM;EAClB;EAEA,MAAMI,gBAAA,GAAmBV,WAAA,CACvB,MAAOW,IAAA,IACL,MAAMF,cAAA,CAAe;IACnBG,IAAA,EAAM;IACND;EACF,IACF,CAACF,cAAA,CAAe;EAGlB,MAAMI,eAAA,GAAkBb,WAAA,CACtB,MAAOW,IAAA;IACL,MAAM;MAAEG,MAAA,EAAQC,YAAY;MAAE,GAAGC;IAAA,CAAM,GAAGL,IAAA;IAE1C,IAAI;MACF,IAAI,CAACI,YAAA,EAAcE,OAAA,EAAS;QAC1B,MAAMC,MAAA,GAAU,MAAMT,cAAA,CAAe;UACnCG,IAAA,EAAM;UACND,IAAA,EAAM;YAAE,GAAGK;UAAK;QAClB;QAA0D;QAE1D,IAAI,CAACD,YAAA,EAAcE,OAAA,EAAS;UAC1B,OAAOC,MAAA;QACT;MACF;IACF,EAAE,OAAOC,IAAA,EAAM;MACbC,OAAA,CAAQC,KAAK,CAACF,IAAA,GAAM;IACtB;IAEA,IAAIE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C1B,OAAOC,MAAA;MACT;IACF,EAAE,OAAOC,IAAA,EAAM;MACbC,OAAA,CAAQC,KAAK,CAACF,IAAA,GAAM;IACtB;EACF,GACA,CAACV,cAAA,CAAe;EAGlB,MAAMwB,qBAAA,GAAwBjC,WAAA,CAC5B,MAAOW,IAAA;IACL,IAAI;MACF,MAAMO,MAAA,GAAU,MAAMT,cAAA,CAAe;QACnCG,IAAA,EAAM;QACND;MACF;MAEA,OAAOO,MAAA;IACT,EAAE,OAAOC,IAAA,EAAM;MACbC,OAAA,CAAQC,KAAK,CAACF,IAAA,GAAM;IACtB;EACF,GACA,CAACV,cAAA,CAAe;EAGlB,MAAMyB,OAAA,GAAUlC,WAAA,CACd,MAAOW,IAAA;IACL,MAAM;MAAEG,MAAA,EAAQC,YAAY;MAAE,GAAGC;IAAA,CAAM,GAAGL,IAAA,IAAQ,CAAC;IAEnD,IAAI;MACF,MAAMO,MAAA,GAAU,MAAMT,cAAA,CAAe;QACnCG,IAAA,EAAM;QACND,IAAA,EAAM;UAAE,GAAGK;QAAK;MAClB;MAAoC;MAEpC,OAAOE,MAAA;IACT,EAAE,OAAOC,IAAA,EAAM;MACbC,OAAA,CAAQC,KAAK,CAACF,IAAA,GAAM;IACtB;EACF,GACA,CAACV,cAAA,CAAe;EAGlB,oBACE0B,IAAA,CAAClC,sBAAA;IACCuB,KAAA,EAAO;MACLS,qBAAA;MACAF,kBAAA;MACArB,gBAAA;MACAsB,gCAAA;MACAN,YAAA;MACAG,aAAA;MACAC,cAAA;MACAjB,eAAA;MACAJ,cAAA;MACAyB;IACF;cAEC1B;;AAGP","ignoreList":[]}
@@ -62,8 +62,7 @@ export const buildColumnState = args => {
62
62
  if (sortTo) {
63
63
  // sort the fields to the order of `defaultColumns` or `columns`
64
64
  sortedFieldMap = sortFieldMap(sortedFieldMap, sortTo);
65
- _sortedFieldMap = sortFieldMap(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort
66
- ;
65
+ _sortedFieldMap = sortFieldMap(_sortedFieldMap, sortTo); // TODO: think of a way to avoid this additional sort
67
66
  }
68
67
  const activeColumnsIndices = [];
69
68
  const sorted = sortedFieldMap?.reduce((acc, clientField, colIndex) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["fieldIsHiddenOrDisabled","fieldIsID","fieldIsPresentationalOnly","flattenTopLevelFields","React","RenderServerComponent","SortColumn","filterFieldsWithPermissions","isColumnActive","renderCell","sortFieldMap","buildColumnState","args","beforeRows","clientFields","collectionSlug","columns","customCellProps","dataType","docs","enableLinkedCell","enableRowSelections","fieldPermissions","i18n","payload","req","serverFields","sortColumnProps","useAsTitle","viewType","sortedFieldMap","fields","keepPresentationalFields","moveSubFieldsToTop","_sortedFieldMap","idFieldIndex","findIndex","field","idField","splice","unshift","useAsTitleFieldIndex","name","useAsTitleField","sortTo","activeColumnsIndices","sorted","reduce","acc","clientField","colIndex","accessor","undefined","serverField","find","f","fAccessor","hasCustomCell","admin","components","Cell","type","columnPref","preference","isActive","column","includes","push","CustomLabel","CustomLabelToRender","Label","clientProps","customLabelServerProps","Component","importMap","serverProps","fieldAffectsDataSubFields","label","labelWithPrefix","dotAccessor","replace","Heading","_jsx","disable","active","renderedCells","map","doc","rowIndex","relationTo","columnIndex","value","isLinkedColumn"],"sources":["../../../../src/providers/TableColumns/buildColumnState/index.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientComponentProps,\n ClientField,\n CollectionPreferences,\n CollectionSlug,\n Column,\n DefaultCellComponentProps,\n Document,\n Field,\n PaginatedDocs,\n Payload,\n PayloadRequest,\n SanitizedCollectionConfig,\n SanitizedFieldsPermissions,\n ServerComponentProps,\n StaticLabel,\n ViewTypes,\n} from 'payload'\n\nimport {\n fieldIsHiddenOrDisabled,\n fieldIsID,\n fieldIsPresentationalOnly,\n flattenTopLevelFields,\n} from 'payload/shared'\nimport React from 'react'\n\nimport type { SortColumnProps } from '../../../elements/SortColumn/index.js'\n\nimport { RenderServerComponent } from '../../../elements/RenderServerComponent/index.js'\nimport {\n SortColumn,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\n} from '../../../exports/client/index.js'\nimport { filterFieldsWithPermissions } from './filterFieldsWithPermissions.js'\nimport { isColumnActive } from './isColumnActive.js'\nimport { renderCell } from './renderCell.js'\nimport { sortFieldMap } from './sortFieldMap.js'\n\nexport type BuildColumnStateArgs = {\n beforeRows?: Column[]\n clientFields: ClientField[]\n columns?: CollectionPreferences['columns']\n customCellProps: DefaultCellComponentProps['customCellProps']\n enableLinkedCell?: boolean\n enableRowSelections: boolean\n enableRowTypes?: boolean\n fieldPermissions?: SanitizedFieldsPermissions\n i18n: I18nClient\n payload: Payload\n req?: PayloadRequest\n serverFields: Field[]\n sortColumnProps?: Partial<SortColumnProps>\n useAsTitle: SanitizedCollectionConfig['admin']['useAsTitle']\n viewType?: ViewTypes\n} & (\n | {\n collectionSlug: CollectionSlug\n dataType: 'monomorphic'\n docs: PaginatedDocs['docs']\n }\n | {\n collectionSlug?: undefined\n dataType: 'polymorphic'\n docs: {\n relationTo: CollectionSlug\n value: Document\n }[]\n }\n)\n\nexport const buildColumnState = (args: BuildColumnStateArgs): Column[] => {\n const {\n beforeRows,\n clientFields,\n collectionSlug,\n columns,\n customCellProps,\n dataType,\n docs,\n enableLinkedCell = true,\n enableRowSelections,\n fieldPermissions,\n i18n,\n payload,\n req,\n serverFields,\n sortColumnProps,\n useAsTitle,\n viewType,\n } = args\n\n // clientFields contains the fake `id` column\n let sortedFieldMap = flattenTopLevelFields(\n filterFieldsWithPermissions({ fieldPermissions, fields: clientFields }),\n {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n },\n ) as ClientField[]\n\n let _sortedFieldMap = flattenTopLevelFields(\n filterFieldsWithPermissions({\n fieldPermissions,\n fields: serverFields,\n }),\n {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n },\n ) as Field[] // TODO: think of a way to avoid this additional flatten\n\n // place the `ID` field first, if it exists\n // do the same for the `useAsTitle` field with precedence over the `ID` field\n // then sort the rest of the fields based on the `defaultColumns` or `columns`\n const idFieldIndex = sortedFieldMap?.findIndex((field) => fieldIsID(field))\n\n if (idFieldIndex > -1) {\n const idField = sortedFieldMap.splice(idFieldIndex, 1)[0]\n sortedFieldMap.unshift(idField)\n }\n\n const useAsTitleFieldIndex = useAsTitle\n ? sortedFieldMap.findIndex((field) => 'name' in field && field.name === useAsTitle)\n : -1\n\n if (useAsTitleFieldIndex > -1) {\n const useAsTitleField = sortedFieldMap.splice(useAsTitleFieldIndex, 1)[0]\n sortedFieldMap.unshift(useAsTitleField)\n }\n\n const sortTo = columns\n\n if (sortTo) {\n // sort the fields to the order of `defaultColumns` or `columns`\n sortedFieldMap = sortFieldMap<ClientField>(sortedFieldMap, sortTo)\n _sortedFieldMap = sortFieldMap<Field>(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort\n }\n\n const activeColumnsIndices = []\n\n const sorted: Column[] = sortedFieldMap?.reduce((acc, clientField, colIndex) => {\n if (fieldIsHiddenOrDisabled(clientField) && !fieldIsID(clientField)) {\n return acc\n }\n\n const accessor =\n (clientField as any).accessor ?? ('name' in clientField ? clientField.name : undefined)\n\n const serverField = _sortedFieldMap.find((f) => {\n const fAccessor = (f as any).accessor ?? ('name' in f ? f.name : undefined)\n return fAccessor === accessor\n })\n\n const hasCustomCell =\n serverField?.admin &&\n 'components' in serverField.admin &&\n serverField.admin.components &&\n 'Cell' in serverField.admin.components &&\n serverField.admin.components.Cell\n\n if (serverField && serverField.type === 'group' && !hasCustomCell) {\n return acc // skip any group without a custom cell\n }\n\n const columnPref = columns?.find(\n (preference) => clientField && 'name' in clientField && preference.accessor === accessor,\n )\n\n const isActive = isColumnActive({\n accessor,\n activeColumnsIndices,\n column: columnPref,\n columns,\n })\n\n if (isActive && !activeColumnsIndices.includes(colIndex)) {\n activeColumnsIndices.push(colIndex)\n }\n\n let CustomLabel = undefined\n\n if (dataType === 'monomorphic') {\n const CustomLabelToRender =\n serverField &&\n 'admin' in serverField &&\n 'components' in serverField.admin &&\n 'Label' in serverField.admin.components &&\n serverField.admin.components.Label !== undefined // let it return `null`\n ? serverField.admin.components.Label\n : undefined\n\n // TODO: customComponent will be optional in v4\n const clientProps: Omit<ClientComponentProps, 'customComponents'> = {\n field: clientField,\n }\n\n const customLabelServerProps: Pick<\n ServerComponentProps,\n 'clientField' | 'collectionSlug' | 'field' | 'i18n' | 'payload'\n > = {\n clientField,\n collectionSlug,\n field: serverField,\n i18n,\n payload,\n }\n\n CustomLabel = CustomLabelToRender\n ? RenderServerComponent({\n clientProps,\n Component: CustomLabelToRender,\n importMap: payload.importMap,\n serverProps: customLabelServerProps,\n })\n : undefined\n }\n\n const fieldAffectsDataSubFields =\n clientField &&\n clientField.type &&\n (clientField.type === 'array' ||\n clientField.type === 'group' ||\n clientField.type === 'blocks')\n\n const label =\n clientField && 'labelWithPrefix' in clientField && clientField.labelWithPrefix !== undefined\n ? clientField.labelWithPrefix\n : 'label' in clientField\n ? clientField.label\n : undefined\n\n // Convert accessor to dot notation specifically for SortColumn sorting behavior\n const dotAccessor = accessor?.replace(/-/g, '.')\n\n const Heading = (\n <SortColumn\n disable={fieldAffectsDataSubFields || fieldIsPresentationalOnly(clientField) || undefined}\n Label={CustomLabel}\n label={label as StaticLabel}\n name={dotAccessor}\n {...(sortColumnProps || {})}\n />\n )\n\n const column: Column = {\n accessor,\n active: isActive,\n CustomLabel,\n field: clientField,\n Heading,\n renderedCells: isActive\n ? docs.map((doc, rowIndex) => {\n return renderCell({\n clientField,\n collectionSlug: dataType === 'monomorphic' ? collectionSlug : doc.relationTo,\n columnIndex: colIndex,\n customCellProps,\n doc: dataType === 'monomorphic' ? doc : doc.value,\n enableRowSelections,\n i18n,\n isLinkedColumn: enableLinkedCell && colIndex === activeColumnsIndices[0],\n payload,\n req,\n rowIndex,\n serverField,\n viewType,\n })\n })\n : [],\n }\n\n acc.push(column)\n\n return acc\n }, [])\n\n if (beforeRows) {\n sorted.unshift(...beforeRows)\n }\n\n return sorted\n}\n"],"mappings":";AAoBA,SACEA,uBAAuB,EACvBC,SAAS,EACTC,yBAAyB,EACzBC,qBAAqB,QAChB;AACP,OAAOC,KAAA,MAAW;AAIlB,SAASC,qBAAqB,QAAQ;AACtC,SACEC,UAAU,QAEL;AACP,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,cAAc,QAAQ;AAC/B,SAASC,UAAU,QAAQ;AAC3B,SAASC,YAAY,QAAQ;AAkC7B,OAAO,MAAMC,gBAAA,GAAoBC,IAAA;EAC/B,MAAM;IACJC,UAAU;IACVC,YAAY;IACZC,cAAc;IACdC,OAAO;IACPC,eAAe;IACfC,QAAQ;IACRC,IAAI;IACJC,gBAAA,GAAmB,IAAI;IACvBC,mBAAmB;IACnBC,gBAAgB;IAChBC,IAAI;IACJC,OAAO;IACPC,GAAG;IACHC,YAAY;IACZC,eAAe;IACfC,UAAU;IACVC;EAAQ,CACT,GAAGjB,IAAA;EAEJ;EACA,IAAIkB,cAAA,GAAiB3B,qBAAA,CACnBI,2BAAA,CAA4B;IAAEe,gBAAA;IAAkBS,MAAA,EAAQjB;EAAa,IACrE;IACES,IAAA;IACAS,wBAAA,EAA0B;IAC1BC,kBAAA,EAAoB;EACtB;EAGF,IAAIC,eAAA,GAAkB/B,qBAAA,CACpBI,2BAAA,CAA4B;IAC1Be,gBAAA;IACAS,MAAA,EAAQL;EACV,IACA;IACEH,IAAA;IACAS,wBAAA,EAA0B;IAC1BC,kBAAA,EAAoB;EACtB,EACW;EAAA;EAEb;EACA;EACA;EACA,MAAME,YAAA,GAAeL,cAAA,EAAgBM,SAAA,CAAWC,KAAA,IAAUpC,SAAA,CAAUoC,KAAA;EAEpE,IAAIF,YAAA,GAAe,CAAC,GAAG;IACrB,MAAMG,OAAA,GAAUR,cAAA,CAAeS,MAAM,CAACJ,YAAA,EAAc,EAAE,CA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,CAAC,EAAE;UACxErB,OAAA;UACAC,GAAA;UACA+D,QAAA;UACAnC,WAAA;UACAxB;QACF;MACF,KACA;IACN;IAEAmB,GAAA,CAAImB,IAAI,CAACF,MAAA;IAET,OAAOjB,GAAA;EACT,GAAG,EAAE;EAEL,IAAInC,UAAA,EAAY;IACdiC,MAAA,CAAON,OAAO,IAAI3B,UAAA;EACpB;EAEA,OAAOiC,MAAA;AACT","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["fieldIsHiddenOrDisabled","fieldIsID","fieldIsPresentationalOnly","flattenTopLevelFields","React","RenderServerComponent","SortColumn","filterFieldsWithPermissions","isColumnActive","renderCell","sortFieldMap","buildColumnState","args","beforeRows","clientFields","collectionSlug","columns","customCellProps","dataType","docs","enableLinkedCell","enableRowSelections","fieldPermissions","i18n","payload","req","serverFields","sortColumnProps","useAsTitle","viewType","sortedFieldMap","fields","keepPresentationalFields","moveSubFieldsToTop","_sortedFieldMap","idFieldIndex","findIndex","field","idField","splice","unshift","useAsTitleFieldIndex","name","useAsTitleField","sortTo","activeColumnsIndices","sorted","reduce","acc","clientField","colIndex","accessor","undefined","serverField","find","f","fAccessor","hasCustomCell","admin","components","Cell","type","columnPref","preference","isActive","column","includes","push","CustomLabel","CustomLabelToRender","Label","clientProps","customLabelServerProps","Component","importMap","serverProps","fieldAffectsDataSubFields","label","labelWithPrefix","dotAccessor","replace","Heading","_jsx","disable","active","renderedCells","map","doc","rowIndex","relationTo","columnIndex","value","isLinkedColumn"],"sources":["../../../../src/providers/TableColumns/buildColumnState/index.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientComponentProps,\n ClientField,\n CollectionPreferences,\n CollectionSlug,\n Column,\n DefaultCellComponentProps,\n Document,\n Field,\n PaginatedDocs,\n Payload,\n PayloadRequest,\n SanitizedCollectionConfig,\n SanitizedFieldsPermissions,\n ServerComponentProps,\n StaticLabel,\n ViewTypes,\n} from 'payload'\n\nimport {\n fieldIsHiddenOrDisabled,\n fieldIsID,\n fieldIsPresentationalOnly,\n flattenTopLevelFields,\n} from 'payload/shared'\nimport React from 'react'\n\nimport type { SortColumnProps } from '../../../elements/SortColumn/index.js'\n\nimport { RenderServerComponent } from '../../../elements/RenderServerComponent/index.js'\nimport {\n SortColumn,\n // eslint-disable-next-line payload/no-imports-from-exports-dir -- MUST reference the exports dir: https://github.com/payloadcms/payload/issues/12002#issuecomment-2791493587\n} from '../../../exports/client/index.js'\nimport { filterFieldsWithPermissions } from './filterFieldsWithPermissions.js'\nimport { isColumnActive } from './isColumnActive.js'\nimport { renderCell } from './renderCell.js'\nimport { sortFieldMap } from './sortFieldMap.js'\n\nexport type BuildColumnStateArgs = {\n beforeRows?: Column[]\n clientFields: ClientField[]\n columns?: CollectionPreferences['columns']\n customCellProps: DefaultCellComponentProps['customCellProps']\n enableLinkedCell?: boolean\n enableRowSelections: boolean\n enableRowTypes?: boolean\n fieldPermissions?: SanitizedFieldsPermissions\n i18n: I18nClient\n payload: Payload\n req?: PayloadRequest\n serverFields: Field[]\n sortColumnProps?: Partial<SortColumnProps>\n useAsTitle: SanitizedCollectionConfig['admin']['useAsTitle']\n viewType?: ViewTypes\n} & (\n | {\n collectionSlug: CollectionSlug\n dataType: 'monomorphic'\n docs: PaginatedDocs['docs']\n }\n | {\n collectionSlug?: undefined\n dataType: 'polymorphic'\n docs: {\n relationTo: CollectionSlug\n value: Document\n }[]\n }\n)\n\nexport const buildColumnState = (args: BuildColumnStateArgs): Column[] => {\n const {\n beforeRows,\n clientFields,\n collectionSlug,\n columns,\n customCellProps,\n dataType,\n docs,\n enableLinkedCell = true,\n enableRowSelections,\n fieldPermissions,\n i18n,\n payload,\n req,\n serverFields,\n sortColumnProps,\n useAsTitle,\n viewType,\n } = args\n\n // clientFields contains the fake `id` column\n let sortedFieldMap = flattenTopLevelFields(\n filterFieldsWithPermissions({ fieldPermissions, fields: clientFields }),\n {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n },\n ) as ClientField[]\n\n let _sortedFieldMap = flattenTopLevelFields(\n filterFieldsWithPermissions({\n fieldPermissions,\n fields: serverFields,\n }),\n {\n i18n,\n keepPresentationalFields: true,\n moveSubFieldsToTop: true,\n },\n ) as Field[] // TODO: think of a way to avoid this additional flatten\n\n // place the `ID` field first, if it exists\n // do the same for the `useAsTitle` field with precedence over the `ID` field\n // then sort the rest of the fields based on the `defaultColumns` or `columns`\n const idFieldIndex = sortedFieldMap?.findIndex((field) => fieldIsID(field))\n\n if (idFieldIndex > -1) {\n const idField = sortedFieldMap.splice(idFieldIndex, 1)[0]\n sortedFieldMap.unshift(idField)\n }\n\n const useAsTitleFieldIndex = useAsTitle\n ? sortedFieldMap.findIndex((field) => 'name' in field && field.name === useAsTitle)\n : -1\n\n if (useAsTitleFieldIndex > -1) {\n const useAsTitleField = sortedFieldMap.splice(useAsTitleFieldIndex, 1)[0]\n sortedFieldMap.unshift(useAsTitleField)\n }\n\n const sortTo = columns\n\n if (sortTo) {\n // sort the fields to the order of `defaultColumns` or `columns`\n sortedFieldMap = sortFieldMap<ClientField>(sortedFieldMap, sortTo)\n _sortedFieldMap = sortFieldMap<Field>(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort\n }\n\n const activeColumnsIndices = []\n\n const sorted: Column[] = sortedFieldMap?.reduce((acc, clientField, colIndex) => {\n if (fieldIsHiddenOrDisabled(clientField) && !fieldIsID(clientField)) {\n return acc\n }\n\n const accessor =\n (clientField as any).accessor ?? ('name' in clientField ? clientField.name : undefined)\n\n const serverField = _sortedFieldMap.find((f) => {\n const fAccessor = (f as any).accessor ?? ('name' in f ? f.name : undefined)\n return fAccessor === accessor\n })\n\n const hasCustomCell =\n serverField?.admin &&\n 'components' in serverField.admin &&\n serverField.admin.components &&\n 'Cell' in serverField.admin.components &&\n serverField.admin.components.Cell\n\n if (serverField && serverField.type === 'group' && !hasCustomCell) {\n return acc // skip any group without a custom cell\n }\n\n const columnPref = columns?.find(\n (preference) => clientField && 'name' in clientField && preference.accessor === accessor,\n )\n\n const isActive = isColumnActive({\n accessor,\n activeColumnsIndices,\n column: columnPref,\n columns,\n })\n\n if (isActive && !activeColumnsIndices.includes(colIndex)) {\n activeColumnsIndices.push(colIndex)\n }\n\n let CustomLabel = undefined\n\n if (dataType === 'monomorphic') {\n const CustomLabelToRender =\n serverField &&\n 'admin' in serverField &&\n 'components' in serverField.admin &&\n 'Label' in serverField.admin.components &&\n serverField.admin.components.Label !== undefined // let it return `null`\n ? serverField.admin.components.Label\n : undefined\n\n // TODO: customComponent will be optional in v4\n const clientProps: Omit<ClientComponentProps, 'customComponents'> = {\n field: clientField,\n }\n\n const customLabelServerProps: Pick<\n ServerComponentProps,\n 'clientField' | 'collectionSlug' | 'field' | 'i18n' | 'payload'\n > = {\n clientField,\n collectionSlug,\n field: serverField,\n i18n,\n payload,\n }\n\n CustomLabel = CustomLabelToRender\n ? RenderServerComponent({\n clientProps,\n Component: CustomLabelToRender,\n importMap: payload.importMap,\n serverProps: customLabelServerProps,\n })\n : undefined\n }\n\n const fieldAffectsDataSubFields =\n clientField &&\n clientField.type &&\n (clientField.type === 'array' ||\n clientField.type === 'group' ||\n clientField.type === 'blocks')\n\n const label =\n clientField && 'labelWithPrefix' in clientField && clientField.labelWithPrefix !== undefined\n ? clientField.labelWithPrefix\n : 'label' in clientField\n ? clientField.label\n : undefined\n\n // Convert accessor to dot notation specifically for SortColumn sorting behavior\n const dotAccessor = accessor?.replace(/-/g, '.')\n\n const Heading = (\n <SortColumn\n disable={fieldAffectsDataSubFields || fieldIsPresentationalOnly(clientField) || undefined}\n Label={CustomLabel}\n label={label as StaticLabel}\n name={dotAccessor}\n {...(sortColumnProps || {})}\n />\n )\n\n const column: Column = {\n accessor,\n active: isActive,\n CustomLabel,\n field: clientField,\n Heading,\n renderedCells: isActive\n ? docs.map((doc, rowIndex) => {\n return renderCell({\n clientField,\n collectionSlug: dataType === 'monomorphic' ? collectionSlug : doc.relationTo,\n columnIndex: colIndex,\n customCellProps,\n doc: dataType === 'monomorphic' ? doc : doc.value,\n enableRowSelections,\n i18n,\n isLinkedColumn: enableLinkedCell && colIndex === activeColumnsIndices[0],\n payload,\n req,\n rowIndex,\n serverField,\n viewType,\n })\n })\n : [],\n }\n\n acc.push(column)\n\n return acc\n }, [])\n\n if (beforeRows) {\n sorted.unshift(...beforeRows)\n }\n\n return sorted\n}\n"],"mappings":";AAoBA,SACEA,uBAAuB,EACvBC,SAAS,EACTC,yBAAyB,EACzBC,qBAAqB,QAChB;AACP,OAAOC,KAAA,MAAW;AAIlB,SAASC,qBAAqB,QAAQ;AACtC,SACEC,UAAU,QAEL;AACP,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,cAAc,QAAQ;AAC/B,SAASC,UAAU,QAAQ;AAC3B,SAASC,YAAY,QAAQ;AAkC7B,OAAO,MAAMC,gBAAA,GAAoBC,IAAA;EAC/B,MAAM;IACJC,UAAU;IACVC,YAAY;IACZC,cAAc;IACdC,OAAO;IACPC,eAAe;IACfC,QAAQ;IACRC,IAAI;IACJC,gBAAA,GAAmB,IAAI;IACvBC,mBAAmB;IACnBC,gBAAgB;IAChBC,IAAI;IACJC,OAAO;IACPC,GAAG;IACHC,YAAY;IACZC,eAAe;IACfC,UAAU;IACVC;EAAQ,CACT,GAAGjB,IAAA;EAEJ;EACA,IAAIkB,cAAA,GAAiB3B,qBAAA,CACnBI,2BAAA,CAA4B;IAAEe,gBAAA;IAAkBS,MAAA,EAAQjB;EAAa,IACrE;IACES,IAAA;IACAS,wBAAA,EAA0B;IAC1BC,kBAAA,EAAoB;EACtB;EAGF,IAAIC,eAAA,GAAkB/B,qBAAA,CACpBI,2BAAA,CAA4B;IAC1Be,gBAAA;IACAS,MAAA,EAAQL;EACV,IACA;IACEH,IAAA;IACAS,wBAAA,EAA0B;IAC1BC,kBAAA,EAAoB;EACtB,EACW;EAAA;EAEb;EACA;EACA;EACA,MAAME,YAAA,GAAeL,cAAA,EAAgBM,SAAA,CAAWC,KAAA,IA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