@strapi/content-manager 5.23.0 → 5.23.1

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 (74) hide show
  1. package/dist/admin/components/LeftMenu.js +13 -15
  2. package/dist/admin/components/LeftMenu.js.map +1 -1
  3. package/dist/admin/components/LeftMenu.mjs +14 -16
  4. package/dist/admin/components/LeftMenu.mjs.map +1 -1
  5. package/dist/admin/components/Widgets.js +4 -2
  6. package/dist/admin/components/Widgets.js.map +1 -1
  7. package/dist/admin/components/Widgets.mjs +4 -2
  8. package/dist/admin/components/Widgets.mjs.map +1 -1
  9. package/dist/admin/pages/EditView/EditViewPage.js +3 -11
  10. package/dist/admin/pages/EditView/EditViewPage.js.map +1 -1
  11. package/dist/admin/pages/EditView/EditViewPage.mjs +4 -12
  12. package/dist/admin/pages/EditView/EditViewPage.mjs.map +1 -1
  13. package/dist/admin/pages/EditView/components/Blocker.js +18 -0
  14. package/dist/admin/pages/EditView/components/Blocker.js.map +1 -0
  15. package/dist/admin/pages/EditView/components/Blocker.mjs +16 -0
  16. package/dist/admin/pages/EditView/components/Blocker.mjs.map +1 -0
  17. package/dist/admin/pages/EditView/components/InputRenderer.js +15 -5
  18. package/dist/admin/pages/EditView/components/InputRenderer.js.map +1 -1
  19. package/dist/admin/pages/EditView/components/InputRenderer.mjs +15 -5
  20. package/dist/admin/pages/EditView/components/InputRenderer.mjs.map +1 -1
  21. package/dist/admin/pages/EditView/utils/data.js +26 -7
  22. package/dist/admin/pages/EditView/utils/data.js.map +1 -1
  23. package/dist/admin/pages/EditView/utils/data.mjs +26 -7
  24. package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
  25. package/dist/admin/preview/components/InputPopover.js +73 -0
  26. package/dist/admin/preview/components/InputPopover.js.map +1 -0
  27. package/dist/admin/preview/components/InputPopover.mjs +70 -0
  28. package/dist/admin/preview/components/InputPopover.mjs.map +1 -0
  29. package/dist/admin/preview/hooks/usePreviewInputManager.js +67 -0
  30. package/dist/admin/preview/hooks/usePreviewInputManager.js.map +1 -0
  31. package/dist/admin/preview/hooks/usePreviewInputManager.mjs +46 -0
  32. package/dist/admin/preview/hooks/usePreviewInputManager.mjs.map +1 -0
  33. package/dist/admin/preview/pages/Preview.js +119 -118
  34. package/dist/admin/preview/pages/Preview.js.map +1 -1
  35. package/dist/admin/preview/pages/Preview.mjs +120 -119
  36. package/dist/admin/preview/pages/Preview.mjs.map +1 -1
  37. package/dist/admin/preview/utils/constants.js +2 -1
  38. package/dist/admin/preview/utils/constants.js.map +1 -1
  39. package/dist/admin/preview/utils/constants.mjs +2 -2
  40. package/dist/admin/preview/utils/constants.mjs.map +1 -1
  41. package/dist/admin/preview/utils/getSendMessage.js +22 -0
  42. package/dist/admin/preview/utils/getSendMessage.js.map +1 -0
  43. package/dist/admin/preview/utils/getSendMessage.mjs +20 -0
  44. package/dist/admin/preview/utils/getSendMessage.mjs.map +1 -0
  45. package/dist/admin/preview/utils/previewScript.js +103 -10
  46. package/dist/admin/preview/utils/previewScript.js.map +1 -1
  47. package/dist/admin/preview/utils/previewScript.mjs +103 -10
  48. package/dist/admin/preview/utils/previewScript.mjs.map +1 -1
  49. package/dist/admin/src/pages/EditView/components/Blocker.d.ts +5 -0
  50. package/dist/admin/src/pages/EditView/components/InputRenderer.d.ts +1 -1
  51. package/dist/admin/src/preview/components/InputPopover.d.ts +6 -0
  52. package/dist/admin/src/preview/hooks/usePreviewInputManager.d.ts +4 -0
  53. package/dist/admin/src/preview/pages/Preview.d.ts +8 -0
  54. package/dist/admin/src/preview/utils/constants.d.ts +4 -1
  55. package/dist/admin/src/preview/utils/getSendMessage.d.ts +11 -0
  56. package/dist/admin/src/preview/utils/previewScript.d.ts +5 -1
  57. package/dist/admin/translations/en.json.js +1 -0
  58. package/dist/admin/translations/en.json.js.map +1 -1
  59. package/dist/admin/translations/en.json.mjs +1 -0
  60. package/dist/admin/translations/en.json.mjs.map +1 -1
  61. package/dist/admin/translations/es.json.js +1 -0
  62. package/dist/admin/translations/es.json.js.map +1 -1
  63. package/dist/admin/translations/es.json.mjs +1 -0
  64. package/dist/admin/translations/es.json.mjs.map +1 -1
  65. package/dist/admin/translations/fr.json.js +1 -0
  66. package/dist/admin/translations/fr.json.js.map +1 -1
  67. package/dist/admin/translations/fr.json.mjs +1 -0
  68. package/dist/admin/translations/fr.json.mjs.map +1 -1
  69. package/dist/server/homepage/services/homepage.js +1 -1
  70. package/dist/server/homepage/services/homepage.js.map +1 -1
  71. package/dist/server/homepage/services/homepage.mjs +1 -1
  72. package/dist/server/homepage/services/homepage.mjs.map +1 -1
  73. package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
  74. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"InputRenderer.mjs","sources":["../../../../../admin/src/pages/EditView/components/InputRenderer.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n useStrapiApp,\n useForm,\n InputRenderer as FormInputRenderer,\n useField,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\n\nimport { SINGLE_TYPES } from '../../../constants/collections';\nimport { useDocumentRBAC } from '../../../features/DocumentRBAC';\nimport { type UseDocument } from '../../../hooks/useDocument';\nimport { useDocumentContext } from '../../../hooks/useDocumentContext';\nimport { useDocumentLayout } from '../../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../../hooks/useLazyComponents';\n\nimport { BlocksInput } from './FormInputs/BlocksInput/BlocksInput';\nimport { ComponentInput } from './FormInputs/Component/Input';\nimport { DynamicZone, useDynamicZone } from './FormInputs/DynamicZone/Field';\nimport { NotAllowedInput } from './FormInputs/NotAllowed';\nimport { RelationsInput } from './FormInputs/Relations/Relations';\nimport { UIDInput } from './FormInputs/UID';\nimport { Wysiwyg } from './FormInputs/Wysiwyg/Field';\n\nimport type { EditFieldLayout } from '../../../hooks/useDocumentLayout';\nimport type { Schema } from '@strapi/types';\nimport type { DistributiveOmit } from 'react-redux';\n\ntype InputRendererProps = DistributiveOmit<EditFieldLayout, 'size'> & {\n document: ReturnType<UseDocument>;\n};\n\n/**\n * @internal\n *\n * @description An abstraction around the regular form input renderer designed\n * specifically to be used in the EditView of the content-manager this understands\n * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific\n * components such as Blocks / Relations.\n */\nconst InputRenderer = ({ visible, hint: providedHint, document, ...props }: InputRendererProps) => {\n const { currentDocumentMeta } = useDocumentContext('DynamicComponent');\n const {\n edit: { components },\n } = useDocumentLayout(currentDocumentMeta.model);\n\n const collectionType =\n document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';\n\n const isInDynamicZone = useDynamicZone('isInDynamicZone', (state) => state.isInDynamicZone);\n\n const isFormDisabled = useForm('InputRenderer', (state) => state.disabled);\n const canCreateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canCreateFields);\n const canReadFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canReadFields);\n const canUpdateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUpdateFields);\n const canUserAction = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUserAction);\n\n let idToCheck = document.document?.documentId;\n if (collectionType === SINGLE_TYPES) {\n idToCheck = document?.document?.documentId;\n }\n\n const editableFields = idToCheck ? canUpdateFields : canCreateFields;\n const readableFields = idToCheck ? canReadFields : canCreateFields;\n\n /**\n * Component fields are always readable and editable,\n * however the fields within them may not be.\n */\n const canUserReadField = canUserAction(props.name, readableFields, props.type);\n const canUserEditField = canUserAction(props.name, editableFields, props.type);\n\n const fields = useStrapiApp('InputRenderer', (app) => app.fields);\n const { lazyComponentStore } = useLazyComponents(\n attributeHasCustomFieldProperty(props.attribute) ? [props.attribute.customField] : undefined\n );\n\n const hint = useFieldHint(providedHint, props.attribute);\n\n // We pass field in case of Custom Fields to keep backward compatibility\n const field = useField(props.name);\n\n if (!visible) {\n return null;\n }\n\n /**\n * If the user can't read the field then we don't want to ever render it.\n */\n if (!canUserReadField && !isInDynamicZone) {\n return <NotAllowedInput hint={hint} {...props} />;\n }\n\n const fieldIsDisabled =\n (!canUserEditField && !isInDynamicZone) || props.disabled || isFormDisabled;\n\n /**\n * Because a custom field has a unique prop but the type could be confused with either\n * the useField hook or the type of the field we need to handle it separately and first.\n */\n if (attributeHasCustomFieldProperty(props.attribute)) {\n const CustomInput = lazyComponentStore[props.attribute.customField];\n\n if (CustomInput) {\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n return <CustomInput {...props} {...field} hint={hint} disabled={fieldIsDisabled} />;\n }\n\n return (\n <FormInputRenderer\n {...props}\n hint={hint}\n // @ts-expect-error – this workaround lets us display that the custom field is missing.\n type={props.attribute.customField}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * This is where we handle ONLY the fields from the `useLibrary` hook.\n */\n const addedInputTypes = Object.keys(fields);\n if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {\n const CustomInput = fields[props.type];\n // @ts-expect-error – TODO: fix this type error in the useLibrary hook.\n return <CustomInput {...props} hint={hint} disabled={fieldIsDisabled} />;\n }\n\n /**\n * These include the content-manager specific fields, failing that we fall back\n * to the more generic form input renderer.\n */\n switch (props.type) {\n case 'blocks':\n return <BlocksInput {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n case 'component':\n return (\n <ComponentInput\n {...props}\n hint={hint}\n layout={components[props.attribute.component].layout}\n disabled={fieldIsDisabled}\n >\n {(inputProps) => <InputRenderer {...inputProps} />}\n </ComponentInput>\n );\n case 'dynamiczone':\n return <DynamicZone {...props} hint={hint} disabled={fieldIsDisabled} />;\n case 'relation':\n return <RelationsInput {...props} hint={hint} disabled={fieldIsDisabled} />;\n case 'richtext':\n return <Wysiwyg {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n case 'uid':\n return <UIDInput {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n /**\n * Enumerations are a special case because they require options.\n */\n case 'enumeration':\n return (\n <FormInputRenderer\n {...props}\n hint={hint}\n options={props.attribute.enum.map((value) => ({ value }))}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n default:\n // These props are not needed for the generic form input renderer.\n const { unique: _unique, mainField: _mainField, ...restProps } = props;\n return (\n <FormInputRenderer\n {...restProps}\n hint={hint}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n }\n};\n\nconst attributeHasCustomFieldProperty = (\n attribute: Schema.Attribute.AnyAttribute\n): attribute is Schema.Attribute.AnyAttribute & Schema.Attribute.CustomField<string> =>\n 'customField' in attribute && typeof attribute.customField === 'string';\n\nconst useFieldHint = (\n hint: React.ReactNode = undefined,\n attribute: Schema.Attribute.AnyAttribute\n) => {\n const { formatMessage } = useIntl();\n\n const { maximum, minimum } = getMinMax(attribute);\n\n if (!maximum && !minimum) {\n return hint;\n }\n\n const units = !['biginteger', 'integer', 'number', 'dynamiczone', 'component'].includes(\n attribute.type\n )\n ? formatMessage(\n {\n id: 'content-manager.form.Input.hint.character.unit',\n defaultMessage: '{maxValue, plural, one { character} other { characters}}',\n },\n {\n maxValue: Math.max(minimum || 0, maximum || 0),\n }\n )\n : null;\n\n const hasMinAndMax = typeof minimum === 'number' && typeof maximum === 'number';\n\n return formatMessage(\n {\n id: 'content-manager.form.Input.hint.text',\n defaultMessage:\n '{min, select, undefined {} other {min. {min}}}{divider}{max, select, undefined {} other {max. {max}}}{unit}{br}{description}',\n },\n {\n min: minimum,\n max: maximum,\n description: hint,\n unit: units,\n divider: hasMinAndMax\n ? formatMessage({\n id: 'content-manager.form.Input.hint.minMaxDivider',\n defaultMessage: ' / ',\n })\n : null,\n br: <br />,\n }\n );\n};\n\nconst getMinMax = (attribute: Schema.Attribute.AnyAttribute) => {\n if ('min' in attribute || 'max' in attribute) {\n return {\n maximum: !Number.isNaN(Number(attribute.max)) ? Number(attribute.max) : undefined,\n minimum: !Number.isNaN(Number(attribute.min)) ? Number(attribute.min) : undefined,\n };\n } else if ('maxLength' in attribute || 'minLength' in attribute) {\n return { maximum: attribute.maxLength, minimum: attribute.minLength };\n } else {\n return { maximum: undefined, minimum: undefined };\n }\n};\n\nconst MemoizedInputRenderer = React.memo(InputRenderer);\n\nexport type { InputRendererProps };\nexport { MemoizedInputRenderer as InputRenderer, useFieldHint };\n"],"names":["InputRenderer","visible","hint","providedHint","document","props","currentDocumentMeta","useDocumentContext","edit","components","useDocumentLayout","model","collectionType","schema","kind","isInDynamicZone","useDynamicZone","state","isFormDisabled","useForm","disabled","canCreateFields","useDocumentRBAC","rbac","canReadFields","canUpdateFields","canUserAction","idToCheck","documentId","SINGLE_TYPES","editableFields","readableFields","canUserReadField","name","type","canUserEditField","fields","useStrapiApp","app","lazyComponentStore","useLazyComponents","attributeHasCustomFieldProperty","attribute","customField","undefined","useFieldHint","field","useField","_jsx","NotAllowedInput","fieldIsDisabled","CustomInput","FormInputRenderer","addedInputTypes","Object","keys","includes","BlocksInput","ComponentInput","layout","component","inputProps","DynamicZone","RelationsInput","Wysiwyg","UIDInput","options","enum","map","value","unique","_unique","mainField","_mainField","restProps","formatMessage","useIntl","maximum","minimum","getMinMax","units","id","defaultMessage","maxValue","Math","max","hasMinAndMax","min","description","unit","divider","br","Number","isNaN","maxLength","minLength","MemoizedInputRenderer","React","memo"],"mappings":";;;;;;;;;;;;;;;;;AAiCA;;;;;;;AAOC,IACD,MAAMA,aAAAA,GAAgB,CAAC,EAAEC,OAAO,EAAEC,IAAMC,EAAAA,YAAY,EAAEC,QAAQ,EAAE,GAAGC,KAA2B,EAAA,GAAA;AAC5F,IAAA,MAAM,EAAEC,mBAAmB,EAAE,GAAGC,kBAAmB,CAAA,kBAAA,CAAA;IACnD,MAAM,EACJC,MAAM,EAAEC,UAAU,EAAE,EACrB,GAAGC,iBAAkBJ,CAAAA,mBAAAA,CAAoBK,KAAK,CAAA;AAE/C,IAAA,MAAMC,iB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AA;AAEJ;AAEA,MAAMZ,YAAY,CAACrC,SAAAA,GAAAA;IACjB,IAAI,KAAA,IAASA,SAAa,IAAA,KAAA,IAASA,SAAW,EAAA;QAC5C,OAAO;YACLmC,OAAS,EAAA,CAACe,MAAOC,CAAAA,KAAK,CAACD,MAAAA,CAAOlD,SAAU2C,CAAAA,GAAG,CAAKO,CAAAA,GAAAA,MAAAA,CAAOlD,SAAU2C,CAAAA,GAAG,CAAIzC,GAAAA,SAAAA;YACxEkC,OAAS,EAAA,CAACc,MAAOC,CAAAA,KAAK,CAACD,MAAAA,CAAOlD,SAAU6C,CAAAA,GAAG,CAAKK,CAAAA,GAAAA,MAAAA,CAAOlD,SAAU6C,CAAAA,GAAG,CAAI3C,GAAAA;AAC1E,SAAA;AACF,KAAA,MAAO,IAAI,WAAA,IAAeF,SAAa,IAAA,WAAA,IAAeA,SAAW,EAAA;QAC/D,OAAO;AAAEmC,YAAAA,OAAAA,EAASnC,UAAUoD,SAAS;AAAEhB,YAAAA,OAAAA,EAASpC,UAAUqD;AAAU,SAAA;KAC/D,MAAA;QACL,OAAO;YAAElB,OAASjC,EAAAA,SAAAA;YAAWkC,OAASlC,EAAAA;AAAU,SAAA;AAClD;AACF,CAAA;AAEMoD,MAAAA,qBAAAA,iBAAwBC,KAAMC,CAAAA,IAAI,CAAClG,aAAAA;;;;"}
1
+ {"version":3,"file":"InputRenderer.mjs","sources":["../../../../../admin/src/pages/EditView/components/InputRenderer.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n useStrapiApp,\n useForm,\n InputRenderer as FormInputRenderer,\n useField,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\n\nimport { SINGLE_TYPES } from '../../../constants/collections';\nimport { useDocumentRBAC } from '../../../features/DocumentRBAC';\nimport { type UseDocument } from '../../../hooks/useDocument';\nimport { useDocumentContext } from '../../../hooks/useDocumentContext';\nimport { useDocumentLayout } from '../../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../../hooks/useLazyComponents';\nimport { usePreviewInputManager } from '../../../preview/hooks/usePreviewInputManager';\n\nimport { BlocksInput } from './FormInputs/BlocksInput/BlocksInput';\nimport { ComponentInput } from './FormInputs/Component/Input';\nimport { DynamicZone, useDynamicZone } from './FormInputs/DynamicZone/Field';\nimport { NotAllowedInput } from './FormInputs/NotAllowed';\nimport { RelationsInput } from './FormInputs/Relations/Relations';\nimport { UIDInput } from './FormInputs/UID';\nimport { Wysiwyg } from './FormInputs/Wysiwyg/Field';\n\nimport type { EditFieldLayout } from '../../../hooks/useDocumentLayout';\nimport type { Schema } from '@strapi/types';\nimport type { DistributiveOmit } from 'react-redux';\n\ntype InputRendererProps = DistributiveOmit<EditFieldLayout, 'size'> & {\n document: ReturnType<UseDocument>;\n};\n\n/**\n * @internal\n *\n * @description An abstraction around the regular form input renderer designed\n * specifically to be used in the EditView of the content-manager this understands\n * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific\n * components such as Blocks / Relations.\n */\nconst InputRenderer = ({\n visible,\n hint: providedHint,\n document,\n ...inputProps\n}: InputRendererProps) => {\n const { currentDocumentMeta } = useDocumentContext('DynamicComponent');\n const {\n edit: { components },\n } = useDocumentLayout(currentDocumentMeta.model);\n\n const collectionType =\n document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';\n\n const isInDynamicZone = useDynamicZone('isInDynamicZone', (state) => state.isInDynamicZone);\n\n const isFormDisabled = useForm('InputRenderer', (state) => state.disabled);\n const canCreateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canCreateFields);\n const canReadFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canReadFields);\n const canUpdateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUpdateFields);\n const canUserAction = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUserAction);\n\n let idToCheck = document.document?.documentId;\n if (collectionType === SINGLE_TYPES) {\n idToCheck = document?.document?.documentId;\n }\n\n const editableFields = idToCheck ? canUpdateFields : canCreateFields;\n const readableFields = idToCheck ? canReadFields : canCreateFields;\n\n // Everything preview related\n const previewProps = usePreviewInputManager(inputProps.name);\n const props = { ...inputProps, ...previewProps };\n\n /**\n * Component fields are always readable and editable,\n * however the fields within them may not be.\n */\n const canUserReadField = canUserAction(props.name, readableFields, props.type);\n const canUserEditField = canUserAction(props.name, editableFields, props.type);\n\n const fields = useStrapiApp('InputRenderer', (app) => app.fields);\n const { lazyComponentStore } = useLazyComponents(\n attributeHasCustomFieldProperty(props.attribute) ? [props.attribute.customField] : undefined\n );\n\n const hint = useFieldHint(providedHint, props.attribute);\n\n // We pass field in case of Custom Fields to keep backward compatibility\n const field = useField(props.name);\n\n if (!visible) {\n return null;\n }\n\n /**\n * If the user can't read the field then we don't want to ever render it.\n */\n if (!canUserReadField && !isInDynamicZone) {\n return <NotAllowedInput hint={hint} {...props} />;\n }\n\n const fieldIsDisabled =\n (!canUserEditField && !isInDynamicZone) || props.disabled || isFormDisabled;\n\n /**\n * Because a custom field has a unique prop but the type could be confused with either\n * the useField hook or the type of the field we need to handle it separately and first.\n */\n if (attributeHasCustomFieldProperty(props.attribute)) {\n const CustomInput = lazyComponentStore[props.attribute.customField];\n\n if (CustomInput) {\n return (\n <CustomInput\n {...props}\n {...field}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n return (\n <FormInputRenderer\n {...props}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – this workaround lets us display that the custom field is missing.\n type={props.attribute.customField}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * This is where we handle ONLY the fields from the `useLibrary` hook.\n */\n const addedInputTypes = Object.keys(fields);\n if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {\n const CustomInput = fields[props.type];\n return (\n <CustomInput\n {...props}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * These include the content-manager specific fields, failing that we fall back\n * to the more generic form input renderer.\n */\n switch (props.type) {\n case 'blocks':\n return <BlocksInput {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n case 'component':\n return (\n <ComponentInput\n {...props}\n hint={hint}\n layout={components[props.attribute.component].layout}\n disabled={fieldIsDisabled}\n >\n {(componentInputProps) => <InputRenderer {...componentInputProps} />}\n </ComponentInput>\n );\n case 'dynamiczone':\n return <DynamicZone {...props} hint={hint} disabled={fieldIsDisabled} />;\n case 'relation':\n return <RelationsInput {...props} hint={hint} disabled={fieldIsDisabled} />;\n case 'richtext':\n return <Wysiwyg {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n case 'uid':\n return <UIDInput {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n /**\n * Enumerations are a special case because they require options.\n */\n case 'enumeration':\n return (\n <FormInputRenderer\n {...props}\n {...previewProps}\n hint={hint}\n options={props.attribute.enum.map((value) => ({ value }))}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n default:\n // These props are not needed for the generic form input renderer.\n const { unique: _unique, mainField: _mainField, ...restProps } = props;\n return (\n <FormInputRenderer\n {...restProps}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n }\n};\n\nconst attributeHasCustomFieldProperty = (\n attribute: Schema.Attribute.AnyAttribute\n): attribute is Schema.Attribute.AnyAttribute & Schema.Attribute.CustomField<string> =>\n 'customField' in attribute && typeof attribute.customField === 'string';\n\nconst useFieldHint = (\n hint: React.ReactNode = undefined,\n attribute: Schema.Attribute.AnyAttribute\n) => {\n const { formatMessage } = useIntl();\n\n const { maximum, minimum } = getMinMax(attribute);\n\n if (!maximum && !minimum) {\n return hint;\n }\n\n const units = !['biginteger', 'integer', 'number', 'dynamiczone', 'component'].includes(\n attribute.type\n )\n ? formatMessage(\n {\n id: 'content-manager.form.Input.hint.character.unit',\n defaultMessage: '{maxValue, plural, one { character} other { characters}}',\n },\n {\n maxValue: Math.max(minimum || 0, maximum || 0),\n }\n )\n : null;\n\n const hasMinAndMax = typeof minimum === 'number' && typeof maximum === 'number';\n\n return formatMessage(\n {\n id: 'content-manager.form.Input.hint.text',\n defaultMessage:\n '{min, select, undefined {} other {min. {min}}}{divider}{max, select, undefined {} other {max. {max}}}{unit}{br}{description}',\n },\n {\n min: minimum,\n max: maximum,\n description: hint,\n unit: units,\n divider: hasMinAndMax\n ? formatMessage({\n id: 'content-manager.form.Input.hint.minMaxDivider',\n defaultMessage: ' / ',\n })\n : null,\n br: <br />,\n }\n );\n};\n\nconst getMinMax = (attribute: Schema.Attribute.AnyAttribute) => {\n if ('min' in attribute || 'max' in attribute) {\n return {\n maximum: !Number.isNaN(Number(attribute.max)) ? Number(attribute.max) : undefined,\n minimum: !Number.isNaN(Number(attribute.min)) ? Number(attribute.min) : undefined,\n };\n } else if ('maxLength' in attribute || 'minLength' in attribute) {\n return { maximum: attribute.maxLength, minimum: attribute.minLength };\n } else {\n return { maximum: undefined, minimum: undefined };\n }\n};\n\nconst MemoizedInputRenderer = React.memo(InputRenderer);\n\nexport type { InputRendererProps };\nexport { MemoizedInputRenderer as InputRenderer, useFieldHint };\n"],"names":["InputRenderer","visible","hint","providedHint","document","inputProps","currentDocumentMeta","useDocumentContext","edit","components","useDocumentLayout","model","collectionType","schema","kind","isInDynamicZone","useDynamicZone","state","isFormDisabled","useForm","disabled","canCreateFields","useDocumentRBAC","rbac","canReadFields","canUpdateFields","canUserAction","idToCheck","documentId","SINGLE_TYPES","editableFields","readableFields","previewProps","usePreviewInputManager","name","props","canUserReadField","type","canUserEditField","fields","useStrapiApp","app","lazyComponentStore","useLazyComponents","attributeHasCustomFieldProperty","attribute","customField","undefined","useFieldHint","field","useField","_jsx","NotAllowedInput","fieldIsDisabled","CustomInput","FormInputRenderer","addedInputTypes","Object","keys","includes","BlocksInput","ComponentInput","layout","component","componentInputProps","DynamicZone","RelationsInput","Wysiwyg","UIDInput","options","enum","map","value","unique","_unique","mainField","_mainField","restProps","formatMessage","useIntl","maximum","minimum","getMinMax","units","id","defaultMessage","maxValue","Math","max","hasMinAndMax","min","description","unit","divider","br","Number","isNaN","maxLength","minLength","MemoizedInputRenderer","React","memo"],"mappings":";;;;;;;;;;;;;;;;;;AAkCA;;;;;;;AAOC,IACD,MAAMA,aAAAA,GAAgB,CAAC,EACrBC,OAAO,EACPC,IAAMC,EAAAA,YAAY,EAClBC,QAAQ,EACR,GAAGC,UACgB,EAAA,GAAA;AACnB,IAAA,MAAM,EAAEC,mBAAmB,EAAE,GAAGC,kBAAmB,CAAA,kBAAA,CAAA;IACnD,MAAM,EACJC,MAAM,EAAEC,UAAU,EAAE,EACrB,GAAGC,iBAAkBJ,CAAAA,mBAAAA,CAAoBK,KAAK,CAAA;AAE/C,IAAA,MAAMC,iBACJR,QAASS,CAAAA,MAAM,EAAEC,IAAAA,KAAS,mBAAmB,kBAAqB,GAAA,cAAA;AAEpE,IAAA,MAAMC,kBAAkBC,cAAe,CAAA,iBAAA,EAAmB,CAACC,KAAAA,GAAUA,MAAMF,eAAe,CAAA;AAE1F,IAAA,MAAMG,iBAAiBC,OAAQ,CAAA,eAAA,EAAiB,CAACF,KAAAA,GAAUA,MAAMG,QAAQ,CAAA;AACzE,IAAA,MAAMC,kBAAkBC,eAAgB,CAAA,eAAA,EAAiB,CAACC,IAAAA,GAASA,KAAKF,eAAe,CAAA;AACvF,IAAA,MAAMG,gBAAgBF,eAAgB,CAAA,eAAA,EAAiB,CAACC,IAAAA,GAASA,KAAKC,aAAa,CAAA;AACnF,IAAA,MAAMC,kBAAkBH,eAAgB,CAAA,eAAA,EAAiB,CAACC,IAAAA,GAASA,KAAKE,eAAe,CAAA;AACvF,IAAA,MAAMC,gBAAgBJ,eAAgB,CAAA,eAAA,EAAiB,CAACC,IAAAA,GAASA,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C,CAAAA,GAAG,CAAI3C,GAAAA;AAC1E,SAAA;AACF,KAAA,MAAO,IAAI,WAAA,IAAeF,SAAa,IAAA,WAAA,IAAeA,SAAW,EAAA;QAC/D,OAAO;AAAEmC,YAAAA,OAAAA,EAASnC,UAAUoD,SAAS;AAAEhB,YAAAA,OAAAA,EAASpC,UAAUqD;AAAU,SAAA;KAC/D,MAAA;QACL,OAAO;YAAElB,OAASjC,EAAAA,SAAAA;YAAWkC,OAASlC,EAAAA;AAAU,SAAA;AAClD;AACF,CAAA;AAEMoD,MAAAA,qBAAAA,iBAAwBC,KAAMC,CAAAA,IAAI,CAACrG,aAAAA;;;;"}
@@ -127,6 +127,21 @@ const BLOCK_LIST_ATTRIBUTE_KEYS = [
127
127
  ])(schema, components), removeNullValues, prepareRelations(schema, components), prepareTempKeys(schema, components));
128
128
  return transformations(document);
129
129
  };
130
+ /**
131
+ * @internal
132
+ * @description Finds the initial value for a component or dynamic zone item (based on its __temp_key__ and not its index).
133
+ * @param initialValue - The initial values object.
134
+ * @param item - The item to find the initial value for.
135
+ * @returns The initial value for the item.
136
+ */ const getItemInitialValue = (initialValue, item)=>{
137
+ if (initialValue && Array.isArray(initialValue)) {
138
+ const matchingInitialItem = initialValue.find((initialItem)=>initialItem.__temp_key__ === item.__temp_key__);
139
+ if (matchingInitialItem) {
140
+ return matchingInitialItem;
141
+ }
142
+ }
143
+ return {};
144
+ };
130
145
  /**
131
146
  * Removes values from the data object if their corresponding attribute has a
132
147
  * visibility condition that evaluates to false.
@@ -167,14 +182,17 @@ const BLOCK_LIST_ATTRIBUTE_KEYS = [
167
182
  continue;
168
183
  }
169
184
  if (attrDef.repeatable && Array.isArray(value)) {
170
- result[attrName] = value.map((item, index)=>handleInvisibleAttributes(item, {
185
+ result[attrName] = value.map((item)=>{
186
+ const componentInitialValue = getItemInitialValue(initialValue, item);
187
+ return handleInvisibleAttributes(item, {
171
188
  schema: compSchema,
172
- initialValues: initialValue?.[index] ?? {},
189
+ initialValues: componentInitialValue,
173
190
  components
174
191
  }, [
175
192
  ...path,
176
- `${attrName}[${index}]`
177
- ], removedAttributes).data);
193
+ `${attrName}[${item.__temp_key__}]`
194
+ ], removedAttributes).data;
195
+ });
178
196
  } else {
179
197
  result[attrName] = handleInvisibleAttributes(value, {
180
198
  schema: compSchema,
@@ -193,16 +211,17 @@ const BLOCK_LIST_ATTRIBUTE_KEYS = [
193
211
  result[attrName] = [];
194
212
  continue;
195
213
  }
196
- result[attrName] = currentValue.map((dzItem, index)=>{
214
+ result[attrName] = currentValue.map((dzItem)=>{
197
215
  const compUID = dzItem?.__component;
198
216
  const compSchema = components[compUID];
217
+ const componentInitialValue = getItemInitialValue(initialValue, dzItem);
199
218
  const cleaned = handleInvisibleAttributes(dzItem, {
200
219
  schema: compSchema,
201
- initialValues: initialValue?.[index] ?? {},
220
+ initialValues: componentInitialValue,
202
221
  components
203
222
  }, [
204
223
  ...path,
205
- `${attrName}[${index}]`
224
+ `${attrName}[${dzItem.__temp_key__}]`
206
225
  ], removedAttributes).data;
207
226
  // For newly created components, we want to be sure that the id is undefined (in case of reordering items)
208
227
  const processedItem = dzItem.id === undefined || dzItem.id === null ? {
@@ -1 +1 @@
1
- {"version":3,"file":"data.js","sources":["../../../../../admin/src/pages/EditView/utils/data.ts"],"sourcesContent":["import { createRulesEngine } from '@strapi/admin/strapi-admin';\nimport { generateNKeysBetween } from 'fractional-indexing';\nimport pipe from 'lodash/fp/pipe';\n\nimport { DOCUMENT_META_FIELDS } from '../../../constants/attributes';\n\nimport type { ComponentsDictionary, Document } from '../../../hooks/useDocument';\nimport type { Schema, UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * traverseData\n * -----------------------------------------------------------------------------------------------*/\n\n// Make only attributes required since it's the only one Content History has\ntype PartialSchema = Partial<Schema.Schema> & Pick<Schema.Schema, 'attributes'>;\n\ntype Predicate = <TAttribute extends Schema.Attribute.AnyAttribute>(\n attribute: TAttribute,\n value: Schema.Attribute.Value<TAttribute>\n) => boolean;\ntype Transform = <TAttribute extends Schema.Attribute.AnyAttribute>(\n value: any,\n attribute: TAttribute\n) => any;\ntype AnyData = Omit<Document, 'id'>;\n\nconst BLOCK_LIST_ATTRIBUTE_KEYS = ['__component', '__temp_key__'];\n\n/**\n * @internal This function is used to traverse the data and transform the values.\n * Given a predicate function, it will transform the value (using the given transform function)\n * if the predicate returns true. If it finds that the attribute is a component or dynamiczone,\n * it will recursively traverse those data structures as well.\n *\n * It is possible to break the ContentManager by using this function incorrectly, for example,\n * if you transform a number into a string but the attribute type is a number, the ContentManager\n * will not be able to save the data and the Form will likely crash because the component it's\n * passing the data too won't succesfully be able to handle the value.\n */\nconst traverseData =\n (predicate: Predicate, transform: Transform) =>\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (data: AnyData = {}) => {\n const traverse = (datum: AnyData, attributes: Schema.Schema['attributes']) => {\n return Object.entries(datum).reduce<AnyData>((acc, [key, value]) => {\n const attribute = attributes[key];\n\n /**\n * If the attribute is a block list attribute, we don't want to transform it.\n * We also don't want to transform null or undefined values.\n */\n if (BLOCK_LIST_ATTRIBUTE_KEYS.includes(key) || value === null || value === undefined) {\n acc[key] = value;\n return acc;\n }\n\n if (attribute.type === 'component') {\n if (attribute.repeatable) {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n acc[key] = componentValue.map((componentData) =>\n traverse(componentData, components[attribute.component]?.attributes ?? {})\n );\n } else {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, false>>;\n\n acc[key] = traverse(componentValue, components[attribute.component]?.attributes ?? {});\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamicZoneValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n acc[key] = dynamicZoneValue.map((componentData) =>\n traverse(componentData, components[componentData.__component]?.attributes ?? {})\n );\n } else if (predicate(attribute, value)) {\n acc[key] = transform(value, attribute);\n } else {\n acc[key] = value;\n }\n\n return acc;\n }, {});\n };\n\n return traverse(data, schema.attributes);\n };\n\n/* -------------------------------------------------------------------------------------------------\n * removeProhibitedFields\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal Removes all the fields that are not allowed.\n */\nconst removeProhibitedFields = (prohibitedFields: Schema.Attribute.Kind[]) =>\n traverseData(\n (attribute) => prohibitedFields.includes(attribute.type),\n () => ''\n );\n\n/* -------------------------------------------------------------------------------------------------\n * prepareRelations\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Sets all relation values to an empty array.\n */\nconst prepareRelations = traverseData(\n (attribute) => attribute.type === 'relation',\n () => ({\n connect: [],\n disconnect: [],\n })\n);\n\n/* -------------------------------------------------------------------------------------------------\n * prepareTempKeys\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each component and dynamiczone item. This gives us\n * a stable identifier regardless of its ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = traverseData(\n (attribute) =>\n (attribute.type === 'component' && attribute.repeatable) || attribute.type === 'dynamiczone',\n (data) => {\n if (Array.isArray(data) && data.length > 0) {\n const keys = generateNKeysBetween(undefined, undefined, data.length);\n\n return data.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n }\n\n return data;\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * removeFieldsThatDontExistOnSchema\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Fields that don't exist in the schema like createdAt etc. are only on the first level (not nested),\n * as such we don't need to traverse the components to remove them.\n */\nconst removeFieldsThatDontExistOnSchema = (schema: PartialSchema) => (data: AnyData) => {\n const schemaKeys = Object.keys(schema.attributes);\n const dataKeys = Object.keys(data);\n\n const keysToRemove = dataKeys.filter((key) => !schemaKeys.includes(key));\n\n const revisedData = [...keysToRemove, ...DOCUMENT_META_FIELDS].reduce((acc, key) => {\n delete acc[key];\n\n return acc;\n }, structuredClone(data));\n\n return revisedData;\n};\n\n/**\n * @internal\n * @description We need to remove null fields from the data-structure because it will pass it\n * to the specific inputs breaking them as most would prefer empty strings or `undefined` if\n * they're controlled / uncontrolled.\n */\nconst removeNullValues = (data: AnyData) => {\n return Object.entries(data).reduce<AnyData>((acc, [key, value]) => {\n if (value === null) {\n return acc;\n }\n\n acc[key] = value;\n\n return acc;\n }, {});\n};\n\n/* -------------------------------------------------------------------------------------------------\n * transformDocuments\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Takes a document data structure (this could be from the API or a default form structure)\n * and applies consistent data transformations to it. This is also used when we add new components to the\n * form to ensure the data is correctly prepared from their default state e.g. relations are set to an empty array.\n */\nconst transformDocument =\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (document: AnyData) => {\n const transformations = pipe(\n removeFieldsThatDontExistOnSchema(schema),\n removeProhibitedFields(['password'])(schema, components),\n removeNullValues,\n prepareRelations(schema, components),\n prepareTempKeys(schema, components)\n );\n\n return transformations(document);\n };\n\ntype HandleOptions = {\n schema?: Schema.ContentType | Schema.Component;\n initialValues?: AnyData;\n components?: Record<string, Schema.Component>;\n};\n\ntype RemovedFieldPath = string;\n\n/**\n * Removes values from the data object if their corresponding attribute has a\n * visibility condition that evaluates to false.\n *\n * @param {object} schema - The content type schema (with attributes).\n * @param {object} data - The data object to filter based on visibility.\n * @returns {object} A new data object with only visible fields retained.\n */\nconst handleInvisibleAttributes = (\n data: AnyData,\n { schema, initialValues = {}, components = {} }: HandleOptions,\n path: string[] = [],\n removedAttributes: RemovedFieldPath[] = []\n): {\n data: AnyData;\n removedAttributes: RemovedFieldPath[];\n} => {\n if (!schema?.attributes) return { data, removedAttributes };\n\n const rulesEngine = createRulesEngine();\n const result: AnyData = {};\n\n for (const [attrName, attrDef] of Object.entries(schema.attributes)) {\n const fullPath = [...path, attrName].join('.');\n const condition = attrDef?.conditions?.visible;\n const isVisible = condition ? rulesEngine.evaluate(condition, { ...data, ...result }) : true;\n\n if (!isVisible) {\n removedAttributes.push(fullPath);\n continue;\n }\n\n const userProvided = Object.prototype.hasOwnProperty.call(data, attrName);\n const currentValue = userProvided ? data[attrName] : undefined;\n const initialValue = initialValues?.[attrName];\n\n // 🔹 Handle components\n if (attrDef.type === 'component') {\n const compSchema = components[attrDef.component];\n const value = currentValue ?? initialValue;\n\n if (!value) {\n result[attrName] = attrDef.repeatable ? [] : null;\n continue;\n }\n\n if (attrDef.repeatable && Array.isArray(value)) {\n result[attrName] = value.map(\n (item, index) =>\n handleInvisibleAttributes(\n item,\n {\n schema: compSchema,\n initialValues: initialValue?.[index] ?? {},\n components,\n },\n [...path, `${attrName}[${index}]`],\n removedAttributes\n ).data\n );\n } else {\n result[attrName] = handleInvisibleAttributes(\n value,\n {\n schema: compSchema,\n initialValues: initialValue ?? {},\n components,\n },\n [...path, attrName],\n removedAttributes\n ).data;\n }\n\n continue;\n }\n\n // 🔸 Handle dynamic zones\n if (attrDef.type === 'dynamiczone') {\n if (!Array.isArray(currentValue)) {\n result[attrName] = [];\n continue;\n }\n\n result[attrName] = currentValue.map((dzItem, index) => {\n const compUID = dzItem?.__component;\n const compSchema = components[compUID];\n\n const cleaned = handleInvisibleAttributes(\n dzItem,\n {\n schema: compSchema,\n initialValues: initialValue?.[index] ?? {},\n components,\n },\n [...path, `${attrName}[${index}]`],\n removedAttributes\n ).data;\n\n // For newly created components, we want to be sure that the id is undefined (in case of reordering items)\n const processedItem =\n dzItem.id === undefined || dzItem.id === null\n ? { __component: compUID, ...cleaned, id: undefined }\n : { __component: compUID, ...cleaned };\n\n return processedItem;\n });\n\n continue;\n }\n\n // 🟡 Handle scalar/primitive\n if (currentValue !== undefined) {\n result[attrName] = currentValue;\n } else if (initialValue !== undefined) {\n result[attrName] = initialValue;\n } else {\n if (attrName === 'id' || attrName === 'documentId') {\n // If the attribute is 'id', we don't want to set it to null, as it should not be removed.\n continue;\n }\n result[attrName] = null;\n }\n }\n\n return {\n data: result,\n removedAttributes,\n };\n};\n\nexport {\n removeProhibitedFields,\n prepareRelations,\n prepareTempKeys,\n removeFieldsThatDontExistOnSchema,\n transformDocument,\n handleInvisibleAttributes,\n};\nexport type { AnyData };\n"],"names":["BLOCK_LIST_ATTRIBUTE_KEYS","traverseData","predicate","transform","schema","components","data","traverse","datum","attributes","Object","entries","reduce","acc","key","value","attribute","includes","undefined","type","repeatable","componentValue","map","componentData","component","dynamicZoneValue","__component","removeProhibitedFields","prohibitedFields","prepareRelations","connect","disconnect","prepareTempKeys","Array","isArray","length","keys","generateNKeysBetween","index","__temp_key__","removeFieldsThatDontExistOnSchema","schemaKeys","dataKeys","keysToRemove","filter","revisedData","DOCUMENT_META_FIELDS","structuredClone","removeNullValues","transformDocument","document","transformations","pipe","handleInvisibleAttributes","initialValues","path","removedAttributes","rulesEngine","createRulesEngine","result","attrName","attrDef","fullPath","join","condition","conditions","visible","isVisible","evaluate","push","userProvided","prototype","hasOwnProperty","call","currentValue","initialValue","compSchema","item","dzItem","compUID","cleaned","processedItem","id"],"mappings":";;;;;;;AA0BA,MAAMA,yBAA4B,GAAA;AAAC,IAAA,aAAA;AAAe,IAAA;AAAe,CAAA;AAEjE;;;;;;;;;;AAUC,IACD,MAAMC,YAAAA,GACJ,CAACC,SAAAA,EAAsBC,YACvB,CAACC,MAAAA,EAAuBC,UAAmC,GAAA,EAAE,GAC7D,CAACC,IAAAA,GAAgB,EAAE,GAAA;YACjB,MAAMC,QAAAA,GAAW,CAACC,KAAgBC,EAAAA,UAAAA,GAAAA;gBAChC,OAAOC,MAAAA,CAAOC,OAAO,CAACH,KAAOI,CAAAA,CAAAA,MAAM,CAAU,CAACC,GAAAA,EAAK,CAACC,GAAAA,EAAKC,KAAM,CAAA,GAAA;oBAC7D,MAAMC,SAAAA,GAAYP,UAAU,CAACK,GAAI,CAAA;AAEjC;;;YAIA,IAAId,0BAA0BiB,QAAQ,CAACH,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,MAAA,IAAIC,iBAAiBzD,SAAW,EAAA;YACrCyC,MAAM,CAACC,SAAS,GAAGe,YAAAA;SACd,MAAA;YACL,IAAIf,QAAAA,KAAa,IAAQA,IAAAA,QAAAA,KAAa,YAAc,EAAA;AAElD,gBAAA;AACF;YACAD,MAAM,CAACC,SAAS,GAAG,IAAA;AACrB;AACF;IAEA,OAAO;QACLtD,IAAMqD,EAAAA,MAAAA;AACNH,QAAAA;AACF,KAAA;AACF;;;;;;;;;"}
1
+ {"version":3,"file":"data.js","sources":["../../../../../admin/src/pages/EditView/utils/data.ts"],"sourcesContent":["import { createRulesEngine } from '@strapi/admin/strapi-admin';\nimport { generateNKeysBetween } from 'fractional-indexing';\nimport pipe from 'lodash/fp/pipe';\n\nimport { DOCUMENT_META_FIELDS } from '../../../constants/attributes';\n\nimport type { ComponentsDictionary, Document } from '../../../hooks/useDocument';\nimport type { Schema, UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * traverseData\n * -----------------------------------------------------------------------------------------------*/\n\n// Make only attributes required since it's the only one Content History has\ntype PartialSchema = Partial<Schema.Schema> & Pick<Schema.Schema, 'attributes'>;\n\ntype Predicate = <TAttribute extends Schema.Attribute.AnyAttribute>(\n attribute: TAttribute,\n value: Schema.Attribute.Value<TAttribute>\n) => boolean;\ntype Transform = <TAttribute extends Schema.Attribute.AnyAttribute>(\n value: any,\n attribute: TAttribute\n) => any;\ntype AnyData = Omit<Document, 'id'>;\n\nconst BLOCK_LIST_ATTRIBUTE_KEYS = ['__component', '__temp_key__'];\n\n/**\n * @internal This function is used to traverse the data and transform the values.\n * Given a predicate function, it will transform the value (using the given transform function)\n * if the predicate returns true. If it finds that the attribute is a component or dynamiczone,\n * it will recursively traverse those data structures as well.\n *\n * It is possible to break the ContentManager by using this function incorrectly, for example,\n * if you transform a number into a string but the attribute type is a number, the ContentManager\n * will not be able to save the data and the Form will likely crash because the component it's\n * passing the data too won't succesfully be able to handle the value.\n */\nconst traverseData =\n (predicate: Predicate, transform: Transform) =>\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (data: AnyData = {}) => {\n const traverse = (datum: AnyData, attributes: Schema.Schema['attributes']) => {\n return Object.entries(datum).reduce<AnyData>((acc, [key, value]) => {\n const attribute = attributes[key];\n\n /**\n * If the attribute is a block list attribute, we don't want to transform it.\n * We also don't want to transform null or undefined values.\n */\n if (BLOCK_LIST_ATTRIBUTE_KEYS.includes(key) || value === null || value === undefined) {\n acc[key] = value;\n return acc;\n }\n\n if (attribute.type === 'component') {\n if (attribute.repeatable) {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n acc[key] = componentValue.map((componentData) =>\n traverse(componentData, components[attribute.component]?.attributes ?? {})\n );\n } else {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, false>>;\n\n acc[key] = traverse(componentValue, components[attribute.component]?.attributes ?? {});\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamicZoneValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n acc[key] = dynamicZoneValue.map((componentData) =>\n traverse(componentData, components[componentData.__component]?.attributes ?? {})\n );\n } else if (predicate(attribute, value)) {\n acc[key] = transform(value, attribute);\n } else {\n acc[key] = value;\n }\n\n return acc;\n }, {});\n };\n\n return traverse(data, schema.attributes);\n };\n\n/* -------------------------------------------------------------------------------------------------\n * removeProhibitedFields\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal Removes all the fields that are not allowed.\n */\nconst removeProhibitedFields = (prohibitedFields: Schema.Attribute.Kind[]) =>\n traverseData(\n (attribute) => prohibitedFields.includes(attribute.type),\n () => ''\n );\n\n/* -------------------------------------------------------------------------------------------------\n * prepareRelations\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Sets all relation values to an empty array.\n */\nconst prepareRelations = traverseData(\n (attribute) => attribute.type === 'relation',\n () => ({\n connect: [],\n disconnect: [],\n })\n);\n\n/* -------------------------------------------------------------------------------------------------\n * prepareTempKeys\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each component and dynamiczone item. This gives us\n * a stable identifier regardless of its ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = traverseData(\n (attribute) =>\n (attribute.type === 'component' && attribute.repeatable) || attribute.type === 'dynamiczone',\n (data) => {\n if (Array.isArray(data) && data.length > 0) {\n const keys = generateNKeysBetween(undefined, undefined, data.length);\n\n return data.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n }\n\n return data;\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * removeFieldsThatDontExistOnSchema\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Fields that don't exist in the schema like createdAt etc. are only on the first level (not nested),\n * as such we don't need to traverse the components to remove them.\n */\nconst removeFieldsThatDontExistOnSchema = (schema: PartialSchema) => (data: AnyData) => {\n const schemaKeys = Object.keys(schema.attributes);\n const dataKeys = Object.keys(data);\n\n const keysToRemove = dataKeys.filter((key) => !schemaKeys.includes(key));\n\n const revisedData = [...keysToRemove, ...DOCUMENT_META_FIELDS].reduce((acc, key) => {\n delete acc[key];\n\n return acc;\n }, structuredClone(data));\n\n return revisedData;\n};\n\n/**\n * @internal\n * @description We need to remove null fields from the data-structure because it will pass it\n * to the specific inputs breaking them as most would prefer empty strings or `undefined` if\n * they're controlled / uncontrolled.\n */\nconst removeNullValues = (data: AnyData) => {\n return Object.entries(data).reduce<AnyData>((acc, [key, value]) => {\n if (value === null) {\n return acc;\n }\n\n acc[key] = value;\n\n return acc;\n }, {});\n};\n\n/* -------------------------------------------------------------------------------------------------\n * transformDocuments\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Takes a document data structure (this could be from the API or a default form structure)\n * and applies consistent data transformations to it. This is also used when we add new components to the\n * form to ensure the data is correctly prepared from their default state e.g. relations are set to an empty array.\n */\nconst transformDocument =\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (document: AnyData) => {\n const transformations = pipe(\n removeFieldsThatDontExistOnSchema(schema),\n removeProhibitedFields(['password'])(schema, components),\n removeNullValues,\n prepareRelations(schema, components),\n prepareTempKeys(schema, components)\n );\n\n return transformations(document);\n };\n\ntype HandleOptions = {\n schema?: Schema.ContentType | Schema.Component;\n initialValues?: AnyData;\n components?: Record<string, Schema.Component>;\n};\n\ntype RemovedFieldPath = string;\n\n/**\n * @internal\n * @description Finds the initial value for a component or dynamic zone item (based on its __temp_key__ and not its index).\n * @param initialValue - The initial values object.\n * @param item - The item to find the initial value for.\n * @returns The initial value for the item.\n */\nconst getItemInitialValue = (initialValue: AnyData, item: AnyData) => {\n if (initialValue && Array.isArray(initialValue)) {\n const matchingInitialItem = initialValue.find(\n (initialItem) => initialItem.__temp_key__ === item.__temp_key__\n );\n if (matchingInitialItem) {\n return matchingInitialItem;\n }\n }\n return {};\n};\n\n/**\n * Removes values from the data object if their corresponding attribute has a\n * visibility condition that evaluates to false.\n *\n * @param {object} schema - The content type schema (with attributes).\n * @param {object} data - The data object to filter based on visibility.\n * @returns {object} A new data object with only visible fields retained.\n */\nconst handleInvisibleAttributes = (\n data: AnyData,\n { schema, initialValues = {}, components = {} }: HandleOptions,\n path: string[] = [],\n removedAttributes: RemovedFieldPath[] = []\n): {\n data: AnyData;\n removedAttributes: RemovedFieldPath[];\n} => {\n if (!schema?.attributes) return { data, removedAttributes };\n\n const rulesEngine = createRulesEngine();\n const result: AnyData = {};\n\n for (const [attrName, attrDef] of Object.entries(schema.attributes)) {\n const fullPath = [...path, attrName].join('.');\n const condition = attrDef?.conditions?.visible;\n const isVisible = condition ? rulesEngine.evaluate(condition, { ...data, ...result }) : true;\n\n if (!isVisible) {\n removedAttributes.push(fullPath);\n continue;\n }\n\n const userProvided = Object.prototype.hasOwnProperty.call(data, attrName);\n const currentValue = userProvided ? data[attrName] : undefined;\n const initialValue = initialValues?.[attrName];\n\n // 🔹 Handle components\n if (attrDef.type === 'component') {\n const compSchema = components[attrDef.component];\n const value = currentValue ?? initialValue;\n\n if (!value) {\n result[attrName] = attrDef.repeatable ? [] : null;\n continue;\n }\n\n if (attrDef.repeatable && Array.isArray(value)) {\n result[attrName] = value.map((item) => {\n const componentInitialValue = getItemInitialValue(initialValue, item);\n\n return handleInvisibleAttributes(\n item,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${item.__temp_key__}]`],\n removedAttributes\n ).data;\n });\n } else {\n result[attrName] = handleInvisibleAttributes(\n value,\n {\n schema: compSchema,\n initialValues: initialValue ?? {},\n components,\n },\n [...path, attrName],\n removedAttributes\n ).data;\n }\n\n continue;\n }\n\n // 🔸 Handle dynamic zones\n if (attrDef.type === 'dynamiczone') {\n if (!Array.isArray(currentValue)) {\n result[attrName] = [];\n continue;\n }\n\n result[attrName] = currentValue.map((dzItem) => {\n const compUID = dzItem?.__component;\n const compSchema = components[compUID];\n\n const componentInitialValue = getItemInitialValue(initialValue, dzItem);\n\n const cleaned = handleInvisibleAttributes(\n dzItem,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${dzItem.__temp_key__}]`],\n removedAttributes\n ).data;\n\n // For newly created components, we want to be sure that the id is undefined (in case of reordering items)\n const processedItem =\n dzItem.id === undefined || dzItem.id === null\n ? { __component: compUID, ...cleaned, id: undefined }\n : { __component: compUID, ...cleaned };\n\n return processedItem;\n });\n\n continue;\n }\n\n // 🟡 Handle scalar/primitive\n if (currentValue !== undefined) {\n result[attrName] = currentValue;\n } else if (initialValue !== undefined) {\n result[attrName] = initialValue;\n } else {\n if (attrName === 'id' || attrName === 'documentId') {\n // If the attribute is 'id', we don't want to set it to null, as it should not be removed.\n continue;\n }\n result[attrName] = null;\n }\n }\n\n return {\n data: result,\n removedAttributes,\n };\n};\n\nexport {\n removeProhibitedFields,\n prepareRelations,\n prepareTempKeys,\n removeFieldsThatDontExistOnSchema,\n transformDocument,\n handleInvisibleAttributes,\n};\nexport type { AnyData };\n"],"names":["BLOCK_LIST_ATTRIBUTE_KEYS","traverseData","predicate","transform","schema","components","data","traverse","datum","attributes","Object","entries","reduce","acc","key","value","attribute","includes","undefined","type","repeatable","componentValue","map","componentData","component","dynamicZoneValue","__component","removeProhibitedFields","prohibitedFields","prepareRelations","connect","disconnect","prepareTempKeys","Array","isArray","length","keys","generateNKeysBetween","index","__temp_key__","removeFieldsThatDontExistOnSchema","schemaKeys","dataKeys","keysToRemove","filter","revisedData","DOCUMENT_META_FIELDS","structuredClone","removeNullValues","transformDocument","document","transformations","pipe","getItemInitialValue","initialValue","item","matchingInitialItem","find","initialItem","handleInvisibleAttributes","initialValues","path","removedAttributes","rulesEngine","createRulesEngine","result","attrName","attrDef","fullPath","join","condition","conditions","visible","isVisible","evaluate","push","userProvided","prototype","hasOwnProperty","call","currentValue","compSchema","componentInitialValue","dzItem","compUID","cleaned","processedItem","id"],"mappings":";;;;;;;AA0BA,MAAMA,yBAA4B,GAAA;AAAC,IAAA,aAAA;AAAe,IAAA;AAAe,CAAA;AAEjE;;;;;;;;;;AAUC,IACD,MAAMC,YAAAA,GACJ,CAACC,SAAAA,EAAsBC,YACvB,CAACC,MAAAA,EAAuBC,UAAmC,GAAA,EAAE,GAC7D,CAACC,IAAAA,GAAgB,EAAE,GAAA;YACjB,MAAMC,QAAAA,GAAW,CAACC,KAAgBC,EAAAA,UAAAA,GAAAA;gBAChC,OAAOC,MAAAA,CAAOC,OAAO,CAACH,KAAOI,CAAAA,CAAAA,MAAM,CAAU,CAACC,GAAAA,EAAK,CAACC,GAAAA,EAAKC,KAAM,CAAA,GAAA;oBAC7D,MAAMC,SAAAA,GAAYP,UAAU,CAACK,GAAI,CAAA;AAEjC;;;YAIA,IAAId,0BAA0BiB,QAAQ,CAACH,QAAQC,KAAU,KAAA,IAA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AAE,iBAAA,EAChDuB,mBACAxD,IAAI;;gBAGN,MAAMgF,aAAAA,GACJH,OAAOI,EAAE,KAAKrE,aAAaiE,MAAOI,CAAAA,EAAE,KAAK,IACrC,GAAA;oBAAE7D,WAAa0D,EAAAA,OAAAA;AAAS,oBAAA,GAAGC,OAAO;oBAAEE,EAAIrE,EAAAA;iBACxC,GAAA;oBAAEQ,WAAa0D,EAAAA,OAAAA;AAAS,oBAAA,GAAGC;AAAQ,iBAAA;gBAEzC,OAAOC,aAAAA;AACT,aAAA,CAAA;AAEA,YAAA;AACF;;AAGA,QAAA,IAAIN,iBAAiB9D,SAAW,EAAA;YAC9B+C,MAAM,CAACC,SAAS,GAAGc,YAAAA;SACd,MAAA,IAAI1B,iBAAiBpC,SAAW,EAAA;YACrC+C,MAAM,CAACC,SAAS,GAAGZ,YAAAA;SACd,MAAA;YACL,IAAIY,QAAAA,KAAa,IAAQA,IAAAA,QAAAA,KAAa,YAAc,EAAA;AAElD,gBAAA;AACF;YACAD,MAAM,CAACC,SAAS,GAAG,IAAA;AACrB;AACF;IAEA,OAAO;QACL5D,IAAM2D,EAAAA,MAAAA;AACNH,QAAAA;AACF,KAAA;AACF;;;;;;;;;"}
@@ -125,6 +125,21 @@ const BLOCK_LIST_ATTRIBUTE_KEYS = [
125
125
  ])(schema, components), removeNullValues, prepareRelations(schema, components), prepareTempKeys(schema, components));
126
126
  return transformations(document);
127
127
  };
128
+ /**
129
+ * @internal
130
+ * @description Finds the initial value for a component or dynamic zone item (based on its __temp_key__ and not its index).
131
+ * @param initialValue - The initial values object.
132
+ * @param item - The item to find the initial value for.
133
+ * @returns The initial value for the item.
134
+ */ const getItemInitialValue = (initialValue, item)=>{
135
+ if (initialValue && Array.isArray(initialValue)) {
136
+ const matchingInitialItem = initialValue.find((initialItem)=>initialItem.__temp_key__ === item.__temp_key__);
137
+ if (matchingInitialItem) {
138
+ return matchingInitialItem;
139
+ }
140
+ }
141
+ return {};
142
+ };
128
143
  /**
129
144
  * Removes values from the data object if their corresponding attribute has a
130
145
  * visibility condition that evaluates to false.
@@ -165,14 +180,17 @@ const BLOCK_LIST_ATTRIBUTE_KEYS = [
165
180
  continue;
166
181
  }
167
182
  if (attrDef.repeatable && Array.isArray(value)) {
168
- result[attrName] = value.map((item, index)=>handleInvisibleAttributes(item, {
183
+ result[attrName] = value.map((item)=>{
184
+ const componentInitialValue = getItemInitialValue(initialValue, item);
185
+ return handleInvisibleAttributes(item, {
169
186
  schema: compSchema,
170
- initialValues: initialValue?.[index] ?? {},
187
+ initialValues: componentInitialValue,
171
188
  components
172
189
  }, [
173
190
  ...path,
174
- `${attrName}[${index}]`
175
- ], removedAttributes).data);
191
+ `${attrName}[${item.__temp_key__}]`
192
+ ], removedAttributes).data;
193
+ });
176
194
  } else {
177
195
  result[attrName] = handleInvisibleAttributes(value, {
178
196
  schema: compSchema,
@@ -191,16 +209,17 @@ const BLOCK_LIST_ATTRIBUTE_KEYS = [
191
209
  result[attrName] = [];
192
210
  continue;
193
211
  }
194
- result[attrName] = currentValue.map((dzItem, index)=>{
212
+ result[attrName] = currentValue.map((dzItem)=>{
195
213
  const compUID = dzItem?.__component;
196
214
  const compSchema = components[compUID];
215
+ const componentInitialValue = getItemInitialValue(initialValue, dzItem);
197
216
  const cleaned = handleInvisibleAttributes(dzItem, {
198
217
  schema: compSchema,
199
- initialValues: initialValue?.[index] ?? {},
218
+ initialValues: componentInitialValue,
200
219
  components
201
220
  }, [
202
221
  ...path,
203
- `${attrName}[${index}]`
222
+ `${attrName}[${dzItem.__temp_key__}]`
204
223
  ], removedAttributes).data;
205
224
  // For newly created components, we want to be sure that the id is undefined (in case of reordering items)
206
225
  const processedItem = dzItem.id === undefined || dzItem.id === null ? {
@@ -1 +1 @@
1
- {"version":3,"file":"data.mjs","sources":["../../../../../admin/src/pages/EditView/utils/data.ts"],"sourcesContent":["import { createRulesEngine } from '@strapi/admin/strapi-admin';\nimport { generateNKeysBetween } from 'fractional-indexing';\nimport pipe from 'lodash/fp/pipe';\n\nimport { DOCUMENT_META_FIELDS } from '../../../constants/attributes';\n\nimport type { ComponentsDictionary, Document } from '../../../hooks/useDocument';\nimport type { Schema, UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * traverseData\n * -----------------------------------------------------------------------------------------------*/\n\n// Make only attributes required since it's the only one Content History has\ntype PartialSchema = Partial<Schema.Schema> & Pick<Schema.Schema, 'attributes'>;\n\ntype Predicate = <TAttribute extends Schema.Attribute.AnyAttribute>(\n attribute: TAttribute,\n value: Schema.Attribute.Value<TAttribute>\n) => boolean;\ntype Transform = <TAttribute extends Schema.Attribute.AnyAttribute>(\n value: any,\n attribute: TAttribute\n) => any;\ntype AnyData = Omit<Document, 'id'>;\n\nconst BLOCK_LIST_ATTRIBUTE_KEYS = ['__component', '__temp_key__'];\n\n/**\n * @internal This function is used to traverse the data and transform the values.\n * Given a predicate function, it will transform the value (using the given transform function)\n * if the predicate returns true. If it finds that the attribute is a component or dynamiczone,\n * it will recursively traverse those data structures as well.\n *\n * It is possible to break the ContentManager by using this function incorrectly, for example,\n * if you transform a number into a string but the attribute type is a number, the ContentManager\n * will not be able to save the data and the Form will likely crash because the component it's\n * passing the data too won't succesfully be able to handle the value.\n */\nconst traverseData =\n (predicate: Predicate, transform: Transform) =>\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (data: AnyData = {}) => {\n const traverse = (datum: AnyData, attributes: Schema.Schema['attributes']) => {\n return Object.entries(datum).reduce<AnyData>((acc, [key, value]) => {\n const attribute = attributes[key];\n\n /**\n * If the attribute is a block list attribute, we don't want to transform it.\n * We also don't want to transform null or undefined values.\n */\n if (BLOCK_LIST_ATTRIBUTE_KEYS.includes(key) || value === null || value === undefined) {\n acc[key] = value;\n return acc;\n }\n\n if (attribute.type === 'component') {\n if (attribute.repeatable) {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n acc[key] = componentValue.map((componentData) =>\n traverse(componentData, components[attribute.component]?.attributes ?? {})\n );\n } else {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, false>>;\n\n acc[key] = traverse(componentValue, components[attribute.component]?.attributes ?? {});\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamicZoneValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n acc[key] = dynamicZoneValue.map((componentData) =>\n traverse(componentData, components[componentData.__component]?.attributes ?? {})\n );\n } else if (predicate(attribute, value)) {\n acc[key] = transform(value, attribute);\n } else {\n acc[key] = value;\n }\n\n return acc;\n }, {});\n };\n\n return traverse(data, schema.attributes);\n };\n\n/* -------------------------------------------------------------------------------------------------\n * removeProhibitedFields\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal Removes all the fields that are not allowed.\n */\nconst removeProhibitedFields = (prohibitedFields: Schema.Attribute.Kind[]) =>\n traverseData(\n (attribute) => prohibitedFields.includes(attribute.type),\n () => ''\n );\n\n/* -------------------------------------------------------------------------------------------------\n * prepareRelations\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Sets all relation values to an empty array.\n */\nconst prepareRelations = traverseData(\n (attribute) => attribute.type === 'relation',\n () => ({\n connect: [],\n disconnect: [],\n })\n);\n\n/* -------------------------------------------------------------------------------------------------\n * prepareTempKeys\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each component and dynamiczone item. This gives us\n * a stable identifier regardless of its ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = traverseData(\n (attribute) =>\n (attribute.type === 'component' && attribute.repeatable) || attribute.type === 'dynamiczone',\n (data) => {\n if (Array.isArray(data) && data.length > 0) {\n const keys = generateNKeysBetween(undefined, undefined, data.length);\n\n return data.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n }\n\n return data;\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * removeFieldsThatDontExistOnSchema\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Fields that don't exist in the schema like createdAt etc. are only on the first level (not nested),\n * as such we don't need to traverse the components to remove them.\n */\nconst removeFieldsThatDontExistOnSchema = (schema: PartialSchema) => (data: AnyData) => {\n const schemaKeys = Object.keys(schema.attributes);\n const dataKeys = Object.keys(data);\n\n const keysToRemove = dataKeys.filter((key) => !schemaKeys.includes(key));\n\n const revisedData = [...keysToRemove, ...DOCUMENT_META_FIELDS].reduce((acc, key) => {\n delete acc[key];\n\n return acc;\n }, structuredClone(data));\n\n return revisedData;\n};\n\n/**\n * @internal\n * @description We need to remove null fields from the data-structure because it will pass it\n * to the specific inputs breaking them as most would prefer empty strings or `undefined` if\n * they're controlled / uncontrolled.\n */\nconst removeNullValues = (data: AnyData) => {\n return Object.entries(data).reduce<AnyData>((acc, [key, value]) => {\n if (value === null) {\n return acc;\n }\n\n acc[key] = value;\n\n return acc;\n }, {});\n};\n\n/* -------------------------------------------------------------------------------------------------\n * transformDocuments\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Takes a document data structure (this could be from the API or a default form structure)\n * and applies consistent data transformations to it. This is also used when we add new components to the\n * form to ensure the data is correctly prepared from their default state e.g. relations are set to an empty array.\n */\nconst transformDocument =\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (document: AnyData) => {\n const transformations = pipe(\n removeFieldsThatDontExistOnSchema(schema),\n removeProhibitedFields(['password'])(schema, components),\n removeNullValues,\n prepareRelations(schema, components),\n prepareTempKeys(schema, components)\n );\n\n return transformations(document);\n };\n\ntype HandleOptions = {\n schema?: Schema.ContentType | Schema.Component;\n initialValues?: AnyData;\n components?: Record<string, Schema.Component>;\n};\n\ntype RemovedFieldPath = string;\n\n/**\n * Removes values from the data object if their corresponding attribute has a\n * visibility condition that evaluates to false.\n *\n * @param {object} schema - The content type schema (with attributes).\n * @param {object} data - The data object to filter based on visibility.\n * @returns {object} A new data object with only visible fields retained.\n */\nconst handleInvisibleAttributes = (\n data: AnyData,\n { schema, initialValues = {}, components = {} }: HandleOptions,\n path: string[] = [],\n removedAttributes: RemovedFieldPath[] = []\n): {\n data: AnyData;\n removedAttributes: RemovedFieldPath[];\n} => {\n if (!schema?.attributes) return { data, removedAttributes };\n\n const rulesEngine = createRulesEngine();\n const result: AnyData = {};\n\n for (const [attrName, attrDef] of Object.entries(schema.attributes)) {\n const fullPath = [...path, attrName].join('.');\n const condition = attrDef?.conditions?.visible;\n const isVisible = condition ? rulesEngine.evaluate(condition, { ...data, ...result }) : true;\n\n if (!isVisible) {\n removedAttributes.push(fullPath);\n continue;\n }\n\n const userProvided = Object.prototype.hasOwnProperty.call(data, attrName);\n const currentValue = userProvided ? data[attrName] : undefined;\n const initialValue = initialValues?.[attrName];\n\n // 🔹 Handle components\n if (attrDef.type === 'component') {\n const compSchema = components[attrDef.component];\n const value = currentValue ?? initialValue;\n\n if (!value) {\n result[attrName] = attrDef.repeatable ? [] : null;\n continue;\n }\n\n if (attrDef.repeatable && Array.isArray(value)) {\n result[attrName] = value.map(\n (item, index) =>\n handleInvisibleAttributes(\n item,\n {\n schema: compSchema,\n initialValues: initialValue?.[index] ?? {},\n components,\n },\n [...path, `${attrName}[${index}]`],\n removedAttributes\n ).data\n );\n } else {\n result[attrName] = handleInvisibleAttributes(\n value,\n {\n schema: compSchema,\n initialValues: initialValue ?? {},\n components,\n },\n [...path, attrName],\n removedAttributes\n ).data;\n }\n\n continue;\n }\n\n // 🔸 Handle dynamic zones\n if (attrDef.type === 'dynamiczone') {\n if (!Array.isArray(currentValue)) {\n result[attrName] = [];\n continue;\n }\n\n result[attrName] = currentValue.map((dzItem, index) => {\n const compUID = dzItem?.__component;\n const compSchema = components[compUID];\n\n const cleaned = handleInvisibleAttributes(\n dzItem,\n {\n schema: compSchema,\n initialValues: initialValue?.[index] ?? {},\n components,\n },\n [...path, `${attrName}[${index}]`],\n removedAttributes\n ).data;\n\n // For newly created components, we want to be sure that the id is undefined (in case of reordering items)\n const processedItem =\n dzItem.id === undefined || dzItem.id === null\n ? { __component: compUID, ...cleaned, id: undefined }\n : { __component: compUID, ...cleaned };\n\n return processedItem;\n });\n\n continue;\n }\n\n // 🟡 Handle scalar/primitive\n if (currentValue !== undefined) {\n result[attrName] = currentValue;\n } else if (initialValue !== undefined) {\n result[attrName] = initialValue;\n } else {\n if (attrName === 'id' || attrName === 'documentId') {\n // If the attribute is 'id', we don't want to set it to null, as it should not be removed.\n continue;\n }\n result[attrName] = null;\n }\n }\n\n return {\n data: result,\n removedAttributes,\n };\n};\n\nexport {\n removeProhibitedFields,\n prepareRelations,\n prepareTempKeys,\n removeFieldsThatDontExistOnSchema,\n transformDocument,\n handleInvisibleAttributes,\n};\nexport type { AnyData };\n"],"names":["BLOCK_LIST_ATTRIBUTE_KEYS","traverseData","predicate","transform","schema","components","data","traverse","datum","attributes","Object","entries","reduce","acc","key","value","attribute","includes","undefined","type","repeatable","componentValue","map","componentData","component","dynamicZoneValue","__component","removeProhibitedFields","prohibitedFields","prepareRelations","connect","disconnect","prepareTempKeys","Array","isArray","length","keys","generateNKeysBetween","index","__temp_key__","removeFieldsThatDontExistOnSchema","schemaKeys","dataKeys","keysToRemove","filter","revisedData","DOCUMENT_META_FIELDS","structuredClone","removeNullValues","transformDocument","document","transformations","pipe","handleInvisibleAttributes","initialValues","path","removedAttributes","rulesEngine","createRulesEngine","result","attrName","attrDef","fullPath","join","condition","conditions","visible","isVisible","evaluate","push","userProvided","prototype","hasOwnProperty","call","currentValue","initialValue","compSchema","item","dzItem","compUID","cleaned","processedItem","id"],"mappings":";;;;;AA0BA,MAAMA,yBAA4B,GAAA;AAAC,IAAA,aAAA;AAAe,IAAA;AAAe,CAAA;AAEjE;;;;;;;;;;AAUC,IACD,MAAMC,YAAAA,GACJ,CAACC,SAAAA,EAAsBC,YACvB,CAACC,MAAAA,EAAuBC,UAAmC,GAAA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I,CAAAA,EAAE,KAAK,IACrC,GAAA;oBAAExD,WAAaqD,EAAAA,OAAAA;AAAS,oBAAA,GAAGC,OAAO;oBAAEE,EAAIhE,EAAAA;iBACxC,GAAA;oBAAEQ,WAAaqD,EAAAA,OAAAA;AAAS,oBAAA,GAAGC;AAAQ,iBAAA;gBAEzC,OAAOC,aAAAA;AACT,aAAA,CAAA;AAEA,YAAA;AACF;;AAGA,QAAA,IAAIP,iBAAiBxD,SAAW,EAAA;YAC9ByC,MAAM,CAACC,SAAS,GAAGc,YAAAA;SACd,MAAA,IAAIC,iBAAiBzD,SAAW,EAAA;YACrCyC,MAAM,CAACC,SAAS,GAAGe,YAAAA;SACd,MAAA;YACL,IAAIf,QAAAA,KAAa,IAAQA,IAAAA,QAAAA,KAAa,YAAc,EAAA;AAElD,gBAAA;AACF;YACAD,MAAM,CAACC,SAAS,GAAG,IAAA;AACrB;AACF;IAEA,OAAO;QACLtD,IAAMqD,EAAAA,MAAAA;AACNH,QAAAA;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"data.mjs","sources":["../../../../../admin/src/pages/EditView/utils/data.ts"],"sourcesContent":["import { createRulesEngine } from '@strapi/admin/strapi-admin';\nimport { generateNKeysBetween } from 'fractional-indexing';\nimport pipe from 'lodash/fp/pipe';\n\nimport { DOCUMENT_META_FIELDS } from '../../../constants/attributes';\n\nimport type { ComponentsDictionary, Document } from '../../../hooks/useDocument';\nimport type { Schema, UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * traverseData\n * -----------------------------------------------------------------------------------------------*/\n\n// Make only attributes required since it's the only one Content History has\ntype PartialSchema = Partial<Schema.Schema> & Pick<Schema.Schema, 'attributes'>;\n\ntype Predicate = <TAttribute extends Schema.Attribute.AnyAttribute>(\n attribute: TAttribute,\n value: Schema.Attribute.Value<TAttribute>\n) => boolean;\ntype Transform = <TAttribute extends Schema.Attribute.AnyAttribute>(\n value: any,\n attribute: TAttribute\n) => any;\ntype AnyData = Omit<Document, 'id'>;\n\nconst BLOCK_LIST_ATTRIBUTE_KEYS = ['__component', '__temp_key__'];\n\n/**\n * @internal This function is used to traverse the data and transform the values.\n * Given a predicate function, it will transform the value (using the given transform function)\n * if the predicate returns true. If it finds that the attribute is a component or dynamiczone,\n * it will recursively traverse those data structures as well.\n *\n * It is possible to break the ContentManager by using this function incorrectly, for example,\n * if you transform a number into a string but the attribute type is a number, the ContentManager\n * will not be able to save the data and the Form will likely crash because the component it's\n * passing the data too won't succesfully be able to handle the value.\n */\nconst traverseData =\n (predicate: Predicate, transform: Transform) =>\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (data: AnyData = {}) => {\n const traverse = (datum: AnyData, attributes: Schema.Schema['attributes']) => {\n return Object.entries(datum).reduce<AnyData>((acc, [key, value]) => {\n const attribute = attributes[key];\n\n /**\n * If the attribute is a block list attribute, we don't want to transform it.\n * We also don't want to transform null or undefined values.\n */\n if (BLOCK_LIST_ATTRIBUTE_KEYS.includes(key) || value === null || value === undefined) {\n acc[key] = value;\n return acc;\n }\n\n if (attribute.type === 'component') {\n if (attribute.repeatable) {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, true>>;\n acc[key] = componentValue.map((componentData) =>\n traverse(componentData, components[attribute.component]?.attributes ?? {})\n );\n } else {\n const componentValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.Component<UID.Component, false>>;\n\n acc[key] = traverse(componentValue, components[attribute.component]?.attributes ?? {});\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamicZoneValue = (\n predicate(attribute, value) ? transform(value, attribute) : value\n ) as Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n\n acc[key] = dynamicZoneValue.map((componentData) =>\n traverse(componentData, components[componentData.__component]?.attributes ?? {})\n );\n } else if (predicate(attribute, value)) {\n acc[key] = transform(value, attribute);\n } else {\n acc[key] = value;\n }\n\n return acc;\n }, {});\n };\n\n return traverse(data, schema.attributes);\n };\n\n/* -------------------------------------------------------------------------------------------------\n * removeProhibitedFields\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal Removes all the fields that are not allowed.\n */\nconst removeProhibitedFields = (prohibitedFields: Schema.Attribute.Kind[]) =>\n traverseData(\n (attribute) => prohibitedFields.includes(attribute.type),\n () => ''\n );\n\n/* -------------------------------------------------------------------------------------------------\n * prepareRelations\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Sets all relation values to an empty array.\n */\nconst prepareRelations = traverseData(\n (attribute) => attribute.type === 'relation',\n () => ({\n connect: [],\n disconnect: [],\n })\n);\n\n/* -------------------------------------------------------------------------------------------------\n * prepareTempKeys\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Adds a `__temp_key__` to each component and dynamiczone item. This gives us\n * a stable identifier regardless of its ids etc. that we can then use for drag and drop.\n */\nconst prepareTempKeys = traverseData(\n (attribute) =>\n (attribute.type === 'component' && attribute.repeatable) || attribute.type === 'dynamiczone',\n (data) => {\n if (Array.isArray(data) && data.length > 0) {\n const keys = generateNKeysBetween(undefined, undefined, data.length);\n\n return data.map((datum, index) => ({\n ...datum,\n __temp_key__: keys[index],\n }));\n }\n\n return data;\n }\n);\n\n/* -------------------------------------------------------------------------------------------------\n * removeFieldsThatDontExistOnSchema\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Fields that don't exist in the schema like createdAt etc. are only on the first level (not nested),\n * as such we don't need to traverse the components to remove them.\n */\nconst removeFieldsThatDontExistOnSchema = (schema: PartialSchema) => (data: AnyData) => {\n const schemaKeys = Object.keys(schema.attributes);\n const dataKeys = Object.keys(data);\n\n const keysToRemove = dataKeys.filter((key) => !schemaKeys.includes(key));\n\n const revisedData = [...keysToRemove, ...DOCUMENT_META_FIELDS].reduce((acc, key) => {\n delete acc[key];\n\n return acc;\n }, structuredClone(data));\n\n return revisedData;\n};\n\n/**\n * @internal\n * @description We need to remove null fields from the data-structure because it will pass it\n * to the specific inputs breaking them as most would prefer empty strings or `undefined` if\n * they're controlled / uncontrolled.\n */\nconst removeNullValues = (data: AnyData) => {\n return Object.entries(data).reduce<AnyData>((acc, [key, value]) => {\n if (value === null) {\n return acc;\n }\n\n acc[key] = value;\n\n return acc;\n }, {});\n};\n\n/* -------------------------------------------------------------------------------------------------\n * transformDocuments\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description Takes a document data structure (this could be from the API or a default form structure)\n * and applies consistent data transformations to it. This is also used when we add new components to the\n * form to ensure the data is correctly prepared from their default state e.g. relations are set to an empty array.\n */\nconst transformDocument =\n (schema: PartialSchema, components: ComponentsDictionary = {}) =>\n (document: AnyData) => {\n const transformations = pipe(\n removeFieldsThatDontExistOnSchema(schema),\n removeProhibitedFields(['password'])(schema, components),\n removeNullValues,\n prepareRelations(schema, components),\n prepareTempKeys(schema, components)\n );\n\n return transformations(document);\n };\n\ntype HandleOptions = {\n schema?: Schema.ContentType | Schema.Component;\n initialValues?: AnyData;\n components?: Record<string, Schema.Component>;\n};\n\ntype RemovedFieldPath = string;\n\n/**\n * @internal\n * @description Finds the initial value for a component or dynamic zone item (based on its __temp_key__ and not its index).\n * @param initialValue - The initial values object.\n * @param item - The item to find the initial value for.\n * @returns The initial value for the item.\n */\nconst getItemInitialValue = (initialValue: AnyData, item: AnyData) => {\n if (initialValue && Array.isArray(initialValue)) {\n const matchingInitialItem = initialValue.find(\n (initialItem) => initialItem.__temp_key__ === item.__temp_key__\n );\n if (matchingInitialItem) {\n return matchingInitialItem;\n }\n }\n return {};\n};\n\n/**\n * Removes values from the data object if their corresponding attribute has a\n * visibility condition that evaluates to false.\n *\n * @param {object} schema - The content type schema (with attributes).\n * @param {object} data - The data object to filter based on visibility.\n * @returns {object} A new data object with only visible fields retained.\n */\nconst handleInvisibleAttributes = (\n data: AnyData,\n { schema, initialValues = {}, components = {} }: HandleOptions,\n path: string[] = [],\n removedAttributes: RemovedFieldPath[] = []\n): {\n data: AnyData;\n removedAttributes: RemovedFieldPath[];\n} => {\n if (!schema?.attributes) return { data, removedAttributes };\n\n const rulesEngine = createRulesEngine();\n const result: AnyData = {};\n\n for (const [attrName, attrDef] of Object.entries(schema.attributes)) {\n const fullPath = [...path, attrName].join('.');\n const condition = attrDef?.conditions?.visible;\n const isVisible = condition ? rulesEngine.evaluate(condition, { ...data, ...result }) : true;\n\n if (!isVisible) {\n removedAttributes.push(fullPath);\n continue;\n }\n\n const userProvided = Object.prototype.hasOwnProperty.call(data, attrName);\n const currentValue = userProvided ? data[attrName] : undefined;\n const initialValue = initialValues?.[attrName];\n\n // 🔹 Handle components\n if (attrDef.type === 'component') {\n const compSchema = components[attrDef.component];\n const value = currentValue ?? initialValue;\n\n if (!value) {\n result[attrName] = attrDef.repeatable ? [] : null;\n continue;\n }\n\n if (attrDef.repeatable && Array.isArray(value)) {\n result[attrName] = value.map((item) => {\n const componentInitialValue = getItemInitialValue(initialValue, item);\n\n return handleInvisibleAttributes(\n item,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${item.__temp_key__}]`],\n removedAttributes\n ).data;\n });\n } else {\n result[attrName] = handleInvisibleAttributes(\n value,\n {\n schema: compSchema,\n initialValues: initialValue ?? {},\n components,\n },\n [...path, attrName],\n removedAttributes\n ).data;\n }\n\n continue;\n }\n\n // 🔸 Handle dynamic zones\n if (attrDef.type === 'dynamiczone') {\n if (!Array.isArray(currentValue)) {\n result[attrName] = [];\n continue;\n }\n\n result[attrName] = currentValue.map((dzItem) => {\n const compUID = dzItem?.__component;\n const compSchema = components[compUID];\n\n const componentInitialValue = getItemInitialValue(initialValue, dzItem);\n\n const cleaned = handleInvisibleAttributes(\n dzItem,\n {\n schema: compSchema,\n initialValues: componentInitialValue,\n components,\n },\n [...path, `${attrName}[${dzItem.__temp_key__}]`],\n removedAttributes\n ).data;\n\n // For newly created components, we want to be sure that the id is undefined (in case of reordering items)\n const processedItem =\n dzItem.id === undefined || dzItem.id === null\n ? { __component: compUID, ...cleaned, id: undefined }\n : { __component: compUID, ...cleaned };\n\n return processedItem;\n });\n\n continue;\n }\n\n // 🟡 Handle scalar/primitive\n if (currentValue !== undefined) {\n result[attrName] = currentValue;\n } else if (initialValue !== undefined) {\n result[attrName] = initialValue;\n } else {\n if (attrName === 'id' || attrName === 'documentId') {\n // If the attribute is 'id', we don't want to set it to null, as it should not be removed.\n continue;\n }\n result[attrName] = null;\n }\n }\n\n return {\n data: result,\n removedAttributes,\n };\n};\n\nexport {\n removeProhibitedFields,\n prepareRelations,\n prepareTempKeys,\n removeFieldsThatDontExistOnSchema,\n transformDocument,\n handleInvisibleAttributes,\n};\nexport type { AnyData };\n"],"names":["BLOCK_LIST_ATTRIBUTE_KEYS","traverseData","predicate","transform","schema","components","data","traverse","datum","attributes","Object","entries","reduce","acc","key","value","attribute","includes","undefined","type","repeatable","componentValue","map","componentData","component","dynamicZoneValue","__component","removeProhibitedFields","prohibitedFields","prepareRelations","connect","disconnect","prepareTempKeys","Array","isArray","length","keys","generateNKeysBetween","index","__temp_key__","removeFieldsThatDontExistOnSchema","schemaKeys","dataKeys","keysToRemove","filter","revisedData","DOCUMENT_META_FIELDS","structuredClone","removeNullValues","transformDocument","document","transformations","pipe","getItemInitialValue","initialValue","item","matchingInitialItem","find","initialItem","handleInvisibleAttributes","initialValues","path","removedAttributes","rulesEngine","createRulesEngine","result","attrName","attrDef","fullPath","join","condition","conditions","visible","isVisible","evaluate","push","userProvided","prototype","hasOwnProperty","call","currentValue","compSchema","componentInitialValue","dzItem","compUID","cleaned","processedItem","id"],"mappings":";;;;;AA0BA,MAAMA,yBAA4B,GAAA;AAAC,IAAA,aAAA;AAAe,IAAA;AAAe,CAAA;AAEjE;;;;;;;;;;AAUC,IACD,MAAMC,YAAAA,GACJ,CAACC,SAAAA,EAAsBC,YACvB,CAACC,MAAAA,EAAuBC,UAAmC,GAAA,EAAE,GAC7D,CAACC,IAAAA,G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AAC+E,OAAQ,CAAA;gBAEtC,MAAMF,qBAAAA,GAAwB7B,oBAAoBC,YAAc6B,EAAAA,MAAAA,CAAAA;gBAEhE,MAAME,OAAAA,GAAU1B,0BACdwB,MACA,EAAA;oBACE/E,MAAQ6E,EAAAA,UAAAA;oBACRrB,aAAesB,EAAAA,qBAAAA;AACf7E,oBAAAA;iBAEF,EAAA;AAAIwD,oBAAAA,GAAAA,IAAAA;oBAAM,CAAC,EAAEK,SAAS,CAAC,EAAEiB,OAAO5C,YAAY,CAAC,CAAC;AAAE,iBAAA,EAChDuB,mBACAxD,IAAI;;gBAGN,MAAMgF,aAAAA,GACJH,OAAOI,EAAE,KAAKrE,aAAaiE,MAAOI,CAAAA,EAAE,KAAK,IACrC,GAAA;oBAAE7D,WAAa0D,EAAAA,OAAAA;AAAS,oBAAA,GAAGC,OAAO;oBAAEE,EAAIrE,EAAAA;iBACxC,GAAA;oBAAEQ,WAAa0D,EAAAA,OAAAA;AAAS,oBAAA,GAAGC;AAAQ,iBAAA;gBAEzC,OAAOC,aAAAA;AACT,aAAA,CAAA;AAEA,YAAA;AACF;;AAGA,QAAA,IAAIN,iBAAiB9D,SAAW,EAAA;YAC9B+C,MAAM,CAACC,SAAS,GAAGc,YAAAA;SACd,MAAA,IAAI1B,iBAAiBpC,SAAW,EAAA;YACrC+C,MAAM,CAACC,SAAS,GAAGZ,YAAAA;SACd,MAAA;YACL,IAAIY,QAAAA,KAAa,IAAQA,IAAAA,QAAAA,KAAa,YAAc,EAAA;AAElD,gBAAA;AACF;YACAD,MAAM,CAACC,SAAS,GAAG,IAAA;AACrB;AACF;IAEA,OAAO;QACL5D,IAAM2D,EAAAA,MAAAA;AACNH,QAAAA;AACF,KAAA;AACF;;;;"}
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ require('react');
5
+ var strapiAdmin = require('@strapi/admin/strapi-admin');
6
+ var designSystem = require('@strapi/design-system');
7
+ var InputRenderer = require('../../pages/EditView/components/InputRenderer.js');
8
+ var Preview = require('../pages/Preview.js');
9
+
10
+ const [InputPopoverProvider, useInputPopoverContext] = strapiAdmin.createContext('InputPopover');
11
+ const InputPopover = ({ documentResponse })=>{
12
+ const iframeRef = Preview.usePreviewContext('VisualEditingPopover', (state)=>state.iframeRef);
13
+ const popoverField = Preview.usePreviewContext('VisualEditingPopover', (state)=>state.popoverField);
14
+ const setPopoverField = Preview.usePreviewContext('VisualEditingPopover', (state)=>state.setPopoverField);
15
+ if (!popoverField || !documentResponse.schema || !iframeRef.current) {
16
+ return null;
17
+ }
18
+ const iframeRect = iframeRef.current.getBoundingClientRect();
19
+ return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
20
+ children: [
21
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
22
+ position: 'fixed',
23
+ top: iframeRect.top + 'px',
24
+ left: iframeRect.left + 'px',
25
+ width: iframeRect.width + 'px',
26
+ height: iframeRect.height + 'px',
27
+ zIndex: 4
28
+ }),
29
+ /*#__PURE__*/ jsxRuntime.jsx(InputPopoverProvider, {
30
+ children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Popover.Root, {
31
+ open: true,
32
+ onOpenChange: (open)=>!open && setPopoverField(null),
33
+ children: [
34
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Popover.Trigger, {
35
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
36
+ position: "fixed",
37
+ width: popoverField.position.width + 'px',
38
+ height: popoverField.position.height + 'px',
39
+ top: 0,
40
+ left: 0,
41
+ transform: `translate(${iframeRect.left + popoverField.position.left}px, ${iframeRect.top + popoverField.position.top}px)`
42
+ })
43
+ }),
44
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Popover.Content, {
45
+ sideOffset: 4,
46
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
47
+ padding: 4,
48
+ width: "400px",
49
+ children: /*#__PURE__*/ jsxRuntime.jsx(InputRenderer.InputRenderer, {
50
+ document: documentResponse,
51
+ attribute: documentResponse.schema.attributes[popoverField.path],
52
+ label: popoverField.path,
53
+ name: popoverField.path,
54
+ type: documentResponse.schema.attributes[popoverField.path].type,
55
+ visible: true
56
+ })
57
+ })
58
+ })
59
+ ]
60
+ })
61
+ })
62
+ ]
63
+ });
64
+ };
65
+ function useHasInputPopoverParent() {
66
+ const context = useInputPopoverContext('useHasInputPopoverParent', ()=>true, false);
67
+ // useContext will return undefined if the called is not wrapped in the provider
68
+ return context !== undefined;
69
+ }
70
+
71
+ exports.InputPopover = InputPopover;
72
+ exports.useHasInputPopoverParent = useHasInputPopoverParent;
73
+ //# sourceMappingURL=InputPopover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InputPopover.js","sources":["../../../../admin/src/preview/components/InputPopover.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext } from '@strapi/admin/strapi-admin';\nimport { Box, Popover } from '@strapi/design-system';\n\nimport { type UseDocument } from '../../hooks/useDocument';\nimport { InputRenderer } from '../../pages/EditView/components/InputRenderer';\nimport { usePreviewContext } from '../pages/Preview';\n\n/**\n * No need for actual data in the context. It's just to let children check if they're rendered\n * inside of a preview InputPopover without relying on prop drilling.\n */\ninterface InputPopoverContextValue {}\n\nconst [InputPopoverProvider, useInputPopoverContext] =\n createContext<InputPopoverContextValue>('InputPopover');\n\nconst InputPopover = ({ documentResponse }: { documentResponse: ReturnType<UseDocument> }) => {\n const iframeRef = usePreviewContext('VisualEditingPopover', (state) => state.iframeRef);\n const popoverField = usePreviewContext('VisualEditingPopover', (state) => state.popoverField);\n const setPopoverField = usePreviewContext(\n 'VisualEditingPopover',\n (state) => state.setPopoverField\n );\n\n if (!popoverField || !documentResponse.schema || !iframeRef.current) {\n return null;\n }\n\n const iframeRect = iframeRef.current.getBoundingClientRect();\n\n return (\n <>\n {/**\n * Overlay an empty div on top of the iframe while the popover is open so it can\n * intercept clicks. Without it, we wouldn't be able to close the popover by clicking outside,\n * because the click would be detected by the iframe window, not by the admin.\n **/}\n <Box\n position={'fixed'}\n top={iframeRect.top + 'px'}\n left={iframeRect.left + 'px'}\n width={iframeRect.width + 'px'}\n height={iframeRect.height + 'px'}\n zIndex={4}\n />\n <InputPopoverProvider>\n <Popover.Root open={true} onOpenChange={(open) => !open && setPopoverField(null)}>\n <Popover.Trigger>\n <Box\n position=\"fixed\"\n width={popoverField.position.width + 'px'}\n height={popoverField.position.height + 'px'}\n top={0}\n left={0}\n transform={`translate(${iframeRect.left + popoverField.position.left}px, ${iframeRect.top + popoverField.position.top}px)`}\n />\n </Popover.Trigger>\n <Popover.Content sideOffset={4}>\n <Box padding={4} width=\"400px\">\n <InputRenderer\n document={documentResponse}\n attribute={documentResponse.schema.attributes[popoverField.path] as any}\n label={popoverField.path}\n name={popoverField.path}\n type={documentResponse.schema.attributes[popoverField.path].type}\n visible={true}\n />\n </Box>\n </Popover.Content>\n </Popover.Root>\n </InputPopoverProvider>\n </>\n );\n};\n\nfunction useHasInputPopoverParent() {\n const context = useInputPopoverContext('useHasInputPopoverParent', () => true, false);\n\n // useContext will return undefined if the called is not wrapped in the provider\n return context !== undefined;\n}\n\nexport { InputPopover, useHasInputPopoverParent };\n"],"names":["InputPopoverProvider","useInputPopoverContext","createContext","InputPopover","documentResponse","iframeRef","usePreviewContext","state","popoverField","setPopoverField","schema","current","iframeRect","getBoundingClientRect","_jsxs","_Fragment","_jsx","Box","position","top","left","width","height","zIndex","Popover","Root","open","onOpenChange","Trigger","transform","Content","sideOffset","padding","InputRenderer","document","attribute","attributes","path","label","name","type","visible","useHasInputPopoverParent","context","undefined"],"mappings":";;;;;;;;;AAeA,MAAM,CAACA,oBAAAA,EAAsBC,sBAAuB,CAAA,GAClDC,yBAAwC,CAAA,cAAA,CAAA;AAE1C,MAAMC,YAAe,GAAA,CAAC,EAAEC,gBAAgB,EAAiD,GAAA;AACvF,IAAA,MAAMC,YAAYC,yBAAkB,CAAA,sBAAA,EAAwB,C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I,MAAM,GAAG,IAAA;gCACvCH,GAAK,EAAA,CAAA;gCACLC,IAAM,EAAA,CAAA;gCACNS,SAAW,EAAA,CAAC,UAAU,EAAEjB,UAAAA,CAAWQ,IAAI,GAAGZ,YAAAA,CAAaU,QAAQ,CAACE,IAAI,CAAC,IAAI,EAAER,UAAAA,CAAWO,GAAG,GAAGX,YAAAA,CAAaU,QAAQ,CAACC,GAAG,CAAC,GAAG;;;AAG7H,sCAAAH,cAAA,CAACQ,qBAAQM,OAAO,EAAA;4BAACC,UAAY,EAAA,CAAA;AAC3B,4BAAA,QAAA,gBAAAf,cAACC,CAAAA,gBAAAA,EAAAA;gCAAIe,OAAS,EAAA,CAAA;gCAAGX,KAAM,EAAA,OAAA;AACrB,gCAAA,QAAA,gBAAAL,cAACiB,CAAAA,2BAAAA,EAAAA;oCACCC,QAAU9B,EAAAA,gBAAAA;AACV+B,oCAAAA,SAAAA,EAAW/B,iBAAiBM,MAAM,CAAC0B,UAAU,CAAC5B,YAAAA,CAAa6B,IAAI,CAAC;AAChEC,oCAAAA,KAAAA,EAAO9B,aAAa6B,IAAI;AACxBE,oCAAAA,IAAAA,EAAM/B,aAAa6B,IAAI;oCACvBG,IAAMpC,EAAAA,gBAAAA,CAAiBM,MAAM,CAAC0B,UAAU,CAAC5B,YAAa6B,CAAAA,IAAI,CAAC,CAACG,IAAI;oCAChEC,OAAS,EAAA;;;;;;;;;AAQzB;AAEA,SAASC,wBAAAA,GAAAA;AACP,IAAA,MAAMC,OAAU1C,GAAAA,sBAAAA,CAAuB,0BAA4B,EAAA,IAAM,IAAM,EAAA,KAAA,CAAA;;AAG/E,IAAA,OAAO0C,OAAYC,KAAAA,SAAAA;AACrB;;;;;"}
@@ -0,0 +1,70 @@
1
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
+ import 'react';
3
+ import { createContext } from '@strapi/admin/strapi-admin';
4
+ import { Box, Popover } from '@strapi/design-system';
5
+ import { InputRenderer as MemoizedInputRenderer } from '../../pages/EditView/components/InputRenderer.mjs';
6
+ import { usePreviewContext } from '../pages/Preview.mjs';
7
+
8
+ const [InputPopoverProvider, useInputPopoverContext] = createContext('InputPopover');
9
+ const InputPopover = ({ documentResponse })=>{
10
+ const iframeRef = usePreviewContext('VisualEditingPopover', (state)=>state.iframeRef);
11
+ const popoverField = usePreviewContext('VisualEditingPopover', (state)=>state.popoverField);
12
+ const setPopoverField = usePreviewContext('VisualEditingPopover', (state)=>state.setPopoverField);
13
+ if (!popoverField || !documentResponse.schema || !iframeRef.current) {
14
+ return null;
15
+ }
16
+ const iframeRect = iframeRef.current.getBoundingClientRect();
17
+ return /*#__PURE__*/ jsxs(Fragment, {
18
+ children: [
19
+ /*#__PURE__*/ jsx(Box, {
20
+ position: 'fixed',
21
+ top: iframeRect.top + 'px',
22
+ left: iframeRect.left + 'px',
23
+ width: iframeRect.width + 'px',
24
+ height: iframeRect.height + 'px',
25
+ zIndex: 4
26
+ }),
27
+ /*#__PURE__*/ jsx(InputPopoverProvider, {
28
+ children: /*#__PURE__*/ jsxs(Popover.Root, {
29
+ open: true,
30
+ onOpenChange: (open)=>!open && setPopoverField(null),
31
+ children: [
32
+ /*#__PURE__*/ jsx(Popover.Trigger, {
33
+ children: /*#__PURE__*/ jsx(Box, {
34
+ position: "fixed",
35
+ width: popoverField.position.width + 'px',
36
+ height: popoverField.position.height + 'px',
37
+ top: 0,
38
+ left: 0,
39
+ transform: `translate(${iframeRect.left + popoverField.position.left}px, ${iframeRect.top + popoverField.position.top}px)`
40
+ })
41
+ }),
42
+ /*#__PURE__*/ jsx(Popover.Content, {
43
+ sideOffset: 4,
44
+ children: /*#__PURE__*/ jsx(Box, {
45
+ padding: 4,
46
+ width: "400px",
47
+ children: /*#__PURE__*/ jsx(MemoizedInputRenderer, {
48
+ document: documentResponse,
49
+ attribute: documentResponse.schema.attributes[popoverField.path],
50
+ label: popoverField.path,
51
+ name: popoverField.path,
52
+ type: documentResponse.schema.attributes[popoverField.path].type,
53
+ visible: true
54
+ })
55
+ })
56
+ })
57
+ ]
58
+ })
59
+ })
60
+ ]
61
+ });
62
+ };
63
+ function useHasInputPopoverParent() {
64
+ const context = useInputPopoverContext('useHasInputPopoverParent', ()=>true, false);
65
+ // useContext will return undefined if the called is not wrapped in the provider
66
+ return context !== undefined;
67
+ }
68
+
69
+ export { InputPopover, useHasInputPopoverParent };
70
+ //# sourceMappingURL=InputPopover.mjs.map