Fix crash when deleting a selected side panel component

This commit is contained in:
Andrew Kingston 2022-11-23 12:33:31 +00:00
parent 2f129e94fc
commit cf308bac94
1 changed files with 11 additions and 16 deletions

View File

@ -28,40 +28,32 @@
$: open = $sidePanelStore.contentId === $component.id $: open = $sidePanelStore.contentId === $component.id
const showInSidePanel = (el, visible) => { const showInSidePanel = (el, visible) => {
const target = document.getElementById("side-panel-container")
const node = el.parentNode
const destroy = () => {
if (target.contains(node)) {
target.removeChild(node)
}
}
const update = visible => { const update = visible => {
const target = document.getElementById("side-panel-container")
const node = el
if (visible) { if (visible) {
if (!target.contains(node)) { if (!target.contains(node)) {
target.appendChild(node) target.appendChild(node)
} }
el.hidden = false
} else { } else {
destroy() if (target.contains(node)) {
el.hidden = true target.removeChild(node)
}
} }
} }
// Apply initial visibility // Apply initial visibility
update(visible) update(visible)
return { return { update }
update,
destroy,
}
} }
</script> </script>
<div <div
use:styleable={$component.styles} use:styleable={$component.styles}
use:showInSidePanel={open} use:showInSidePanel={open}
hidden
class="side-panel" class="side-panel"
class:open
> >
<slot /> <slot />
</div> </div>
@ -69,12 +61,15 @@
<style> <style>
.side-panel { .side-panel {
flex: 1 1 auto; flex: 1 1 auto;
display: flex; display: none;
flex-direction: column; flex-direction: column;
justify-content: flex-start; justify-content: flex-start;
align-items: stretch; align-items: stretch;
gap: var(--spacing-xl); gap: var(--spacing-xl);
} }
.side-panel.open {
display: flex;
}
.side-panel :global(.component > *) { .side-panel :global(.component > *) {
max-width: 100%; max-width: 100%;
} }