Skip to content

Commit

Permalink
fix: fix moveable container #732
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Sep 11, 2022
1 parent 90f40e2 commit d2fec43
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions packages/svelte-moveable/src/Moveable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
const dispatch = createEventDispatcher();
let options = {};
let container;
let moveableElement;
let moveable;
beforeUpdate(() => {
Expand All @@ -27,32 +28,26 @@
options[name] = props[name];
}
});
container = options.container || $$props.container || document.body;
if (moveable) {
tick().then(() => {
moveable.setState({
...options,
container,
parentElement: container
});
});
}
});
onMount(() => {
moveable = new VanillaMoveable(container || document.body, options);
moveable = new VanillaMoveable(moveableElement, {
...options
portalContainer: moveableElement,
});
EVENTS.forEach(name => {
const onName = camelize(`on ${name}`);
moveable.on(name, e => {
const result = $$props[onName] && $$props[onName](e);
const result2 = dispatch(name, e);
return !isUndefined(result)
? result
: !isUndefined(result2)
? result2
: undefined;
$$props[onName] && $$props[onName](e);
dispatch(name, e);
});
});
});
Expand All @@ -64,3 +59,4 @@
return moveable;
}
</script>
<div bind:this={moveableElement}></div>

0 comments on commit d2fec43

Please sign in to comment.