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.

0 lines
5.0 KiB

1 month ago
  1. {"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,CAACF,KAAK,CAAC;IACzD,IAAIC,KAAK,KAAK,CAAC,CAAC,IAAI