2022-02-09 20:59:21 +01:00
|
|
|
<script lang="ts">
|
2023-10-22 21:03:51 +02:00
|
|
|
import { createEventDispatcher, onMount, setContext, tick } from "svelte";
|
2022-02-09 20:59:21 +01:00
|
|
|
import { normUrl } from "../util/history";
|
|
|
|
import IconButton from "./utils/IconButton.svelte";
|
2023-10-22 13:38:52 +02:00
|
|
|
import { selected } from "./EntitySelect.svelte";
|
2023-10-22 21:03:51 +02:00
|
|
|
import type { BrowseContext } from "../util/browse";
|
|
|
|
import { writable } from "svelte/store";
|
|
|
|
import { useParams } from "svelte-navigator";
|
2022-02-09 20:59:21 +01:00
|
|
|
const dispatch = createEventDispatcher();
|
2023-10-22 21:03:51 +02:00
|
|
|
const params = useParams();
|
2022-02-09 20:59:21 +01:00
|
|
|
|
2023-10-22 20:38:10 +02:00
|
|
|
export let address: string | undefined = undefined;
|
2023-10-22 21:03:51 +02:00
|
|
|
export let index: number;
|
2022-02-09 20:59:21 +01:00
|
|
|
export let only: boolean;
|
2023-10-23 11:20:59 +02:00
|
|
|
export let background = "var(--background-lighter)";
|
2022-02-09 20:59:21 +01:00
|
|
|
|
2022-02-09 23:58:56 +01:00
|
|
|
let detail = only;
|
|
|
|
let detailChanged = false;
|
|
|
|
$: if (!detailChanged) detail = only;
|
2022-03-20 16:43:50 +01:00
|
|
|
$: if (detailChanged) tick().then(() => dispatch("detail", detail));
|
2022-02-09 20:59:21 +01:00
|
|
|
|
2023-10-22 21:03:51 +02:00
|
|
|
let indexStore = writable(index);
|
|
|
|
$: $indexStore = index;
|
|
|
|
|
|
|
|
let addressesStore = writable([]);
|
|
|
|
$: $addressesStore = $params.addresses?.split(",") || [];
|
|
|
|
|
|
|
|
setContext("browse", {
|
|
|
|
index: indexStore,
|
|
|
|
addresses: addressesStore,
|
|
|
|
} as BrowseContext);
|
|
|
|
|
2022-03-22 21:54:46 +01:00
|
|
|
onMount(() => {
|
|
|
|
// Required to make detail mode detection work in Browse
|
|
|
|
dispatch("detail", detail);
|
|
|
|
});
|
2023-10-22 13:38:52 +02:00
|
|
|
$: if ($selected.length) {
|
|
|
|
detail = false;
|
|
|
|
}
|
2022-03-22 21:54:46 +01:00
|
|
|
|
2022-02-09 20:59:21 +01:00
|
|
|
function visit() {
|
2023-10-22 20:38:10 +02:00
|
|
|
window.open(normUrl(`/browse/${address}`), "_blank");
|
2022-02-09 20:59:21 +01:00
|
|
|
}
|
2023-03-07 19:32:33 +01:00
|
|
|
|
|
|
|
let width = 460;
|
2023-06-05 19:42:15 +02:00
|
|
|
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-10-23 11:20:59 +02:00
|
|
|
<div
|
|
|
|
class="browse-column"
|
|
|
|
class:detail
|
|
|
|
style="--background-color: {background}"
|
|
|
|
>
|
2023-09-01 19:52:49 +02:00
|
|
|
<div class="view" style="--width: {width}px">
|
2023-03-07 19:32:33 +01:00
|
|
|
<header>
|
2023-10-22 20:38:10 +02:00
|
|
|
{#if address}
|
2023-10-22 13:38:52 +02:00
|
|
|
<IconButton name="link" on:click={() => visit()} disabled={only}>
|
|
|
|
Detach
|
|
|
|
</IconButton>
|
|
|
|
{/if}
|
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>
|
2023-10-22 20:38:10 +02:00
|
|
|
{#if address}
|
|
|
|
<IconButton
|
|
|
|
name="intersect"
|
|
|
|
on:click={() => dispatch("combine", address)}
|
|
|
|
>
|
|
|
|
Combine
|
|
|
|
</IconButton>
|
|
|
|
{/if}
|
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>
|
2023-10-22 13:38:52 +02:00
|
|
|
<slot {detail} />
|
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 {
|
2023-06-05 19:42:15 +02:00
|
|
|
@media screen and (min-width: 600px) {
|
|
|
|
min-width: 75vw;
|
2023-09-01 19:51:59 +02:00
|
|
|
max-width: min(75vw, 1920px);
|
2023-06-05 19:42:15 +02:00
|
|
|
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;
|
|
|
|
|
2023-10-23 11:20:59 +02:00
|
|
|
background: var(--background-color);
|
2022-02-09 20:59:21 +01:00
|
|
|
color: var(--foreground-lighter);
|
|
|
|
border: 1px solid var(--foreground-lightest);
|
|
|
|
border-radius: 0.5em;
|
|
|
|
padding: 1rem;
|
|
|
|
|
2022-09-04 22:53:23 +02:00
|
|
|
// transition: min-width 0.2s, max-width 0.2s;
|
|
|
|
// TODO - container has nowhere to scroll, breaking `detail` scroll
|
|
|
|
|
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;
|
2023-06-05 19:42:15 +02:00
|
|
|
|
|
|
|
@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>
|