d6e5c7c140dbed44921ce16fbc62a839585583521a00338a8892689ef410928b6e5272b63da5874643384f03b2d3c199c7d67d1f25373a6116316465748de1 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { ref, computed } from 'vue';
  2. import { castArray } from 'lodash-unified';
  3. import { isArray } from '@vue/shared';
  4. function useFormLabelWidth() {
  5. const potentialLabelWidthArr = ref([]);
  6. const autoLabelWidth = computed(() => {
  7. if (!potentialLabelWidthArr.value.length)
  8. return "0";
  9. const max = Math.max(...potentialLabelWidthArr.value);
  10. return max ? `${max}px` : "";
  11. });
  12. function getLabelWidthIndex(width) {
  13. const index = potentialLabelWidthArr.value.indexOf(width);
  14. if (index === -1 && autoLabelWidth.value === "0") ;
  15. return index;
  16. }
  17. function registerLabelWidth(val, oldVal) {
  18. if (val && oldVal) {
  19. const index = getLabelWidthIndex(oldVal);
  20. potentialLabelWidthArr.value.splice(index, 1, val);
  21. } else if (val) {
  22. potentialLabelWidthArr.value.push(val);
  23. }
  24. }
  25. function deregisterLabelWidth(val) {
  26. const index = getLabelWidthIndex(val);
  27. if (index > -1) {
  28. potentialLabelWidthArr.value.splice(index, 1);
  29. }
  30. }
  31. return {
  32. autoLabelWidth,
  33. registerLabelWidth,
  34. deregisterLabelWidth
  35. };
  36. }
  37. const filterFields = (fields, props) => {
  38. const normalized = castArray(props).map((prop) => isArray(prop) ? prop.join(".") : prop);
  39. return normalized.length > 0 ? fields.filter((field) => field.propString && normalized.includes(field.propString)) : fields;
  40. };
  41. export { filterFields, useFormLabelWidth };
  42. //# sourceMappingURL=utils.mjs.map