~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0
138 lines · 3.3 KB Raw History
<script lang="ts">
	import Icon from '#lib/atoms/Icon.svelte';
	import type { Grant } from '#lib/scopes';
	import { words } from '#lib/words';

	// What a permission set grants, behind its `Details` disclosure: the
	// calls it may make, where to, and the data it may change.
	let { grant }: { grant: Grant } = $props();

	// An NSID's or DID's runs, each ending at a `.`, `:` or `#`, where it may wrap.
	const runs = (name: string): string[] => name.split(/(?<=[.:#])/);
</script>

{#snippet code(name: string)}<code>{#each runs(name) as run, i (i)}{run}<wbr />{/each}</code>{/snippet}

<details class="details">
	<summary>{words.setDetails}</summary>
	<div class="body">
		{#if grant.calls.length || grant.data.length || grant.spaces.length}
			<p>{words.setRequests}</p>
			{#if grant.calls.length}
				<table>
					<thead><tr><th>{words.call}</th><th>{words.towards}</th></tr></thead>
					<tbody>
						{#each grant.calls as { aud, towards, methods } (aud)}
							{#each methods as method, i (method)}
								<tr>
									<td>{@render code(method)}</td>
									{#if i === 0}<td rowspan={methods.length}>{#if typeof towards === 'string'}{towards}{:else}{@render code(towards.code)}{/if}</td>{/if}
								</tr>
							{/each}
						{/each}
					</tbody>
				</table>
			{/if}
			{#if grant.data.length}
				<table>
					<thead>
						<tr><th>{words.data}</th>{#each words.actions as action (action)}<th class="action">{action}</th>{/each}</tr>
					</thead>
					<tbody>
						{#each grant.data as { collection, actions } (collection)}
							<tr>
								<td>{@render code(collection)}</td>
								{#each actions as asked, i (i)}<td class="action">{#if asked}<Icon name="check" size={14} label={words.yes} />{/if}</td>{/each}
							</tr>
						{/each}
					</tbody>
				</table>
			{/if}
			{#each grant.spaces as space, i (i)}
				<div class="space">
					<h3>{#each space.heading as part, j (j)}{#if typeof part === 'string'}{part}{:else}{@render code(part.code)}{/if}{/each}</h3>
					<p>{space.sentence}</p>
				</div>
			{/each}
		{:else}
			<p>{words.setGrantsNothing}</p>
		{/if}
	</div>
</details>

<style>
	.details {
		font-size: var(--text-sm);
	}

	summary {
		width: fit-content;
		color: var(--mute);
		font-weight: var(--weight-medium);
		cursor: pointer;
		border-radius: var(--radius-sm);
	}

	summary:hover {
		color: var(--fg);
	}

	.body {
		display: flex;
		flex-direction: column;
		gap: var(--space-2);
		margin-top: var(--space-2);
		padding: var(--space-2-5) var(--space-3);
		border-radius: var(--radius-md);
		background: var(--soft);
		color: var(--mute);
		font-size: var(--text-xs);
		line-height: var(--leading-snug);
	}

	table {
		width: 100%;
		border-collapse: collapse;
	}

	th,
	td {
		padding: var(--space-1) var(--space-1-5);
		border-bottom: var(--border) solid var(--line);
		text-align: left;
		vertical-align: top;
		overflow-wrap: anywhere;
	}

	th {
		font-weight: var(--weight-medium);
	}

	.action {
		width: 1%;
		text-align: center;
		vertical-align: middle;
		white-space: nowrap;
		overflow-wrap: normal;
	}

	.space {
		display: flex;
		flex-direction: column;
		gap: var(--space-0-5);
		overflow-wrap: anywhere;
	}

	h3 {
		margin: 0;
		color: var(--fg);
		font-size: inherit;
		font-weight: var(--weight-medium);
		line-height: inherit;
	}

	code {
		color: var(--fg);
		overflow-wrap: anywhere;
	}
</style>