@payloadcms/ui 4.0.0-canary.32 → 4.0.0-canary.34

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 (160) hide show
  1. package/dist/elements/APIKeyInput/index.d.ts +2 -0
  2. package/dist/elements/APIKeyInput/index.d.ts.map +1 -1
  3. package/dist/elements/APIKeyInput/index.js +27 -29
  4. package/dist/elements/APIKeyInput/index.js.map +1 -1
  5. package/dist/elements/BulkUpload/FormsManager/createFormData.d.ts +1 -1
  6. package/dist/elements/BulkUpload/FormsManager/createFormData.d.ts.map +1 -1
  7. package/dist/elements/BulkUpload/FormsManager/createFormData.js +7 -3
  8. package/dist/elements/BulkUpload/FormsManager/createFormData.js.map +1 -1
  9. package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
  10. package/dist/elements/BulkUpload/FormsManager/index.js +4 -2
  11. package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
  12. package/dist/elements/DocumentHeader/Tabs/Tab/index.d.ts +1 -0
  13. package/dist/elements/DocumentHeader/Tabs/Tab/index.d.ts.map +1 -1
  14. package/dist/elements/DocumentHeader/Tabs/Tab/index.js +3 -2
  15. package/dist/elements/DocumentHeader/Tabs/Tab/index.js.map +1 -1
  16. package/dist/elements/DocumentHeader/Tabs/index.d.ts +1 -0
  17. package/dist/elements/DocumentHeader/Tabs/index.d.ts.map +1 -1
  18. package/dist/elements/DocumentHeader/Tabs/index.js +5 -3
  19. package/dist/elements/DocumentHeader/Tabs/index.js.map +1 -1
  20. package/dist/elements/DocumentHeader/index.d.ts +1 -0
  21. package/dist/elements/DocumentHeader/index.d.ts.map +1 -1
  22. package/dist/elements/DocumentHeader/index.js +4 -2
  23. package/dist/elements/DocumentHeader/index.js.map +1 -1
  24. package/dist/elements/Nav/SidebarTabs/renderTabServerFn.js +3 -2
  25. package/dist/elements/Nav/SidebarTabs/renderTabServerFn.js.map +1 -1
  26. package/dist/elements/QueryPresets/QueryPresetBar/index.d.ts.map +1 -1
  27. package/dist/elements/QueryPresets/QueryPresetBar/index.js +14 -1
  28. package/dist/elements/QueryPresets/QueryPresetBar/index.js.map +1 -1
  29. package/dist/forms/Form/context.d.ts +3 -1
  30. package/dist/forms/Form/context.d.ts.map +1 -1
  31. package/dist/forms/Form/context.js +3 -1
  32. package/dist/forms/Form/context.js.map +1 -1
  33. package/dist/forms/Form/index.d.ts.map +1 -1
  34. package/dist/forms/Form/index.js +13 -4
  35. package/dist/forms/Form/index.js.map +1 -1
  36. package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
  37. package/dist/forms/fieldSchemasToFormState/renderField.js +3 -2
  38. package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
  39. package/dist/forms/fieldSchemasToFormState/serverFunctions/mergeAllowedFieldOverrides.d.ts +12 -0
  40. package/dist/forms/fieldSchemasToFormState/serverFunctions/mergeAllowedFieldOverrides.d.ts.map +1 -0
  41. package/dist/forms/fieldSchemasToFormState/serverFunctions/mergeAllowedFieldOverrides.js +42 -0
  42. package/dist/forms/fieldSchemasToFormState/serverFunctions/mergeAllowedFieldOverrides.js.map +1 -0
  43. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.d.ts +8 -6
  44. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.d.ts.map +1 -1
  45. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js +22 -9
  46. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.js.map +1 -1
  47. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.spec.js +150 -0
  48. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.spec.js.map +1 -0
  49. package/dist/forms/fieldSchemasToFormState/types.d.ts +1 -0
  50. package/dist/forms/fieldSchemasToFormState/types.d.ts.map +1 -1
  51. package/dist/forms/fieldSchemasToFormState/types.js.map +1 -1
  52. package/dist/layouts/Root/index.js +6 -5
  53. package/dist/layouts/Root/index.js.map +1 -1
  54. package/dist/providers/LivePreview/index.d.ts.map +1 -1
  55. package/dist/providers/LivePreview/index.js +13 -6
  56. package/dist/providers/LivePreview/index.js.map +1 -1
  57. package/dist/styles.css +1 -1
  58. package/dist/utilities/buildFormState.d.ts.map +1 -1
  59. package/dist/utilities/buildFormState.js +6 -2
  60. package/dist/utilities/buildFormState.js.map +1 -1
  61. package/dist/utilities/formatAbsoluteURL.d.ts +1 -1
  62. package/dist/utilities/formatAbsoluteURL.d.ts.map +1 -1
  63. package/dist/utilities/formatAbsoluteURL.js +18 -8
  64. package/dist/utilities/formatAbsoluteURL.js.map +1 -1
  65. package/dist/utilities/formatAbsoluteURL.spec.js +27 -0
  66. package/dist/utilities/formatAbsoluteURL.spec.js.map +1 -0
  67. package/dist/utilities/handleServerFunctions.d.ts.map +1 -1
  68. package/dist/utilities/handleServerFunctions.js +4 -2
  69. package/dist/utilities/handleServerFunctions.js.map +1 -1
  70. package/dist/utilities/initReq.d.ts.map +1 -1
  71. package/dist/utilities/initReq.js +40 -5
  72. package/dist/utilities/initReq.js.map +1 -1
  73. package/dist/utilities/initReq.spec.js +226 -0
  74. package/dist/utilities/initReq.spec.js.map +1 -0
  75. package/dist/utilities/isAbsoluteURL.d.ts +3 -0
  76. package/dist/utilities/isAbsoluteURL.d.ts.map +1 -0
  77. package/dist/utilities/isAbsoluteURL.js +15 -0
  78. package/dist/utilities/isAbsoluteURL.js.map +1 -0
  79. package/dist/utilities/isAbsoluteURL.spec.js +11 -0
  80. package/dist/utilities/isAbsoluteURL.spec.js.map +1 -0
  81. package/dist/utilities/isHttpURL.d.ts +3 -0
  82. package/dist/utilities/isHttpURL.d.ts.map +1 -0
  83. package/dist/utilities/isHttpURL.js +12 -0
  84. package/dist/utilities/isHttpURL.js.map +1 -0
  85. package/dist/utilities/isHttpURL.spec.js +25 -0
  86. package/dist/utilities/isHttpURL.spec.js.map +1 -0
  87. package/dist/utilities/isPublicAdminRoute.d.ts.map +1 -1
  88. package/dist/utilities/isPublicAdminRoute.js +9 -6
  89. package/dist/utilities/isPublicAdminRoute.js.map +1 -1
  90. package/dist/utilities/isPublicAdminRoute.spec.js +34 -0
  91. package/dist/utilities/isPublicAdminRoute.spec.js.map +1 -0
  92. package/dist/utilities/schedulePublishHandler.d.ts.map +1 -1
  93. package/dist/utilities/schedulePublishHandler.js +4 -1
  94. package/dist/utilities/schedulePublishHandler.js.map +1 -1
  95. package/dist/views/Account/index.d.ts +1 -1
  96. package/dist/views/Account/index.d.ts.map +1 -1
  97. package/dist/views/Account/index.js +8 -5
  98. package/dist/views/Account/index.js.map +1 -1
  99. package/dist/views/Dashboard/Default/ModularDashboard/index.d.ts.map +1 -1
  100. package/dist/views/Dashboard/Default/ModularDashboard/index.js +1 -0
  101. package/dist/views/Dashboard/Default/ModularDashboard/index.js.map +1 -1
  102. package/dist/views/Dashboard/Default/ModularDashboard/renderWidget/getDefaultLayoutServerFn.d.ts.map +1 -1
  103. package/dist/views/Dashboard/Default/ModularDashboard/renderWidget/getDefaultLayoutServerFn.js +3 -1
  104. package/dist/views/Dashboard/Default/ModularDashboard/renderWidget/getDefaultLayoutServerFn.js.map +1 -1
  105. package/dist/views/Dashboard/Default/ModularDashboard/renderWidget/renderWidgetServerFn.d.ts.map +1 -1
  106. package/dist/views/Dashboard/Default/ModularDashboard/renderWidget/renderWidgetServerFn.js +2 -0
  107. package/dist/views/Dashboard/Default/ModularDashboard/renderWidget/renderWidgetServerFn.js.map +1 -1
  108. package/dist/views/Dashboard/index.d.ts.map +1 -1
  109. package/dist/views/Dashboard/index.js +2 -3
  110. package/dist/views/Dashboard/index.js.map +1 -1
  111. package/dist/views/Document/handleServerFunction.d.ts.map +1 -1
  112. package/dist/views/Document/handleServerFunction.js +2 -0
  113. package/dist/views/Document/handleServerFunction.js.map +1 -1
  114. package/dist/views/Document/index.d.ts +1 -1
  115. package/dist/views/Document/index.d.ts.map +1 -1
  116. package/dist/views/Document/index.js +9 -4
  117. package/dist/views/Document/index.js.map +1 -1
  118. package/dist/views/Document/renderDocumentSlots.d.ts +1 -0
  119. package/dist/views/Document/renderDocumentSlots.d.ts.map +1 -1
  120. package/dist/views/Document/renderDocumentSlots.js +7 -4
  121. package/dist/views/Document/renderDocumentSlots.js.map +1 -1
  122. package/dist/views/Edit/Auth/APIKey.d.ts +1 -1
  123. package/dist/views/Edit/Auth/APIKey.d.ts.map +1 -1
  124. package/dist/views/Edit/Auth/APIKey.js +233 -59
  125. package/dist/views/Edit/Auth/APIKey.js.map +1 -1
  126. package/dist/views/Edit/Auth/APIKeyGenerationModal.d.ts +12 -0
  127. package/dist/views/Edit/Auth/APIKeyGenerationModal.d.ts.map +1 -0
  128. package/dist/views/Edit/Auth/APIKeyGenerationModal.js +117 -0
  129. package/dist/views/Edit/Auth/APIKeyGenerationModal.js.map +1 -0
  130. package/dist/views/Edit/Auth/index.css +91 -0
  131. package/dist/views/Edit/Auth/index.d.ts.map +1 -1
  132. package/dist/views/Edit/Auth/index.js +10 -28
  133. package/dist/views/Edit/Auth/index.js.map +1 -1
  134. package/dist/views/Edit/Auth/types.d.ts +3 -1
  135. package/dist/views/Edit/Auth/types.d.ts.map +1 -1
  136. package/dist/views/Edit/Auth/types.js.map +1 -1
  137. package/dist/views/ForgotPassword/ForgotPasswordForm/index.css +14 -0
  138. package/dist/views/ForgotPassword/ForgotPasswordForm/index.d.ts.map +1 -1
  139. package/dist/views/ForgotPassword/ForgotPasswordForm/index.js +209 -161
  140. package/dist/views/ForgotPassword/ForgotPasswordForm/index.js.map +1 -1
  141. package/dist/views/ForgotPassword/index.d.ts.map +1 -1
  142. package/dist/views/ForgotPassword/index.js +2 -11
  143. package/dist/views/ForgotPassword/index.js.map +1 -1
  144. package/dist/views/List/handleServerFunction.d.ts.map +1 -1
  145. package/dist/views/List/handleServerFunction.js +3 -1
  146. package/dist/views/List/handleServerFunction.js.map +1 -1
  147. package/dist/views/List/index.d.ts.map +1 -1
  148. package/dist/views/List/index.js +2 -1
  149. package/dist/views/List/index.js.map +1 -1
  150. package/dist/views/NotFound/page.d.ts.map +1 -1
  151. package/dist/views/NotFound/page.js +4 -3
  152. package/dist/views/NotFound/page.js.map +1 -1
  153. package/dist/views/Root/index.d.ts.map +1 -1
  154. package/dist/views/Root/index.js +5 -3
  155. package/dist/views/Root/index.js.map +1 -1
  156. package/dist/views/Verify/index.d.ts +1 -1
  157. package/dist/views/Verify/index.d.ts.map +1 -1
  158. package/dist/views/Verify/index.js +4 -4
  159. package/dist/views/Verify/index.js.map +1 -1
  160. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"renderFieldServerFn.js","names":["deepMerge","UnauthorizedError","getClientConfig","getClientSchemaMap","getSchemaMap","renderField","_internal_renderFieldHandler","field","fieldArg","initialValue","path","req","schemaPath","user","entityType","entitySlug","fieldPath","split","schemaMap","collectionSlug","undefined","config","payload","globalSlug","i18n","clientSchemaMap","importMap","targetField","get","join","Error","clone","data","name","fieldState","clientFieldSchemaMap","fieldConfig","fieldSchemaMap","formState","indexPath","lastRenderedPath","operation","parentPath","parentSchemaPath","permissions","preferences","fields","forceCreateClientField","previousFieldState","renderAllFields","siblingData","customComponents"],"sources":["../../../../src/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.ts"],"sourcesContent":["import {\n deepMerge,\n type Field,\n type FieldState,\n type ServerFunction,\n UnauthorizedError,\n} from 'payload'\n\nimport { getClientConfig } from '../../../utilities/getClientConfig.js'\nimport { getClientSchemaMap } from '../../../utilities/getClientSchemaMap.js'\nimport { getSchemaMap } from '../../../utilities/getSchemaMap.js'\nimport { renderField } from '../renderField.js'\n\nexport type RenderFieldServerFnArgs<TField = Field> = {\n /**\n * Override field config pulled from schemaPath lookup\n */\n field?: Partial<TField>\n /**\n * Pass the value this field will receive when rendering it on the server.\n * For richText, this helps provide initial state for sub-fields that are immediately rendered (like blocks)\n * so that we can avoid multiple waterfall requests for each block that renders on the client.\n */\n initialValue?: unknown\n /**\n * Path to the field to render\n * @default field name\n */\n path?: string\n /**\n * Dot schema path to a richText field declared in your config.\n * Format:\n * \"collection.<collectionSlug>.<fieldPath>\"\n * \"global.<globalSlug>.<fieldPath>\"\n *\n * Examples:\n * \"collection.posts.richText\"\n * \"global.siteSettings.content\"\n */\n schemaPath: string\n}\nexport type RenderFieldServerFnReturnType = {} & FieldState['customComponents']\n\n/**\n * @experimental - may break in minor releases\n */\nexport const _internal_renderFieldHandler: ServerFunction<\n RenderFieldServerFnArgs,\n Promise<RenderFieldServerFnReturnType>\n // eslint-disable-next-line @typescript-eslint/require-await\n> = async ({ field: fieldArg, initialValue, path, req, schemaPath }) => {\n if (!req.user) {\n throw new UnauthorizedError()\n }\n\n const [entityType, entitySlug, ...fieldPath] = schemaPath.split('.')\n\n const schemaMap = getSchemaMap({\n collectionSlug: entityType === 'collection' ? entitySlug : undefined,\n config: req.payload.config,\n globalSlug: entityType === 'global' ? entitySlug : undefined,\n i18n: req.i18n,\n })\n\n // Provide client schema map as it would have been provided if the target editor field would have been rendered.\n // For lexical, only then will it contain all the lexical-internal entries\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug: entityType === 'collection' ? entitySlug : undefined,\n config: getClientConfig({\n config: req.payload.config,\n i18n: req.i18n,\n importMap: req.payload.importMap,\n user: req.user,\n }),\n globalSlug: entityType === 'global' ? entitySlug : undefined,\n i18n: req.i18n,\n payload: req.payload,\n schemaMap,\n })\n\n const targetField = schemaMap.get(`${entitySlug}.${fieldPath.join('.')}`) as Field | undefined\n\n if (!targetField) {\n throw new Error(`Could not find target field at schemaPath: ${schemaPath}`)\n }\n\n const field: Field = fieldArg ? deepMerge(targetField, fieldArg, { clone: false }) : targetField\n\n let data = {}\n if (typeof initialValue !== 'undefined') {\n if ('name' in field) {\n data[field.name] = initialValue\n } else {\n data = initialValue\n }\n }\n\n const fieldState: FieldState = {}\n renderField({\n clientFieldSchemaMap: clientSchemaMap,\n collectionSlug: entityType === 'collection' && entitySlug ? entitySlug : '-',\n data,\n fieldConfig: field,\n fieldSchemaMap: schemaMap,\n fieldState, // TODO,\n formState: {}, // TODO,\n indexPath: '',\n lastRenderedPath: '',\n operation: 'create',\n parentPath: '',\n parentSchemaPath: '',\n path: path ?? ('name' in field ? field.name : ''),\n permissions: true,\n preferences: {\n fields: {},\n },\n // If we are passed a field override, we want to ensure we create a new client field based on that override\n forceCreateClientField: fieldArg ? true : false,\n previousFieldState: undefined,\n renderAllFields: true,\n req,\n schemaPath: `${entitySlug}.${fieldPath.join('.')}`,\n siblingData: data,\n })\n\n return fieldState.customComponents ?? {}\n}\n"],"mappings":"AAAA,SACEA,SAAS,EAITC,iBAAiB,QACZ;AAEP,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SAASC,WAAW,QAAQ;AAgC5B;;;AAGA,OAAO,MAAMC,4BAAA,GAIT,MAAAA,CAAO;EAAEC,KAAA,EAAOC,QAAQ;EAAEC,YAAY;EAAEC,IAAI;EAAEC,GAAG;EAAEC;AAAU,CAAE;EACjE,IAAI,CAACD,GAAA,CAAIE,IAAI,EAAE;IACb,MAAM,IAAIZ,iBAAA;EACZ;EAEA,MAAM,CAACa,UAAA,EAAYC,UAAA,EAAY,GAAGC,SAAA,CAAU,GAAGJ,UAAA,CAAWK,KAAK,CAAC;EAEhE,MAAMC,SAAA,GAAYd,YAAA,CAAa;IAC7Be,cAAA,EAAgBL,UAAA,KAAe,eAAeC,UAAA,GAAaK,SAAA;IAC3DC,MAAA,EAAQV,GAAA,CAAIW,OAAO,CAACD,MAAM;IAC1BE,UAAA,EAAYT,UAAA,KAAe,WAAWC,UAAA,GAAaK,SAAA;IACnDI,IAAA,EAAMb,GAAA,CAAIa;EACZ;EAEA;EACA;EACA,MAAMC,eAAA,GAAkBtB,kBAAA,CAAmB;IACzCgB,cAAA,EAAgBL,UAAA,KAAe,eAAeC,UAAA,GAAaK,SAAA;IAC3DC,MAAA,EAAQnB,eAAA,CAAgB;MACtBm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AAA,KAAS,UAAUH,KAAA,GAAQA,KAAA,CAAM0B,IAAI,GAAG,EAAC;IAC/CW,WAAA,EAAa;IACbC,WAAA,EAAa;MACXC,MAAA,EAAQ,CAAC;IACX;IACA;IACAC,sBAAA,EAAwBvC,QAAA,GAAW,OAAO;IAC1CwC,kBAAA,EAAoB5B,SAAA;IACpB6B,eAAA,EAAiB;IACjBtC,GAAA;IACAC,UAAA,EAAY,GAAGG,UAAA,IAAcC,SAAA,CAAUa,IAAI,CAAC,MAAM;IAClDqB,WAAA,EAAalB;EACf;EAEA,OAAOE,UAAA,CAAWiB,gBAAgB,IAAI,CAAC;AACzC","ignoreList":[]}
1
+ {"version":3,"file":"renderFieldServerFn.js","names":["UnauthorizedError","getClientConfig","getClientSchemaMap","getSchemaMap","renderField","mergeAllowedFieldOverrides","_internal_renderFieldHandler","name","hidden","initialValue","label","path","req","schemaPath","user","entityType","entitySlug","fieldPath","split","schemaMap","collectionSlug","undefined","config","payload","globalSlug","i18n","clientSchemaMap","importMap","targetField","get","join","Error","field","overrides","admin","hasPropOverrides","data","fieldState","clientFieldSchemaMap","fieldConfig","fieldSchemaMap","formState","indexPath","lastRenderedPath","operation","parentPath","parentSchemaPath","permissions","preferences","fields","forceCreateClientField","previousFieldState","renderAllFields","siblingData","customComponents"],"sources":["../../../../src/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.ts"],"sourcesContent":["import { type Field, type FieldState, type ServerFunction, UnauthorizedError } from 'payload'\n\nimport { getClientConfig } from '../../../utilities/getClientConfig.js'\nimport { getClientSchemaMap } from '../../../utilities/getClientSchemaMap.js'\nimport { getSchemaMap } from '../../../utilities/getSchemaMap.js'\nimport { renderField } from '../renderField.js'\nimport { mergeAllowedFieldOverrides } from './mergeAllowedFieldOverrides.js'\n\nexport type RenderFieldServerFnArgs = {\n /** Overrides admin.hidden from the schemaPath lookup. */\n hidden?: boolean\n /**\n * Pass the value this field will receive when rendering it on the server.\n * For richText, this helps provide initial state for sub-fields that are immediately rendered (like blocks)\n * so that we can avoid multiple waterfall requests for each block that renders on the client.\n */\n initialValue?: unknown\n /** Overrides the label from the schemaPath lookup. Use false to hide it. */\n label?: false | Record<string, string> | string\n /** Overrides the form field name from the schemaPath lookup. */\n name?: string\n /**\n * Path to the field to render\n * @default field name\n */\n path?: string\n /**\n * Dot schema path to a richText field declared in your config.\n * Format:\n * \"collection.<collectionSlug>.<fieldPath>\"\n * \"global.<globalSlug>.<fieldPath>\"\n *\n * Examples:\n * \"collection.posts.richText\"\n * \"global.siteSettings.content\"\n */\n schemaPath: string\n}\nexport type RenderFieldServerFnReturnType = {} & FieldState['customComponents']\n\n/**\n * @experimental - may break in minor releases\n */\nexport const _internal_renderFieldHandler: ServerFunction<\n RenderFieldServerFnArgs,\n Promise<RenderFieldServerFnReturnType>\n // eslint-disable-next-line @typescript-eslint/require-await\n> = async ({ name, hidden, initialValue, label, path, req, schemaPath, user }) => {\n if (!req.user) {\n throw new UnauthorizedError()\n }\n\n const [entityType, entitySlug, ...fieldPath] = schemaPath.split('.')\n\n const schemaMap = getSchemaMap({\n collectionSlug: entityType === 'collection' ? entitySlug : undefined,\n config: req.payload.config,\n globalSlug: entityType === 'global' ? entitySlug : undefined,\n i18n: req.i18n,\n })\n\n // Provide client schema map as it would have been provided if the target editor field would have been rendered.\n // For lexical, only then will it contain all the lexical-internal entries\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug: entityType === 'collection' ? entitySlug : undefined,\n config: getClientConfig({\n config: req.payload.config,\n i18n: req.i18n,\n importMap: req.payload.importMap,\n user: req.user,\n }),\n globalSlug: entityType === 'global' ? entitySlug : undefined,\n i18n: req.i18n,\n payload: req.payload,\n schemaMap,\n })\n\n const targetField = schemaMap.get(`${entitySlug}.${fieldPath.join('.')}`) as Field | undefined\n\n if (!targetField) {\n throw new Error(`Could not find target field at schemaPath: ${schemaPath}`)\n }\n\n const field: Field = mergeAllowedFieldOverrides({\n overrides: { name, admin: { hidden }, label },\n targetField,\n })\n const hasPropOverrides = name !== undefined || label !== undefined || hidden !== undefined\n\n let data = {}\n if (typeof initialValue !== 'undefined') {\n if ('name' in field) {\n data[field.name] = initialValue\n } else {\n data = initialValue\n }\n }\n\n const fieldState: FieldState = {}\n renderField({\n clientFieldSchemaMap: clientSchemaMap,\n collectionSlug: entityType === 'collection' && entitySlug ? entitySlug : '-',\n data,\n fieldConfig: field,\n fieldSchemaMap: schemaMap,\n fieldState, // TODO,\n formState: {}, // TODO,\n indexPath: '',\n lastRenderedPath: '',\n operation: 'create',\n parentPath: '',\n parentSchemaPath: '',\n path: path ?? ('name' in field ? field.name : ''),\n permissions: true,\n preferences: {\n fields: {},\n },\n // Create a new client field when presentation values differ from the schema config.\n forceCreateClientField: hasPropOverrides,\n previousFieldState: undefined,\n renderAllFields: true,\n req,\n schemaPath: `${entitySlug}.${fieldPath.join('.')}`,\n siblingData: data,\n user,\n })\n\n return fieldState.customComponents ?? {}\n}\n"],"mappings":"AAAA,SAA2DA,iBAAiB,QAAQ;AAEpF,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SAASC,WAAW,QAAQ;AAC5B,SAASC,0BAA0B,QAAQ;AAkC3C;;;AAGA,OAAO,MAAMC,4BAAA,GAIT,MAAAA,CAAO;EAAEC,IAAI;EAAEC,MAAM;EAAEC,YAAY;EAAEC,KAAK;EAAEC,IAAI;EAAEC,GAAG;EAAEC,UAAU;EAAEC;AAAI,CAAE;EAC3E,IAAI,CAACF,GAAA,CAAIE,IAAI,EAAE;IACb,MAAM,IAAId,iBAAA;EACZ;EAEA,MAAM,CAACe,UAAA,EAAYC,UAAA,EAAY,GAAGC,SAAA,CAAU,GAAGJ,UAAA,CAAWK,KAAK,CAAC;EAEhE,MAAMC,SAAA,GAAYhB,YAAA,CAAa;IAC7BiB,cAAA,EAAgBL,UAAA,KAAe,eAAeC,UAAA,GAAaK,SAAA;IAC3DC,MAAA,EAAQV,GAAA,CAAIW,O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,YAAA;IACT;EACF;EAEA,MAAM4B,UAAA,GAAyB,CAAC;EAChCjC,WAAA,CAAY;IACVkC,oBAAA,EAAsBZ,eAAA;IACtBN,cAAA,EAAgBL,UAAA,KAAe,gBAAgBC,UAAA,GAAaA,UAAA,GAAa;IACzEoB,IAAA;IACAG,WAAA,EAAaP,KAAA;IACbQ,cAAA,EAAgBrB,SAAA;IAChBkB,UAAA;IACAI,SAAA,EAAW,CAAC;IACZC,SAAA,EAAW;IACXC,gBAAA,EAAkB;IAClBC,SAAA,EAAW;IACXC,UAAA,EAAY;IACZC,gBAAA,EAAkB;IAClBnC,IAAA,EAAMA,IAAA,KAAS,UAAUqB,KAAA,GAAQA,KAAA,CAAMzB,IAAI,GAAG,EAAC;IAC/CwC,WAAA,EAAa;IACbC,WAAA,EAAa;MACXC,MAAA,EAAQ,CAAC;IACX;IACA;IACAC,sBAAA,EAAwBf,gBAAA;IACxBgB,kBAAA,EAAoB9B,SAAA;IACpB+B,eAAA,EAAiB;IACjBxC,GAAA;IACAC,UAAA,EAAY,GAAGG,UAAA,IAAcC,SAAA,CAAUa,IAAI,CAAC,MAAM;IAClDuB,WAAA,EAAajB,IAAA;IACbtB;EACF;EAEA,OAAOuB,UAAA,CAAWiB,gBAAgB,IAAI,CAAC;AACzC","ignoreList":[]}
@@ -0,0 +1,150 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { _internal_renderFieldHandler } from './renderFieldServerFn.js';
3
+ const mocks = vi.hoisted(() => ({
4
+ getClientConfig: vi.fn(),
5
+ getClientSchemaMap: vi.fn(),
6
+ getSchemaMap: vi.fn(),
7
+ renderField: vi.fn()
8
+ }));
9
+ vi.mock('../../../utilities/getClientConfig.js', () => ({
10
+ getClientConfig: mocks.getClientConfig
11
+ }));
12
+ vi.mock('../../../utilities/getClientSchemaMap.js', () => ({
13
+ getClientSchemaMap: mocks.getClientSchemaMap
14
+ }));
15
+ vi.mock('../../../utilities/getSchemaMap.js', () => ({
16
+ getSchemaMap: mocks.getSchemaMap
17
+ }));
18
+ vi.mock('../renderField.js', () => ({
19
+ renderField: mocks.renderField
20
+ }));
21
+ const args = {
22
+ req: {
23
+ user: {
24
+ collection: 'users'
25
+ },
26
+ payload: {
27
+ config: {},
28
+ importMap: {}
29
+ }
30
+ },
31
+ schemaPath: 'collection.posts.content'
32
+ };
33
+ describe('renderFieldServerFn', () => {
34
+ beforeEach(() => {
35
+ vi.resetAllMocks();
36
+ });
37
+ it('should reject disallowed field props', async () => {
38
+ const targetField = {
39
+ name: 'content',
40
+ type: 'richText',
41
+ admin: {
42
+ components: {
43
+ Field: {
44
+ path: './ConfiguredField',
45
+ exportName: 'Field',
46
+ serverProps: {
47
+ heading: 'Configured heading'
48
+ }
49
+ }
50
+ },
51
+ hidden: true
52
+ }
53
+ };
54
+ mocks.getSchemaMap.mockReturnValue(new Map([['posts.content', targetField]]));
55
+ const request = {
56
+ ...args,
57
+ field: {
58
+ admin: {
59
+ components: {
60
+ Field: {
61
+ path: './OtherField',
62
+ exportName: 'Field',
63
+ serverProps: {
64
+ heading: 'Other heading',
65
+ appearance: 'compact'
66
+ }
67
+ }
68
+ }
69
+ }
70
+ },
71
+ initialValue: 'Initial text'
72
+ };
73
+ await _internal_renderFieldHandler(request);
74
+ expect(mocks.renderField).toHaveBeenCalledWith(expect.objectContaining({
75
+ data: {
76
+ content: 'Initial text'
77
+ },
78
+ fieldConfig: {
79
+ ...targetField,
80
+ admin: {
81
+ components: {
82
+ Field: {
83
+ path: './ConfiguredField',
84
+ exportName: 'Field',
85
+ serverProps: {
86
+ heading: 'Configured heading'
87
+ }
88
+ }
89
+ },
90
+ hidden: true
91
+ }
92
+ },
93
+ forceCreateClientField: false,
94
+ path: 'content',
95
+ schemaPath: 'posts.content'
96
+ }));
97
+ expect(targetField).toEqual({
98
+ name: 'content',
99
+ type: 'richText',
100
+ admin: {
101
+ components: {
102
+ Field: {
103
+ path: './ConfiguredField',
104
+ exportName: 'Field',
105
+ serverProps: {
106
+ heading: 'Configured heading'
107
+ }
108
+ }
109
+ },
110
+ hidden: true
111
+ }
112
+ });
113
+ });
114
+ it('should accept allowed field props', async () => {
115
+ const targetField = {
116
+ name: 'content',
117
+ type: 'richText',
118
+ admin: {
119
+ hidden: true
120
+ }
121
+ };
122
+ mocks.getSchemaMap.mockReturnValue(new Map([['posts.content', targetField]]));
123
+ await _internal_renderFieldHandler({
124
+ ...args,
125
+ name: 'editor',
126
+ label: false,
127
+ hidden: false
128
+ });
129
+ expect(mocks.renderField).toHaveBeenCalledWith(expect.objectContaining({
130
+ fieldConfig: {
131
+ name: 'editor',
132
+ label: false,
133
+ admin: {
134
+ hidden: false
135
+ },
136
+ type: 'richText'
137
+ },
138
+ forceCreateClientField: true,
139
+ path: 'editor'
140
+ }));
141
+ expect(targetField).toEqual({
142
+ name: 'content',
143
+ type: 'richText',
144
+ admin: {
145
+ hidden: true
146
+ }
147
+ });
148
+ });
149
+ });
150
+ //# sourceMappingURL=renderFieldServerFn.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderFieldServerFn.spec.js","names":["beforeEach","describe","expect","it","vi","_internal_renderFieldHandler","mocks","hoisted","getClientConfig","fn","getClientSchemaMap","getSchemaMap","renderField","mock","args","req","user","collection","payload","config","importMap","schemaPath","resetAllMocks","targetField","name","type","admin","components","Field","path","exportName","serverProps","heading","hidden","mockReturnValue","Map","request","field","appearance","initialValue","toHaveBeenCalledWith","objectContaining","data","content","fieldConfig","forceCreateClientField","toEqual","label"],"sources":["../../../../src/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.spec.ts"],"sourcesContent":["import { beforeEach, describe, expect, it, vi } from 'vitest'\n\nimport { _internal_renderFieldHandler } from './renderFieldServerFn.js'\n\nconst mocks = vi.hoisted(() => ({\n getClientConfig: vi.fn(),\n getClientSchemaMap: vi.fn(),\n getSchemaMap: vi.fn(),\n renderField: vi.fn(),\n}))\n\nvi.mock('../../../utilities/getClientConfig.js', () => ({\n getClientConfig: mocks.getClientConfig,\n}))\nvi.mock('../../../utilities/getClientSchemaMap.js', () => ({\n getClientSchemaMap: mocks.getClientSchemaMap,\n}))\nvi.mock('../../../utilities/getSchemaMap.js', () => ({ getSchemaMap: mocks.getSchemaMap }))\nvi.mock('../renderField.js', () => ({ renderField: mocks.renderField }))\n\ntype HandlerArgs = Parameters<typeof _internal_renderFieldHandler>[0]\n\nconst args = {\n req: { user: { collection: 'users' }, payload: { config: {}, importMap: {} } },\n schemaPath: 'collection.posts.content',\n} as HandlerArgs\n\ndescribe('renderFieldServerFn', () => {\n beforeEach(() => {\n vi.resetAllMocks()\n })\n\n it('should reject disallowed field props', async () => {\n const targetField = {\n name: 'content',\n type: 'richText',\n admin: {\n components: {\n Field: {\n path: './ConfiguredField',\n exportName: 'Field',\n serverProps: { heading: 'Configured heading' },\n },\n },\n hidden: true,\n },\n }\n\n mocks.getSchemaMap.mockReturnValue(new Map([['posts.content', targetField]]))\n\n const request = {\n ...args,\n field: {\n admin: {\n components: {\n Field: {\n path: './OtherField',\n exportName: 'Field',\n serverProps: { heading: 'Other heading', appearance: 'compact' },\n },\n },\n },\n },\n initialValue: 'Initial text',\n }\n\n await _internal_renderFieldHandler(request)\n\n expect(mocks.renderField).toHaveBeenCalledWith(\n expect.objectContaining({\n data: { content: 'Initial text' },\n fieldConfig: {\n ...targetField,\n admin: {\n components: {\n Field: {\n path: './ConfiguredField',\n exportName: 'Field',\n serverProps: { heading: 'Configured heading' },\n },\n },\n hidden: true,\n },\n },\n forceCreateClientField: false,\n path: 'content',\n schemaPath: 'posts.content',\n }),\n )\n expect(targetField).toEqual({\n name: 'content',\n type: 'richText',\n admin: {\n components: {\n Field: {\n path: './ConfiguredField',\n exportName: 'Field',\n serverProps: { heading: 'Configured heading' },\n },\n },\n hidden: true,\n },\n })\n })\n\n it('should accept allowed field props', async () => {\n const targetField = { name: 'content', type: 'richText', admin: { hidden: true } }\n\n mocks.getSchemaMap.mockReturnValue(new Map([['posts.content', targetField]]))\n\n await _internal_renderFieldHandler({\n ...args,\n name: 'editor',\n label: false,\n hidden: false,\n })\n\n expect(mocks.renderField).toHaveBeenCalledWith(\n expect.objectContaining({\n fieldConfig: {\n name: 'editor',\n label: false,\n admin: { hidden: false },\n type: 'richText',\n },\n forceCreateClientField: true,\n path: 'editor',\n }),\n )\n expect(targetField).toEqual({ name: 'content', type: 'richText', admin: { hidden: true } })\n })\n})\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ;AAErD,SAASC,4BAA4B,QAAQ;AAE7C,MAAMC,KAAA,GAAQF,EAAA,CAAGG,OAAO,CAAC,OAAO;EAC9BC,eAAA,EAAiBJ,EAAA,CAAGK,EAAE;EACtBC,kBAAA,EAAoBN,EAAA,CAAGK,EAAE;EACzBE,YAAA,EAAcP,EAAA,CAAGK,EAAE;EACnBG,WAAA,EAAaR,EAAA,CAAGK,EAAE;AACpB;AAEAL,EAAA,CAAGS,IAAI,CAAC,yCAAyC,OAAO;EACtDL,eAAA,EAAiBF,KAAA,CAAME;AACzB;AACAJ,EAAA,CAAGS,IAAI,CAAC,4CAA4C,OAAO;EACzDH,kBAAA,EAAoBJ,KAAA,CAAMI;AAC5B;AACAN,EAAA,CAAGS,IAAI,CAAC,sCAAsC,OAAO;EAAEF,YAAA,EAAcL,KAAA,CAAMK;AAAa;AACxFP,EAAA,CAAGS,IAAI,CAAC,qBAAqB,OAAO;EAAED,WAAA,EAAaN,KAAA,CAAMM;AAAY;AAIrE,MAAME,IAAA,GAAO;EACXC,GAAA,EAAK;IAAEC,IAAA,EAAM;MAAEC,UAAA,EAAY;IAAQ;IAAGC,OAAA,EAAS;MAAEC,MAAA,EAAQ,CAAC;MAAGC,SAAA,EAAW,CAAC;IAAE;EAAE;EAC7EC,UAAA,EAAY;AACd;AAEApB,QAAA,CAAS,uBAAuB;EAC9BD,UAAA,CAAW;IACTI,EAAA,CAAGkB,aAAa;EAClB;EAEAn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O;YACLC,IAAA,EAAM;YACNC,UAAA,EAAY;YACZC,WAAA,EAAa;cAAEC,OAAA,EAAS;YAAqB;UAC/C;QACF;QACAC,MAAA,EAAQ;MACV;IACF;EACF;EAEA9B,EAAA,CAAG,qCAAqC;IACtC,MAAMoB,WAAA,GAAc;MAAEC,IAAA,EAAM;MAAWC,IAAA,EAAM;MAAYC,KAAA,EAAO;QAAEO,MAAA,EAAQ;MAAK;IAAE;IAEjF3B,KAAA,CAAMK,YAAY,CAACuB,eAAe,CAAC,IAAIC,GAAA,CAAI,CAAC,CAAC,iBAAiBZ,WAAA,CAAY,CAAC;IAE3E,MAAMlB,4BAAA,CAA6B;MACjC,GAAGS,IAAI;MACPU,IAAA,EAAM;MACNuB,KAAA,EAAO;MACPd,MAAA,EAAQ;IACV;IAEA/B,MAAA,CAAOI,KAAA,CAAMM,WAAW,EAAE4B,oBAAoB,CAC5CtC,MAAA,CAAOuC,gBAAgB,CAAC;MACtBG,WAAA,EAAa;QACXpB,IAAA,EAAM;QACNuB,KAAA,EAAO;QACPrB,KAAA,EAAO;UAAEO,MAAA,EAAQ;QAAM;QACvBR,IAAA,EAAM;MACR;MACAoB,sBAAA,EAAwB;MACxBhB,IAAA,EAAM;IACR;IAEF3B,MAAA,CAAOqB,WAAA,EAAauB,OAAO,CAAC;MAAEtB,IAAA,EAAM;MAAWC,IAAA,EAAM;MAAYC,KAAA,EAAO;QAAEO,MAAA,EAAQ;MAAK;IAAE;EAC3F;AACF","ignoreList":[]}
@@ -29,6 +29,7 @@ export type RenderFieldArgs = {
29
29
  req: PayloadRequest;
30
30
  schemaPath: string;
31
31
  siblingData: Data;
32
+ user?: PayloadRequest['user'];
32
33
  };
33
34
  export type RenderFieldMethod = (args: RenderFieldArgs) => void;
34
35
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,IAAI,EACJ,mBAAmB,EACnB,KAAK,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,SAAS,EACT,cAAc,EACd,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAEhB,MAAM,MAAM,eAAe,GAAG;IAC5B,oBAAoB,CAAC,EAAE,oBAAoB,CAAA;IAC3C,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,KAAK,CAAA;IAClB,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,UAAU,CAAA;IACtB;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,SAAS,EAAE,SAAS,CAAA;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,SAAS,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,yBAAyB,CAAA;IACtC,WAAW,EAAE,mBAAmB,CAAA;IAChC,kBAAkB,EAAE,UAAU,CAAA;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,eAAe,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,IAAI,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,IAAI,EACJ,mBAAmB,EACnB,KAAK,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,SAAS,EACT,cAAc,EACd,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAEhB,MAAM,MAAM,eAAe,GAAG;IAC5B,oBAAoB,CAAC,EAAE,oBAAoB,CAAA;IAC3C,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,KAAK,CAAA;IAClB,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,UAAU,CAAA;IACtB;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,SAAS,EAAE,SAAS,CAAA;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,EAAE,SAAS,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,yBAAyB,CAAA;IACtC,WAAW,EAAE,mBAAmB,CAAA;IAChC,kBAAkB,EAAE,UAAU,CAAA;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,eAAe,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,IAAI,CAAA;IACjB,IAAI,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"sourcesContent":["import type {\n ClientFieldSchemaMap,\n Data,\n DocumentPreferences,\n Field,\n FieldSchemaMap,\n FieldState,\n FormState,\n Operation,\n PayloadRequest,\n SanitizedFieldPermissions,\n} from 'payload'\n\nexport type RenderFieldArgs = {\n clientFieldSchemaMap?: ClientFieldSchemaMap\n collectionSlug: string\n data: Data\n fieldConfig: Field\n fieldSchemaMap: FieldSchemaMap\n fieldState: FieldState\n /**\n * If set to true, it will force creating a clientField based on the passed fieldConfig instead of pulling\n * the client field from the clientFieldSchemaMap. This is useful if the passed fieldConfig differs from the one in the schema map,\n * e.g. when calling the render-field server function and passing a field config override.\n */\n forceCreateClientField?: boolean\n formState: FormState\n id?: number | string\n indexPath: string\n lastRenderedPath: string\n mockRSCs?: boolean\n operation: Operation\n parentPath: string\n parentSchemaPath: string\n path: string\n permissions: SanitizedFieldPermissions\n preferences: DocumentPreferences\n previousFieldState: FieldState\n readOnly?: boolean\n renderAllFields: boolean\n req: PayloadRequest\n schemaPath: string\n siblingData: Data\n}\n\nexport type RenderFieldMethod = (args: RenderFieldArgs) => void\n"],"mappings":"AA6CA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"sourcesContent":["import type {\n ClientFieldSchemaMap,\n Data,\n DocumentPreferences,\n Field,\n FieldSchemaMap,\n FieldState,\n FormState,\n Operation,\n PayloadRequest,\n SanitizedFieldPermissions,\n} from 'payload'\n\nexport type RenderFieldArgs = {\n clientFieldSchemaMap?: ClientFieldSchemaMap\n collectionSlug: string\n data: Data\n fieldConfig: Field\n fieldSchemaMap: FieldSchemaMap\n fieldState: FieldState\n /**\n * If set to true, it will force creating a clientField based on the passed fieldConfig instead of pulling\n * the client field from the clientFieldSchemaMap. This is useful if the passed fieldConfig differs from the one in the schema map,\n * e.g. when calling the render-field server function and passing a field config override.\n */\n forceCreateClientField?: boolean\n formState: FormState\n id?: number | string\n indexPath: string\n lastRenderedPath: string\n mockRSCs?: boolean\n operation: Operation\n parentPath: string\n parentSchemaPath: string\n path: string\n permissions: SanitizedFieldPermissions\n preferences: DocumentPreferences\n previousFieldState: FieldState\n readOnly?: boolean\n renderAllFields: boolean\n req: PayloadRequest\n schemaPath: string\n siblingData: Data\n user?: PayloadRequest['user']\n}\n\nexport type RenderFieldMethod = (args: RenderFieldArgs) => void\n"],"mappings":"AA8CA","ignoreList":[]}
@@ -53,7 +53,8 @@ const RootLayoutContent = async ({
53
53
  payload: {
54
54
  config
55
55
  }
56
- }
56
+ },
57
+ user
57
58
  } = await initReq({
58
59
  configPromise,
59
60
  importMap,
@@ -91,7 +92,7 @@ const RootLayoutContent = async ({
91
92
  config,
92
93
  i18n: req.i18n,
93
94
  importMap,
94
- user: req.user
95
+ user
95
96
  });
96
97
  await applyLocaleFiltering({
97
98
  clientConfig,
@@ -123,12 +124,12 @@ const RootLayoutContent = async ({
123
124
  languageCode: languageCode,
124
125
  languageOptions: languageOptions,
125
126
  locale: req.locale,
126
- permissions: req.user ? permissions : null,
127
+ permissions: user ? permissions : null,
127
128
  RouterAdapter: RouterAdapter,
128
129
  serverFunction: serverFunction,
129
130
  theme: theme,
130
131
  translations: req.i18n.translations,
131
- user: req.user,
132
+ user: user,
132
133
  children: [/*#__PURE__*/_jsx(ProgressBar, {}), Array.isArray(config.admin?.components?.providers) && config.admin?.components?.providers.length > 0 ? /*#__PURE__*/_jsx(NestProviders, {
133
134
  importMap: req.payload.importMap,
134
135
  providers: config.admin?.components?.providers,
@@ -137,7 +138,7 @@ const RootLayoutContent = async ({
137
138
  payload: req.payload,
138
139
  permissions,
139
140
  server: req.server,
140
- user: req.user
141
+ user
141
142
  },
142
143
  children: children
143
144
  }) : children]
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["applyLocaleFiltering","React","Suspense","getNavPrefs","ProgressBar","RootProvider","checkDependencies","getClientConfig","getLanguageDir","getRequestEmbed","getRequestHighContrast","getRequestTheme","initReq","NestProviders","getViewportMeta","metadata","description","title","RootLayout","props","additionalDependencyChecks","content","_jsx","RootLayoutContent","process","env","PAYLOAD_CACHE_COMPONENTS_ENABLED","fallback","children","config","configPromise","fonts","head","headFromProps","htmlProps","importMap","RouterAdapter","serverAdapter","serverFunction","cookies","headers","languageCode","permissions","req","payload","key","theme","highContrastMode","dir","embed","languageOptions","Object","entries","i18n","supportedLanguages","reduce","acc","language","languageConfig","keys","includes","push","label","translations","general","thisLanguage","value","navPrefs","clientConfig","user","fontClassNames","map","f","variable","className","filter","Boolean","viewportMeta","get","undefined","_jsxs","join","lang","suppressHydrationWarning","admin","dateFNSKey","fallbackLang","fallbackLanguage","isNavOpen","open","locale","Array","isArray","components","providers","length","serverProps","server","id"],"sources":["../../../src/layouts/Root/index.tsx"],"sourcesContent":["import type {\n ImportMap,\n LanguageOptions,\n SanitizedConfig,\n ServerAdapter,\n ServerFunctionClient,\n} from 'payload'\n\nimport { applyLocaleFiltering } from 'payload/shared'\nimport React, { Suspense } from 'react'\n\nimport { getNavPrefs } from '../../elements/Nav/getNavPrefs.js'\n// eslint-disable-next-line payload/no-imports-from-exports-dir -- Server component must reference exports/client bundle for proper client boundary in prod builds\nimport { ProgressBar, RootProvider } from '../../exports/client/index.js'\nimport { checkDependencies, type CheckDependenciesArgs } from '../../utilities/checkDependencies.js'\nimport { getClientConfig } from '../../utilities/getClientConfig.js'\nimport { getLanguageDir } from '../../utilities/getLanguageDir.js'\nimport { getRequestEmbed } from '../../utilities/getRequestEmbed.js'\nimport { getRequestHighContrast } from '../../utilities/getRequestHighContrast.js'\nimport { getRequestTheme } from '../../utilities/getRequestTheme.js'\nimport { initReq } from '../../utilities/initReq.js'\nimport { NestProviders } from './NestProviders.js'\nimport { getViewportMeta } from './viewport.js'\n// eslint-disable-next-line payload/no-imports-from-self -- Self-import via package path ensures consumer's bundler resolves the full CSS chain (design tokens, preflight, etc.) in prod builds\nimport '@payloadcms/ui/css/app.css'\n\ntype Font = {\n className?: string\n variable?: string\n}\n\nexport const metadata = {\n description: 'Generated by Next.js',\n title: 'Next.js',\n}\n\ntype RootLayoutProps = {\n /**\n * Framework-specific peer-dependency version constraints, merged on top of the\n * universal React/react-dom checks. Each framework adapter supplies its own\n * (e.g. Next.js passes `{ dependencyVersions: { next: { version: '>=15.0.0' } } }`).\n */\n readonly additionalDependencyChecks?: CheckDependenciesArgs\n readonly children: React.ReactNode\n readonly config: Promise<SanitizedConfig>\n /**\n * Fonts to apply to the admin `<html>` element. Each entry's\n * `variable ?? className` is appended to the `<html>` class list.\n * Framework-specific font loaders (e.g. `next/font`) are supplied by the caller.\n */\n readonly fonts?: Font[]\n /**\n * Custom content to render inside the admin panel's `<head>` element.\n *\n * Use this to inject scripts, meta tags, or links — for example, analytics\n * snippets via `next/script`, custom favicons, or preconnect hints.\n *\n * @example\n * ```tsx\n * import Script from 'next/script'\n *\n * <RootLayout\n * head={<Script src=\"https://example.com/analytics.js\" strategy=\"afterInteractive\" />}\n * {...rest}\n * />\n * ```\n */\n readonly head?: React.ReactNode\n readonly htmlProps?: React.HtmlHTMLAttributes<HTMLHtmlElement>\n readonly importMap: ImportMap\n /**\n * Client router adapter. Caller supplies a framework-specific provider\n * (for Next.js use the `NextRouterAdapter` exported from `@payloadcms/next`).\n */\n readonly RouterAdapter: React.FC<{ children: React.ReactNode }>\n /**\n * Server adapter providing framework-specific access to headers, cookies, redirects,\n * and other server APIs (for Next.js use `nextServerAdapter` from `@payloadcms/next`).\n */\n readonly serverAdapter: ServerAdapter\n readonly serverFunction: ServerFunctionClient\n}\n\nexport const RootLayout = (props: RootLayoutProps) => {\n checkDependencies(props.additionalDependencyChecks)\n\n const content = <RootLayoutContent {...props} />\n\n if (process.env.PAYLOAD_CACHE_COMPONENTS_ENABLED === 'true') {\n return <Suspense fallback={null}>{content}</Suspense>\n }\n\n return content\n}\n\nconst RootLayoutContent = async ({\n children,\n config: configPromise,\n fonts = [],\n head: headFromProps,\n htmlProps = {},\n importMap,\n RouterAdapter,\n serverAdapter,\n serverFunction,\n}: RootLayoutProps) => {\n const {\n cookies,\n headers,\n languageCode,\n permissions,\n req,\n req: {\n payload: { config },\n },\n } = await initReq({ configPromise, importMap, key: 'RootLayout', serverAdapter })\n\n const theme = getRequestTheme({\n config,\n cookies,\n headers,\n })\n\n const highContrastMode = getRequestHighContrast({\n config,\n cookies,\n headers,\n })\n\n const dir = getLanguageDir({ languageCode })\n const embed = getRequestEmbed({ config, cookies })\n\n const languageOptions: LanguageOptions = Object.entries(\n config.i18n.supportedLanguages || {},\n ).reduce((acc, [language, languageConfig]) => {\n if (Object.keys(config.i18n.supportedLanguages).includes(language)) {\n acc.push({\n label: languageConfig.translations.general.thisLanguage,\n value: language,\n })\n }\n\n return acc\n }, [])\n\n const navPrefs = await getNavPrefs(req)\n\n const clientConfig = getClientConfig({\n config,\n i18n: req.i18n,\n importMap,\n user: req.user,\n })\n\n await applyLocaleFiltering({ clientConfig, config, req })\n\n const fontClassNames = fonts.map((f) => f.variable ?? f.className).filter(Boolean)\n const viewportMeta = getViewportMeta(headers.get('user-agent') ?? undefined)\n\n return (\n <html\n {...htmlProps}\n className={[...fontClassNames, htmlProps?.className].filter(Boolean).join(' ')}\n data-enhanced-contrast={highContrastMode ? '' : undefined}\n data-theme={theme}\n dir={dir}\n lang={languageCode}\n suppressHydrationWarning={config?.admin?.suppressHydrationWarning ?? false}\n >\n <head>\n {viewportMeta}\n <style>{`@layer payload-default, payload;`}</style>\n {headFromProps}\n </head>\n <body>\n <RootProvider\n config={clientConfig}\n dateFNSKey={req.i18n.dateFNSKey}\n embed={embed}\n fallbackLang={config.i18n.fallbackLanguage}\n highContrastMode={highContrastMode}\n isNavOpen={navPrefs?.open ?? true}\n languageCode={languageCode}\n languageOptions={languageOptions}\n locale={req.locale}\n permissions={req.user ? permissions : null}\n RouterAdapter={RouterAdapter}\n serverFunction={serverFunction}\n theme={theme}\n translations={req.i18n.translations}\n user={req.user}\n >\n <ProgressBar />\n {Array.isArray(config.admin?.components?.providers) &&\n config.admin?.components?.providers.length > 0 ? (\n <NestProviders\n importMap={req.payload.importMap}\n providers={config.admin?.components?.providers}\n serverProps={{\n i18n: req.i18n,\n payload: req.payload,\n permissions,\n server: req.server,\n user: req.user,\n }}\n >\n {children}\n </NestProviders>\n ) : (\n children\n )}\n </RootProvider>\n <div id=\"portal\" />\n </body>\n </html>\n )\n}\n"],"mappings":";AAQA,SAASA,oBAAoB,QAAQ;AACrC,OAAOC,KAAA,IAASC,QAAQ,QAAQ;AAEhC,SAASC,WAAW,QAAQ;AAC5B;AACA,SAASC,WAAW,EAAEC,YAAY,QAAQ;AAC1C,SAASC,iBAAiB,QAAoC;AAC9D,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,eAAe,QAAQ;AAChC,SAASC,OAAO,QAAQ;AACxB,SAASC,aAAa,QAAQ;AAC9B,SAASC,eAAe,QAAQ;AAChC;AACA,OAAO;AAOP,OAAO,MAAMC,QAAA,GAAW;EACtBC,WAAA,EAAa;EACbC,KAAA,EAAO;AACT;AAiDA,OAAO,MAAMC,UAAA,GAAcC,KAAA;EACzBb,iBAAA,CAAkBa,KAAA,CAAMC,0BAA0B;EAElD,MAAMC,OAAA,gBAAUC,IAAA,CAACC,iBAAA;IAAmB,GAAGJ;;EAEvC,IAAIK,OAAA,CAAQC,GAAG,CAACC,gCAAgC,KAAK,QAAQ;IAC3D,oBAAOJ,IAAA,CAACpB,QAAA;MAASyB,QAAA,EAAU;gBAAON;;EACpC;EAEA,OAAOA,OAAA;AACT;AAEA,MAAME,iBAAA,GAAoB,MAAAA,CAAO;EAC/BK,QAAQ;EACRC,MAAA,EAAQC,aAAa;EACrBC,KAAA,GAAQ,EAAE;EACVC,IAAA,EAAMC,aAAa;EACnBC,SAAA,GAAY,CAAC,CAAC;EACdC,SAAS;EACTC,aAAa;EACbC,aAAa;EACbC;AAAc,CACE;EAChB,MAAM;IACJC,OAAO;IACPC,OAAO;IACPC,YAAY;IACZC,WAAW;IACXC,GAAG;IACHA,GAAA,EAAK;MACHC,OAAA,EAAS;QAAEf;MAAM;IA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MAAA,CAAOuD,KAAK,EAAES,UAAA,EAAYC,SAAA,KACzCjE,MAAA,CAAOuD,KAAK,EAAES,UAAA,EAAYC,SAAA,CAAUC,MAAA,GAAS,iBAC3CzE,IAAA,CAACT,aAAA;UACCsB,SAAA,EAAWQ,GAAA,CAAIC,OAAO,CAACT,SAAS;UAChC2D,SAAA,EAAWjE,MAAA,CAAOuD,KAAK,EAAES,UAAA,EAAYC,SAAA;UACrCE,WAAA,EAAa;YACX3C,IAAA,EAAMV,GAAA,CAAIU,IAAI;YACdT,OAAA,EAASD,GAAA,CAAIC,OAAO;YACpBF,WAAA;YACAuD,MAAA,EAAQtD,GAAA,CAAIsD,MAAM;YAClB5B,IAAA,EAAM1B,GAAA,CAAI0B;UACZ;oBAECzC;aAGHA,QAAA;uBAGJN,IAAA,CAAC;QAAI4E,EAAA,EAAG;;;;AAIhB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["applyLocaleFiltering","React","Suspense","getNavPrefs","ProgressBar","RootProvider","checkDependencies","getClientConfig","getLanguageDir","getRequestEmbed","getRequestHighContrast","getRequestTheme","initReq","NestProviders","getViewportMeta","metadata","description","title","RootLayout","props","additionalDependencyChecks","content","_jsx","RootLayoutContent","process","env","PAYLOAD_CACHE_COMPONENTS_ENABLED","fallback","children","config","configPromise","fonts","head","headFromProps","htmlProps","importMap","RouterAdapter","serverAdapter","serverFunction","cookies","headers","languageCode","permissions","req","payload","user","key","theme","highContrastMode","dir","embed","languageOptions","Object","entries","i18n","supportedLanguages","reduce","acc","language","languageConfig","keys","includes","push","label","translations","general","thisLanguage","value","navPrefs","clientConfig","fontClassNames","map","f","variable","className","filter","Boolean","viewportMeta","get","undefined","_jsxs","join","lang","suppressHydrationWarning","admin","dateFNSKey","fallbackLang","fallbackLanguage","isNavOpen","open","locale","Array","isArray","components","providers","length","serverProps","server","id"],"sources":["../../../src/layouts/Root/index.tsx"],"sourcesContent":["import type {\n ImportMap,\n LanguageOptions,\n SanitizedConfig,\n ServerAdapter,\n ServerFunctionClient,\n} from 'payload'\n\nimport { applyLocaleFiltering } from 'payload/shared'\nimport React, { Suspense } from 'react'\n\nimport { getNavPrefs } from '../../elements/Nav/getNavPrefs.js'\n// eslint-disable-next-line payload/no-imports-from-exports-dir -- Server component must reference exports/client bundle for proper client boundary in prod builds\nimport { ProgressBar, RootProvider } from '../../exports/client/index.js'\nimport { checkDependencies, type CheckDependenciesArgs } from '../../utilities/checkDependencies.js'\nimport { getClientConfig } from '../../utilities/getClientConfig.js'\nimport { getLanguageDir } from '../../utilities/getLanguageDir.js'\nimport { getRequestEmbed } from '../../utilities/getRequestEmbed.js'\nimport { getRequestHighContrast } from '../../utilities/getRequestHighContrast.js'\nimport { getRequestTheme } from '../../utilities/getRequestTheme.js'\nimport { initReq } from '../../utilities/initReq.js'\nimport { NestProviders } from './NestProviders.js'\nimport { getViewportMeta } from './viewport.js'\n// eslint-disable-next-line payload/no-imports-from-self -- Self-import via package path ensures consumer's bundler resolves the full CSS chain (design tokens, preflight, etc.) in prod builds\nimport '@payloadcms/ui/css/app.css'\n\ntype Font = {\n className?: string\n variable?: string\n}\n\nexport const metadata = {\n description: 'Generated by Next.js',\n title: 'Next.js',\n}\n\ntype RootLayoutProps = {\n /**\n * Framework-specific peer-dependency version constraints, merged on top of the\n * universal React/react-dom checks. Each framework adapter supplies its own\n * (e.g. Next.js passes `{ dependencyVersions: { next: { version: '>=15.0.0' } } }`).\n */\n readonly additionalDependencyChecks?: CheckDependenciesArgs\n readonly children: React.ReactNode\n readonly config: Promise<SanitizedConfig>\n /**\n * Fonts to apply to the admin `<html>` element. Each entry's\n * `variable ?? className` is appended to the `<html>` class list.\n * Framework-specific font loaders (e.g. `next/font`) are supplied by the caller.\n */\n readonly fonts?: Font[]\n /**\n * Custom content to render inside the admin panel's `<head>` element.\n *\n * Use this to inject scripts, meta tags, or links — for example, analytics\n * snippets via `next/script`, custom favicons, or preconnect hints.\n *\n * @example\n * ```tsx\n * import Script from 'next/script'\n *\n * <RootLayout\n * head={<Script src=\"https://example.com/analytics.js\" strategy=\"afterInteractive\" />}\n * {...rest}\n * />\n * ```\n */\n readonly head?: React.ReactNode\n readonly htmlProps?: React.HtmlHTMLAttributes<HTMLHtmlElement>\n readonly importMap: ImportMap\n /**\n * Client router adapter. Caller supplies a framework-specific provider\n * (for Next.js use the `NextRouterAdapter` exported from `@payloadcms/next`).\n */\n readonly RouterAdapter: React.FC<{ children: React.ReactNode }>\n /**\n * Server adapter providing framework-specific access to headers, cookies, redirects,\n * and other server APIs (for Next.js use `nextServerAdapter` from `@payloadcms/next`).\n */\n readonly serverAdapter: ServerAdapter\n readonly serverFunction: ServerFunctionClient\n}\n\nexport const RootLayout = (props: RootLayoutProps) => {\n checkDependencies(props.additionalDependencyChecks)\n\n const content = <RootLayoutContent {...props} />\n\n if (process.env.PAYLOAD_CACHE_COMPONENTS_ENABLED === 'true') {\n return <Suspense fallback={null}>{content}</Suspense>\n }\n\n return content\n}\n\nconst RootLayoutContent = async ({\n children,\n config: configPromise,\n fonts = [],\n head: headFromProps,\n htmlProps = {},\n importMap,\n RouterAdapter,\n serverAdapter,\n serverFunction,\n}: RootLayoutProps) => {\n const {\n cookies,\n headers,\n languageCode,\n permissions,\n req,\n req: {\n payload: { config },\n },\n user,\n } = await initReq({ configPromise, importMap, key: 'RootLayout', serverAdapter })\n\n const theme = getRequestTheme({\n config,\n cookies,\n headers,\n })\n\n const highContrastMode = getRequestHighContrast({\n config,\n cookies,\n headers,\n })\n\n const dir = getLanguageDir({ languageCode })\n const embed = getRequestEmbed({ config, cookies })\n\n const languageOptions: LanguageOptions = Object.entries(\n config.i18n.supportedLanguages || {},\n ).reduce((acc, [language, languageConfig]) => {\n if (Object.keys(config.i18n.supportedLanguages).includes(language)) {\n acc.push({\n label: languageConfig.translations.general.thisLanguage,\n value: language,\n })\n }\n\n return acc\n }, [])\n\n const navPrefs = await getNavPrefs(req)\n\n const clientConfig = getClientConfig({\n config,\n i18n: req.i18n,\n importMap,\n user,\n })\n\n await applyLocaleFiltering({ clientConfig, config, req })\n\n const fontClassNames = fonts.map((f) => f.variable ?? f.className).filter(Boolean)\n const viewportMeta = getViewportMeta(headers.get('user-agent') ?? undefined)\n\n return (\n <html\n {...htmlProps}\n className={[...fontClassNames, htmlProps?.className].filter(Boolean).join(' ')}\n data-enhanced-contrast={highContrastMode ? '' : undefined}\n data-theme={theme}\n dir={dir}\n lang={languageCode}\n suppressHydrationWarning={config?.admin?.suppressHydrationWarning ?? false}\n >\n <head>\n {viewportMeta}\n <style>{`@layer payload-default, payload;`}</style>\n {headFromProps}\n </head>\n <body>\n <RootProvider\n config={clientConfig}\n dateFNSKey={req.i18n.dateFNSKey}\n embed={embed}\n fallbackLang={config.i18n.fallbackLanguage}\n highContrastMode={highContrastMode}\n isNavOpen={navPrefs?.open ?? true}\n languageCode={languageCode}\n languageOptions={languageOptions}\n locale={req.locale}\n permissions={user ? permissions : null}\n RouterAdapter={RouterAdapter}\n serverFunction={serverFunction}\n theme={theme}\n translations={req.i18n.translations}\n user={user}\n >\n <ProgressBar />\n {Array.isArray(config.admin?.components?.providers) &&\n config.admin?.components?.providers.length > 0 ? (\n <NestProviders\n importMap={req.payload.importMap}\n providers={config.admin?.components?.providers}\n serverProps={{\n i18n: req.i18n,\n payload: req.payload,\n permissions,\n server: req.server,\n user,\n }}\n >\n {children}\n </NestProviders>\n ) : (\n children\n )}\n </RootProvider>\n <div id=\"portal\" />\n </body>\n </html>\n )\n}\n"],"mappings":";AAQA,SAASA,oBAAoB,QAAQ;AACrC,OAAOC,KAAA,IAASC,QAAQ,QAAQ;AAEhC,SAASC,WAAW,QAAQ;AAC5B;AACA,SAASC,WAAW,EAAEC,YAAY,QAAQ;AAC1C,SAASC,iBAAiB,QAAoC;AAC9D,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,eAAe,QAAQ;AAChC,SAASC,OAA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AAA,EAAG;;;;AAIhB","ignoreList":[]}
@@ -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;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;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,CAwQlE,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,CAgRlE,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';
@@ -39,7 +40,13 @@ export const LivePreviewProvider = ({
39
40
  width: '100%'
40
41
  }], [incomingBreakpoints]);
41
42
  const [url, setURL] = useState('');
42
- const [previewURL, setPreviewURL] = useState(previewURLFromProps);
43
+ const [previewURL, _setPreviewURL] = useState();
44
+ const setPreviewURL = useCallback(incomingURL => {
45
+ _setPreviewURL(isHttpURL(incomingURL) ? incomingURL : undefined);
46
+ }, []);
47
+ useEffect(() => {
48
+ setPreviewURL(previewURLFromProps);
49
+ }, [previewURLFromProps, setPreviewURL]);
43
50
  const {
44
51
  isPopupOpen,
45
52
  openPopupWindow,
@@ -84,16 +91,16 @@ export const LivePreviewProvider = ({
84
91
  * - resets `appIsReady` to `false` while the new URL is loading
85
92
  */
86
93
  const setLivePreviewURL = useCallback(_incomingURL => {
87
- let incomingURL;
94
+ let incomingURL_0;
88
95
  if (typeof _incomingURL === 'string') {
89
- incomingURL = formatAbsoluteURL(_incomingURL);
96
+ incomingURL_0 = formatAbsoluteURL(_incomingURL);
90
97
  }
91
- if (!incomingURL) {
98
+ if (!incomingURL_0) {
92
99
  setIsLivePreviewing(false);
93
100
  }
94
- if (incomingURL !== url) {
101
+ if (incomingURL_0 !== url) {
95
102
  setAppIsReady(false);
96
- setURL(incomingURL);
103
+ setURL(incomingURL_0);
97
104
  }
98
105
  }, [setIsLivePreviewing, url]);
99
106
  /**
@@ -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","_setIsLivePreviewing","shouldRenderIframe","setShouldRenderIframe","setIsLivePreviewing","livePreviewing","name","height","label","width","setURL","setPreviewURL","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","lastReadyAt","setLastReadyAt","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","isExpanded","setIsExpanded","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","Date","now","window","addEventListener","removeEventListener","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 [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 // Tracks when any preview (iframe or popup) signals it's ready\n // Used to trigger an initial sync to newly opened previews\n const [lastReadyAt, setLastReadyAt] = useState<number>(0)\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 [isExpanded, setIsExpanded] = useState(false)\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 [setIsLivePreviewing, 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 setLastReadyAt(Date.now())\n }\n }\n }\n\n window.addEventListener('message', handleMessage)\n\n return () => {\n window.removeEventListener('message', handleMessage)\n }\n }, [url])\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 isExpanded,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n isPreviewEnabled,\n lastReadyAt,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewURL,\n setBreakpoint,\n setHeight,\n setIsExpanded,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\n setPreviewURL,\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,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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2C,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","_setIsLivePreviewing","shouldRenderIframe","setShouldRenderIframe","setIsLivePreviewing","livePreviewing","name","height","label","width","setURL","_setPreviewURL","setPreviewURL","incomingURL","undefined","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","lastReadyAt","setLastReadyAt","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","isExpanded","setIsExpanded","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","Date","now","window","addEventListener","removeEventListener","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 [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 // Tracks when any preview (iframe or popup) signals it's ready\n // Used to trigger an initial sync to newly opened previews\n const [lastReadyAt, setLastReadyAt] = useState<number>(0)\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 [isExpanded, setIsExpanded] = useState(false)\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 [setIsLivePreviewing, 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 setLastReadyAt(Date.now())\n }\n }\n }\n\n window.addEventListener('message', handleMessage)\n\n return () => {\n window.removeEventListener('message', handleMessage)\n }\n }, [url])\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 isExpanded,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n isPreviewEnabled,\n lastReadyAt,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewURL,\n setBreakpoint,\n setHeight,\n setIsExpanded,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\n setPreviewURL,\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,mB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