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

Please make isItemsDragDisabled exported #617

Open
derheld42 opened this issue Nov 29, 2024 · 7 comments
Open

Please make isItemsDragDisabled exported #617

derheld42 opened this issue Nov 29, 2024 · 7 comments

Comments

@derheld42
Copy link

With the updated draggable handle, I've found a use case where I'd like to be able to subscribe to isItemsDragDisabled.

@isaacHagoel
Copy link
Owner

isaacHagoel commented Nov 30, 2024 via email

@derheld42
Copy link
Author

Totally open to other approaches -- this was me just trying to make things work :)
I wanted to track when dragging was happening in a state or a store. I used that to pause updates that were happening to the list that's being changed in the dragging.

In my local node_modules, I patched svelte-dnd-action with this to enable

file=node_modules/svelte-dnd-action/dist/index.mjs
patched="dndzone, isItemsDragDisabled, dragHandle"
unpatched="dndzone, dragHandle"
if ! grep "$patched" $file > /dev/null 2>&1; then
	echo Patching $file
	cp -v $file $file.orig
	sed -i "s/$unpatched/$patched/" $file
else
	echo $file already patched.
fi

file=node_modules/svelte-dnd-action/dist/index.d.ts
patched="export let isItemsDragDisabled: { subscribe: (cb : (arg: boolean) => void) => void };"
if ! grep "$patched" $file > /dev/null 2>&1; then
	echo Patching $file
	cp -v $file $file.orig
	echo $patched >> $file
else
	echo $file already patched.
fi

Then in my client code, I was able to subscribe to dragging events with:

import {
	type DndEvent,
	dragHandleZone,
	dragHandle,
	isItemsDragDisabled,
} from 'svelte-dnd-action';
...
isItemsDragDisabled.subscribe((disabled: boolean) => {
	if (!disabled) {
		g.itemsAddRemoveMutex++;
	}
	//console.log('isItemsDragDisabled:', disabled, g.itemsAddRemoveMutex);
});

@isaacHagoel
Copy link
Owner

isaacHagoel commented Nov 30, 2024 via email

@derheld42
Copy link
Author

The use case is that the items are draggable and when they start being drug, I want a callback to fire so I can do some logic.

I tried adding onmousedown and ontouchstart to the drag handle div, but it appears like the DragHandle action overrides them. When I removed the draghandle action, my onmousedown/ontouchstart callbacks were firing. After staring at the svelte-dnd-action code, I figured I'd try to subscribe to the isItemsDragDisabled store and it worked well --- after it was exported.

@isaacHagoel
Copy link
Owner

isaacHagoel commented Nov 30, 2024 via email

@derheld42
Copy link
Author

I think I tried that and the thought consider required a mouse move or thumb move before onconsider was called. If I’m wrong I’ll have to try that again.

@isaacHagoel
Copy link
Owner

isaacHagoel commented Nov 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants