~james/core

core/docs/src/components/PullSelectors.svelte -rw-r--r-- 4.3 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<script lang="ts">
	// a mock of the pull-request commit view, composed from the web app's own
	// pieces the way the home page's StackDemo is: the real
	// PullCommitListHeader (which carries the round version selector), a
	// RangeSelector for the commit list, and DiffStatPill. the data is fake so
	// the docs build stays clear of the app's auth, profile and API graphs.
	import Card from "$lib/components/ui/Card.svelte";
	import RangeSelector, {
		type Range,
		type RowActions,
	} from "$lib/components/ui/RangeSelector.svelte";
	import PullCommitListHeader from "$lib/components/repo/pulls/PullCommitListHeader.svelte";
	import Avatar from "$lib/components/ui/Avatar.svelte";
	import DiffStatPill from "$lib/components/repo/DiffStatPill.svelte";
	import type { PullSubmission } from "$lib/api";
	import type { CommitSummary } from "$lib/components/repo/types";

	const versions: PullSubmission[] = [
		{
			head: "456789abcdef0123456789abcdef0123456789ab",
			base: "fedcba9876543210fedcba9876543210fedcba98",
			createdAt: "2026-07-27T12:00:00Z",
		},
		{
			head: "89abcdef0123456789abcdef0123456789abcdef",
			base: "fedcba9876543210fedcba9876543210fedcba98",
			createdAt: "2026-07-27T18:40:00Z",
		},
		{
			head: "0123456789abcdef0123456789abcdef01234567",
			base: "cba9876543210fedcba9876543210fedcba98765",
			createdAt: "2026-07-28T09:30:00Z",
		},
	];

	const commits: CommitSummary[] = [
		{
			hash: "d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3",
			shortHash: "d4e5f6a7",
			subject: "tidy diff toolbar spacing",
			body: "",
			authorName: "alice",
			authorEmail: "alice@tangled.org",
			when: "2026-07-28T09:10:00Z",
			changeId: "zsuskuln",
			stat: { insertions: 4, deletions: 9 },
		},
		{
			hash: "c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2",
			shortHash: "c3d4e5f6",
			subject: "fix hydrate leak on version switch",
			body: "",
			authorName: "alice",
			authorEmail: "alice@tangled.org",
			when: "2026-07-28T08:40:00Z",
			changeId: "rlvkpxrz",
			stat: { insertions: 12, deletions: 3 },
		},
		{
			hash: "b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1",
			shortHash: "b2c3d4e5",
			subject: "add interdiff change-id narrowing",
			body: "",
			authorName: "bob",
			authorEmail: "bob@tangled.org",
			when: "2026-07-27T18:20:00Z",
			changeId: "kkmtprmw",
			stat: { insertions: 148, deletions: 0 },
		},
	];

	type Item = CommitSummary | "base";
	const items: Item[] = [...commits, "base"];

	let versionRange = $state<Range>({
		start: versions.length - 1,
		end: versions.length - 1,
	});
	let showChangeIds = $state(true);
	let commitRange = $state<Range>({ start: 0, end: commits.length });

	const resetRange = () => (commitRange = { start: 0, end: commits.length });
</script>

<Card
	padding="small"
	class="not-content my-lg space-y-xs typography-paragraph-regular">
	<PullCommitListHeader
		{versions}
		{commits}
		{versionRange}
		bind:showChangeIds
		oncommitVersions={(next) => (versionRange = next)} />

	{#snippet commitRow(_index: number, item: Item, actions: RowActions)}
		{#if item === "base"}
			<div class="relative flex h-10 flex-1 items-center px-sm">
				<button
					type="button"
					class="absolute inset-0 cursor-pointer"
					aria-label="Show all changes"
					onclick={resetRange}>
				</button>
				<span
					class="pointer-events-none relative text-foreground-muted">
					Base
				</span>
			</div>
		{:else}
			<div
				role="none"
				class="relative grid min-h-10 flex-1 grid-cols-[minmax(0,1fr)] gap-x-xs px-sm sm:grid-cols-[5rem_minmax(0,1fr)_8rem]"
				{...actions}>
				<span
					class="col-start-1 row-start-1 hidden h-10 items-center truncate typography-monospace-regular text-foreground-muted sm:flex">
					{showChangeIds && item.changeId
						? item.changeId.slice(0, 8)
						: item.shortHash}
				</span>
				<div
					class="col-start-1 row-start-1 flex h-10 min-w-0 items-center gap-xs sm:col-start-2">
					<Avatar handle={item.authorName} size="large" />
					<span class="min-w-0 truncate">{item.subject}</span>
				</div>
				<div
					class="col-start-3 row-start-1 hidden h-10 items-center justify-end gap-sm sm:flex">
					{#if item.stat}<DiffStatPill
							stat={item.stat}
							size="small" />{/if}
				</div>
			</div>
		{/if}
	{/snippet}

	<RangeSelector
		{items}
		row={commitRow}
		minLength={2}
		muteFullSelection
		mode="select-top"
		bind:range={commitRange} />
</Card>