mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
Implement new design
Co-authored-by: dnlklmn <pelicansinberlin@gmail.com> Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
@@ -5,11 +5,18 @@
|
||||
import { toHtml } from "hast-util-to-html";
|
||||
|
||||
import * as Syntax from "@app/lib/syntax";
|
||||
import { isMarkdownPath, twemoji } from "@app/lib/utils";
|
||||
import { isMarkdownPath } from "@app/lib/utils";
|
||||
import { lineNumbersGutter } from "@app/lib/syntax";
|
||||
import { routeToPath } from "@app/lib/router";
|
||||
|
||||
import Readme from "./Readme.svelte";
|
||||
import SquareButton from "@app/components/SquareButton.svelte";
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import FilePath from "@app/components/FilePath.svelte";
|
||||
import IconSmall from "@app/components/IconSmall.svelte";
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import Markdown from "@app/components/Markdown.svelte";
|
||||
import Placeholder from "@app/components/Placeholder.svelte";
|
||||
import Radio from "@app/components/Radio.svelte";
|
||||
import InlineMarkdown from "@app/components/InlineMarkdown.svelte";
|
||||
|
||||
export let baseUrl: BaseUrl;
|
||||
export let projectId: string;
|
||||
@@ -22,11 +29,6 @@
|
||||
|
||||
$: lastCommit = blob.lastCommit;
|
||||
|
||||
$: parentDir = blob.path
|
||||
.match(/^.*\/|/)
|
||||
?.values()
|
||||
.next().value;
|
||||
|
||||
$: content = highlighted ? lineNumbersGutter(highlighted) : undefined;
|
||||
|
||||
let selectedLineId: string | undefined = undefined;
|
||||
@@ -47,9 +49,29 @@
|
||||
$: isMarkdown = isMarkdownPath(blob.path);
|
||||
$: showMarkdown = isMarkdown && selectedLineId === undefined;
|
||||
|
||||
function toggleMarkdown() {
|
||||
window.location.hash = "";
|
||||
showMarkdown = !showMarkdown;
|
||||
let linkBaseUrl: string | undefined;
|
||||
|
||||
$: {
|
||||
if (!path || path === "/") {
|
||||
// For the default root path, the `tree/<revision>` portion is omitted
|
||||
// from the URL. This means that links cannot be resolved with respect
|
||||
// to the current location. To work around this we provide path that
|
||||
// results a fully expanded URL with which we can resolve all links in the
|
||||
// Markdown.
|
||||
linkBaseUrl = new URL(
|
||||
routeToPath({
|
||||
resource: "project.source",
|
||||
project: projectId,
|
||||
node: baseUrl,
|
||||
peer,
|
||||
revision,
|
||||
path: "README.md",
|
||||
}),
|
||||
window.origin,
|
||||
).href;
|
||||
} else {
|
||||
linkBaseUrl = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
afterUpdate(() => {
|
||||
@@ -75,61 +97,37 @@
|
||||
</script>
|
||||
|
||||
<style>
|
||||
header .file-header {
|
||||
.file-header {
|
||||
display: flex;
|
||||
height: 3rem;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 0.5rem 0 1rem;
|
||||
color: var(--color-foreground);
|
||||
border-width: 1px 1px 0 1px;
|
||||
border-color: var(--color-foreground-3);
|
||||
border-color: var(--color-border-hint);
|
||||
border-style: solid;
|
||||
border-top-left-radius: var(--border-radius-small);
|
||||
border-top-right-radius: var(--border-radius-small);
|
||||
}
|
||||
|
||||
.file-header .right {
|
||||
.right {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
overflow-x: hidden;
|
||||
text-overflow: ellipsis;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
header .file-name {
|
||||
font-weight: var(--font-weight-normal);
|
||||
flex-shrink: 0;
|
||||
gap: 0.5rem;
|
||||
margin-left: auto;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.last-commit {
|
||||
padding: 0.5rem 0.75rem;
|
||||
color: var(--color-secondary);
|
||||
background-color: var(--color-secondary-2);
|
||||
font-size: var(--font-size-tiny);
|
||||
border-radius: var(--border-radius-small);
|
||||
overflow-x: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.last-commit .hash {
|
||||
font-weight: var(--font-weight-bold);
|
||||
font-family: var(--font-family-monospace);
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
margin-right: 0.5rem;
|
||||
.file-name {
|
||||
font-weight: var(--font-weight-semibold);
|
||||
font-size: var(--font-size-small);
|
||||
flex-shrink: 0;
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
|
||||
.code :global(.line-number) {
|
||||
color: var(--color-foreground-4);
|
||||
font-family: var(--font-family-monospace);
|
||||
color: var(--color-foreground-disabled);
|
||||
text-align: right;
|
||||
padding: 0;
|
||||
user-select: none;
|
||||
@@ -140,7 +138,7 @@
|
||||
}
|
||||
.code :global(.line-number:hover) {
|
||||
cursor: pointer;
|
||||
color: var(--color-foreground);
|
||||
color: var(--color-foreground-gray);
|
||||
}
|
||||
|
||||
.code :global(.content) {
|
||||
@@ -153,10 +151,16 @@
|
||||
line-height: 22px; /* This seems to be the line-height of a pre code block */
|
||||
}
|
||||
.code :global(.highlight) {
|
||||
background-color: var(--color-caution-3);
|
||||
background-color: var(--color-fill-float-hover);
|
||||
box-shadow: 0 0 0 1px var(--color-fill-secondary);
|
||||
}
|
||||
.code :global(.highlight td a) {
|
||||
color: var(--color-foreground);
|
||||
.code :global(.highlight td:first-child) {
|
||||
background-color: var(--color-fill-float-hover);
|
||||
border-left: 1px solid var(--color-fill-secondary);
|
||||
}
|
||||
.code :global(.highlight td:last-child) {
|
||||
background-color: var(--color-fill-float-hover);
|
||||
border-right: 1px solid var(--color-fill-secondary);
|
||||
}
|
||||
|
||||
.code :global(.line-content) {
|
||||
@@ -174,108 +178,130 @@
|
||||
}
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
display: flex;
|
||||
overflow-x: auto;
|
||||
border: 1px solid var(--color-foreground-3);
|
||||
border-top-style: dashed;
|
||||
border: 1px solid var(--color-border-hint);
|
||||
border-top-style: solid;
|
||||
border-bottom-left-radius: var(--border-radius-small);
|
||||
border-bottom-right-radius: var(--border-radius-small);
|
||||
background: var(--color-background-1);
|
||||
}
|
||||
|
||||
.binary {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background: var(--color-background-float);
|
||||
width: 100%;
|
||||
height: 16rem;
|
||||
background-color: var(--color-foreground-1);
|
||||
color: var(--color-foreground-6);
|
||||
font-family: var(--font-family-monospace);
|
||||
}
|
||||
.binary > * {
|
||||
margin-bottom: 1rem;
|
||||
border-bottom-left-radius: var(--border-radius-small);
|
||||
border-bottom-right-radius: var(--border-radius-small);
|
||||
}
|
||||
|
||||
.no-scrollbar {
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.markdown {
|
||||
max-width: 64rem;
|
||||
}
|
||||
|
||||
.no-scrollbar::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.code {
|
||||
font-size: var(--font-size-small);
|
||||
}
|
||||
.commit-teaser {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
border-radius: var(--border-radius-tiny);
|
||||
background-color: var(--color-fill-ghost-hover);
|
||||
gap: 0.75rem;
|
||||
padding-right: 0.75rem;
|
||||
height: var(--button-small-height);
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.right {
|
||||
justify-content: center;
|
||||
.commit-teaser {
|
||||
padding: 0 0.75rem;
|
||||
}
|
||||
.file-header {
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0;
|
||||
border-left: none;
|
||||
border-right: none;
|
||||
}
|
||||
.hash-button {
|
||||
display: none;
|
||||
}
|
||||
.container {
|
||||
border-left: none;
|
||||
border-right: none;
|
||||
border-bottom-left-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class:markdown={isMarkdown}>
|
||||
<header>
|
||||
<div class="file-header">
|
||||
<span class="file-name">
|
||||
<span style:color="var(--color-foreground-5)">{parentDir}</span>
|
||||
​
|
||||
<span>{blob.name}</span>
|
||||
</span>
|
||||
<div class="right">
|
||||
{#if isMarkdown}
|
||||
<div title="Toggle render method" class="toggle">
|
||||
<SquareButton clickable on:click={toggleMarkdown}>
|
||||
{showMarkdown ? "Plain" : "Markdown"}
|
||||
</SquareButton>
|
||||
</div>
|
||||
{/if}
|
||||
<a href="{rawPath}/{blob.path}" class="toggle">
|
||||
<SquareButton clickable>Raw</SquareButton>
|
||||
</a>
|
||||
<div class="last-commit" title={lastCommit.author.name} use:twemoji>
|
||||
<span class="hash">
|
||||
{lastCommit.id.slice(0, 7)}
|
||||
</span>
|
||||
{lastCommit.summary}
|
||||
</div>
|
||||
<div class="file-header">
|
||||
<span class="file-name">
|
||||
<FilePath filenameWithPath={blob.path} />
|
||||
</span>
|
||||
<div class="right">
|
||||
<div class="commit-teaser">
|
||||
<div class="hash-button">
|
||||
<Link
|
||||
route={{
|
||||
resource: "project.commit",
|
||||
project: projectId,
|
||||
node: baseUrl,
|
||||
commit: lastCommit.id,
|
||||
}}>
|
||||
<Button variant="gray" styleBorderRadius="0">
|
||||
<span
|
||||
class="global-hash"
|
||||
style:font-weight="var(--font-weight-bold)">
|
||||
{lastCommit.id.slice(0, 7)}
|
||||
</span>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<InlineMarkdown fontSize="small" content={lastCommit.summary} />
|
||||
</div>
|
||||
<div class="layout-desktop-flex" style:gap="0.5rem">
|
||||
{#if isMarkdown}
|
||||
<Radio ariaLabel="Toggle render method">
|
||||
<Button
|
||||
styleBorderRadius="0"
|
||||
variant={showMarkdown ? "secondary" : "gray"}
|
||||
on:click={() => {
|
||||
window.location.hash = "";
|
||||
showMarkdown = true;
|
||||
}}>
|
||||
Plain
|
||||
</Button>
|
||||
<Button
|
||||
styleBorderRadius="0"
|
||||
variant={!showMarkdown ? "secondary" : "gray"}
|
||||
on:click={() => {
|
||||
showMarkdown = false;
|
||||
}}>
|
||||
Markdown
|
||||
</Button>
|
||||
</Radio>
|
||||
{/if}
|
||||
<a href="{rawPath}/{blob.path}">
|
||||
<Button variant="secondary">
|
||||
Raw
|
||||
<IconSmall name="arrow-box-up-right" />
|
||||
</Button>
|
||||
</a>
|
||||
</div>
|
||||
</header>
|
||||
<div class="container">
|
||||
{#if blob.binary}
|
||||
<div class="binary">
|
||||
<div use:twemoji>👀</div>
|
||||
<span class="txt-tiny">Binary content</span>
|
||||
</div>
|
||||
{:else if showMarkdown && blob.content}
|
||||
<Readme
|
||||
{baseUrl}
|
||||
{projectId}
|
||||
{peer}
|
||||
{revision}
|
||||
content={blob.content}
|
||||
{rawPath}
|
||||
{path} />
|
||||
{:else if content}
|
||||
<table class="code no-scrollbar">
|
||||
{@html toHtml(content)}
|
||||
</table>
|
||||
{:else}
|
||||
<div class="binary">
|
||||
<div use:twemoji>🍂</div>
|
||||
<span class="txt-tiny">Empty file</span>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
{#if blob.binary}
|
||||
<div style:margin="4rem 0" style:width="100%">
|
||||
<Placeholder iconName="binary-file" caption="Binary file" />
|
||||
</div>
|
||||
{:else if showMarkdown && blob.content}
|
||||
<div style:padding="2rem">
|
||||
<Markdown {linkBaseUrl} content={blob.content} {rawPath} {path} />
|
||||
</div>
|
||||
{:else if content}
|
||||
<table class="code no-scrollbar">
|
||||
{@html toHtml(content)}
|
||||
</table>
|
||||
{:else}
|
||||
<div style:margin="4rem 0" style:width="100%">
|
||||
<Placeholder iconName="empty-file" caption="Empty file" />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,85 +1,91 @@
|
||||
<script lang="ts">
|
||||
import * as utils from "@app/lib/utils";
|
||||
import { closeFocused } from "@app/components/Floating.svelte";
|
||||
|
||||
import Dropdown from "@app/components/Dropdown.svelte";
|
||||
import DropdownItem from "@app/components/Dropdown/DropdownItem.svelte";
|
||||
import Floating from "@app/components/Floating.svelte";
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import type { BaseUrl, Project } from "@httpd-client";
|
||||
import type { Route } from "@app/lib/router";
|
||||
|
||||
import * as utils from "@app/lib/utils";
|
||||
import { closeFocused } from "@app/components/Popover.svelte";
|
||||
|
||||
import DropdownList from "@app/components/DropdownList.svelte";
|
||||
import DropdownListItem from "@app/components/DropdownList/DropdownListItem.svelte";
|
||||
import Popover from "@app/components/Popover.svelte";
|
||||
import IconSmall from "@app/components/IconSmall.svelte";
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import Button from "@app/components/Button.svelte";
|
||||
|
||||
export let branches: Array<{ name: string; route: Route }>;
|
||||
export let node: BaseUrl;
|
||||
export let project: Project;
|
||||
export let selectedBranch: string | undefined;
|
||||
export let selectedCommitId: string;
|
||||
export let branches: Array<{ name: string; route: Route }>;
|
||||
|
||||
$: hideDropdown = branches.length <= 1;
|
||||
$: selectedCommitShortId = utils.formatCommit(selectedCommitId);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.commit {
|
||||
.branch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
line-height: initial;
|
||||
gap: 1px;
|
||||
}
|
||||
|
||||
font-family: var(--font-family-monospace);
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
.branch-name {
|
||||
height: 2rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background-color: var(--color-secondary-2);
|
||||
border-radius: var(--border-radius-small) 0 0 var(--border-radius-small);
|
||||
}
|
||||
.branch-name.not-allowed {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.branch-name:hover:not(.not-allowed) {
|
||||
background-color: var(--color-foreground-2);
|
||||
}
|
||||
.commit-id {
|
||||
height: 2rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background-color: var(--color-secondary-1);
|
||||
border-radius: 0 var(--border-radius-small) var(--border-radius-small) 0;
|
||||
}
|
||||
.commit-id.standalone {
|
||||
border-radius: var(--border-radius-small);
|
||||
.identifier {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="commit" title="Current branch">
|
||||
<div class="branch" title="Current branch">
|
||||
{#if selectedBranch}
|
||||
<Floating disabled={hideDropdown}>
|
||||
<div
|
||||
<Popover
|
||||
popoverPadding="0"
|
||||
popoverPositionTop="2.5rem"
|
||||
popoverBorderRadius="var(--border-radius-small)"
|
||||
disabled={hideDropdown}>
|
||||
<Button
|
||||
let:expanded
|
||||
slot="toggle"
|
||||
styleBorderRadius="var(--border-radius-tiny) 0 0 var(--border-radius-tiny)"
|
||||
title="Change branch"
|
||||
class="branch-name"
|
||||
class:not-allowed={hideDropdown}>
|
||||
{selectedBranch}
|
||||
</div>
|
||||
<Dropdown slot="modal" items={branches}>
|
||||
<Link
|
||||
slot="item"
|
||||
let:item
|
||||
route={item.route}
|
||||
on:afterNavigate={() => closeFocused()}>
|
||||
<DropdownItem selected={item.name === selectedBranch} size="tiny">
|
||||
{item.name}
|
||||
</DropdownItem>
|
||||
</Link>
|
||||
</Dropdown>
|
||||
</Floating>
|
||||
<div class="commit-id">
|
||||
{selectedCommitShortId}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="commit-id standalone layout-desktop">
|
||||
{selectedCommitId}
|
||||
</div>
|
||||
<div class="commit-id standalone layout-mobile">
|
||||
{selectedCommitShortId}
|
||||
</div>
|
||||
disabled={hideDropdown}>
|
||||
<IconSmall name="branch" />
|
||||
<div class="identifier">{selectedBranch}</div>
|
||||
<IconSmall name={expanded ? "chevron-up" : "chevron-down"} />
|
||||
</Button>
|
||||
|
||||
<DropdownList slot="popover" items={branches}>
|
||||
<svelte:fragment slot="item" let:item>
|
||||
<Link route={item.route} on:afterNavigate={() => closeFocused()}>
|
||||
<DropdownListItem selected={item.name === selectedBranch}>
|
||||
<div class="identifier">{item.name}</div>
|
||||
</DropdownListItem>
|
||||
</Link>
|
||||
</svelte:fragment>
|
||||
</DropdownList>
|
||||
</Popover>
|
||||
{/if}
|
||||
|
||||
<Button
|
||||
styleBorderRadius={selectedBranch
|
||||
? "0 var(--border-radius-tiny) var(--border-radius-tiny) 0"
|
||||
: "var(--border-radius-tiny)"}>
|
||||
<Link
|
||||
route={{
|
||||
resource: "project.commit",
|
||||
project: project.id,
|
||||
node,
|
||||
commit: selectedCommitId,
|
||||
}}>
|
||||
<div
|
||||
class="identifier global-hash"
|
||||
style:font-weight="var(--font-weight-bold)">
|
||||
{#if !selectedBranch}
|
||||
<IconSmall name="branch" />
|
||||
{/if}
|
||||
|
||||
{selectedCommitShortId}
|
||||
</div>
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -7,12 +7,15 @@
|
||||
import BranchSelector from "./BranchSelector.svelte";
|
||||
import PeerSelector from "./PeerSelector.svelte";
|
||||
|
||||
import IconSmall from "@app/components/IconSmall.svelte";
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import SquareButton from "@app/components/SquareButton.svelte";
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import Radio from "@app/components/Radio.svelte";
|
||||
|
||||
export let node: BaseUrl;
|
||||
export let branches: Array<{ name: string; route: Route }>;
|
||||
export let peers: Array<{ remote: Remote; selected: boolean; route: Route }>;
|
||||
export let filesLinkActive: boolean;
|
||||
export let historyLinkActive: boolean;
|
||||
export let revision: string | undefined;
|
||||
export let tree: Tree;
|
||||
@@ -35,19 +38,14 @@
|
||||
<style>
|
||||
.header {
|
||||
font-size: var(--font-size-tiny);
|
||||
padding: 0 2rem 0 8rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: left;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 2rem;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.header {
|
||||
padding-left: 2rem;
|
||||
}
|
||||
.header {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
@@ -59,24 +57,54 @@
|
||||
<PeerSelector {peers} />
|
||||
{/if}
|
||||
|
||||
<BranchSelector {branches} selectedCommitId={commitId} {selectedBranch} />
|
||||
<BranchSelector
|
||||
{branches}
|
||||
{project}
|
||||
{node}
|
||||
selectedCommitId={commitId}
|
||||
{selectedBranch} />
|
||||
|
||||
<Link
|
||||
route={{
|
||||
resource: "project.history",
|
||||
project: project.id,
|
||||
node: node,
|
||||
peer,
|
||||
revision,
|
||||
}}>
|
||||
<SquareButton active={historyLinkActive}>
|
||||
<span class="txt-bold">{tree.stats.commits}</span>
|
||||
{pluralize("commit", tree.stats.commits)}
|
||||
</SquareButton>
|
||||
</Link>
|
||||
<Radio>
|
||||
<Link
|
||||
route={{
|
||||
resource: "project.source",
|
||||
project: project.id,
|
||||
node: node,
|
||||
peer,
|
||||
revision,
|
||||
}}>
|
||||
<Button
|
||||
styleBorderRadius="0"
|
||||
variant={filesLinkActive ? "secondary" : "gray"}>
|
||||
<IconSmall name="file" />Files
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<SquareButton hoverable={false}>
|
||||
<span class="txt-bold">{tree.stats.contributors}</span>
|
||||
{pluralize("contributor", tree.stats.contributors)}
|
||||
</SquareButton>
|
||||
<Link
|
||||
route={{
|
||||
resource: "project.history",
|
||||
project: project.id,
|
||||
node: node,
|
||||
peer,
|
||||
revision,
|
||||
}}>
|
||||
<Button
|
||||
styleBorderRadius="0"
|
||||
variant={historyLinkActive ? "secondary" : "gray"}>
|
||||
<IconSmall name="commit" />
|
||||
<div>
|
||||
{tree.stats.commits}
|
||||
{pluralize("commit", tree.stats.commits)}
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<Button styleBorderRadius="0" disabled>
|
||||
<IconSmall name="user" />
|
||||
<div>
|
||||
{tree.stats.contributors}
|
||||
{pluralize("contributor", tree.stats.contributors)}
|
||||
</div>
|
||||
</Button>
|
||||
</Radio>
|
||||
</div>
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
import type { Remote } from "@httpd-client";
|
||||
import { type Route } from "@app/lib/router";
|
||||
|
||||
import { closeFocused } from "@app/components/Floating.svelte";
|
||||
import { formatNodeId, truncateId } from "@app/lib/utils";
|
||||
import { closeFocused } from "@app/components/Popover.svelte";
|
||||
import { formatNodeId } from "@app/lib/utils";
|
||||
import { pluralize } from "@app/lib/pluralize";
|
||||
|
||||
import Avatar from "@app/components/Avatar.svelte";
|
||||
import NodeId from "@app/components/NodeId.svelte";
|
||||
import Badge from "@app/components/Badge.svelte";
|
||||
import Dropdown from "@app/components/Dropdown.svelte";
|
||||
import DropdownItem from "@app/components/Dropdown/DropdownItem.svelte";
|
||||
import Floating from "@app/components/Floating.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import DropdownList from "@app/components/DropdownList.svelte";
|
||||
import DropdownListItem from "@app/components/DropdownList/DropdownListItem.svelte";
|
||||
import Popover from "@app/components/Popover.svelte";
|
||||
import IconSmall from "@app/components/IconSmall.svelte";
|
||||
import Link from "@app/components/Link.svelte";
|
||||
import Button from "@app/components/Button.svelte";
|
||||
|
||||
export let peers: Array<{ remote: Remote; selected: boolean; route: Route }>;
|
||||
|
||||
@@ -27,104 +28,65 @@
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-family: var(--font-family-monospace);
|
||||
}
|
||||
.selector .peer {
|
||||
padding: 0.5rem 0.75rem;
|
||||
color: var(--color-secondary);
|
||||
background-color: var(--color-secondary-2);
|
||||
border-radius: var(--border-radius-small);
|
||||
}
|
||||
.selector .peer.not-allowed {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.peer:hover {
|
||||
background-color: var(--color-foreground-2);
|
||||
}
|
||||
.prefix {
|
||||
display: inline-block;
|
||||
color: var(--color-secondary-6);
|
||||
}
|
||||
.stat {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-family: var(--font-family-monospace);
|
||||
padding: 0.5rem;
|
||||
height: 2rem;
|
||||
line-height: initial;
|
||||
background: var(--color-foreground-1);
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.avatar-id {
|
||||
display: flex;
|
||||
gap: 0.25rem;
|
||||
gap: 0.5rem;
|
||||
color: var(--color-fill-secondary);
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.alias {
|
||||
color: var(--color-secondary-6);
|
||||
.avatar-id.selected {
|
||||
color: red;
|
||||
}
|
||||
</style>
|
||||
|
||||
<Floating>
|
||||
<div slot="toggle" class="selector" title="Change peer">
|
||||
<div class="stat peer" class:not-allowed={!peers}>
|
||||
{#if selectedPeer}
|
||||
<span class="avatar-id">
|
||||
<Avatar nodeId={selectedPeer.id} inline />
|
||||
<!-- Ignore prettier to avoid getting a whitespace between
|
||||
did:key: and the nid due to a newline. -->
|
||||
<!-- prettier-ignore -->
|
||||
<span><span style:color="var(--color-secondary-5)">did:key:</span>{truncateId(selectedPeer.id)}</span>
|
||||
{#if selectedPeer.alias}
|
||||
<span class="alias">({selectedPeer.alias})</span>
|
||||
{/if}
|
||||
</span>
|
||||
{#if selectedPeer.delegate}
|
||||
<Badge variant="primary">delegate</Badge>
|
||||
{/if}
|
||||
{:else}
|
||||
<Icon size="small" name="fork" />{peers.length}
|
||||
{pluralize("remote", peers.length)}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<Popover
|
||||
popoverPadding="0"
|
||||
popoverPositionTop="2.5rem"
|
||||
popoverBorderRadius="var(--border-radius-small)">
|
||||
<Button let:expanded slot="toggle" title="Change peer" disabled={!peers}>
|
||||
{#if !selectedPeer}
|
||||
<IconSmall name="delegate" />
|
||||
{/if}
|
||||
|
||||
<svelte:fragment slot="modal">
|
||||
<Dropdown items={peers}>
|
||||
<svelte:fragment slot="item" let:item>
|
||||
<div class="dropdown-item">
|
||||
<Link on:afterNavigate={() => closeFocused()} route={item.route}>
|
||||
<DropdownItem
|
||||
selected={item.selected}
|
||||
title={createTitle(item.remote)}
|
||||
size="tiny">
|
||||
<span class="avatar-id">
|
||||
<Avatar nodeId={item.remote.id} inline />
|
||||
<div class="layout-desktop">
|
||||
<!-- prettier-ignore -->
|
||||
<span><span class="prefix">did:key:</span>{item.remote.id}</span>
|
||||
{#if item.remote.alias}
|
||||
<span class="alias">({item.remote.alias})</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="layout-mobile">
|
||||
<!-- prettier-ignore -->
|
||||
<span><span class="prefix">did:key:</span>{truncateId(item.remote.id)}</span>
|
||||
{#if item.remote.alias}
|
||||
<span class="alias">({item.remote.alias})</span>
|
||||
{/if}
|
||||
</div>
|
||||
</span>
|
||||
{#if item.remote.delegate}
|
||||
<Badge variant="primary">delegate</Badge>
|
||||
{/if}
|
||||
</DropdownItem>
|
||||
</Link>
|
||||
</div>
|
||||
</svelte:fragment>
|
||||
</Dropdown>
|
||||
</svelte:fragment>
|
||||
</Floating>
|
||||
{#if selectedPeer}
|
||||
<NodeId nodeId={selectedPeer.id} alias={selectedPeer.alias} />
|
||||
{#if selectedPeer.delegate}
|
||||
<Badge size="tiny" variant="secondary">delegate</Badge>
|
||||
{/if}
|
||||
{:else}
|
||||
{peers.length}
|
||||
{pluralize("remote", peers.length)}
|
||||
{/if}
|
||||
<IconSmall name={expanded ? "chevron-up" : "chevron-down"} />
|
||||
</Button>
|
||||
|
||||
<DropdownList slot="popover" items={peers}>
|
||||
<svelte:fragment slot="item" let:item>
|
||||
<Link on:afterNavigate={() => closeFocused()} route={item.route}>
|
||||
<DropdownListItem
|
||||
selected={item.selected}
|
||||
title={createTitle(item.remote)}>
|
||||
<span class="avatar-id" class:selected={item.selected}>
|
||||
<NodeId
|
||||
disableTooltip
|
||||
styleColor={item.selected
|
||||
? "var(--color-foreground-match-background)"
|
||||
: undefined}
|
||||
nodeId={item.remote.id}
|
||||
alias={item.remote.alias} />
|
||||
</span>
|
||||
{#if item.remote.delegate}
|
||||
<div style:color="var(--color-fill-secondary)">
|
||||
<Badge
|
||||
size="tiny"
|
||||
variant={item.selected ? "background" : "secondary"}>
|
||||
delegate
|
||||
</Badge>
|
||||
</div>
|
||||
{/if}
|
||||
</DropdownListItem>
|
||||
</Link>
|
||||
</svelte:fragment>
|
||||
</DropdownList>
|
||||
</Popover>
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
<script lang="ts">
|
||||
import type { BaseUrl } from "@httpd-client";
|
||||
|
||||
import Markdown from "@app/components/Markdown.svelte";
|
||||
import { routeToPath } from "@app/lib/router";
|
||||
|
||||
export let projectId: string;
|
||||
export let peer: string | undefined;
|
||||
export let baseUrl: BaseUrl;
|
||||
export let revision: string | undefined;
|
||||
export let content: string;
|
||||
export let path: string;
|
||||
export let rawPath: string;
|
||||
|
||||
let linkBaseUrl: string | undefined;
|
||||
|
||||
$: {
|
||||
if (!path || path === "/") {
|
||||
// For the default root path, the `tree/<revision>` portion is omitted
|
||||
// from the URL. This means that links cannot be resolved with respect
|
||||
// to the current location. To work around this we provide path that
|
||||
// results a fully expanded URL with which we can resolve all links in the
|
||||
// Markdown.
|
||||
linkBaseUrl = new URL(
|
||||
routeToPath({
|
||||
resource: "project.source",
|
||||
project: projectId,
|
||||
node: baseUrl,
|
||||
peer,
|
||||
revision,
|
||||
path: "README.md",
|
||||
}),
|
||||
window.origin,
|
||||
).href;
|
||||
} else {
|
||||
linkBaseUrl = undefined;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
article {
|
||||
padding: 2rem;
|
||||
width: 100%;
|
||||
background: var(--color-background-1);
|
||||
border-bottom-left-radius: var(--border-radius-small);
|
||||
border-bottom-right-radius: var(--border-radius-small);
|
||||
}
|
||||
</style>
|
||||
|
||||
<article>
|
||||
<Markdown {linkBaseUrl} {content} {rawPath} {path} />
|
||||
</article>
|
||||
@@ -7,23 +7,27 @@
|
||||
|
||||
<style>
|
||||
.file {
|
||||
color: var(--color-foreground-6);
|
||||
border-radius: var(--border-radius-small);
|
||||
border-radius: var(--border-radius-tiny);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
line-height: 1.5em;
|
||||
margin: 0.125rem 0;
|
||||
margin: 0.25rem 0;
|
||||
padding: 0.25rem;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.file:hover {
|
||||
background-color: var(--color-foreground-1);
|
||||
background-color: var(--color-fill-ghost);
|
||||
}
|
||||
|
||||
.file.active {
|
||||
color: var(--color-foreground) !important;
|
||||
background-color: var(--color-foreground-1);
|
||||
color: var(--color-foreground-match-background) !important;
|
||||
background-color: var(--color-fill-secondary);
|
||||
}
|
||||
|
||||
.file.active:hover {
|
||||
color: var(--color-foreground-match-background) !important;
|
||||
background-color: var(--color-fill-secondary-hover);
|
||||
}
|
||||
|
||||
.name {
|
||||
@@ -32,14 +36,18 @@
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis !important;
|
||||
overflow: hidden;
|
||||
max-width: 24ch;
|
||||
font-size: var(--font-size-regular);
|
||||
font-weight: var(--font-weight-medium);
|
||||
}
|
||||
.icon-container {
|
||||
color: var(--color-foreground-5);
|
||||
color: var(--color-fill-secondary);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.active .icon-container {
|
||||
color: var(--color-foreground-match-background);
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="file" class:active>
|
||||
|
||||
@@ -43,25 +43,25 @@
|
||||
display: flex;
|
||||
cursor: pointer;
|
||||
padding: 0.25rem;
|
||||
margin: 0.125rem 0;
|
||||
color: var(--color-foreground-5);
|
||||
margin: 0.25rem 0;
|
||||
user-select: none;
|
||||
line-height: 1.5rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.folder:hover {
|
||||
background-color: var(--color-foreground-1);
|
||||
border-radius: var(--border-radius-small);
|
||||
background-color: var(--color-fill-ghost);
|
||||
border-radius: var(--border-radius-tiny);
|
||||
}
|
||||
|
||||
.folder-name {
|
||||
margin-left: 0.25rem;
|
||||
color: var(--color-secondary-6);
|
||||
font-size: var(--font-size-regular);
|
||||
font-weight: var(--font-weight-medium);
|
||||
}
|
||||
|
||||
.container {
|
||||
padding-left: 0.5rem;
|
||||
margin: 0 0 0 0.5rem;
|
||||
padding-left: 1rem;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.loading {
|
||||
@@ -72,12 +72,12 @@
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: var(--color-fill-secondary);
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<div class="folder" on:click={onClick}>
|
||||
<div role="button" tabindex="0" class="folder" on:click={onClick}>
|
||||
<div class="icon-container">
|
||||
{#if expanded}
|
||||
<Icon name="folder-open" />
|
||||
|
||||
Reference in New Issue
Block a user