@payloadcms/ui 3.59.0-internal.fae0e05 → 3.59.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.
Files changed (65) hide show
  1. package/dist/elements/CodeEditor/CodeEditor.d.ts.map +1 -1
  2. package/dist/elements/CodeEditor/CodeEditor.js +2 -2
  3. package/dist/elements/CodeEditor/CodeEditor.js.map +1 -1
  4. package/dist/elements/DocumentDrawer/Provider.d.ts +1 -1
  5. package/dist/elements/DocumentDrawer/Provider.js.map +1 -1
  6. package/dist/elements/DocumentLocked/index.js +1 -1
  7. package/dist/elements/DocumentLocked/index.js.map +1 -1
  8. package/dist/elements/GroupByBuilder/index.js +1 -1
  9. package/dist/elements/GroupByBuilder/index.js.map +1 -1
  10. package/dist/elements/LivePreview/Toggler/index.d.ts.map +1 -1
  11. package/dist/elements/LivePreview/Toggler/index.js +5 -1
  12. package/dist/elements/LivePreview/Toggler/index.js.map +1 -1
  13. package/dist/elements/RelationshipTable/index.d.ts.map +1 -1
  14. package/dist/elements/RelationshipTable/index.js +3 -2
  15. package/dist/elements/RelationshipTable/index.js.map +1 -1
  16. package/dist/elements/Table/index.scss +1 -0
  17. package/dist/exports/client/{CodeEditor-B56LZ4XC.js → CodeEditor-UTOLPRAV.js} +2 -2
  18. package/dist/exports/client/{chunk-IOKOROQ2.js → chunk-S2X3JKSP.js} +4 -4
  19. package/dist/exports/client/chunk-S2X3JKSP.js.map +7 -0
  20. package/dist/exports/client/index.d.ts +3 -0
  21. package/dist/exports/client/index.d.ts.map +1 -1
  22. package/dist/exports/client/index.js +12 -12
  23. package/dist/exports/client/index.js.map +4 -4
  24. package/dist/fields/Slug/index.d.ts +8 -0
  25. package/dist/fields/Slug/index.d.ts.map +1 -0
  26. package/dist/fields/Slug/index.js +128 -0
  27. package/dist/fields/Slug/index.js.map +1 -0
  28. package/dist/fields/Slug/index.scss +17 -0
  29. package/dist/fields/Upload/RelationshipContent/index.js +1 -1
  30. package/dist/fields/Upload/RelationshipContent/index.js.map +1 -1
  31. package/dist/forms/Form/fieldReducer.d.ts.map +1 -1
  32. package/dist/forms/Form/fieldReducer.js +40 -16
  33. package/dist/forms/Form/fieldReducer.js.map +1 -1
  34. package/dist/forms/Form/types.d.ts +2 -2
  35. package/dist/forms/Form/types.js.map +1 -1
  36. package/dist/forms/RenderFields/context.d.ts +2 -2
  37. package/dist/forms/RenderFields/context.js +2 -2
  38. package/dist/forms/RenderFields/context.js.map +1 -1
  39. package/dist/providers/Config/index.d.ts +1 -1
  40. package/dist/providers/Config/index.js +1 -1
  41. package/dist/providers/Config/index.js.map +1 -1
  42. package/dist/providers/LivePreview/context.d.ts +2 -2
  43. package/dist/providers/LivePreview/context.d.ts.map +1 -1
  44. package/dist/providers/LivePreview/context.js.map +1 -1
  45. package/dist/providers/LivePreview/index.d.ts.map +1 -1
  46. package/dist/providers/LivePreview/index.js +10 -2
  47. package/dist/providers/LivePreview/index.js.map +1 -1
  48. package/dist/styles.css +1 -1
  49. package/dist/utilities/dateLocales.d.ts +1 -0
  50. package/dist/utilities/dateLocales.d.ts.map +1 -1
  51. package/dist/utilities/dateLocales.js +2 -0
  52. package/dist/utilities/dateLocales.js.map +1 -1
  53. package/dist/utilities/getColumns.js +1 -1
  54. package/dist/utilities/getColumns.js.map +1 -1
  55. package/dist/utilities/handleLivePreview.d.ts +4 -4
  56. package/dist/utilities/handleLivePreview.d.ts.map +1 -1
  57. package/dist/utilities/handleLivePreview.js +1 -1
  58. package/dist/utilities/handleLivePreview.js.map +1 -1
  59. package/dist/views/Edit/index.d.ts +1 -1
  60. package/dist/views/Edit/index.d.ts.map +1 -1
  61. package/dist/views/Edit/index.js +17 -9
  62. package/dist/views/Edit/index.js.map +1 -1
  63. package/package.json +5 -5
  64. package/dist/exports/client/chunk-IOKOROQ2.js.map +0 -7
  65. /package/dist/exports/client/{CodeEditor-B56LZ4XC.js.map → CodeEditor-UTOLPRAV.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","React","createContext","use","useCallback","useEffect","useMemo","useRef","useState","RootConfigContext","undefined","ConfigProvider","children","config","configFromProps","setConfig","isFirstRenderRef","current","collectionsBySlug","globalsBySlug","collection","collections","slug","global","globals","getEntityConfig","args","collectionSlug","globalSlug","value","_jsx","useConfig","PageConfigProvider","t0","$","rootConfig","setRootConfig","t1","t2","unauthenticated","t3"],"sources":["../../../src/providers/Config/index.tsx"],"sourcesContent":["/* eslint-disable perfectionist/sort-object-types */ // Need to disable this rule because the order of the overloads is important\n'use client'\nimport type {\n ClientCollectionConfig,\n ClientConfig,\n ClientGlobalConfig,\n CollectionSlug,\n GlobalSlug,\n} from 'payload'\n\nimport React, { createContext, use, useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\ntype GetEntityConfigFn = {\n // Overload #1: collectionSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug: {} | CollectionSlug; globalSlug?: never }): ClientCollectionConfig\n\n // Overload #2: globalSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug?: never; globalSlug: {} | GlobalSlug }): ClientGlobalConfig\n\n // Overload #3: both/none (fall back to union | null)\n (args: {\n collectionSlug?: {} | CollectionSlug\n globalSlug?: {} | GlobalSlug\n }): ClientCollectionConfig | ClientGlobalConfig | null\n}\n\nexport type ClientConfigContext = {\n config: ClientConfig\n /**\n * Get a collection or global config by its slug. This is preferred over\n * using `config.collections.find` or `config.globals.find`, because\n * getEntityConfig uses a lookup map for O(1) lookups.\n */\n getEntityConfig: GetEntityConfigFn\n setConfig: (config: ClientConfig) => void\n}\n\nconst RootConfigContext = createContext<ClientConfigContext | undefined>(undefined)\n\nexport const ConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const [config, setConfig] = useState<ClientConfig>(configFromProps)\n\n const isFirstRenderRef = useRef(true)\n\n // Need to update local config state if config from props changes, for HMR.\n // That way, config changes will be updated in the UI immediately without needing a refresh.\n useEffect(() => {\n if (isFirstRenderRef.current) {\n isFirstRenderRef.current = false\n return\n }\n\n setConfig(configFromProps)\n }, [configFromProps, setConfig])\n\n // Build lookup maps for collections and globals so we can do O(1) lookups by slug\n const { collectionsBySlug, globalsBySlug } = useMemo(() => {\n const collectionsBySlug: Record<string, ClientCollectionConfig> = {}\n const globalsBySlug: Record<string, ClientGlobalConfig> = {}\n\n for (const collection of config.collections) {\n collectionsBySlug[collection.slug] = collection\n }\n\n for (const global of config.globals) {\n globalsBySlug[global.slug] = global\n }\n\n return { collectionsBySlug, globalsBySlug }\n }, [config])\n\n const getEntityConfig = useCallback<GetEntityConfigFn>(\n (args) => {\n if ('collectionSlug' in args) {\n return collectionsBySlug[args.collectionSlug] ?? null\n }\n\n if ('globalSlug' in args) {\n return globalsBySlug[args.globalSlug] ?? null\n }\n\n return null as any\n },\n [collectionsBySlug, globalsBySlug],\n )\n\n const value = useMemo(\n () => ({ config, getEntityConfig, setConfig }),\n [config, getEntityConfig, setConfig],\n )\n\n return <RootConfigContext value={value}>{children}</RootConfigContext>\n}\n\nexport const useConfig = (): ClientConfigContext => use(RootConfigContext)\n\n/**\n * This provider shadows the `ConfigProvider` on the _page_ level, allowing us to\n * update the config when needed, e.g. after authentication.\n * The layout `ConfigProvider` is not updated on page navigation / authentication,\n * as the layout does not re-render in those cases.\n *\n * If the config here has the same reference as the config from the layout, we\n * simply reuse the context from the layout to avoid unnecessary re-renders.\n *\n * @experimental This component is experimental and may change or be removed in future releases. Use at your own discretion.\n */\nexport const PageConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const { config: rootConfig, setConfig: setRootConfig } = useConfig()\n\n /**\n * This `useEffect` is required in order for the _page_ to be able to refresh the client config,\n * which may have been cached on the _layout_ level, where the `ConfigProvider` is managed.\n * Since the layout does not re-render on page navigation / authentication, we need to manually\n * update the config, as the user may have been authenticated in the process, which affects the client config.\n */\n useEffect(() => {\n setRootConfig(configFromProps)\n }, [configFromProps, setRootConfig])\n\n // If this component receives a different config than what is in context from the layout, it is stale.\n // While stale, we instantiate a new context provider that provides the new config until the root context is updated.\n // Unfortunately, referential equality alone does not work bc the reference is lost during server/client serialization,\n // so we need to also compare the `unauthenticated` property.\n if (\n rootConfig !== configFromProps &&\n rootConfig.unauthenticated !== configFromProps.unauthenticated\n ) {\n return <ConfigProvider config={configFromProps}>{children}</ConfigProvider>\n }\n\n return children\n}\n"],"mappings":"AAAA,sDAAsD;AACtD;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AASA,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AA6B7F,MAAMC,iBAAA,gBAAoBP,aAAA,CAA+CQ,SAAA;AAEzE,OAAO,MAAMC,cAAA,GAGRA,CAAC;EAAEC,QAAQ;EAAEC,MAAA,EAAQC;AAAe,CAAE;EACzC,MAAM,CAACD,MAAA,EAAQE,SAAA,CAAU,GAAGP,QAAA,CAAuBM,eAAA;EAEnD,MAAME,gBAAA,GAAmBT,MAAA,CAAO;EAEhC;EACA;EACAF,SAAA,CAAU;IACR,IAAIW,gBAAA,CAAiBC,OAAO,EAAE;MAC5BD,gBAAA,CAAiBC,OAAO,GAAG;MAC3B;IACF;IAEAF,SAAA,CAAUD,eAAA;EACZ,GAAG,CAACA,eAAA,EAAiBC,SAAA,CAAU;EAE/B;EACA,MAAM;IAAEG,iBAAiB,EAAjBA,mBAAiB;IAAEC,aAAa,EAAbA;EAAa,CAAE,GAAGb,OAAA,CAAQ;IACnD,MAAMY,iBAAA,GAA4D,CAAC;IACnE,MAAMC,aAAA,GAAoD,CAAC;IAE3D,KAAK,MAAMC,UAAA,IAAcP,MAAA,CAAOQ,WAAW,EAAE;MAC3CH,iBAAiB,CAACE,UAAA,CAAWE,IAAI,CAAC,GAAGF,UAA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cF,CAAA,MAAApB,eAAA;IAAAoB,CAAA,MAAAE,aAAA;IAAAF,CAAA,MAAAG,EAAA;IAAAH,CAAA,MAAAI,EAAA;EAAA;IAAAD,EAAA,GAAAH,CAAA;IAAAI,EAAA,GAAAJ,CAAA;EAAA;EAFnC7B,SAAA,CAAUgC,EAEV,EAAGC,EAAgC;EAAA,IAOjCH,UAAA,KAAerB,eAAA,IACfqB,UAAA,CAAAI,eAAA,KAA+BzB,eAAA,CAAAyB,eAA+B;IAAA,IAAAC,EAAA;IAAA,IAAAN,CAAA,QAAAtB,QAAA,IAAAsB,CAAA,QAAApB,eAAA;MAEvD0B,EAAA,GAAAV,IAAA,CAAAnB,cAAA;QAAAE,MAAA,EAAwBC,eAAA;QAAAF;MAAA,C;;;;;;;WAAxB4B,E;;SAGF5B,QAAA;AAAA,CACT","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["c","_c","React","createContext","use","useCallback","useEffect","useMemo","useRef","useState","RootConfigContext","undefined","ConfigProvider","children","config","configFromProps","setConfig","isFirstRenderRef","current","collectionsBySlug","globalsBySlug","collection","collections","slug","global","globals","getEntityConfig","args","collectionSlug","globalSlug","value","_jsx","useConfig","PageConfigProvider","t0","$","rootConfig","setRootConfig","t1","t2","unauthenticated","t3"],"sources":["../../../src/providers/Config/index.tsx"],"sourcesContent":["/* eslint-disable perfectionist/sort-object-types */ // Need to disable this rule because the order of the overloads is important\n'use client'\nimport type {\n ClientCollectionConfig,\n ClientConfig,\n ClientGlobalConfig,\n CollectionSlug,\n GlobalSlug,\n} from 'payload'\n\nimport React, { createContext, use, useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\ntype GetEntityConfigFn = {\n // Overload #1: collectionSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug: {} | CollectionSlug; globalSlug?: never }): ClientCollectionConfig\n\n // Overload #2: globalSlug only\n // @todo remove \"{} |\" in 4.0, which would be a breaking change\n (args: { collectionSlug?: never; globalSlug: {} | GlobalSlug }): ClientGlobalConfig\n\n // Overload #3: both/none (fall back to union | null)\n (args: {\n collectionSlug?: {} | CollectionSlug\n globalSlug?: {} | GlobalSlug\n }): ClientCollectionConfig | ClientGlobalConfig | null\n}\n\nexport type ClientConfigContext = {\n config: ClientConfig\n /**\n * Get a collection or global config by its slug. This is preferred over\n * using `config.collections.find` or `config.globals.find`, because\n * getEntityConfig uses a lookup map for O(1) lookups.\n */\n getEntityConfig: GetEntityConfigFn\n setConfig: (config: ClientConfig) => void\n}\n\nconst RootConfigContext = createContext<ClientConfigContext | undefined>(undefined)\n\nexport const ConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const [config, setConfig] = useState<ClientConfig>(configFromProps)\n\n const isFirstRenderRef = useRef(true)\n\n // Need to update local config state if config from props changes, for HMR.\n // That way, config changes will be updated in the UI immediately without needing a refresh.\n useEffect(() => {\n if (isFirstRenderRef.current) {\n isFirstRenderRef.current = false\n return\n }\n\n setConfig(configFromProps)\n }, [configFromProps, setConfig])\n\n // Build lookup maps for collections and globals so we can do O(1) lookups by slug\n const { collectionsBySlug, globalsBySlug } = useMemo(() => {\n const collectionsBySlug: Record<string, ClientCollectionConfig> = {}\n const globalsBySlug: Record<string, ClientGlobalConfig> = {}\n\n for (const collection of config.collections) {\n collectionsBySlug[collection.slug] = collection\n }\n\n for (const global of config.globals) {\n globalsBySlug[global.slug] = global\n }\n\n return { collectionsBySlug, globalsBySlug }\n }, [config])\n\n const getEntityConfig = useCallback<GetEntityConfigFn>(\n (args) => {\n if ('collectionSlug' in args) {\n return collectionsBySlug[args.collectionSlug] ?? null\n }\n\n if ('globalSlug' in args) {\n return globalsBySlug[args.globalSlug] ?? null\n }\n\n return null as any\n },\n [collectionsBySlug, globalsBySlug],\n )\n\n const value = useMemo(\n () => ({ config, getEntityConfig, setConfig }),\n [config, getEntityConfig, setConfig],\n )\n\n return <RootConfigContext value={value}>{children}</RootConfigContext>\n}\n\nexport const useConfig = (): ClientConfigContext => use(RootConfigContext)\n\n/**\n * This provider shadows the `ConfigProvider` on the _page_ level, allowing us to\n * update the config when needed, e.g. after authentication.\n * The layout `ConfigProvider` is not updated on page navigation / authentication,\n * as the layout does not re-render in those cases.\n *\n * If the config here has the same reference as the config from the layout, we\n * simply reuse the context from the layout to avoid unnecessary re-renders.\n *\n * @experimental This component is experimental and may change or be removed in future releases. Use at your own risk.\n */\nexport const PageConfigProvider: React.FC<{\n readonly children: React.ReactNode\n readonly config: ClientConfig\n}> = ({ children, config: configFromProps }) => {\n const { config: rootConfig, setConfig: setRootConfig } = useConfig()\n\n /**\n * This `useEffect` is required in order for the _page_ to be able to refresh the client config,\n * which may have been cached on the _layout_ level, where the `ConfigProvider` is managed.\n * Since the layout does not re-render on page navigation / authentication, we need to manually\n * update the config, as the user may have been authenticated in the process, which affects the client config.\n */\n useEffect(() => {\n setRootConfig(configFromProps)\n }, [configFromProps, setRootConfig])\n\n // If this component receives a different config than what is in context from the layout, it is stale.\n // While stale, we instantiate a new context provider that provides the new config until the root context is updated.\n // Unfortunately, referential equality alone does not work bc the reference is lost during server/client serialization,\n // so we need to also compare the `unauthenticated` property.\n if (\n rootConfig !== configFromProps &&\n rootConfig.unauthenticated !== configFromProps.unauthenticated\n ) {\n return <ConfigProvider config={configFromProps}>{children}</ConfigProvider>\n }\n\n return children\n}\n"],"mappings":"AAAA,sDAAsD;AACtD;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AASA,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AA6B7F,MAAMC,iBAAA,gBAAoBP,aAAA,CAA+CQ,SAAA;AAEzE,OAAO,MAAMC,cAAA,GAGRA,CAAC;EAAEC,QAAQ;EAAEC,MAAA,EAAQC;AAAe,CAAE;EACzC,MAAM,CAACD,MAAA,EAAQE,SAAA,CAAU,GAAGP,QAA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,EAAOA,KAAA;cAAQjB;;AAC3C;AAEA,OAAO,MAAMmB,SAAA,GAAYA,CAAA,KAA2B5B,GAAA,CAAIM,iBAAA;AAExD;;;;;;;;;;;AAWA,OAAO,MAAMuB,kBAAA,GAGRC,EAAA;EAAA,MAAAC,CAAA,GAAAlC,EAAA;EAAC;IAAAY,QAAA;IAAAC,MAAA,EAAAC;EAAA,IAAAmB,EAAqC;EACzC;IAAApB,MAAA,EAAAsB,UAAA;IAAApB,SAAA,EAAAqB;EAAA,IAAyDL,SAAA;EAAA,IAAAM,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAJ,CAAA,QAAApB,eAAA,IAAAoB,CAAA,QAAAE,aAAA;IAQ/CC,EAAA,GAAAA,CAAA;MACRD,aAAA,CAActB,eAAA;IAAA;IACbwB,EAAA,IAACxB,eAAA,EAAiBsB,aAAA;IAAcF,CAAA,MAAApB,eAAA;IAAAoB,CAAA,MAAAE,aAAA;IAAAF,CAAA,MAAAG,EAAA;IAAAH,CAAA,MAAAI,EAAA;EAAA;IAAAD,EAAA,GAAAH,CAAA;IAAAI,EAAA,GAAAJ,CAAA;EAAA;EAFnC7B,SAAA,CAAUgC,EAEV,EAAGC,EAAgC;EAAA,IAOjCH,UAAA,KAAerB,eAAA,IACfqB,UAAA,CAAAI,eAAA,KAA+BzB,eAAA,CAAAyB,eAA+B;IAAA,IAAAC,EAAA;IAAA,IAAAN,CAAA,QAAAtB,QAAA,IAAAsB,CAAA,QAAApB,eAAA;MAEvD0B,EAAA,GAAAV,IAAA,CAAAnB,cAAA;QAAAE,MAAA,EAAwBC,eAAA;QAAAF;MAAA,C;;;;;;;WAAxB4B,E;;SAGF5B,QAAA;AAAA,CACT","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { LivePreviewConfig } from 'payload';
1
+ import type { LivePreviewConfig, LivePreviewURLType } from 'payload';
2
2
  import type { Dispatch } from 'react';
3
3
  import type React from 'react';
4
4
  import type { usePopupWindow } from '../../hooks/usePopupWindow.js';
@@ -60,7 +60,7 @@ export interface LivePreviewContextType {
60
60
  * It is important to know which one it is, so that we can opt in/out of certain behaviors, e.g. calling the server to get the URL.
61
61
  */
62
62
  typeofLivePreviewURL?: 'function' | 'string';
63
- url: string | undefined;
63
+ url: LivePreviewURLType;
64
64
  zoom: number;
65
65
  }
66
66
  export declare const LivePreviewContext: React.Context<LivePreviewContextType>;
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEzD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,OAAO,CAAA;IACnB,UAAU,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;IAC5D,WAAW,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;IAC7C,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAA;IACpD,oBAAoB,EAAE,OAAO,CAAA;IAC7B,gBAAgB,EAAE,OAAO,CAAA;IACzB,WAAW,EAAE,OAAO,CAAA;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kBAAkB,EAAE;QAClB,MAAM,EAAE,MAAM,CAAA;QACd,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,eAAe,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,iBAAiB,CAAC,CAAA;IACrE,QA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oB,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAA;IAC5C,GAAG,EAAE,kBAAkB,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,eAAO,MAAM,kBAAkB,uCAsC7B,CAAA;AAEF,eAAO,MAAM,qBAAqB,8BAAgC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":["createContext","use","LivePreviewContext","appIsReady","breakpoint","undefined","breakpoints","iframeRef","isLivePreviewEnabled","isLivePreviewing","isPopupOpen","measuredDeviceSize","height","width","openPopupWindow","popupRef","previewWindowType","setAppIsReady","setBreakpoint","setHeight","setIsLivePreviewing","setLoadedURL","setMeasuredDeviceSize","setPreviewWindowType","setSize","setToolbarPosition","setURL","setWidth","setZoom","size","toolbarPosition","x","y","typeofLivePreviewURL","url","zoom","useLivePreviewContext"],"sources":["../../../src/providers/LivePreview/context.ts"],"sourcesContent":["'use client'\nimport type { LivePreviewConfig } from 'payload'\nimport type { Dispatch } from 'react'\nimport type React from 'react'\n\nimport { createContext, use } from 'react'\n\nimport type { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport type { SizeReducerAction } from './sizeReducer.js'\n\nexport interface LivePreviewContextType {\n appIsReady: boolean\n breakpoint: LivePreviewConfig['breakpoints'][number]['name']\n breakpoints: LivePreviewConfig['breakpoints']\n iframeRef: React.RefObject<HTMLIFrameElement | null>\n isLivePreviewEnabled: boolean\n isLivePreviewing: boolean\n isPopupOpen: boolean\n listeningForMessages?: boolean\n /**\n * The URL that has finished loading in the iframe or popup.\n * For example, if you set the `url`, it will begin to load into the iframe,\n * but `loadedURL` will not be set until the iframe's `onLoad` event fires.\n */\n loadedURL?: string\n measuredDeviceSize: {\n height: number\n width: number\n }\n openPopupWindow: ReturnType<typeof usePopupWindow>['openPopupWindow']\n popupRef?: React.RefObject<null | Window>\n previewWindowType: 'iframe' | 'popup'\n setAppIsReady: (appIsReady: boolean) => void\n setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void\n setHeight: (height: number) => void\n setIsLivePreviewing: (isLivePreviewing: boolean) => void\n setLoadedURL: (loadedURL: string) => void\n setMeasuredDeviceSize: (size: { height: number; width: number }) => void\n setPreviewWindowType: (previewWindowType: 'iframe' | 'popup') => void\n setSize: Dispatch<SizeReducerAction>\n setToolbarPosition: (position: { x: number; y: number }) => void\n /**\n * Sets the URL of the preview (either iframe or popup).\n * Will trigger a reload of the window.\n */\n setURL: (url: string) => void\n setWidth: (width: number) => void\n setZoom: (zoom: number) => void\n size: {\n height: number\n width: number\n }\n toolbarPosition: {\n x: number\n y: number\n }\n /**\n * The live preview url property can be either a string or a function that returns a string.\n * It is important to know which one it is, so that we can opt in/out of certain behaviors, e.g. calling the server to get the URL.\n */\n typeofLivePreviewURL?: 'function' | 'string'\n url: string | undefined\n zoom: number\n}\n\nexport const LivePreviewContext = createContext<LivePreviewContextType>({\n appIsReady: false,\n breakpoint: undefined,\n breakpoints: undefined,\n iframeRef: undefined,\n isLivePreviewEnabled: undefined,\n isLivePreviewing: false,\n isPopupOpen: false,\n measuredDeviceSize: {\n height: 0,\n width: 0,\n },\n openPopupWindow: () => {},\n popupRef: undefined,\n previewWindowType: 'iframe',\n setAppIsReady: () => {},\n setBreakpoint: () => {},\n setHeight: () => {},\n setIsLivePreviewing: () => {},\n setLoadedURL: () => {},\n setMeasuredDeviceSize: () => {},\n setPreviewWindowType: () => {},\n setSize: () => {},\n setToolbarPosition: () => {},\n setURL: () => {},\n setWidth: () => {},\n setZoom: () => {},\n size: {\n height: 0,\n width: 0,\n },\n toolbarPosition: {\n x: 0,\n y: 0,\n },\n typeofLivePreviewURL: undefined,\n url: undefined,\n zoom: 1,\n})\n\nexport const useLivePreviewContext = () => use(LivePreviewContext)\n"],"mappings":"AAAA;;AAKA,SAASA,aAAa,EAAEC,GAAG,QAAQ;AA4DnC,OAAO,MAAMC,kBAAA,GAAqBF,aAAA,CAAsC;EACtEG,UAAA,EAAY;EACZC,UAAA,EAAYC,SAAA;EACZC,WAAA,EAAaD,SAAA;EACbE,SAAA,EAAWF,SAAA;EACXG,oBAAA,EAAsBH,SAAA;EACtBI,gBAAA,EAAkB;EAClBC,WAAA,EAAa;EACbC,kBAAA,EAAoB;IAClBC,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAC,eAAA,EAAiBA,CAAA,MAAO;EACxBC,QAAA,EAAUV,SAAA;EACVW,iBAAA,EAAmB;EACnBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,SAAA,EAAWA,CAAA,MAAO;EAClBC,mBAAA,EAAqBA,CAAA,MAAO;EAC5BC,YAAA,EAAcA,CAAA,MAAO;EACrBC,qBAAA,EAAuBA,CAAA,MAAO;EAC9BC,oBAAA,EAAsBA,CAAA,MAAO;EAC7BC,OAAA,EAASA,CAAA,MAAO;EAChBC,kBAAA,EAAoBA,CAAA,MAAO;EAC3BC,MAAA,EAAQA,CAAA,MAAO;EACfC,QAAA,EAAUA,CAAA,MAAO;EACjBC,OAAA,EAASA,CAAA,MAAO;EAChBC,IAAA,EAAM;IACJjB,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAiB,eAAA,EAAiB;IACfC,CAAA,EAAG;IACHC,CAAA,EAAG;EACL;EACAC,oBAAA,EAAsB5B,SAAA;EACtB6B,GAAA,EAAK7B,SAAA;EACL8B,IAAA,EAAM;AACR;AAEA,OAAO,MAAMC,qBAAA,GAAwBA,CAAA,KAAMnC,GAAA,CAAIC,kBAAA","ignoreList":[]}
1
+ {"version":3,"file":"context.js","names":["createContext","use","LivePreviewContext","appIsReady","breakpoint","undefined","breakpoints","iframeRef","isLivePreviewEnabled","isLivePreviewing","isPopupOpen","measuredDeviceSize","height","width","openPopupWindow","popupRef","previewWindowType","setAppIsReady","setBreakpoint","setHeight","setIsLivePreviewing","setLoadedURL","setMeasuredDeviceSize","setPreviewWindowType","setSize","setToolbarPosition","setURL","setWidth","setZoom","size","toolbarPosition","x","y","typeofLivePreviewURL","url","zoom","useLivePreviewContext"],"sources":["../../../src/providers/LivePreview/context.ts"],"sourcesContent":["'use client'\nimport type { LivePreviewConfig, LivePreviewURLType } from 'payload'\nimport type { Dispatch } from 'react'\nimport type React from 'react'\n\nimport { createContext, use } from 'react'\n\nimport type { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport type { SizeReducerAction } from './sizeReducer.js'\n\nexport interface LivePreviewContextType {\n appIsReady: boolean\n breakpoint: LivePreviewConfig['breakpoints'][number]['name']\n breakpoints: LivePreviewConfig['breakpoints']\n iframeRef: React.RefObject<HTMLIFrameElement | null>\n isLivePreviewEnabled: boolean\n isLivePreviewing: boolean\n isPopupOpen: boolean\n listeningForMessages?: boolean\n /**\n * The URL that has finished loading in the iframe or popup.\n * For example, if you set the `url`, it will begin to load into the iframe,\n * but `loadedURL` will not be set until the iframe's `onLoad` event fires.\n */\n loadedURL?: string\n measuredDeviceSize: {\n height: number\n width: number\n }\n openPopupWindow: ReturnType<typeof usePopupWindow>['openPopupWindow']\n popupRef?: React.RefObject<null | Window>\n previewWindowType: 'iframe' | 'popup'\n setAppIsReady: (appIsReady: boolean) => void\n setBreakpoint: (breakpoint: LivePreviewConfig['breakpoints'][number]['name']) => void\n setHeight: (height: number) => void\n setIsLivePreviewing: (isLivePreviewing: boolean) => void\n setLoadedURL: (loadedURL: string) => void\n setMeasuredDeviceSize: (size: { height: number; width: number }) => void\n setPreviewWindowType: (previewWindowType: 'iframe' | 'popup') => void\n setSize: Dispatch<SizeReducerAction>\n setToolbarPosition: (position: { x: number; y: number }) => void\n /**\n * Sets the URL of the preview (either iframe or popup).\n * Will trigger a reload of the window.\n */\n setURL: (url: string) => void\n setWidth: (width: number) => void\n setZoom: (zoom: number) => void\n size: {\n height: number\n width: number\n }\n toolbarPosition: {\n x: number\n y: number\n }\n /**\n * The live preview url property can be either a string or a function that returns a string.\n * It is important to know which one it is, so that we can opt in/out of certain behaviors, e.g. calling the server to get the URL.\n */\n typeofLivePreviewURL?: 'function' | 'string'\n url: LivePreviewURLType\n zoom: number\n}\n\nexport const LivePreviewContext = createContext<LivePreviewContextType>({\n appIsReady: false,\n breakpoint: undefined,\n breakpoints: undefined,\n iframeRef: undefined,\n isLivePreviewEnabled: undefined,\n isLivePreviewing: false,\n isPopupOpen: false,\n measuredDeviceSize: {\n height: 0,\n width: 0,\n },\n openPopupWindow: () => {},\n popupRef: undefined,\n previewWindowType: 'iframe',\n setAppIsReady: () => {},\n setBreakpoint: () => {},\n setHeight: () => {},\n setIsLivePreviewing: () => {},\n setLoadedURL: () => {},\n setMeasuredDeviceSize: () => {},\n setPreviewWindowType: () => {},\n setSize: () => {},\n setToolbarPosition: () => {},\n setURL: () => {},\n setWidth: () => {},\n setZoom: () => {},\n size: {\n height: 0,\n width: 0,\n },\n toolbarPosition: {\n x: 0,\n y: 0,\n },\n typeofLivePreviewURL: undefined,\n url: undefined,\n zoom: 1,\n})\n\nexport const useLivePreviewContext = () => use(LivePreviewContext)\n"],"mappings":"AAAA;;AAKA,SAASA,aAAa,EAAEC,GAAG,QAAQ;AA4DnC,OAAO,MAAMC,kBAAA,GAAqBF,aAAA,CAAsC;EACtEG,UAAA,EAAY;EACZC,UAAA,EAAYC,SAAA;EACZC,WAAA,EAAaD,SAAA;EACbE,SAAA,EAAWF,SAAA;EACXG,oBAAA,EAAsBH,SAAA;EACtBI,gBAAA,EAAkB;EAClBC,WAAA,EAAa;EACbC,kBAAA,EAAoB;IAClBC,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAC,eAAA,EAAiBA,CAAA,MAAO;EACxBC,QAAA,EAAUV,SAAA;EACVW,iBAAA,EAAmB;EACnBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,aAAA,EAAeA,CAAA,MAAO;EACtBC,SAAA,EAAWA,CAAA,MAAO;EAClBC,mBAAA,EAAqBA,CAAA,MAAO;EAC5BC,YAAA,EAAcA,CAAA,MAAO;EACrBC,qBAAA,EAAuBA,CAAA,MAAO;EAC9BC,oBAAA,EAAsBA,CAAA,MAAO;EAC7BC,OAAA,EAASA,CAAA,MAAO;EAChBC,kBAAA,EAAoBA,CAAA,MAAO;EAC3BC,MAAA,EAAQA,CAAA,MAAO;EACfC,QAAA,EAAUA,CAAA,MAAO;EACjBC,OAAA,EAASA,CAAA,MAAO;EAChBC,IAAA,EAAM;IACJjB,MAAA,EAAQ;IACRC,KAAA,EAAO;EACT;EACAiB,eAAA,EAAiB;IACfC,CAAA,EAAG;IACHC,CAAA,EAAG;EACL;EACAC,oBAAA,EAAsB5B,SAAA;EACtB6B,GAAA,EAAK7B,SAAA;EACL8B,IAAA,EAAM;AACR;AAEA,OAAO,MAAMC,qBAAA,GAAwBA,CAAA,KAAMnC,GAAA,CAAIC,kBAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/LivePreview/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGvE,OAAO,KAA4D,MAAM,OAAO,CAAA;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAU1D,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;CAC1B,GAAG,IAAI,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,KAAK,CAAC,CAAA;AAEhE,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAiPlE,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,KAA4D,MAAM,OAAO,CAAA;AAEhF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAU1D,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;CAC1B,GAAG,IAAI,CAAC,sBAAsB,EAAE,sBAAsB,GAAG,KAAK,CAAC,CAAA;AAEhE,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CA2PlE,CAAA"}
@@ -68,7 +68,13 @@ export const LivePreviewProvider = ({
68
68
  * - resets `appIsReady` to `false` while the new URL is loading
69
69
  */
70
70
  const setLivePreviewURL = useCallback(_incomingURL => {
71
- const incomingURL = formatAbsoluteURL(_incomingURL);
71
+ let incomingURL;
72
+ if (typeof _incomingURL === 'string') {
73
+ incomingURL = formatAbsoluteURL(_incomingURL);
74
+ }
75
+ if (!incomingURL) {
76
+ setIsLivePreviewing(false);
77
+ }
72
78
  if (incomingURL !== url) {
73
79
  setAppIsReady(false);
74
80
  setURL(incomingURL);
@@ -78,7 +84,9 @@ export const LivePreviewProvider = ({
78
84
  * `url` needs to be relative to the window, which cannot be done on initial render.
79
85
  */
80
86
  useEffect(() => {
81
- setURL(formatAbsoluteURL(urlFromProps));
87
+ if (typeof urlFromProps === 'string') {
88
+ setURL(formatAbsoluteURL(urlFromProps));
89
+ }
82
90
  }, [urlFromProps]);
83
91
  // The toolbar needs to freely drag and drop around the page
84
92
  const handleDragEnd = ev => {
@@ -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","typeofLivePreviewURL","url","urlFromProps","previewWindowType","setPreviewWindowType","setIsLivePreviewing","name","height","label","width","setURL","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 } 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} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\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\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 const incomingURL = formatAbsoluteURL(_incomingURL)\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 setURL(formatAbsoluteURL(urlFromProps))\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 listeningForMessages,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\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,MA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oC,kBAAA,EAAoBxC,WAAA;MACpBnB,MAAA,EAAQ6B,iBAAA;MACRS,QAAA;MACArB,OAAA;MACAK,IAAA;MACAsC,eAAA,EAAiB1C,QAAA;MACjB5B,oBAAA;MACAC,GAAA;MACAyB;IACF;cAEA,aAAA0C,IAAA,CAACzF,UAAA;MAAW4F,kBAAA,EAAoBjF,wBAAA;MAA0BkF,SAAA,EAAW9B,aAAA;gBAClE9C;;;AAIT","ignoreList":[]}
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","typeofLivePreviewURL","url","urlFromProps","previewWindowType","setPreviewWindowType","setIsLivePreviewing","name","height","label","width","setURL","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} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\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\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 listeningForMessages,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewWindowType,\n setAppIsReady,\n setBreakpoint,\n setHeight,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\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;AAc5B,OAAO,MAAMC,mBAAA,GAA0DA,CAAC;EACtEC,WAAA,EAAaC,mBAAmB;EAChCC,QAAQ;EACRC,oBAAoB;EACpBC,gBAAA,EAAkBC,wBAAwB;EAC1CC,oBAAoB;EACpBC,GAAA,EAAKC;AAAY,CAClB;EACC,MAAM,CAACC,iBAAA,EAAmBC,oBAAA,CAAqB,GAAGnB,QAAA,CAA6B;EAC/E,MAAM,CAACa,gBAAA,EAAkBO,mBAAA,CAAoB,GAAGpB,QAAA,CAASc,wBAAA;EAEzD,MAAML,WAAA,GAAgDX,OAAA,CACpD,MAAM,C,IACAY,mBAAA,IAAuB,EAAE,GAC7B;IACEW,IAAA,EAAM;IACNC,MAAA,EAAQ;IACRC,KAAA,EAAO;IACPC,KAAA,EAAO;EACT,EACD,EACD,CAACd,mBAAA,CAAoB;EAGvB,MAAM,CAACM,GAAA,EAAKS,MAAA,CAAO,GAAGzB,QAAA,CAAiB;EAEvC,MAAM;IAAE0B,WAAW;IAAEC,eAAe;IAAEC;EAAQ,CAAE,GAAG3B,cAAA,CAAe;IAChE4B,SAAA,EAAW;IACXb;EACF;EAEA,M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