| 1 |
<script lang="ts"> |
| 2 |
import { createEventDispatcher, onMount } from "svelte"; |
| 3 |
import { viewOptions } from "../lib/settings"; |
| 4 |
import ViewOptionsCallStack from "./ViewOptionsCallStack.svelte"; |
| 5 |
import ViewOptionsTimeline from "./ViewOptionsTimeline.svelte"; |
| 6 |
import { onClickOutside } from "../lib/utils"; |
| 7 |
|
| 8 |
const dispatch = createEventDispatcher(); |
| 9 |
function clickOutside() { |
| 10 |
dispatch("close"); |
| 11 |
} |
| 12 |
let rootElement: HTMLElement | undefined; |
| 13 |
let boxElement: HTMLElement | undefined; |
| 14 |
onMount(() => { |
| 15 |
if (!boxElement) return; |
| 16 |
return onClickOutside(boxElement, clickOutside, {ignore: [".js-view-options-button"]}); |
| 17 |
}) |
| 18 |
function ensureBoxIsOnScreen() { |
| 19 |
// small screens might have the box off-screen |
| 20 |
if (!rootElement || !boxElement) return; |
| 21 |
const rootRect = rootElement.getBoundingClientRect(); |
| 22 |
const boxRect = boxElement.getBoundingClientRect(); |
| 23 |
const boxWidth = boxRect.width; |
| 24 |
if (rootRect.right - boxWidth - 20 < 0) { |
| 25 |
boxElement.style.right = `${rootRect.right - boxWidth - 20}px`; |
| 26 |
} else { |
| 27 |
boxElement.style.right = "0"; |
| 28 |
} |
| 29 |
} |
| 30 |
onMount(() => { |
| 31 |
ensureBoxIsOnScreen(); |
| 32 |
window.addEventListener("resize", ensureBoxIsOnScreen); |
| 33 |
return () => window.removeEventListener("resize", ensureBoxIsOnScreen); |
| 34 |
}); |
| 35 |
|
| 36 |
let title = "View options"; |
| 37 |
$: if ($viewOptions.viewMode === "call-stack") { |
| 38 |
title = "Call stack view options"; |
| 39 |
} else if ($viewOptions.viewMode === "timeline") { |
| 40 |
title = "Timeline view options"; |
| 41 |
} |
| 42 |
</script> |
| 43 |
|
| 44 |
<div class="view-options" bind:this={rootElement}> |
| 45 |
<div class="box" bind:this={boxElement}> |
| 46 |
<div class="title-row">{title}</div> |
| 47 |
<div class="body"> |
| 48 |
{#if $viewOptions.viewMode === "call-stack"} |
| 49 |
<ViewOptionsCallStack /> |
| 50 |
{:else if $viewOptions.viewMode === "timeline"} |
| 51 |
<ViewOptionsTimeline /> |
| 52 |
{/if} |
| 53 |
</div> |
| 54 |
</div> |
| 55 |
</div> |
| 56 |
|
| 57 |
<style lang="scss"> |
| 58 |
.view-options { |
| 59 |
position: absolute; |
| 60 |
z-index: 1; |
| 61 |
right: 0; |
| 62 |
} |
| 63 |
.box { |
| 64 |
width: 90vw; |
| 65 |
max-width: 282px; |
| 66 |
height: max-content; |
| 67 |
max-height: calc(100vh - 100px); |
| 68 |
position: absolute; |
| 69 |
right: 0; |
| 70 |
top: calc(100% + 4px); |
| 71 |
border-radius: 5px; |
| 72 |
border: 1px solid #4e5255; |
| 73 |
background: #2a2f32; |
| 74 |
box-shadow: 0px 2px 14px -5px rgba(0, 0, 0, 0.25); |
| 75 |
overflow: hidden; |
| 76 |
display: flex; |
| 77 |
flex-direction: column; |
| 78 |
} |
| 79 |
.title-row { |
| 80 |
padding: 5px 9px; |
| 81 |
font-size: 12px; |
| 82 |
font-weight: 600; |
| 83 |
background-color: #3c4144; |
| 84 |
} |
| 85 |
.body { |
| 86 |
overflow-y: auto; |
| 87 |
flex-basis: content; |
| 88 |
flex-shrink: 1; |
| 89 |
} |
| 90 |
</style> |