{"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 if (attribute.type === 'component') {\n const mainFieldType = components[attribute.component]?.attributes?.[mainFieldName]?.type;\n\n return {\n name: mainFieldType ? mainFieldName : 'id',\n type: mainFieldType ?? 'custom',\n };\n }\n\n if (attribute.type === 'relation') {\n const target =\n 'targetModel' in attribute\n ? attribute.targetModel\n : 'target' in attribute\n ? attribute.target\n : undefined;\n const targetSchema = schemas.find((schema) => schema.uid === target);\n const mainFieldType = targetSchema?.attributes?.[mainFieldName]?.type;\n\n return {\n name: !targetSchema || mainFieldType ? mainFieldName : 'id',\n type: mainFieldType ?? 'custom',\n };\n }\n\n return {\n name: mainFieldName,\n type: '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","name","target","targetModel","targetSchema","find","schema","uid"],"mappings":"AAGA,MAAMA,gCAAgC,CAACC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