{"version":3,"file":"use-check.js","sources":["../../../../../../../packages/components/transfer/src/composables/use-check.ts"],"sourcesContent":["import { computed, watch } from 'vue'\nimport { isFunction } from '@element-plus/utils'\nimport { CHECKED_CHANGE_EVENT } from '../transfer-panel'\nimport { usePropsAlias } from './use-props-alias'\n\nimport type { SetupContext } from 'vue'\nimport type { CheckboxValueType } from '@element-plus/components/checkbox'\nimport type { TransferKey } from '../transfer'\nimport type {\n TransferPanelEmits,\n TransferPanelProps,\n TransferPanelState,\n} from '../transfer-panel'\n\nexport const useCheck = (\n props: TransferPanelProps,\n panelState: TransferPanelState,\n emit: SetupContext['emit']\n) => {\n const propsAlias = usePropsAlias(props)\n\n const filteredData = computed(() => {\n return props.data.filter((item) => {\n if (isFunction(props.filterMethod)) {\n return props.filterMethod(panelState.query, item)\n } else {\n const label = String(\n item[propsAlias.value.label] || item[propsAlias.value.key]\n )\n return label.toLowerCase().includes(panelState.query.toLowerCase())\n }\n })\n })\n\n const checkableData = computed(() =>\n filteredData.value.filter((item) => !item[propsAlias.value.disabled])\n )\n\n const checkedSummary = computed(() => {\n const checkedLength = panelState.checked.length\n const dataLength = props.data.length\n const { noChecked, hasChecked } = props.format\n\n if (noChecked && hasChecked) {\n return checkedLength > 0\n ? hasChecked\n .replace(/\\${checked}/g, checkedLength.toString())\n .replace(/\\${total}/g, dataLength.toString())\n : noChecked.replace(/\\${total}/g, dataLength.toString())\n } else {\n return `${checkedLength}/${dataLength}`\n }\n })\n\n const isIndeterminate = computed(() => {\n const checkedLength = panelState.checked.length\n return checkedLength > 0 && checkedLength < checkableData.value.length\n })\n\n const updateAllChecked = () => {\n const checkableDataKeys = checkableData.value.map(\n (item) => item[propsAlias.value.key]\n )\n panelState.allChecked =\n checkableDataKeys.length > 0 &&\n checkableDataKeys.every((item) => panelState.checked.includes(item))\n }\n\n const handleAllCheckedChange = (value: CheckboxValueType) => {\n panelState.checked = value\n ? checkableData.value.map((item) => item[propsAlias.value.key])\n : []\n }\n\n watch(\n () => panelState.checked,\n (val, oldVal) => {\n updateAllChecked()\n\n if (panelState.checkChangeByUser) {\n const movedKeys = val\n .concat(oldVal)\n .filter((v) => !val.includes(v) || !oldVal.includes(v))\n emit(CHECKED_CHANGE_EVENT, val, movedKeys)\n } else {\n emit(CHECKED_CHANGE_EVENT, val)\n panelState.checkChangeByUser = true\n }\n }\n )\n\n watch(checkableData, () => {\n updateAllChecked()\n })\n\n watch(\n () => props.data,\n () => {\n const checked: TransferKey[] = []\n const filteredDataKeys = filteredData.value.map(\n (item) => item[propsAlias.value.key]\n )\n panelState.checked.forEach((item) => {\n if (filteredDataKeys.includes(item)) {\n checked.push(item)\n }\n })\n panelState.checkChangeByUser = false\n panelState.checked = checked\n }\n )\n\n watch(\n () => props.defaultChecked,\n (val, oldVal) => {\n if (\n oldVal &&\n val.length === oldVal.length &&\n val.every((item) => oldVal.includes(item))\n )\n return\n\n const checked: TransferKey[] = []\n const checkableDataKeys = checkableData.value.map(\n (item) => item[propsAlias.value.key]\n )\n\n val.forEach((item) => {\n if (checkableDataKeys.includes(item)) {\n checked.push(item)\n }\n })\n panelState.checkChangeByUser = false\n panelState.checked = checked\n },\n {\n immediate: true,\n }\n )\n\n return {\n filteredData,\n checkableData,\n checkedSummary,\n isIndeterminate,\n updateAllChecked,\n handleAllCheckedChange,\n }\n}\n"],"names":["usePropsAlias","computed","isFunction","watch","CHECKED_CHANGE_EVENT"],"mappings":";;;;;;;;;;AAIY,MAAC,QAAQ,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,KAAK;AACrD,EAAE,MAAM,UAAU,GAAGA,2BAAa,CAAC,KAAK,CAAC,CAAC;AAC1C,EAAE,MAAM,YAAY,GAAGC,YAAQ,CAAC,MAAM;AACtC,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK;AACvC,MAAM,IAAIC,iBAAU,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;AAC1C,QAAQ,OAAO,KAAK,C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