Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove on drag away (question / feature request) #602

Open
vyconm opened this issue Sep 19, 2024 · 10 comments
Open

Remove on drag away (question / feature request) #602

vyconm opened this issue Sep 19, 2024 · 10 comments
Labels
question Further information is requested

Comments

@vyconm
Copy link

vyconm commented Sep 19, 2024

I've looked through all the open issues and examples but can't seem to find something similar, so i'm going to take a shot here :) - is there any way to implement a "delete on drag" method? Like, if I drag an element to somewhere that isn't over or close to a dropzone, it should get deleted from the origin-list - kinda similar to how you can remove items from the macOS dock. Thanks for any input and awesome library! <3

@isaacHagoel
Copy link
Owner

isaacHagoel commented Sep 20, 2024 via email

@vyconm
Copy link
Author

vyconm commented Sep 20, 2024

Thanks for the quick reply!

Basically, yes - just delete it when it is outside of any droppable zone. My Basic Setup is:

Two dropzones - a) with building blocks b) with a timeline that receives the building blocks

--> on dropzone b) it would be convenient to drag an item away from it, and then it would delete it from the dropzone-list-array. A small delay would be helpful, but not necessary. Same for how close it needs to be for the delete action to switch between being on the dropzone or not being on it.

It's not a dealbreaker, but would be (in my usecase) an intuitive enhancement :)

@isaacHagoel
Copy link
Owner

isaacHagoel commented Sep 20, 2024 via email

@vyconm
Copy link
Author

vyconm commented Sep 20, 2024

I need to buy some reading glasses - sorry for the "dumb" question! Thank you so much!

Looking for triggers DRAGGED_LEFT_ALL on consider and DROPPED_OUTSID_OF_ANY provides exactly the functionality I am after.

One thing remaining: I cannot seem to be able to properly handle removing the shadow-item as well when it is being considered to be deleted, this is my functions rn:

function handleDndConsider2(e: CustomEvent<DndEvent>) {
		const { trigger, id } = e.detail.info;

		if (trigger === TRIGGERS.DRAGGED_LEFT_ALL) {
			console.warn(`maybe dropping ${id} outside of any`);
			e.detail.items = e.detail.items.filter(
				(item: AudioModule | unknown) => !item[SHADOW_ITEM_MARKER_PROPERTY_NAME] && item.id !== id
			);
			timelineAudio = e.detail.items;
			return;
		}
		timelineAudio = e.detail.items;
	}

	$inspect('timelineAudio', timelineAudio);
	function handleDndFinalize2(e: CustomEvent<DndEvent>) {
		const copy = timelineAudio;

		const { trigger, id } = e.detail.info;

		if (trigger === TRIGGERS.DROPPED_OUTSIDE_OF_ANY) {
			console.warn(`dropping ${id} outside of any`);
			e.detail.items = e.detail.items.filter(
				(item: AudioModule | unknown) => !item[SHADOW_ITEM_MARKER_PROPERTY_NAME] && item.id !== id
			);
			timelineAudio = e.detail.items;
			mashFiles();
			return;
		}

		if (copy === e.detail.items) {
			timelineAudio = e.detail.items;
			console.warn('No changes detected in the timeline audio array.');
			return;
		}
		timelineAudio = e.detail.items;
		getMaxAudioLength();
		mashFiles();
	}

@isaacHagoel
Copy link
Owner

isaacHagoel commented Sep 20, 2024 via email

@vyconm
Copy link
Author

vyconm commented Sep 20, 2024

Sure thing, good idea:

https://svelte.dev/repl/46ac9355a1a343d59f0a27e19c32e7d3?version=3.59.2

Basically, when dragging the items away from the "timeline" I would like to placeholder to not exist when considering deleting it, ad then reeapper when considering leaving it back or changing its index. Hope that helps!

@isaacHagoel
Copy link
Owner

isaacHagoel commented Sep 20, 2024 via email

@vyconm
Copy link
Author

vyconm commented Sep 20, 2024

I did think about that - unfortunately I need a placeholder when I drag an item from the bottom list into the top one.

I used the dragula example just as a starting point for the repl, as my bottom list basically behaves the same (i used that for reference)

so what I am trying to achieve:

--> if drag from bottom list into top one -- always shadow element
--> if drag from top list back to different position -- always shadow element
--> if drag from top list away (deleting it) -- no shadow element, which would have the added effect of not animating the item back into the position before deleting it

@isaacHagoel
Copy link
Owner

isaacHagoel commented Sep 20, 2024 via email

@isaacHagoel
Copy link
Owner

I just released a new version with an option to disable the final drop animation if you still need that

@isaacHagoel isaacHagoel added the question Further information is requested label Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants