{"version":3,"file":"attributes.mjs","sources":["../../../admin/src/utils/attributes.ts"],"sourcesContent":["import type { ComponentsDictionary, Schema } from '../hooks/useDocument';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\nconst checkIfAttributeIsDisplayable = (attribute: SchemaUtils.Attribute.AnyAttribute) => {\n const { type } = attribute;\n\n if (type === 'relation') {\n return !attribute.relation.toLowerCase().includes('morph');\n }\n\n return !['json', 'dynamiczone', 'richtext', 'password', 'blocks'].includes(type) && !!type;\n};\n\ninterface MainField {\n name: string;\n type: SchemaUtils.Attribute.Kind | 'custom';\n}\n\n/**\n * @internal\n * @description given an attribute, content-type schemas & component schemas, find the mainField name & type.\n * If the attribute does not need a `mainField` then we return undefined. If we do not find the type\n * of the field, we assume it's a string #sensible-defaults\n */\nconst getMainField = (\n attribute: SchemaUtils.Attribute.AnyAttribute,\n mainFieldName: string | undefined,\n { schemas, components }: { schemas: Schema[]; components: ComponentsDictionary }\n): MainField | undefined => {\n if (!mainFieldName) {\n return undefined;\n }\n\n const mainFieldType =\n attribute.type === 'component'\n ? components[attribute.component].attributes[mainFieldName].type\n : // @ts-expect-error – `targetModel` does exist on the attribute for a relation.\n schemas.find((schema) => schema.uid === attribute.targetModel)?.attributes[mainFieldName]\n .type;\n\n return {\n name: mainFieldName,\n type: mainFieldType ?? 'string',\n };\n};\n\nexport { checkIfAttributeIsDisplayable, getMainField };\nexport type { MainField };\n"],"names":["checkIfAttributeIsDisplayable","attribute","type","relation","toLowerCase","includes","getMainField","mainFieldName","schemas","components","undefined","mainFieldType","component","attributes","find","schema","uid","targetModel","name"],"mappings":"AAGA,MAAMA,gCAAgC,CAACC,SAAAA,GAAAA;IACrC,MAAM,EAAEC,IAAI,EAAE,GAAGD,SAAAA;AAEjB,IAAA,IAAIC,SAAS,UAAY,EAAA;AACvB,QAAA,OAAO,CAACD,SAAUE,CAAAA,QAAQ,CAACC,WAAW,EAAA,CAAGC,QAAQ,CAAC,OAAA,CAAA;AACpD;AAEA,IAAA,OAAO,CAAC;AAAC,QAAA,MAAA;AAAQ,QAAA,aAAA;AAAe,QAAA,UAAA;AAAY,QAAA,UAAA;AAAY,QAAA;AAAS,KAAA,CAACA,QAAQ,CAACH,IAAS,CAAA,IAAA,CAAC,CAACA,IAAAA;AACxF;AAOA;;;;;IAMA,MAAMI,eAAe,CACnBL,SAAAA,EACAM,eACA,EAAEC,OAAO,EAAEC,UAAU,EAA2D,GAAA;AAEhF,IAAA,IAAI,CAACF,aAAe,EAAA;QAClB,OAAOG,SAAAA;AACT;AAEA,IAAA,MAAMC,aACJV,GAAAA,SAAAA,CAAUC,IAAI,KAAK,WACfO,GAAAA,UAAU,CAACR,SAAAA,CAAUW,SAAS,CAAC,CAACC,UAAU,CAACN,aAAc,CAAA,CAACL,IAAI,GAE9DM,OAAQM,CAAAA,IAAI,CAAC,CAACC,SAAWA,MAAOC,CAAAA,GAAG,KAAKf,SAAAA,CAAUgB,WAAW,CAAA,EAAGJ,UAAU,CAACN,cAAc,CACtFL,IAAAA;IAET,OAAO;QACLgB,IAAMX,EAAAA,aAAAA;AACNL,QAAAA,IAAAA,EAAMS,aAAiB,IAAA;AACzB,KAAA;AACF;;;;"}