upend/webui/src/components/BrowseColumn.svelte

152 lines
3.4 KiB
Svelte
Raw Normal View History

2022-02-09 20:59:21 +01:00
<script lang="ts">
import { createEventDispatcher, onMount, tick } from "svelte";
2022-02-09 20:59:21 +01:00
import { normUrl } from "../util/history";
import Inspect from "./Inspect.svelte";
import IconButton from "./utils/IconButton.svelte";
const dispatch = createEventDispatcher();
export let address: string;
export let index: number;
export let only: boolean;
let editable = false;
2022-02-09 23:58:56 +01:00
let detail = only;
let detailChanged = false;
$: if (!detailChanged) detail = only;
$: if (detailChanged) tick().then(() => dispatch("detail", detail));
2022-02-09 20:59:21 +01:00
onMount(() => {
// Required to make detail mode detection work in Browse
dispatch("detail", detail);
});
2022-02-09 20:59:21 +01:00
function visit() {
window.open(normUrl(`/browse/${address}`), "_blank");
}
2023-03-07 19:32:33 +01:00
let width = 460;
if (window.innerWidth < 600) {
width = window.innerWidth - 6;
}
2023-03-07 19:32:33 +01:00
function drag(ev: MouseEvent) {
const startWidth = width;
const startX = ev.screenX;
function onMouseMove(ev: MouseEvent) {
width = startWidth + (ev.screenX - startX);
width = width < 300 ? 300 : width;
}
function onMouseUp(_: MouseEvent) {
window.removeEventListener("mousemove", onMouseMove);
window.removeEventListener("mouseup", onMouseUp);
}
window.addEventListener("mousemove", onMouseMove);
window.addEventListener("mouseup", onMouseUp);
}
2022-02-09 20:59:21 +01:00
</script>
2023-06-05 19:51:11 +02:00
<div class="browse-column" class:detail>
2023-03-07 21:46:53 +01:00
<div class="view" class:editable style="--width: {width}px">
2023-03-07 19:32:33 +01:00
<header>
<IconButton
name="pencil"
on:click={() => (editable = !editable)}
active={editable}
2023-04-23 13:14:36 +02:00
>
Edit
</IconButton>
2023-03-07 19:32:33 +01:00
<IconButton
2023-04-20 21:15:03 +02:00
name={detail ? "zoom-out" : "zoom-in"}
2023-03-07 19:32:33 +01:00
on:click={() => {
detail = !detail;
detailChanged = true;
}}
active={detail}
2023-04-23 13:14:36 +02:00
>
Detail
</IconButton>
<IconButton name="link" on:click={() => visit()} disabled={only}>
2023-04-23 19:25:09 +02:00
Detach
2023-04-23 13:14:36 +02:00
</IconButton>
2023-03-07 19:32:33 +01:00
<IconButton
name="x-circle"
on:click={() => dispatch("close")}
disabled={only}
2023-04-23 13:14:36 +02:00
>
Close
</IconButton>
2023-03-07 19:32:33 +01:00
</header>
<Inspect
{address}
editable={editable || false}
{index}
{detail}
on:resolved
on:close
2022-02-09 23:58:56 +01:00
/>
2023-03-07 19:32:33 +01:00
</div>
<div class="resizeHandle" on:mousedown|preventDefault={drag} />
2022-02-09 20:59:21 +01:00
</div>
<style lang="scss">
2023-06-05 19:51:11 +02:00
.browse-column {
2023-03-07 19:32:33 +01:00
display: flex;
}
2023-06-05 19:51:11 +02:00
.browse-column.detail {
2023-03-07 21:46:53 +01:00
width: 100%;
2023-04-20 21:15:03 +02:00
2023-03-07 21:46:53 +01:00
.view {
@media screen and (min-width: 600px) {
min-width: 75vw;
max-width: min(75vw, 1920px);
margin-left: auto;
margin-right: auto;
}
2023-03-07 21:46:53 +01:00
}
}
2022-02-09 20:59:21 +01:00
.view {
2023-03-07 19:32:33 +01:00
min-width: var(--width);
max-width: var(--width);
2022-02-09 20:59:21 +01:00
display: flex;
flex-direction: column;
background: var(--background-lighter);
color: var(--foreground-lighter);
border: 1px solid var(--foreground-lightest);
border-radius: 0.5em;
padding: 1rem;
// transition: min-width 0.2s, max-width 0.2s;
// TODO - container has nowhere to scroll, breaking `detail` scroll
2022-02-09 23:35:17 +01:00
&.editable {
border-style: dashed;
}
2022-02-09 20:59:21 +01:00
header {
font-size: 20px;
position: relative;
min-height: 1em;
display: flex;
justify-content: space-between;
flex: none;
}
}
2023-03-07 19:32:33 +01:00
.resizeHandle {
cursor: ew-resize;
height: 100%;
width: 0.5rem;
@media screen and (max-width: 600px) {
display: none;
}
2023-03-07 19:32:33 +01:00
}
2022-02-09 20:59:21 +01:00
</style>