{"version":3,"file":"use-move.mjs","sources":["../../../../../../../packages/components/transfer/src/composables/use-move.ts"],"sourcesContent":["import { CHANGE_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport { usePropsAlias } from './use-props-alias'\n\nimport type { SetupContext } from 'vue'\nimport type {\n TransferCheckedState,\n TransferDataItem,\n TransferDirection,\n TransferEmits,\n TransferKey,\n TransferProps,\n} from '../transfer'\n\nexport const useMove = (\n props: TransferProps,\n checkedState: TransferCheckedState,\n emit: SetupContext['emit']\n) => {\n const propsAlias = usePropsAlias(props)\n\n const _emit = (\n value: TransferKey[],\n direction: TransferDirection,\n movedKeys: TransferKey[]\n ) => {\n emit(UPDATE_MODEL_EVENT, value)\n emit(CHANGE_EVENT, value, direction, movedKeys)\n }\n\n const addToLeft = () => {\n const currentValue = props.modelValue.slice()\n\n checkedState.rightChecked.forEach((item) => {\n const index = currentValue.indexOf(item)\n if (index > -1) {\n currentValue.splice(index, 1)\n }\n })\n _emit(currentValue, 'left', checkedState.rightChecked)\n }\n\n const addToRight = () => {\n let currentValue = props.modelValue.slice()\n\n const itemsToBeMoved = props.data\n .filter((item: TransferDataItem) => {\n const itemKey = item[propsAlias.value.key]\n return (\n checkedState.leftChecked.includes(itemKey) &&\n !props.modelValue.includes(itemKey)\n )\n })\n .map((item) => item[propsAlias.value.key])\n\n currentValue =\n props.targetOrder === 'unshift'\n ? itemsToBeMoved.concat(currentValue)\n : currentValue.concat(itemsToBeMoved)\n\n if (props.targetOrder === 'original') {\n currentValue = props.data\n .filter((item) => currentValue.includes(item[propsAlias.value.key]))\n .map((item) => item[propsAlias.value.key])\n }\n\n _emit(currentValue, 'right', checkedState.leftChecked)\n }\n\n return {\n addToLeft,\n addToRight,\n }\n}\n"],"names":[],"mappings":";;;;AAEY,MAAC,OAAO,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,KAAK;AACtD,EAAE,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AAC1C,E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