vue3-tree-vue icon indicating copy to clipboard operation
vue3-tree-vue copied to clipboard

Async drop validator does not work properly

Open bbddmm opened this issue 2 years ago • 3 comments

Hello, When using an async function with dropValidator, dropValidator doesn't work properly.

const onBeforeItemDropped = async (droppedItem: TreeViewItem, dropHost: any) => {
  if (!dropHost || !droppedItem) return false;
  if (dropHost.meta?.type !== 'Folder' || droppedItem.meta?.type === 'Folder')
    return false;

  await apiClient.someMethod();

  return true;
};
</script>

<template>
  <Vue3TreeVue
    :items="treeViewItems"
    @drop-validator="onBeforeItemDropped"
    @on-check="onItemChecked"
    @on-select="onItemSelected"
  >
    <template #item-prepend-icon="treeViewItem">
      <template v-if="treeViewItem.meta?.type === 'Folder'">
        <VIcon>{{ mdiFolder }}</VIcon>
      </template>
    </template>
  </Vue3TreeVue>
</template>

bbddmm avatar Oct 27 '23 05:10 bbddmm

I can confirm that correcting the line below fixes the bug.

// use-tree-mouse-actions.ts

      if (!isDropValid || !(await isDropValid(droppedNode, dropHost))) return;

https://github.com/geekhybrid/vue3-tree-vue/blob/e75a80aa88fc311ae63296610b0fe915e7fe48f9/src/composables/use-tree-mouse-actions.ts#L46

bbddmm avatar Oct 27 '23 05:10 bbddmm

Nice.

Thanks for looking into the code.

I think the original design did not consider an async drop validator function.

Feel free to contribute a fix with a PR. Otherwise, i will do that over the weekend.

geekhybrid avatar Oct 27 '23 06:10 geekhybrid

HI Is there any plan to apply this feature? I also need this functionality.

soraJang avatar Jul 31 '24 05:07 soraJang