UNPKG

bootstrap-vue-next

Version:

Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development

52 lines (51 loc) 1.82 kB
import { n as get } from "./object-C7YmCGEm.js"; import { computed, toValue } from "vue"; //#region src/composables/useFormSelect.ts var useFormSelect = (options, props) => { const isComplex = (option) => typeof option === "object" && option !== null && "options" in option && Array.isArray(option.options); const normalizeOption = (option) => { const propsValue = toValue(props); if (typeof option === "string") return { value: option, text: option }; if (typeof option === "number" || typeof option === "boolean") return { value: option, text: `${option}` }; if (option instanceof Date) return { value: option, text: option.toLocaleString() }; const value = get(option, propsValue.valueField); const text = get(option, propsValue.textField); const disabled = get(option, propsValue.disabledField); const opts = propsValue.optionsField ? get(option, propsValue.optionsField) : void 0; const label = (propsValue.labelField ? get(option, propsValue.labelField) : void 0) || text; if (opts !== void 0 && Array.isArray(opts)) return { label, options: opts }; const simpleOption = typeof option === "object" ? { ...option } : {}; const fieldsToOmit = /* @__PURE__ */ new Set(["label", "options"]); if (propsValue.labelField) fieldsToOmit.add(propsValue.labelField); if (propsValue.optionsField) fieldsToOmit.add(propsValue.optionsField); fieldsToOmit.forEach((field) => { delete simpleOption[field]; }); return { ...simpleOption, value, text, disabled }; }; const normalizeOptions = (opts) => opts.map((option) => normalizeOption(option)); return { normalizedOptions: computed(() => normalizeOptions(toValue(options))), isComplex }; }; //#endregion export { useFormSelect as t }; //# sourceMappingURL=useFormSelect-CwS8YuiQ.js.map