@payloadcms/ui 3.89.0-internal.4b0e9b6 → 3.89.0
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/PublishButton/ScheduleDrawer/buildUpcomingScheduleWhere.d.ts +13 -0
- package/dist/elements/PublishButton/ScheduleDrawer/buildUpcomingScheduleWhere.d.ts.map +1 -0
- package/dist/elements/PublishButton/ScheduleDrawer/buildUpcomingScheduleWhere.js +41 -0
- package/dist/elements/PublishButton/ScheduleDrawer/buildUpcomingScheduleWhere.js.map +1 -0
- package/dist/elements/PublishButton/ScheduleDrawer/index.d.ts.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/index.js +8 -54
- package/dist/elements/PublishButton/ScheduleDrawer/index.js.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/types.d.ts +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/types.d.ts.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/types.js.map +1 -1
- package/dist/exports/client/index.js +24 -24
- package/dist/exports/client/index.js.map +4 -4
- package/dist/providers/LivePreview/index.d.ts.map +1 -1
- package/dist/providers/LivePreview/index.js +13 -6
- package/dist/providers/LivePreview/index.js.map +1 -1
- package/dist/providers/ServerFunctions/index.d.ts +5 -1
- package/dist/providers/ServerFunctions/index.d.ts.map +1 -1
- package/dist/providers/ServerFunctions/index.js +15 -0
- package/dist/providers/ServerFunctions/index.js.map +1 -1
- package/dist/utilities/formatAbsoluteURL.d.ts +1 -1
- package/dist/utilities/formatAbsoluteURL.d.ts.map +1 -1
- package/dist/utilities/formatAbsoluteURL.js +18 -8
- package/dist/utilities/formatAbsoluteURL.js.map +1 -1
- package/dist/utilities/formatAbsoluteURL.spec.js +27 -0
- package/dist/utilities/formatAbsoluteURL.spec.js.map +1 -0
- package/dist/utilities/isAbsoluteURL.d.ts +3 -0
- package/dist/utilities/isAbsoluteURL.d.ts.map +1 -0
- package/dist/utilities/isAbsoluteURL.js +15 -0
- package/dist/utilities/isAbsoluteURL.js.map +1 -0
- package/dist/utilities/isAbsoluteURL.spec.js +11 -0
- package/dist/utilities/isAbsoluteURL.spec.js.map +1 -0
- package/dist/utilities/isHttpURL.d.ts +3 -0
- package/dist/utilities/isHttpURL.d.ts.map +1 -0
- package/dist/utilities/isHttpURL.js +12 -0
- package/dist/utilities/isHttpURL.js.map +1 -0
- package/dist/utilities/isHttpURL.spec.js +25 -0
- package/dist/utilities/isHttpURL.spec.js.map +1 -0
- package/dist/utilities/schedulePublishHandler.d.ts +8 -1
- package/dist/utilities/schedulePublishHandler.d.ts.map +1 -1
- package/dist/utilities/schedulePublishHandler.js +74 -4
- package/dist/utilities/schedulePublishHandler.js.map +1 -1
- package/package.json +6 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,iBAAiB,EAAsB,MAAM,SAAS,CAAA;AAG3F,OAAO,KAAmE,MAAM,OAAO,CAAA;AAEvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,iBAAiB,EAAsB,MAAM,SAAS,CAAA;AAG3F,OAAO,KAAmE,MAAM,OAAO,CAAA;AAEvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAW1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAC9C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,UAAU,CAAC,EAAE;QACX,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,gBAAgB,EAAE,OAAO,CAAA;IACzB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,GAAG,IAAI,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,KAAK,CAAC,CAAA;AAEhE,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAqSlE,CAAA"}
|
|
@@ -7,6 +7,7 @@ import { usePopupWindow } from '../../hooks/usePopupWindow.js';
|
|
|
7
7
|
import { useDocumentInfo } from '../../providers/DocumentInfo/index.js';
|
|
8
8
|
import { usePreferences } from '../../providers/Preferences/index.js';
|
|
9
9
|
import { formatAbsoluteURL } from '../../utilities/formatAbsoluteURL.js';
|
|
10
|
+
import { isHttpURL } from '../../utilities/isHttpURL.js';
|
|
10
11
|
import { customCollisionDetection } from './collisionDetection.js';
|
|
11
12
|
import { LivePreviewContext } from './context.js';
|
|
12
13
|
import { sizeReducer } from './sizeReducer.js';
|
|
@@ -40,7 +41,13 @@ export const LivePreviewProvider = ({
|
|
|
40
41
|
width: '100%'
|
|
41
42
|
}], [incomingBreakpoints]);
|
|
42
43
|
const [url, setURL] = useState('');
|
|
43
|
-
const [previewURL,
|
|
44
|
+
const [previewURL, _setPreviewURL] = useState();
|
|
45
|
+
const setPreviewURL = useCallback(incomingURL => {
|
|
46
|
+
_setPreviewURL(isHttpURL(incomingURL) ? incomingURL : undefined);
|
|
47
|
+
}, []);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
setPreviewURL(previewURLFromProps);
|
|
50
|
+
}, [previewURLFromProps, setPreviewURL]);
|
|
44
51
|
const {
|
|
45
52
|
isPopupOpen,
|
|
46
53
|
openPopupWindow,
|
|
@@ -82,16 +89,16 @@ export const LivePreviewProvider = ({
|
|
|
82
89
|
* - resets `appIsReady` to `false` while the new URL is loading
|
|
83
90
|
*/
|
|
84
91
|
const setLivePreviewURL = useCallback(_incomingURL => {
|
|
85
|
-
let
|
|
92
|
+
let incomingURL_0;
|
|
86
93
|
if (typeof _incomingURL === 'string') {
|
|
87
|
-
|
|
94
|
+
incomingURL_0 = formatAbsoluteURL(_incomingURL);
|
|
88
95
|
}
|
|
89
|
-
if (!
|
|
96
|
+
if (!incomingURL_0) {
|
|
90
97
|
setIsLivePreviewing(false);
|
|
91
98
|
}
|
|
92
|
-
if (
|
|
99
|
+
if (incomingURL_0 !== url) {
|
|
93
100
|
setAppIsReady(false);
|
|
94
|
-
setURL(
|
|
101
|
+
setURL(incomingURL_0);
|
|
95
102
|
}
|
|
96
103
|
}, [url]);
|
|
97
104
|
/**
|
|
@@ -1 +1 @@
|
|
|
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","shouldRenderIframe","setShouldRenderIframe","setIsLivePreviewing","livePreviewing","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\n const [isLivePreviewing, _setIsLivePreviewing] =\n useState<LivePreviewContextType['isLivePreviewing']>(incomingIsLivePreviewing)\n\n const [shouldRenderIframe, setShouldRenderIframe] =\n useState<LivePreviewContextType['shouldRenderIframe']>(isLivePreviewing)\n\n /**\n * Rendering the iframe is a one-way event, e.g. defer load and never unmount.\n * This way, subsequent toggles will appear to load instantly.\n */\n const setIsLivePreviewing = useCallback<LivePreviewContextType['setIsLivePreviewing']>(\n (livePreviewing) => {\n if (livePreviewing) {\n setShouldRenderIframe(true)\n }\n\n _setIsLivePreviewing(livePreviewing)\n },\n [],\n )\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 shouldRenderIframe,\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;AAC3B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAA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A,KAAK5C,aAAA,CACHH,cAAA,GAAiB,cAAcA,cAAA,EAAgB,GAAG,UAAUC,UAAA,EAAY,EACxE;MACE+C,YAAA,EAAc7E,gBAAA,GAAmB,iBAAiB;IACpD,GACA;EAEJ,GAAG,CAACA,gBAAA,EAAkBgC,aAAA,EAAeH,cAAA,EAAgBC,UAAA,CAAW;EAEhE,MAAMgD,YAAA,GAAe9F,KAAA;EAErB,oBACE+F,IAAA,CAACtF,kBAAA;IACCmE,KAAA,EAAO;MACLnC,UAAA;MACAsB,UAAA;MACAnD,WAAA;MACAqC,SAAA;MACAlC,oBAAA;MACAC,gBAAA;MACAqB,WAAA;MACAnB,gBAAA;MACAyB,oBAAA;MACAO,SAAA;MACAW,kBAAA;MACAvB,eAAA;MACAC,QAAA;MACApB,UAAA;MACAK,iBAAA;MACAkB,aAAA;MACAsB,aAAA;MACAa,SAAA;MACAhD,mBAAA;MACAsB,YAAA;MACAW,qBAAA;MACA1B,aAAA;MACAX,oBAAA,EAAsBiE,kBAAA;MACtB/B,OAAA;MACAqC,kBAAA,EAAoBzC,WAAA;MACpBpB,MAAA,EAAQ8B,iBAAA;MACRS,QAAA;MACArB,OAAA;MACA1B,kBAAA;MACA+B,IAAA;MACAuC,eAAA,EAAiB3C,QAAA;MACjBjC,oBAAA;MACAC,GAAA;MACA8B;IACF;cAEA,aAAA2C,IAAA,CAACnG,UAAA;MACCsG,kBAAA,EAAoB1F,wBAAA;MACpB;MACA+D,EAAA,EAAIuB,YAAA;MACJK,SAAA,EAAW/B,aAAA;gBAEVtD;;;AAIT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["DndContext","React","useCallback","useEffect","useId","useMemo","useRef","useState","usePopupWindow","useDocumentInfo","usePreferences","formatAbsoluteURL","isHttpURL","customCollisionDetection","LivePreviewContext","sizeReducer","LivePreviewProvider","breakpoints","incomingBreakpoints","children","isLivePreviewEnabled","isLivePreviewing","incomingIsLivePreviewing","isPreviewEnabled","previewURL","previewURLFromProps","typeofLivePreviewURL","url","urlFromProps","previewWindowType","setPreviewWindowType","_setIsLivePreviewing","shouldRenderIframe","setShouldRenderIframe","setIsLivePreviewing","livePreviewing","name","height","label","width","setURL","_setPreviewURL","setPreviewURL","incomingURL","undefined","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","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 { isHttpURL } from '../../utilities/isHttpURL.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\n const [isLivePreviewing, _setIsLivePreviewing] =\n useState<LivePreviewContextType['isLivePreviewing']>(incomingIsLivePreviewing)\n\n const [shouldRenderIframe, setShouldRenderIframe] =\n useState<LivePreviewContextType['shouldRenderIframe']>(isLivePreviewing)\n\n /**\n * Rendering the iframe is a one-way event, e.g. defer load and never unmount.\n * This way, subsequent toggles will appear to load instantly.\n */\n const setIsLivePreviewing = useCallback<LivePreviewContextType['setIsLivePreviewing']>(\n (livePreviewing) => {\n if (livePreviewing) {\n setShouldRenderIframe(true)\n }\n\n _setIsLivePreviewing(livePreviewing)\n },\n [],\n )\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>()\n\n const setPreviewURL = useCallback<LivePreviewContextType['setPreviewURL']>((incomingURL) => {\n _setPreviewURL(isHttpURL(incomingURL) ? incomingURL : undefined)\n }, [])\n\n useEffect(() => {\n setPreviewURL(previewURLFromProps)\n }, [previewURLFromProps, setPreviewURL])\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 shouldRenderIframe,\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;AAC3B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAIhF,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,SAAS,QAAQ;AAC1B,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;E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,IAAA,CAACxF,kBAAA;IACCqE,KAAA,EAAO;MACLlC,UAAA;MACAsB,UAAA;MACAtD,WAAA;MACAwC,SAAA;MACArC,oBAAA;MACAC,gBAAA;MACAwB,WAAA;MACAtB,gBAAA;MACA4B,oBAAA;MACAO,SAAA;MACAW,kBAAA;MACAvB,eAAA;MACAC,QAAA;MACAvB,UAAA;MACAK,iBAAA;MACAqB,aAAA;MACAsB,aAAA;MACAY,SAAA;MACAlD,mBAAA;MACAyB,YAAA;MACAW,qBAAA;MACA5B,aAAA;MACAZ,oBAAA,EAAsBmE,kBAAA;MACtB9B,OAAA;MACAoC,kBAAA,EAAoBxC,WAAA;MACpBvB,MAAA,EAAQiC,iBAAA;MACRQ,QAAA;MACApB,OAAA;MACA7B,kBAAA;MACAkC,IAAA;MACAsC,eAAA,EAAiB1C,QAAA;MACjBpC,oBAAA;MACAC,GAAA;MACAiC;IACF;cAEA,aAAA0C,IAAA,CAACtG,UAAA;MACCyG,kBAAA,EAAoB5F,wBAAA;MACpB;MACAiE,EAAA,EAAIuB,YAAA;MACJK,SAAA,EAAW/B,aAAA;gBAEVxD;;;AAIT","ignoreList":[]}
|
|
@@ -6,13 +6,16 @@ import type { buildFormStateHandler } from '../../utilities/buildFormState.js';
|
|
|
6
6
|
import type { buildTableStateHandler } from '../../utilities/buildTableState.js';
|
|
7
7
|
import type { CopyDataFromLocaleArgs } from '../../utilities/copyDataFromLocale.js';
|
|
8
8
|
import type { getFolderResultsComponentAndDataHandler } from '../../utilities/getFolderResultsComponentAndData.js';
|
|
9
|
-
import type { schedulePublishHandler, SchedulePublishHandlerArgs } from '../../utilities/schedulePublishHandler.js';
|
|
9
|
+
import type { getUpcomingScheduledPublishHandler, GetUpcomingScheduledPublishHandlerArgs, schedulePublishHandler, SchedulePublishHandlerArgs } from '../../utilities/schedulePublishHandler.js';
|
|
10
10
|
type GetFormStateClient = (args: {
|
|
11
11
|
signal?: AbortSignal;
|
|
12
12
|
} & Omit<BuildFormStateArgs, 'clientConfig' | 'req'>) => ReturnType<typeof buildFormStateHandler>;
|
|
13
13
|
type SchedulePublishClient = (args: {
|
|
14
14
|
signal?: AbortSignal;
|
|
15
15
|
} & Omit<SchedulePublishHandlerArgs, 'clientConfig' | 'req'>) => ReturnType<typeof schedulePublishHandler>;
|
|
16
|
+
type GetUpcomingScheduledPublishClient = (args: {
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
} & Omit<GetUpcomingScheduledPublishHandlerArgs, 'clientConfig' | 'req'>) => ReturnType<typeof getUpcomingScheduledPublishHandler>;
|
|
16
19
|
type GetTableStateClient = (args: {
|
|
17
20
|
signal?: AbortSignal;
|
|
18
21
|
} & Omit<BuildTableStateArgs, 'clientConfig' | 'req'>) => ReturnType<typeof buildTableStateHandler>;
|
|
@@ -68,6 +71,7 @@ export type ServerFunctionsContextType = {
|
|
|
68
71
|
getFolderResultsComponentAndData: GetFolderResultsComponentAndDataClient;
|
|
69
72
|
getFormState: GetFormStateClient;
|
|
70
73
|
getTableState: GetTableStateClient;
|
|
74
|
+
getUpcomingScheduledPublish: GetUpcomingScheduledPublishClient;
|
|
71
75
|
renderDocument: RenderDocumentServerFunctionHookFn;
|
|
72
76
|
schedulePublish: SchedulePublishClient;
|
|
73
77
|
serverFunction: ServerFunctionClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/ServerFunctions/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,IAAI,EACJ,mBAAmB,EACnB,aAAa,EACb,SAAS,EACT,oCAAoC,EACpC,MAAM,EACN,gCAAgC,EAChC,cAAc,EACd,oBAAoB,EACpB,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,KAAqC,MAAM,OAAO,CAAA;AAEzD,OAAO,KAA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
@@ -47,6 +47,20 @@ export const ServerFunctionsProvider = ({
|
|
|
47
47
|
error
|
|
48
48
|
};
|
|
49
49
|
}, [serverFunction]);
|
|
50
|
+
const getUpcomingScheduledPublish = useCallback(async args => {
|
|
51
|
+
const {
|
|
52
|
+
signal: remoteSignal,
|
|
53
|
+
...rest
|
|
54
|
+
} = args;
|
|
55
|
+
if (remoteSignal?.aborted) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
const result = await serverFunction({
|
|
59
|
+
name: 'get-upcoming-scheduled-publish',
|
|
60
|
+
args: rest
|
|
61
|
+
});
|
|
62
|
+
return remoteSignal?.aborted ? [] : result;
|
|
63
|
+
}, [serverFunction]);
|
|
50
64
|
const getFormState = useCallback(async args => {
|
|
51
65
|
const {
|
|
52
66
|
signal: remoteSignal,
|
|
@@ -185,6 +199,7 @@ export const ServerFunctionsProvider = ({
|
|
|
185
199
|
getFolderResultsComponentAndData,
|
|
186
200
|
getFormState,
|
|
187
201
|
getTableState,
|
|
202
|
+
getUpcomingScheduledPublish,
|
|
188
203
|
renderDocument,
|
|
189
204
|
schedulePublish,
|
|
190
205
|
serverFunction,
|
|
@@ -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","data","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 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 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 })\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 const result = (await serverFunction({\n name: 'copy-data-from-locale',\n args: rest,\n })) as Data\n\n if (!remoteSignal?.aborted) {\n return { data: result }\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":";AAiBA,OAAOA,KAAA,IAASC,aAAa,EAAEC,WAAW,QAAQ;AA8GlD,OAAO,MAAMC,sBAAA,gBAAyBF,aAAA,CACpCG,SAAA;AAGF,OAAO,MAA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AAA,CAAe;EAGlB,MAAM0B,OAAA,GAAUnC,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,oBACE2B,IAAA,CAACnC,sBAAA;IACCuB,KAAA,EAAO;MACLU,qBAAA;MACAH,kBAAA;MACArB,gBAAA;MACAuB,gCAAA;MACAP,YAAA;MACAG,aAAA;MACAC,cAAA;MACAjB,eAAA;MACAJ,cAAA;MACA0B;IACF;cAEC3B;;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","getUpcomingScheduledPublish","getFormState","fallbackLocale","state","getTableState","renderDocument","copyDataFromLocale","data","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 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 getUpcomingScheduledPublishHandler,\n GetUpcomingScheduledPublishHandlerArgs,\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 GetUpcomingScheduledPublishClient = (\n args: {\n signal?: AbortSignal\n } & Omit<GetUpcomingScheduledPublishHandlerArgs, 'clientConfig' | 'req'>,\n) => ReturnType<typeof getUpcomingScheduledPublishHandler>\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 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 getUpcomingScheduledPublish: GetUpcomingScheduledPublishClient\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 })\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 getUpcomingScheduledPublish = useCallback<GetUpcomingScheduledPublishClient>(\n async (args) => {\n const { signal: remoteSignal, ...rest } = args\n\n if (remoteSignal?.aborted) {\n return []\n }\n\n const result = (await serverFunction({\n name: 'get-upcoming-scheduled-publish',\n args: rest,\n })) as Awaited<ReturnType<typeof getUpcomingScheduledPublishHandler>>\n\n return remoteSignal?.aborted ? [] : result\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 const result = (await serverFunction({\n name: 'copy-data-from-locale',\n args: rest,\n })) as Data\n\n if (!remoteSignal?.aborted) {\n return { data: result }\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 getUpcomingScheduledPublish,\n renderDocument,\n schedulePublish,\n serverFunction,\n slugify,\n }}\n >\n {children}\n </ServerFunctionsContext>\n )\n}\n"],"mappings":";AAiBA,OAAOA,KAAA,IAASC,aAAa,EAAEC,WAAW,QAAQ;AAuHlD,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,GAAS,MAAMT,cAAA,CAAe;UAClCG,IAAA,EAAM;UACND,IAAA,EAAM;YAAE,GAAGK;UAAK;QAClB;QAEA,IAAI,CAACD,YAAA,EAAcE,OAAA,EAAS;UAC1B,OAAOC,MAAA;QACT;MACF;IACF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AA,EAAO;MACLW,qBAAA;MACAH,kBAAA;MACAtB,gBAAA;MACAwB,gCAAA;MACAP,YAAA;MACAG,aAAA;MACAJ,2BAAA;MACAK,cAAA;MACAlB,eAAA;MACAJ,cAAA;MACA2B;IACF;cAEC5B;;AAGP","ignoreList":[]}
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* Note: This MUST be called within the client environment as it relies on the `window` object
|
|
5
5
|
* to determine the absolute URL.
|
|
6
6
|
*/
|
|
7
|
-
export declare const formatAbsoluteURL: (incomingURL: string) =>
|
|
7
|
+
export declare const formatAbsoluteURL: (incomingURL: string) => string | undefined;
|
|
8
8
|
//# sourceMappingURL=formatAbsoluteURL.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatAbsoluteURL.d.ts","sourceRoot":"","sources":["../../src/utilities/formatAbsoluteURL.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatAbsoluteURL.d.ts","sourceRoot":"","sources":["../../src/utilities/formatAbsoluteURL.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,gBAAiB,MAAM,KAAG,MAAM,GAAG,SAmBhE,CAAA"}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
try {
|
|
3
|
-
return new URL(url, window.location.origin).href;
|
|
4
|
-
} catch {
|
|
5
|
-
return url;
|
|
6
|
-
}
|
|
7
|
-
};
|
|
1
|
+
import { isHttpURL } from './isHttpURL.js';
|
|
8
2
|
/**
|
|
9
3
|
* Ensures the provided URL is absolute. If not, it converts it to an absolute URL based
|
|
10
4
|
* on the current window location.
|
|
11
5
|
* Note: This MUST be called within the client environment as it relies on the `window` object
|
|
12
6
|
* to determine the absolute URL.
|
|
13
7
|
*/
|
|
14
|
-
export const formatAbsoluteURL = incomingURL =>
|
|
8
|
+
export const formatAbsoluteURL = incomingURL => {
|
|
9
|
+
try {
|
|
10
|
+
// This throws for malformed URLs, e.g. `https://[wrong`.
|
|
11
|
+
// Preformed absolute URLs ignore `window.location.origin` when parsed.
|
|
12
|
+
const parsedURL = new URL(incomingURL, window.location.origin);
|
|
13
|
+
// If the given URL is already absolute, preserve its original format exactly, i.e. `new URL()` may have added a trailing slash
|
|
14
|
+
if (incomingURL.startsWith('http://') || incomingURL.startsWith('https://')) {
|
|
15
|
+
return incomingURL;
|
|
16
|
+
}
|
|
17
|
+
if (isHttpURL(parsedURL)) {
|
|
18
|
+
return parsedURL.href;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
} catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
15
25
|
//# sourceMappingURL=formatAbsoluteURL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatAbsoluteURL.js","names":["
|
|
1
|
+
{"version":3,"file":"formatAbsoluteURL.js","names":["isHttpURL","formatAbsoluteURL","incomingURL","parsedURL","URL","window","location","origin","startsWith","href","undefined"],"sources":["../../src/utilities/formatAbsoluteURL.ts"],"sourcesContent":["import { isHttpURL } from './isHttpURL.js'\n\n/**\n * Ensures the provided URL is absolute. If not, it converts it to an absolute URL based\n * on the current window location.\n * Note: This MUST be called within the client environment as it relies on the `window` object\n * to determine the absolute URL.\n */\nexport const formatAbsoluteURL = (incomingURL: string): string | undefined => {\n try {\n // This throws for malformed URLs, e.g. `https://[wrong`.\n // Preformed absolute URLs ignore `window.location.origin` when parsed.\n const parsedURL = new URL(incomingURL, window.location.origin)\n\n // If the given URL is already absolute, preserve its original format exactly, i.e. `new URL()` may have added a trailing slash\n if (incomingURL.startsWith('http://') || incomingURL.startsWith('https://')) {\n return incomingURL\n }\n\n if (isHttpURL(parsedURL)) {\n return parsedURL.href\n }\n\n return undefined\n } catch {\n return undefined\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ;AAE1B;;;;;;AAMA,OAAO,MAAMC,iBAAA,GAAqBC,WAAA;EAChC,IAAI;IACF;IACA;IACA,MAAMC,SAAA,GAAY,IAAIC,GAAA,CAAIF,WAAA,EAAaG,MAAA,CAAOC,QAAQ,CAACC,MAAM;IAE7D;IACA,IAAIL,WAAA,CAAYM,UAAU,CAAC,cAAcN,WAAA,CAAYM,UAAU,CAAC,aAAa;MAC3E,OAAON,WAAA;IACT;IAEA,IAAIF,SAAA,CAAUG,SAAA,GAAY;MACxB,OAAOA,SAAA,CAAUM,IAAI;IACvB;IAEA,OAAOC,SAAA;EACT,EAAE,MAAM;IACN,OAAOA,SAAA;EACT;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { formatAbsoluteURL } from './formatAbsoluteURL.js';
|
|
3
|
+
describe('formatAbsoluteURL', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
vi.stubGlobal('window', {
|
|
6
|
+
location: {
|
|
7
|
+
origin: 'https://admin.example.com'
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.unstubAllGlobals();
|
|
13
|
+
});
|
|
14
|
+
it.each([['/preview', 'https://admin.example.com/preview'], ['preview?draft=true', 'https://admin.example.com/preview?draft=true'], ['../preview', 'https://admin.example.com/preview'], ['?draft=true', 'https://admin.example.com/?draft=true'], ['#preview', 'https://admin.example.com/#preview'], ['//preview.example.com/page', 'https://preview.example.com/page'], ['', 'https://admin.example.com/']])('should resolve relative URL %s against the admin origin', (input, expected) => {
|
|
15
|
+
expect(formatAbsoluteURL(input)).toBe(expected);
|
|
16
|
+
});
|
|
17
|
+
it.each(['http://preview.example.com', 'https://preview.example.com', 'https://preview.example.com:443/one/../two?draft=true#preview'])('should preserve absolute HTTP(S) URL %s', input => {
|
|
18
|
+
expect(formatAbsoluteURL(input)).toBe(input);
|
|
19
|
+
});
|
|
20
|
+
it.each(['mailto:editor@example.com', 'file:///preview.html'])('should return undefined for unsupported URL %s', input => {
|
|
21
|
+
expect(formatAbsoluteURL(input)).toBeUndefined();
|
|
22
|
+
});
|
|
23
|
+
it.each(['http://', 'https://', 'https://[invalid'])('should return undefined for invalid URL %s', input => {
|
|
24
|
+
expect(formatAbsoluteURL(input)).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=formatAbsoluteURL.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatAbsoluteURL.spec.js","names":["afterEach","beforeEach","describe","expect","it","vi","formatAbsoluteURL","stubGlobal","location","origin","unstubAllGlobals","each","input","expected","toBe","toBeUndefined"],"sources":["../../src/utilities/formatAbsoluteURL.spec.ts"],"sourcesContent":["import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'\n\nimport { formatAbsoluteURL } from './formatAbsoluteURL.js'\n\ndescribe('formatAbsoluteURL', () => {\n beforeEach(() => {\n vi.stubGlobal('window', {\n location: { origin: 'https://admin.example.com' },\n })\n })\n\n afterEach(() => {\n vi.unstubAllGlobals()\n })\n\n it.each([\n ['/preview', 'https://admin.example.com/preview'],\n ['preview?draft=true', 'https://admin.example.com/preview?draft=true'],\n ['../preview', 'https://admin.example.com/preview'],\n ['?draft=true', 'https://admin.example.com/?draft=true'],\n ['#preview', 'https://admin.example.com/#preview'],\n ['//preview.example.com/page', 'https://preview.example.com/page'],\n ['', 'https://admin.example.com/'],\n ])('should resolve relative URL %s against the admin origin', (input, expected) => {\n expect(formatAbsoluteURL(input)).toBe(expected)\n })\n\n it.each([\n 'http://preview.example.com',\n 'https://preview.example.com',\n 'https://preview.example.com:443/one/../two?draft=true#preview',\n ])('should preserve absolute HTTP(S) URL %s', (input) => {\n expect(formatAbsoluteURL(input)).toBe(input)\n })\n\n it.each(['mailto:editor@example.com', 'file:///preview.html'])(\n 'should return undefined for unsupported URL %s',\n (input) => {\n expect(formatAbsoluteURL(input)).toBeUndefined()\n },\n )\n\n it.each(['http://', 'https://', 'https://[invalid'])(\n 'should return undefined for invalid URL %s',\n (input) => {\n expect(formatAbsoluteURL(input)).toBeUndefined()\n },\n )\n})\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ;AAEhE,SAASC,iBAAiB,QAAQ;AAElCJ,QAAA,CAAS,qBAAqB;EAC5BD,UAAA,CAAW;IACTI,EAAA,CAAGE,UAAU,CAAC,UAAU;MACtBC,QAAA,EAAU;QAAEC,MAAA,EAAQ;MAA4B;IAClD;EACF;EAEAT,SAAA,CAAU;IACRK,EAAA,CAAGK,gBAAgB;EACrB;EAEAN,EAAA,CAAGO,IAAI,CAAC,CACN,CAAC,YAAY,oCAAoC,EACjD,CAAC,sBAAsB,+CAA+C,EACtE,CAAC,cAAc,oCAAoC,EACnD,CAAC,eAAe,wCAAwC,EACxD,CAAC,YAAY,qCAAqC,EAClD,CAAC,8BAA8B,mCAAmC,EAClE,CAAC,IAAI,6BAA6B,CACnC,EAAE,2DAA2D,CAACC,KAAA,EAAOC,QAAA;IACpEV,MAAA,CAAOG,iBAAA,CAAkBM,KAAA,GAAQE,IAAI,CAACD,QAAA;EACxC;EAEAT,EAAA,CAAGO,IAAI,CAAC,CACN,8BACA,+BACA,gEACD,EAAE,2CAA4CC,KAAA;IAC7CT,MAAA,CAAOG,iBAAA,CAAkBM,KAAA,GAAQE,IAAI,CAACF,KAAA;EACxC;EAEAR,EAAA,CAAGO,IAAI,CAAC,CAAC,6BAA6B,uBAAuB,EAC3D,kDACCC,KAAA;IACCT,MAAA,CAAOG,iBAAA,CAAkBM,KAAA,GAAQG,aAAa;EAChD;EAGFX,EAAA,CAAGO,IAAI,CAAC,CAAC,WAAW,YAAY,mBAAmB,EACjD,8CACCC,KAAA;IACCT,MAAA,CAAOG,iBAAA,CAAkBM,KAAA,GAAQG,aAAa;EAChD;AAEJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAbsoluteURL.d.ts","sourceRoot":"","sources":["../../src/utilities/isAbsoluteURL.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,eAAO,MAAM,aAAa,iBAAkB,MAAM,GAAG,GAAG,KAAG,OAe1D,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Checks whether a URL is absolute or relative. */export const isAbsoluteURL = incomingURL => {
|
|
2
|
+
if (!incomingURL) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
if (incomingURL instanceof URL) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
new URL(incomingURL);
|
|
10
|
+
return true;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=isAbsoluteURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAbsoluteURL.js","names":["isAbsoluteURL","incomingURL","URL"],"sources":["../../src/utilities/isAbsoluteURL.ts"],"sourcesContent":["/** Checks whether a URL is absolute or relative. */\nexport const isAbsoluteURL = (incomingURL?: string | URL): boolean => {\n if (!incomingURL) {\n return false\n }\n\n if (incomingURL instanceof URL) {\n return true\n }\n\n try {\n new URL(incomingURL)\n return true\n } catch {\n return false\n }\n}\n"],"mappings":"AAAA,oDACA,OAAO,MAAMA,aAAA,GAAiBC,WAAA;EAC5B,IAAI,CAACA,WAAA,EAAa;IAChB,OAAO;EACT;EAEA,IAAIA,WAAA,YAAuBC,GAAA,EAAK;IAC9B,OAAO;EACT;EAEA,IAAI;IACF,IAAIA,GAAA,CAAID,WAAA;IACR,OAAO;EACT,EAAE,MAAM;IACN,OAAO;EACT;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { isAbsoluteURL } from './isAbsoluteURL.js';
|
|
3
|
+
describe('isAbsoluteURL', () => {
|
|
4
|
+
it.each(['http://example.com', 'https://example.com/preview', 'mailto:editor@example.com', 'file:///preview.html', new URL('https://example.com/preview')])('should accept absolute URL %s', input => {
|
|
5
|
+
expect(isAbsoluteURL(input)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
it.each([undefined, '', '/preview', '../preview', 'preview?draft=true', '?draft=true', '#preview', '//example.com/preview', 'https://', 'https://[invalid'])('should reject relative, absent, or invalid URL %s', input => {
|
|
8
|
+
expect(isAbsoluteURL(input)).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=isAbsoluteURL.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isAbsoluteURL.spec.js","names":["describe","expect","it","isAbsoluteURL","each","URL","input","toBe","undefined"],"sources":["../../src/utilities/isAbsoluteURL.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { isAbsoluteURL } from './isAbsoluteURL.js'\n\ndescribe('isAbsoluteURL', () => {\n it.each([\n 'http://example.com',\n 'https://example.com/preview',\n 'mailto:editor@example.com',\n 'file:///preview.html',\n new URL('https://example.com/preview'),\n ])('should accept absolute URL %s', (input) => {\n expect(isAbsoluteURL(input)).toBe(true)\n })\n\n it.each([\n undefined,\n '',\n '/preview',\n '../preview',\n 'preview?draft=true',\n '?draft=true',\n '#preview',\n '//example.com/preview',\n 'https://',\n 'https://[invalid',\n ])('should reject relative, absent, or invalid URL %s', (input) => {\n expect(isAbsoluteURL(input)).toBe(false)\n })\n})\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ;AAErC,SAASC,aAAa,QAAQ;AAE9BH,QAAA,CAAS,iBAAiB;EACxBE,EAAA,CAAGE,IAAI,CAAC,CACN,sBACA,+BACA,6BACA,wBACA,IAAIC,GAAA,CAAI,+BACT,EAAE,iCAAkCC,KAAA;IACnCL,MAAA,CAAOE,aAAA,CAAcG,KAAA,GAAQC,IAAI,CAAC;EACpC;EAEAL,EAAA,CAAGE,IAAI,CAAC,CACNI,SAAA,EACA,IACA,YACA,cACA,sBACA,eACA,YACA,yBACA,YACA,mBACD,EAAE,qDAAsDF,KAAA;IACvDL,MAAA,CAAOE,aAAA,CAAcG,KAAA,GAAQC,IAAI,CAAC;EACpC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isHttpURL.d.ts","sourceRoot":"","sources":["../../src/utilities/isHttpURL.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,eAAO,MAAM,SAAS,iBAAkB,MAAM,GAAG,GAAG,KAAG,OAatD,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Allows only HTTP(S) URLs, e.g. `http://` or `https://`. */export const isHttpURL = incomingURL => {
|
|
2
|
+
if (!incomingURL) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
try {
|
|
6
|
+
const url = typeof incomingURL === 'string' ? new URL(incomingURL, window.location.origin) : incomingURL;
|
|
7
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
8
|
+
} catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=isHttpURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isHttpURL.js","names":["isHttpURL","incomingURL","url","URL","window","location","origin","protocol"],"sources":["../../src/utilities/isHttpURL.ts"],"sourcesContent":["/** Allows only HTTP(S) URLs, e.g. `http://` or `https://`. */\nexport const isHttpURL = (incomingURL?: string | URL): boolean => {\n if (!incomingURL) {\n return false\n }\n\n try {\n const url =\n typeof incomingURL === 'string' ? new URL(incomingURL, window.location.origin) : incomingURL\n\n return url.protocol === 'http:' || url.protocol === 'https:'\n } catch {\n return false\n }\n}\n"],"mappings":"AAAA,8DACA,OAAO,MAAMA,SAAA,GAAaC,WAAA;EACxB,IAAI,CAACA,WAAA,EAAa;IAChB,OAAO;EACT;EAEA,IAAI;IACF,MAAMC,GAAA,GACJ,OAAOD,WAAA,KAAgB,WAAW,IAAIE,GAAA,CAAIF,WAAA,EAAaG,MAAA,CAAOC,QAAQ,CAACC,MAAM,IAAIL,WAAA;IAEnF,OAAOC,GAAA,CAAIK,QAAQ,KAAK,WAAWL,GAAA,CAAIK,QAAQ,KAAK;EACtD,EAAE,MAAM;IACN,OAAO;EACT;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { isHttpURL } from './isHttpURL.js';
|
|
3
|
+
describe('isHttpURL', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
vi.stubGlobal('window', {
|
|
6
|
+
location: {
|
|
7
|
+
origin: 'https://admin.example.com'
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.unstubAllGlobals();
|
|
13
|
+
});
|
|
14
|
+
it.each([['https://preview.example.com', true], ['mailto:editor@example.com', false]])('should validate parsed URL %s without the client environment', (input, expected) => {
|
|
15
|
+
vi.stubGlobal('window', undefined);
|
|
16
|
+
expect(isHttpURL(new URL(input))).toBe(expected);
|
|
17
|
+
});
|
|
18
|
+
it.each(['http://preview.example.com', 'https://preview.example.com', '/preview', 'preview?draft=true', '../preview', '?draft=true', '#preview', '//preview.example.com/page'])('should accept HTTP(S) or relative URL %s', input => {
|
|
19
|
+
expect(isHttpURL(input)).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
it.each([undefined, '', 'mailto:editor@example.com', 'file:///preview.html', 'https://[invalid', 'http://'])('should reject absent, unsupported, or invalid URL %s', input => {
|
|
22
|
+
expect(isHttpURL(input)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=isHttpURL.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isHttpURL.spec.js","names":["afterEach","beforeEach","describe","expect","it","vi","isHttpURL","stubGlobal","location","origin","unstubAllGlobals","each","input","expected","undefined","URL","toBe"],"sources":["../../src/utilities/isHttpURL.spec.ts"],"sourcesContent":["import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'\n\nimport { isHttpURL } from './isHttpURL.js'\n\ndescribe('isHttpURL', () => {\n beforeEach(() => {\n vi.stubGlobal('window', {\n location: { origin: 'https://admin.example.com' },\n })\n })\n\n afterEach(() => {\n vi.unstubAllGlobals()\n })\n\n it.each([\n ['https://preview.example.com', true],\n ['mailto:editor@example.com', false],\n ] as const)('should validate parsed URL %s without the client environment', (input, expected) => {\n vi.stubGlobal('window', undefined)\n\n expect(isHttpURL(new URL(input))).toBe(expected)\n })\n\n it.each([\n 'http://preview.example.com',\n 'https://preview.example.com',\n '/preview',\n 'preview?draft=true',\n '../preview',\n '?draft=true',\n '#preview',\n '//preview.example.com/page',\n ])('should accept HTTP(S) or relative URL %s', (input) => {\n expect(isHttpURL(input)).toBe(true)\n })\n\n it.each([\n undefined,\n '',\n 'mailto:editor@example.com',\n 'file:///preview.html',\n 'https://[invalid',\n 'http://',\n ])('should reject absent, unsupported, or invalid URL %s', (input) => {\n expect(isHttpURL(input)).toBe(false)\n })\n})\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ;AAEhE,SAASC,SAAS,QAAQ;AAE1BJ,QAAA,CAAS,aAAa;EACpBD,UAAA,CAAW;IACTI,EAAA,CAAGE,UAAU,CAAC,UAAU;MACtBC,QAAA,EAAU;QAAEC,MAAA,EAAQ;MAA4B;IAClD;EACF;EAEAT,SAAA,CAAU;IACRK,EAAA,CAAGK,gBAAgB;EACrB;EAEAN,EAAA,CAAGO,IAAI,CAAC,CACN,CAAC,+BAA+B,KAAK,EACrC,CAAC,6BAA6B,MAAM,CACrC,EAAW,gEAAgE,CAACC,KAAA,EAAOC,QAAA;IAClFR,EAAA,CAAGE,UAAU,CAAC,UAAUO,SAAA;IAExBX,MAAA,CAAOG,SAAA,CAAU,IAAIS,GAAA,CAAIH,KAAA,IAASI,IAAI,CAACH,QAAA;EACzC;EAEAT,EAAA,CAAGO,IAAI,CAAC,CACN,8BACA,+BACA,YACA,sBACA,cACA,eACA,YACA,6BACD,EAAE,4CAA6CC,KAAA;IAC9CT,MAAA,CAAOG,SAAA,CAAUM,KAAA,GAAQI,IAAI,CAAC;EAChC;EAEAZ,EAAA,CAAGO,IAAI,CAAC,CACNG,SAAA,EACA,IACA,6BACA,wBACA,oBACA,UACD,EAAE,wDAAyDF,KAAA;IAC1DT,MAAA,CAAOG,SAAA,CAAUM,KAAA,GAAQI,IAAI,CAAC;EAChC;AACF","ignoreList":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SchedulePublishTaskInput, ServerFunction } from 'payload';
|
|
2
|
+
import type { UpcomingEvent } from '../elements/PublishButton/ScheduleDrawer/types.js';
|
|
2
3
|
export type SchedulePublishHandlerArgs = {
|
|
3
4
|
date?: Date;
|
|
4
5
|
/**
|
|
@@ -8,5 +9,11 @@ export type SchedulePublishHandlerArgs = {
|
|
|
8
9
|
localeToPublish?: string;
|
|
9
10
|
timezone?: string;
|
|
10
11
|
} & Pick<SchedulePublishTaskInput, 'doc' | 'global' | 'type'>;
|
|
12
|
+
export type GetUpcomingScheduledPublishHandlerArgs = {
|
|
13
|
+
collectionSlug?: string;
|
|
14
|
+
globalSlug?: string;
|
|
15
|
+
id?: number | string;
|
|
16
|
+
};
|
|
17
|
+
export declare const getUpcomingScheduledPublishHandler: ServerFunction<GetUpcomingScheduledPublishHandlerArgs, Promise<UpcomingEvent[]>>;
|
|
11
18
|
export declare const schedulePublishHandler: ServerFunction<SchedulePublishHandlerArgs>;
|
|
12
19
|
//# sourceMappingURL=schedulePublishHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedulePublishHandler.d.ts","sourceRoot":"","sources":["../../src/utilities/schedulePublishHandler.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"schedulePublishHandler.d.ts","sourceRoot":"","sources":["../../src/utilities/schedulePublishHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAKvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mDAAmD,CAAA;AAItF,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,CAAC,EAAE,IAAI,CAAA;IACX;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,GAAG,IAAI,CAAC,wBAAwB,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAA;AAE7D,MAAM,MAAM,sCAAsC,GAAG;IACnD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,kCAAkC,EAAE,cAAc,CAC7D,sCAAsC,EACtC,OAAO,CAAC,aAAa,EAAE,CAAC,CA0DzB,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,cAAc,CAAC,0BAA0B,CAyD7E,CAAA"}
|