{"version":3,"file":"forms.mjs","sources":["../../../../../admin/src/pages/EditView/utils/forms.ts"],"sourcesContent":["import type { ComponentsDictionary, Document } from '../../../hooks/useDocument';\nimport type { Schema } from '@strapi/types';\n\ntype AnyData = Omit;\n\n/* -------------------------------------------------------------------------------------------------\n * createDefaultForm\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal Using the content-type schema & the components dictionary of the content-type,\n * creates a form with pre-filled default values. This is used when creating a new entry.\n */\nconst createDefaultForm = (\n contentType: Schema.Schema,\n components: ComponentsDictionary = {}\n): AnyData => {\n const traverseSchema = (attributes: Schema.Schema['attributes']): AnyData => {\n return Object.entries(attributes).reduce((acc, [key, attribute]) => {\n if ('default' in attribute) {\n acc[key] = attribute.default;\n } else if (attribute.type === 'component' && attribute.required) {\n const defaultComponentForm = traverseSchema(components[attribute.component].attributes);\n\n if (attribute.repeatable) {\n acc[key] = attribute.min ? [...Array(attribute.min).fill(defaultComponentForm)] : [];\n } else {\n acc[key] = defaultComponentForm;\n }\n } else if (attribute.type === 'dynamiczone' && attribute.required) {\n acc[key] = [];\n }\n\n return acc;\n }, {});\n };\n\n return traverseSchema(contentType.attributes);\n};\n\nexport { createDefaultForm };\n"],"names":["createDefaultForm","contentType","components","traverseSchema","attributes","Object","entries","reduce","acc","key","attribute","default","type","required","defaultComponentForm","component","repeatable","min","Array","fill"],"mappings":"AAKA;;;;;AAOC,UACKA,iBAAAA,GAAoB,CACxBC,WAAAA,EACAC,UAAAA,GAAmC,EAAE,GAAA;AAErC,IAAA,MAAMC,iBAAiB,CAACC,UAAAA,GAAAA;QACtB,OAAOC,MAAAA,CAAOC,OAAO,CAACF,UAAAA,CAAAA,CAAYG,MAAM,CAAU,CAACC,GAAAA,EAAK,CAACC,GAAAA,EAAKC,SAAAA,CAAU,GAAA;AACtE,YAAA,IAAI,aAAaA,SAAAA,EAAW;AAC1BF,gBAAAA,GAAG,CAACC,GAAAA,CAAI,GAAGC,SAAAA,CAAUC,OAAO;AAC9B,YAAA,CAAA,MAAO,IAAID,SAAAA,CAAUE,IAAI,KAAK,WAAA,IAAeF,SAAAA,CAAUG,QAAQ,EAAE;gBAC/D,MAAMC,oBAAAA,GAAuBX,eAAeD,UAAU,CAACQ,UAAUK,SAAS,CAAC,CAACX,UAAU,CAAA;gBAEtF,IAAIM,SAAAA,CAAUM,UAAU,EAAE;AACxBR,oBAAAA,GAAG,CAACC,GAAAA,CAAI,GAAGC,SAAAA,CAAUO,GAAG,GAAG;AAAIC,wBAAAA,GAAAA,KAAAA,CAAMR,SAAAA,CAAUO,GAAG,CAAA,CAAEE,IAAI,CAACL,oBAAAA;AAAsB,qBAAA,GAAG,EAAE;gBACtF,CAAA,MAAO;oBACLN,GAAG,CAACC,IAAI,GAAGK,oBAAAA;AACb,gBAAA;AACF,YAAA,CAAA,MAAO,IAAIJ,SAAAA,CAAUE,IAAI,KAAK,aAAA,IAAiBF,SAAAA,CAAUG,QAAQ,EAAE;gBACjEL,GAAG,CAACC,GAAAA,CAAI,GAAG,EAAE;AACf,YAAA;YAEA,OAAOD,GAAAA;AACT,QAAA,CAAA,EAAG,EAAC,CAAA;AACN,IAAA,CAAA;IAEA,OAAOL,cAAAA,CAAeF,YAAYG,UAAU,CAAA;AAC9C;;;;"}