You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
5.0 KiB
1 lines
5.0 KiB
{"ast":null,"code":"import { ref, computed } from 'vue';\nimport { castArray } from 'lodash-unified';\nimport { debugWarn } from '../../../utils/error.mjs';\nconst SCOPE = \"ElForm\";\nfunction useFormLabelWidth() {\n const potentialLabelWidthArr = ref([]);\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 function getLabelWidthIndex(width) {\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 function registerLabelWidth(val, oldVal) {\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 function deregisterLabelWidth(val) {\n const index = getLabelWidthIndex(val);\n if (index > -1) {\n potentialLabelWidthArr.value.splice(index, 1);\n }\n }\n return {\n autoLabelWidth,\n registerLabelWidth,\n deregisterLabelWidth\n };\n}\nconst filterFields = (fields, props) => {\n const normalized = castArray(props);\n return normalized.length > 0 ? fields.filter(field => field.prop && normalized.includes(field.prop)) : fields;\n};\nexport { filterFields, useFormLabelWidth };","map":{"version":3,"names":["SCOPE","useFormLabelWidth","potentialLabelWidthArr","ref","autoLabelWidth","computed","value","length","max","Math","getLabelWidthIndex","width","index","indexOf","debugWarn","registerLabelWidth","val","oldVal","splice","push","deregisterLabelWidth","filterFields","fields","props","normalized","castArray","filter","field","prop","includes"],"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<number[]>([])\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<FormItemProp>\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"],"mappings":";;;AAEA,MAAMA,KAAK,GAAG,QAAQ;AACf,SAASC,iBAAiBA,CAAA,EAAG;EAClC,MAAMC,sBAAsB,GAAGC,GAAG,CAAC,EAAE,CAAC;EACtC,MAAMC,cAAc,GAAGC,QAAQ,CAAC,MAAM;IACpC,IAAI,CAACH,sBAAsB,CAACI,KAAK,CAACC,MAAM,EACtC,OAAO,GAAG;IACZ,MAAMC,GAAG,GAAGC,IAAI,CAACD,GAAG,CAAC,GAAGN,sBAAsB,CAACI,KAAK,CAAC;IACrD,OAAOE,GAAG,GAAG,GAAGA,GAAG,IAAI,GAAG,EAAE;EAChC,CAAG,CAAC;EACF,SAASE,kBAAkBA,CAACC,KAAK,EAAE;IACjC,MAAMC,KAAK,GAAGV,sBAAsB,CAACI,KAAK,CAACO,OAAO,CAAC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