fb3732540b976cc07b16f2ee6545d2fb84029ac693360dbcabc9d43a134a11790119c100d042eca7fa4ec499821a33c4857d6c954c7935aeed3f71d80dd1bf 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { usePropsAlias } from './use-props-alias.mjs';
  2. import { UPDATE_MODEL_EVENT, CHANGE_EVENT } from '../../../../constants/event.mjs';
  3. const useMove = (props, checkedState, emit) => {
  4. const propsAlias = usePropsAlias(props);
  5. const _emit = (value, direction, movedKeys) => {
  6. emit(UPDATE_MODEL_EVENT, value);
  7. emit(CHANGE_EVENT, value, direction, movedKeys);
  8. };
  9. const addToLeft = () => {
  10. const currentValue = props.modelValue.slice();
  11. checkedState.rightChecked.forEach((item) => {
  12. const index = currentValue.indexOf(item);
  13. if (index > -1) {
  14. currentValue.splice(index, 1);
  15. }
  16. });
  17. _emit(currentValue, "left", checkedState.rightChecked);
  18. };
  19. const addToRight = () => {
  20. let currentValue = props.modelValue.slice();
  21. const itemsToBeMoved = props.data.filter((item) => {
  22. const itemKey = item[propsAlias.value.key];
  23. return checkedState.leftChecked.includes(itemKey) && !props.modelValue.includes(itemKey);
  24. }).map((item) => item[propsAlias.value.key]);
  25. currentValue = props.targetOrder === "unshift" ? itemsToBeMoved.concat(currentValue) : currentValue.concat(itemsToBeMoved);
  26. if (props.targetOrder === "original") {
  27. currentValue = props.data.filter((item) => currentValue.includes(item[propsAlias.value.key])).map((item) => item[propsAlias.value.key]);
  28. }
  29. _emit(currentValue, "right", checkedState.leftChecked);
  30. };
  31. return {
  32. addToLeft,
  33. addToRight
  34. };
  35. };
  36. export { useMove };
  37. //# sourceMappingURL=use-move.mjs.map