neodrag
neodrag copied to clipboard
add hook to retrigger recompute of control zones manually
there is no way (that I can find) to recompute control zones manually in v3. this is needed in case you may have a resizable element with a drag handle, as the drag handle doesn't seem to recompute it's control area after resize.
this is the hack i've come up with to recompute allow zones on the fly. had to copy over some types as they are not exported. I use this on a callback for onResizeEnd in my resize attachment, it works fine. I tried to do this with compartments and an effect, it worked but sometimes it didn't recompute the allow zones.
function recomputeDraggableZones() {
if (ref && instances.has(ref)) {
const data: ControlsPluginData = instances.get(ref)!.states.get('neodrag:controls');
const { allow_zones, block_zones } = data.compute_zones();
data.allow_zones = allow_zones;
data.block_zones = block_zones;
}
}