{"version":3,"file":"utils.js","sources":["../../../../../../packages/components/form/src/utils.ts"],"sourcesContent":["import { computed, ref } from 'vue'\nimport { debugWarn, ensureArray } from '@element-plus/utils'\nimport type { Arrayable } from '@element-plus/utils'\nimport type { FormItemContext } from './types'\nimport type { FormItemProp } from './form-item'\n\nconst SCOPE = 'ElForm'\n\nexport function useFormLabelWidth() {\n const potentialLabelWidthArr = ref([])\n\n const autoLabelWidth = computed(() => {\n if (!potentialLabelWidthArr.value.length) return '0'\n const max = Math.max(...potentialLabelWidthArr.value)\n return max ? `${max}px` : ''\n })\n\n function getLabelWidthIndex(width: number) {\n const index = potentialLabelWidthArr.value.indexOf(width)\n if (index === -1 && autoLabelWidth.value === '0') {\n debugWarn(SCOPE, `unexpected width ${width}`)\n }\n return index\n }\n\n function registerLabelWidth(val: number, oldVal: number) {\n if (val && oldVal) {\n const index = getLabelWidthIndex(oldVal)\n potentialLabelWidthArr.value.splice(index, 1, val)\n } else if (val) {\n potentialLabelWidthArr.value.push(val)\n }\n }\n\n function deregisterLabelWidth(val: number) {\n const index = getLabelWidthIndex(val)\n if (index > -1) {\n potentialLabelWidthArr.value.splice(index, 1)\n }\n }\n\n return {\n autoLabelWidth,\n registerLabelWidth,\n deregisterLabelWidth,\n }\n}\n\nexport const filterFields = (\n fields: FormItemContext[],\n props: Arrayable\n) => {\n const normalized = ensureArray(props)\n return normalized.length > 0\n ? fields.filter((field) => field.prop && normalized.includes(field.prop))\n : fields\n}\n"],"names":["ref","computed","debugWarn","ensureArray"],"mappings":";;;;;;;;;AAEA,MAAM,KAAK,GAAG,QAAQ,CAAC;AAChB,SAAS,iBAAiB,GAAG;AACpC,EAAE,MAAM,sBAAsB,GAAGA,OAAG,CAAC,EAAE,CAAC,CAAC;AACzC,EAAE,MAAM,cAAc,GAAGC,YAAQ,CAAC,MAAM;AACxC,IAAI,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,MAAM;AAC5C,MAAM,OAAO,GAAG,CAAC;AACjB,IAAI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