utils.js 1.6 KB

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