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
5.6 KiB

1 month ago
  1. {"ast":null,"code":"import { usePropsAlias } from './use-props-alias.mjs';\nimport { UPDATE_MODEL_EVENT, CHANGE_EVENT } from '../../../../constants/event.mjs';\nconst useMove = (props, checkedState, emit) => {\n const propsAlias = usePropsAlias(props);\n const _emit = (value, direction, movedKeys) => {\n emit(UPDATE_MODEL_EVENT, value);\n emit(CHANGE_EVENT, value, direction, movedKeys);\n };\n const addToLeft = () => {\n const currentValue = props.modelValue.slice();\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 const addToRight = () => {\n let currentValue = props.modelValue.slice();\n const itemsToBeMoved = props.data.filter(item => {\n const itemKey = item[propsAlias.value.key];\n return checkedState.leftChecked.includes(itemKey) && !props.modelValue.includes(itemKey);\n }).map(item => item[propsAlias.value.key]);\n currentValue = props.targetOrder === \"unshift\" ? itemsToBeMoved.concat(currentValue) : currentValue.concat(itemsToBeMoved);\n if (props.targetOrder === \"original\") {\n currentValue = props.data.filter(item => currentValue.includes(item[propsAlias.value.key])).map(item => item[propsAlias.value.key]);\n }\n _emit(currentValue, \"right\", checkedState.leftChecked);\n };\n return {\n addToLeft,\n addToRight\n };\n};\nexport { useMove };","map":{"version":3,"names":["useMove","props","checkedState","emit","propsAlias","usePropsAlias","_emit","value","direction","movedKeys","UPDATE_MODEL_EVENT","CHANGE_EVENT","addToLeft","currentValue","modelValue","slice","rightChecked","forEach","item","index","indexOf","splice","addToRight","itemsToBeMoved","data","filter","itemKey","key","leftChecked","includes","map","targetOrder","concat"],"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<TransferEmits>['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"],"mappings":";;AAEY,MAACA,OAAO,GAAGA,CAACC,KAAK,EAAEC,YAAY,EAAEC,IAAI,KAAK;EACp