utils.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var lodashUnified = require('lodash-unified');
  5. var error = require('../../../utils/error.js');
  6. const SCOPE = "ElForm";
  7. function useFormLabelWidth() {
  8. const potentialLabelWidthArr = vue.ref([]);
  9. const autoLabelWidth = vue.computed(() => {
  10. if (!potentialLabelWidthArr.value.length)
  11. return "0";
  12. const max = Math.max(...potentialLabelWidthArr.value);
  13. return max ? `${max}px` : "";
  14. });
  15. function getLabelWidthIndex(width) {
  16. const index = potentialLabelWidthArr.value.indexOf(width);
  17. if (index === -1 && autoLabelWidth.value === "0") {
  18. error.debugWarn(SCOPE, `unexpected width ${width}`);
  19. }
  20. return index;
  21. }
  22. function registerLabelWidth(val, oldVal) {
  23. if (val && oldVal) {
  24. const index = getLabelWidthIndex(oldVal);
  25. potentialLabelWidthArr.value.splice(index, 1, val);
  26. } else if (val) {
  27. potentialLabelWidthArr.value.push(val);
  28. }
  29. }
  30. function deregisterLabelWidth(val) {
  31. const index = getLabelWidthIndex(val);
  32. if (index > -1) {
  33. potentialLabelWidthArr.value.splice(index, 1);
  34. }
  35. }
  36. return {
  37. autoLabelWidth,
  38. registerLabelWidth,
  39. deregisterLabelWidth
  40. };
  41. }
  42. const filterFields = (fields, props) => {
  43. const normalized = lodashUnified.castArray(props);
  44. return normalized.length > 0 ? fields.filter((field) => field.prop && normalized.includes(field.prop)) : fields;
  45. };
  46. exports.filterFields = filterFields;
  47. exports.useFormLabelWidth = useFormLabelWidth;
  48. //# sourceMappingURL=utils.js.map