added automatically fitting commits
This commit is contained in:
@@ -179,7 +179,12 @@
|
|||||||
<Content {items} />
|
<Content {items} />
|
||||||
{/await}
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
<div class="main-container" style="--container-color:var(--ctp-green);">
|
<!-- The wrapper contributes no height, so the row is sized by the Content column alone. -->
|
||||||
|
<div class="relative min-h-0">
|
||||||
|
<div
|
||||||
|
class="main-container absolute inset-0 flex flex-col overflow-hidden"
|
||||||
|
style="--container-color:var(--ctp-green);"
|
||||||
|
>
|
||||||
<div class="section-title fira-mono-bold mr-3 flex py-2 text-4xl">
|
<div class="section-title fira-mono-bold mr-3 flex py-2 text-4xl">
|
||||||
Commits
|
Commits
|
||||||
<div class="flex w-full flex-row-reverse items-center gap-4 pr-4">
|
<div class="flex w-full flex-row-reverse items-center gap-4 pr-4">
|
||||||
@@ -188,6 +193,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="min-h-0 flex-1 overflow-hidden">
|
||||||
{#await data.streamed.latestCommits}
|
{#await data.streamed.latestCommits}
|
||||||
<p>loading commits...</p>
|
<p>loading commits...</p>
|
||||||
{:then commits}
|
{:then commits}
|
||||||
@@ -197,3 +203,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -1,26 +1,93 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
|
||||||
import type { GitCommit } from './types';
|
import type { GitCommit } from './types';
|
||||||
|
|
||||||
let { items }: { items: GitCommit[] } = $props();
|
let { items }: { items: GitCommit[] } = $props();
|
||||||
|
|
||||||
let containerElement: HTMLDivElement;
|
let containerElement = $state<HTMLDivElement>();
|
||||||
let cardElements = $state<HTMLElement[]>([]);
|
let listElement = $state<HTMLDivElement>();
|
||||||
|
|
||||||
let graphHeight = $state(0);
|
let graphHeight = $state(0);
|
||||||
let nodePositions = $state<{ x: number; y: number }[]>([]);
|
let nodePositions = $state<{ x: number; y: number }[]>([]);
|
||||||
|
|
||||||
// Measure the actual centre of every article card.
|
// Only render commits that fit entirely inside the available height.
|
||||||
$effect(() => {
|
let visibleCount = $state(0);
|
||||||
const currentItems = items;
|
let measurementVersion = 0;
|
||||||
const cards = cardElements.filter(Boolean);
|
|
||||||
const container = containerElement;
|
|
||||||
|
|
||||||
if (!container || cards.length !== currentItems.length) return;
|
const visibleItems = $derived(items.slice(0, visibleCount));
|
||||||
|
|
||||||
|
async function fitVisibleItems() {
|
||||||
|
const version = ++measurementVersion;
|
||||||
|
const allItems = items;
|
||||||
|
const list = listElement;
|
||||||
|
const parent = containerElement?.parentElement;
|
||||||
|
|
||||||
|
if (!list || !parent) return;
|
||||||
|
|
||||||
|
// Render every commit first so each row's full height can be measured.
|
||||||
|
visibleCount = allItems.length;
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
if (version !== measurementVersion) return;
|
||||||
|
|
||||||
|
const rows = Array.from(list.children) as HTMLElement[];
|
||||||
|
|
||||||
|
if (rows.length !== allItems.length) return;
|
||||||
|
|
||||||
|
const available = parent.getBoundingClientRect().bottom - list.getBoundingClientRect().top;
|
||||||
|
|
||||||
|
let used = 0;
|
||||||
|
let fit = 0;
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
const height = row.getBoundingClientRect().height;
|
||||||
|
if (used + height > available) break;
|
||||||
|
|
||||||
|
used += height;
|
||||||
|
fit += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version !== measurementVersion) return;
|
||||||
|
|
||||||
|
visibleCount = fit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-measure whenever the items or the available space change.
|
||||||
|
$effect(() => {
|
||||||
|
void items;
|
||||||
|
|
||||||
|
const parent = containerElement?.parentElement;
|
||||||
|
if (!parent) return;
|
||||||
|
|
||||||
|
void fitVisibleItems();
|
||||||
|
|
||||||
|
const observer = new ResizeObserver(() => void fitVisibleItems());
|
||||||
|
observer.observe(parent);
|
||||||
|
|
||||||
|
return () => observer.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Measure the actual centre of every visible article card.
|
||||||
|
$effect(() => {
|
||||||
|
const currentItems = visibleItems;
|
||||||
|
const container = containerElement;
|
||||||
|
const list = listElement;
|
||||||
|
|
||||||
|
if (!container || !list) return;
|
||||||
|
|
||||||
|
const containerEl: HTMLDivElement = container;
|
||||||
|
const listEl: HTMLDivElement = list;
|
||||||
|
|
||||||
function updatePositions() {
|
function updatePositions() {
|
||||||
const containerRect = container.getBoundingClientRect();
|
const rows = Array.from(listEl.children) as HTMLElement[];
|
||||||
|
|
||||||
nodePositions = cards.map((card) => {
|
if (rows.length !== currentItems.length) return;
|
||||||
|
|
||||||
|
const containerRect = containerEl.getBoundingClientRect();
|
||||||
|
|
||||||
|
nodePositions = rows.map((row) => {
|
||||||
|
const card = row.children[1] as HTMLElement;
|
||||||
const rect = card.getBoundingClientRect();
|
const rect = card.getBoundingClientRect();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -29,7 +96,7 @@
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
graphHeight = container.scrollHeight;
|
graphHeight = containerEl.scrollHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial measurement.
|
// Initial measurement.
|
||||||
@@ -38,8 +105,8 @@
|
|||||||
// Watch for changes in card or container dimensions.
|
// Watch for changes in card or container dimensions.
|
||||||
const observer = new ResizeObserver(updatePositions);
|
const observer = new ResizeObserver(updatePositions);
|
||||||
|
|
||||||
observer.observe(container);
|
observer.observe(containerEl);
|
||||||
cards.forEach((card) => observer.observe(card));
|
observer.observe(listEl);
|
||||||
|
|
||||||
// Also handle viewport changes.
|
// Also handle viewport changes.
|
||||||
window.addEventListener('resize', updatePositions);
|
window.addEventListener('resize', updatePositions);
|
||||||
@@ -69,8 +136,10 @@
|
|||||||
y2={nodePositions[index + 1].y}
|
y2={nodePositions[index + 1].y}
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
stroke-width="2"
|
stroke-width="2"
|
||||||
stroke-dasharray={items[index + 1]?.parentRepo != items[index].parentRepo ? '5,4' : '0'}
|
stroke-dasharray={visibleItems[index + 1]?.parentRepo != visibleItems[index]?.parentRepo
|
||||||
class={items[index + 1]?.parentRepo == items[index].parentRepo
|
? '5,4'
|
||||||
|
: '0'}
|
||||||
|
class={visibleItems[index + 1]?.parentRepo == visibleItems[index]?.parentRepo
|
||||||
? 'text-ctp-green'
|
? 'text-ctp-green'
|
||||||
: 'text-ctp-surface2'}
|
: 'text-ctp-surface2'}
|
||||||
stroke-linecap="round"
|
stroke-linecap="round"
|
||||||
@@ -92,15 +161,15 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
<div class="mt-3 mr-3 grid grid-flow-row auto-rows-min">
|
<div bind:this={listElement} class="mt-3 mr-3 grid grid-flow-row auto-rows-min">
|
||||||
{#each items as item, index (item.hash)}
|
{#each visibleItems as item, index (item.hash)}
|
||||||
<div class="relative z-10 grid grid-cols-[1.25rem_minmax(0,1fr)] gap-x-3.5 gap-y-2 pb-2">
|
<div class="relative z-10 grid grid-cols-[1.25rem_minmax(0,1fr)] gap-x-3.5 gap-y-2 pb-2">
|
||||||
<!-- Timeline space -->
|
<!-- Timeline space -->
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
||||||
<div bind:this={cardElements[index]} class="min-w-0">
|
<div class="min-w-0">
|
||||||
<a href={item.link} class="group block">
|
<a href={item.link} class="group block">
|
||||||
{#if items[index - 1]?.parentRepo != item.parentRepo}
|
{#if visibleItems[index - 1]?.parentRepo != item.parentRepo}
|
||||||
<p class="flex flex-row pt-2">
|
<p class="flex flex-row pt-2">
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
|||||||
Reference in New Issue
Block a user