{"version":3,"file":"use-checkbox-model.mjs","sources":["../../../../../../../packages/components/checkbox/src/composables/use-checkbox-model.ts"],"sourcesContent":["import { computed, getCurrentInstance, inject, ref } from 'vue'\nimport { isArray, isUndefined } from '@element-plus/utils'\nimport { UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport { checkboxGroupContextKey } from '../constants'\n\nimport type { CheckboxProps } from '../checkbox'\n\nexport const useCheckboxModel = (props: CheckboxProps) => {\n const selfModel = ref(false)\n const { emit } = getCurrentInstance()!\n const checkboxGroup = inject(checkboxGroupContextKey, undefined)\n const isGroup = computed(() => isUndefined(checkboxGroup) === false)\n const isLimitExceeded = ref(false)\n const model = computed({\n get() {\n return isGroup.value\n ? checkboxGroup?.modelValue?.value\n : props.modelValue ?? selfModel.value\n },\n\n set(val: unknown) {\n if (isGroup.value && isArray(val)) {\n isLimitExceeded.value =\n checkboxGroup?.max?.value !== undefined &&\n val.length > checkboxGroup?.max.value &&\n val.length > model.value.length\n isLimitExceeded.value === false && checkboxGroup?.changeEvent?.(val)\n } else {\n emit(UPDATE_MODEL_EVENT, val)\n selfModel.value = val\n }\n },\n })\n\n return {\n model,\n isGroup,\n isLimitExceeded,\n }\n}\n\nexport type CheckboxModel = ReturnType\n"],"names":[],"mappings":";;;;;;;;AAIY,MAAC,gBAAgB,GAAG,CAAC,KAAK,KAAK;AAC3C,EAAE,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;AAC/B,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,kBAAkB,EAAE,CAAC;AACxC,EAAE,MAAM,aAAa,GAAG,MAAM,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC,CAAC;AAChE,EAAE,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,WAAW,CAAC,aAAa,CAAC,KAAK,KAAK,CAAC,CAAC;AACvE,EAAE,MAAM,eAAe,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;AACrC,EAAE,MAAM,KAAK,GAAG,QAA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