UNPKG

ivue-material-plus

Version:

A high quality UI components Library with Vue.js

53 lines (48 loc) 1.61 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var arrays = require('../../utils/arrays.js'); var error = require('../../utils/error.js'); const filterFields = (fields, props) => { const normalized = arrays.ensureArray(props); return normalized.length > 0 ? fields.filter((field) => field.prop && normalized.includes(field.prop)) : fields; }; function useFormLabelWidth() { const potentialLabelWidthArr = vue.ref([]); const autoLabelWidth = vue.computed(() => { if (!potentialLabelWidthArr.value.length) { return "0"; } const max = Math.max(...potentialLabelWidthArr.value); return max ? `${max}px` : ""; }); const getLabelWidthIndex = (width) => { const index = potentialLabelWidthArr.value.indexOf(width); if (index === -1 && autoLabelWidth.value === "0") { error.debugWarn("ivue-form", `unexpected width ${width}`); } return index; }; const registerLabelWidth = (value, oldValue) => { if (value && oldValue) { const index = getLabelWidthIndex(oldValue); potentialLabelWidthArr.value.splice(index, 1, value); } else if (value) { potentialLabelWidthArr.value.push(value); } }; const deregisterLabelWidth = (value) => { const index = getLabelWidthIndex(value); if (index > -1) { potentialLabelWidthArr.value.splice(index, 1); } }; return { autoLabelWidth, registerLabelWidth, deregisterLabelWidth }; } exports.filterFields = filterFields; exports.useFormLabelWidth = useFormLabelWidth; //# sourceMappingURL=utils.js.map