element-plus
Version:
A Component Library for Vue 3
1 lines • 3.5 kB
Source Map (JSON)
{"version":3,"file":"useMove.mjs","sources":["../../../../../../packages/components/transfer/src/useMove.ts"],"sourcesContent":["import { CHANGE_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants'\n\nimport type { ComputedRef } from 'vue'\nimport type {\n DataItem,\n Key,\n TransferCheckedState,\n TransferProps,\n} from './transfer'\n\nexport const useMove = (\n props: TransferProps,\n checkedState: TransferCheckedState,\n propsKey: ComputedRef<string>,\n emit\n) => {\n const _emit = (value, type: 'left' | 'right', checked: Key[]) => {\n emit(UPDATE_MODEL_EVENT, value)\n emit(CHANGE_EVENT, value, type, checked)\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: DataItem) => {\n const itemKey = item[propsKey.value]\n return (\n checkedState.leftChecked.includes(itemKey) &&\n !props.modelValue.includes(itemKey)\n )\n })\n .map((item) => item[propsKey.value])\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[propsKey.value]))\n .map((item) => item[propsKey.value])\n }\n\n _emit(currentValue, 'right', checkedState.leftChecked)\n }\n\n return {\n addToLeft,\n addToRight,\n }\n}\n"],"names":[],"mappings":";;;AACY,MAAC,OAAO,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,KAAK;AAChE,EAAE,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,KAAK;AAC1C,IAAI,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;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