{"version":3,"file":"index.js","sources":["../../../../../packages/hooks/use-empty-values/index.ts"],"sourcesContent":["import { computed, getCurrentInstance, inject, ref } from 'vue'\nimport { buildProps, debugWarn, isFunction } from '@element-plus/utils'\n\nimport type { ExtractPropTypes, InjectionKey, Ref } from 'vue'\n\ntype EmptyValuesContext = ExtractPropTypes\n\nexport const emptyValuesContextKey: InjectionKey> =\n Symbol('emptyValuesContextKey')\nexport const SCOPE = 'use-empty-values'\nexport const DEFAULT_EMPTY_VALUES = ['', undefined, null]\nexport const DEFAULT_VALUE_ON_CLEAR = undefined\n\nexport const useEmptyValuesProps = buildProps({\n /**\n * @description empty values supported by the component\n */\n emptyValues: Array,\n /**\n * @description return value when cleared, if you want to set `undefined`, use `() => undefined`\n */\n valueOnClear: {\n type: [String, Number, Boolean, Function],\n default: undefined,\n validator: (val: any) => (isFunction(val) ? !val() : !val),\n },\n} as const)\n\nexport const useEmptyValues = (\n props: EmptyValuesContext,\n defaultValue?: null | undefined\n) => {\n const config = getCurrentInstance()\n ? inject(emptyValuesContextKey, ref({}))\n : ref({})\n\n const emptyValues = computed(\n () => props.emptyValues || config.value.emptyValues || DEFAULT_EMPTY_VALUES\n )\n\n const valueOnClear = computed(() => {\n // function is used for undefined cause undefined can't be a value of prop\n if (isFunction(props.valueOnClear)) {\n return props.valueOnClear()\n } else if (props.valueOnClear !== undefined) {\n return props.valueOnClear\n } else if (isFunction(config.value.valueOnClear)) {\n return config.value.valueOnClear()\n } else if (config.value.valueOnClear !== undefined) {\n return config.value.valueOnClear\n }\n return defaultValue !== undefined ? defaultValue : DEFAULT_VALUE_ON_CLEAR\n })\n\n const isEmptyValue = (value: any) => {\n return emptyValues.value.includes(value)\n }\n\n if (!emptyValues.value.includes(valueOnClear.value)) {\n debugWarn(SCOPE, 'value-on-clear should be a value of empty-values')\n }\n\n return {\n emptyValues,\n valueOnClear,\n isEmptyValue,\n }\n}\n"],"names":["buildProps","isFunction","getCurrentInstance","inject","ref","computed","debugWarn"],"mappings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