You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
7.2 KiB

1 month ago
  1. {"ast":null,"code":"import { inject, getCurrentInstance, computed, watch, nextTick } from 'vue';\nimport { checkboxGroupContextKey } from '../constants.mjs';\nimport { useFormItem } from '../../../form/src/hooks/use-form-item.mjs';\nimport { debugWarn } from '../../../../utils/error.mjs';\nconst useCheckboxEvent = (props, {\n model,\n isLimitExceeded,\n hasOwnLabel,\n isDisabled,\n isLabeledByFormItem\n}) => {\n const checkboxGroup = inject(checkboxGroupContextKey, void 0);\n const {\n formItem\n } = useFormItem();\n const {\n emit\n } = getCurrentInstance();\n function getLabeledValue(value) {\n var _a, _b, _c, _d;\n return [true, props.trueValue, props.trueLabel].includes(value) ? (_b = (_a = props.trueValue) != null ? _a : props.trueLabel) != null ? _b : true : (_d = (_c = props.falseValue) != null ? _c : props.falseLabel) != null ? _d : false;\n }\n function emitChangeEvent(checked, e) {\n emit(\"change\", getLabeledValue(checked), e);\n }\n function handleChange(e) {\n if (isLimitExceeded.value) return;\n const target = e.target;\n emit(\"change\", getLabeledValue(target.checked), e);\n }\n async function onClickRoot(e) {\n if (isLimitExceeded.value) return;\n if (!hasOwnLabel.value && !isDisabled.value && isLabeledByFormItem.value) {\n const eventTargets = e.composedPath();\n const hasLabel = eventTargets.some(item => item.tagName === \"LABEL\");\n if (!hasLabel) {\n model.value = getLabeledValue([false, props.falseValue, props.falseLabel].includes(model.value));\n await nextTick();\n emitChangeEvent(model.value, e);\n }\n }\n }\n const validateEvent = computed(() => (checkboxGroup == null ? void 0 : checkboxGroup.validateEvent) || props.validateEvent);\n watch(() => props.modelValue, () => {\n if (validateEvent.value) {\n formItem == null ? void 0 : formItem.validate(\"change\").catch(err => debugWarn(err));\n }\n });\n return {\n handleChange,\n onClickRoot\n };\n};\nexport { useCheckboxEvent };","map":{"version":3,"names":["useCheckboxEvent","props","model","isLimitExceeded","hasOwnLabel","isDisabled","isLabeledByFormItem","checkboxGroup","inject","checkboxGroupContextKey","formItem","useFormItem","emit","getCurrentInstance","getLabeledValue","value","_a","_b","_c","_d","trueValue","trueLabel","includes","falseValue","falseLabel","emitChangeEvent","checked","e","handleChange","target","onClickRoot","eventTargets","composedPath","hasLabel","some","item","tagName","nextTick","validateEvent","computed","watch","modelValue","validate","catch","err","debugWarn"],"sources":["../../../../../../../packages/components/checkbox/src/composables/use-checkbox-event.ts"],"sourcesContent":["import { computed, getCurrentInstance, inject, nextTick, watch } from 'vue'\nimport { useFormItem } from '@element-plus/components/form'\nimport { debugWarn } from '@element-plus/utils'\nimport { checkboxGroupContextKey } from '../constants'\n\nimport type { useFormItemInputId } from '@element-plus/components/form'\nimport type { CheckboxProps } from '../checkbox'\nimport type {\n CheckboxDisabled,\n CheckboxModel,\n CheckboxStatus,\n} from '../composables'\n\nexport const useCheckboxEvent = (\n props: CheckboxProps,\n {\n model,\n isLimitExceeded,\n hasOwnLabel,\n isDisabled,\n isLabeledByFormItem,\n }: Pick<CheckboxModel, 'model' | 'isLimitExceeded'> &\n Pick<CheckboxStatus, 'hasOwnLabel'> &\n Pick<CheckboxDisabled, 'isDisabled'> &\n Pick<ReturnType<typeof useFormItemInputId>, 'isLabeledByFormItem'>\n) => {\n const checkboxGroup = inject(checkboxGroupContextKey, undefined)\n const { formItem } = useFormItem()\n const { emit } = getCurrentInstance()!\n\n function getLabeledValue(value: string | number | boolean) {\n return [true, props.trueValue, props.trueLabel].includes(value)\n ? props.trueValue ?? props.trueLabel ?? true\n : props.falseValue ?? props.falseLabel ?? false\n }\n\n function emitChangeEvent(\n checked: string | number | boolean,\n e: InputEvent | MouseEvent