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.
1 lines
5.6 KiB
1 lines
5.6 KiB
{"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;EACpD,MAAMC,UAAU,GAAGC,aAAa,CAACJ,KAAK,CAAC;EACvC,MAAMK,KAAK,GAAGA,CAACC,KAAK,EAAEC,SAAS,EAAEC,SAAS,KAAK;IAC7CN,IAAI,CAACO,kBAAkB,EAAEH,KAAK,CAAC;IAC/BJ,IAAI,CAACQ,YAAY,EAAEJ,KAAK,EAAEC,SAAS,EAAEC,S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