How can I respond to the _onDrop event in the shell?
I'm working with a SvelteApplication. I can edit the _onDrop method on the sheet but how do I react to it in the svelte shell?
19 Replies
One way is to have the shell parse the drop event
<div on:drop={func}></div>
if you want to still use _onDrop, you'd need to pass the event to the shell, likely through contextSo I don't want to lose the existing drop functionality in the sheet, I just want to #metoo in the shell
make the shell add a function to the window context then, and have _onDrop call that function
Actually I'm a bit confused now about what's handling the drop. I don't have any drop handlers so it must be native for foundry Item?
const application = getContext("#external").application;
has these properties...
but if I try define my own __dragDrop function on the ItemSheet it doesn't get run
Ah.. nvm, I'm being an idiot. There's a drop handler in the shell 🤦🏻♂️Lol
So the problem I'm having is that it doesn't seem to be possible to access properties on the child from the parent if the child is a dynamic
svelete:component
E.g.
Neither remoteComponent
nor childRef
provide a reference, just a proxy object which has none of the child's properties.You are trying to have the child send data to the parent, right?
The dlop handler is on the parent. So when that runs, I want to trigger a value to reset in the child
I am admittedly once again befuddled by why even doing the whole remote component thing but trying to ignore that for now
remote component?
Oh.. that's just an example
It's a dynamic import and a dynamic child element.
Why... because with great power comes great irresponsibility
so you want to do something on the child when a parent gets a drop event?
yes!
that.. parent must direct child, because children are idiots.
i will once again tell you to see the context api https://svelte.dev/tutorial/context-api
Svelte tutorial
Context API / setContext and getContext
I mean, I know what that is. I'm just not quite seeing how it applies here.
you can also export a function from the child component that the parent can call
Well I tried the latter... but can't get that to work with a dynamic component
Because the dyanmic component doesn't let you bind a reference to it.
afaict
The parent creates a context.
The child adds a function to that context that resets something in itself.
The parent calls that function.
The child resets itself.
Brilliant! Tx. I hadn't quite grokked that context was bi-directional, even though I'd sorta been implicitly using it that way without thinking about it in other contexts.
The context API flows from parent to child components. However instead of putting a function into an object from the child perhaps create a custom store that can be set as a context item in the parent.
This way you can potentially reuse this mechanism across any number of child components and not set up a hard association between parent / child.
The custom store would look something like:
dropTargetStore.js:
Parent component:
Child component: