impr: restructure src/lib
This commit is contained in:
376 files changed
+1000
-1033
No files matched your search
@@ -0,0 +1,60 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { TextInput, Select, Option } from 'mono-svelte'
|
||||
|
||||
const multipliers = {
|
||||
minute: 60,
|
||||
hour: 60 * 60,
|
||||
day: 60 * 60 * 24,
|
||||
month: 60 * 60 * 24 * 30,
|
||||
year: 60 * 60 * 24 * 365,
|
||||
permanent: -1,
|
||||
}
|
||||
|
||||
type Duration = keyof typeof multipliers
|
||||
|
||||
function calculateValue(number: number, duration: Duration): number {
|
||||
return number * multipliers[duration]
|
||||
}
|
||||
|
||||
interface Props {
|
||||
value: number
|
||||
max?: number
|
||||
min?: number
|
||||
}
|
||||
|
||||
let { value = $bindable(), max, min = 0 }: Props = $props()
|
||||
|
||||
let number = $state<number>(0)
|
||||
let duration = $state<Duration>(value == -1 ? 'permanent' : 'day')
|
||||
|
||||
$effect(() => {
|
||||
value = calculateValue(number, duration)
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row items-end gap-2">
|
||||
{#if duration != 'permanent'}
|
||||
<TextInput
|
||||
{min}
|
||||
{max}
|
||||
type="number"
|
||||
label="Number"
|
||||
class="w-24"
|
||||
bind:value={number}
|
||||
></TextInput>
|
||||
{/if}
|
||||
<Select
|
||||
selectClass="h-[38px]"
|
||||
baseClass="flex-1"
|
||||
label={$t('form.time.duration')}
|
||||
bind:value={duration}
|
||||
>
|
||||
<Option value="minute">{$t('form.time.minutes')}</Option>
|
||||
<Option value="hour">{$t('form.time.hours')}</Option>
|
||||
<Option value="day">{$t('form.time.days')}</Option>
|
||||
<Option value="month">{$t('form.time.months')}</Option>
|
||||
<Option value="year">{$t('form.time.years')}</Option>
|
||||
<Option value="permanent">{$t('form.time.permanent')}</Option>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script lang="ts">
|
||||
import { tick } from 'svelte'
|
||||
import type { HTMLAttributes } from 'svelte/elements'
|
||||
|
||||
let textarea: HTMLTextAreaElement | undefined = $state()
|
||||
|
||||
async function adjustHeight() {
|
||||
await tick()
|
||||
if (textarea) {
|
||||
textarea.style.height = 'auto' // Reset height to auto to calculate new height
|
||||
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
|
||||
}
|
||||
}
|
||||
interface Props extends HTMLAttributes<HTMLTextAreaElement> {
|
||||
label?: string | undefined
|
||||
value: string
|
||||
required?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
label = undefined,
|
||||
value = $bindable(),
|
||||
required = false,
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
if (value) adjustHeight()
|
||||
})
|
||||
</script>
|
||||
|
||||
<label class="w-full">
|
||||
{#if label}
|
||||
<div class="text-sm font-medium">
|
||||
{label}
|
||||
{#if required}
|
||||
<span class="text-red-600 font-bold">*</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<textarea
|
||||
bind:this={textarea}
|
||||
oninput={() => adjustHeight()}
|
||||
bind:value
|
||||
{required}
|
||||
{...rest}
|
||||
rows={1}
|
||||
class="font-semibold text-2xl focus:outline-hidden w-full bg-transparent resize-none {clazz}"
|
||||
></textarea>
|
||||
</label>
|
||||
@@ -0,0 +1,128 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/app/auth.svelte.js'
|
||||
import ProgressBar from '$lib/ui/info/ProgressBar.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { uploadImage } from '$lib/util.svelte.js'
|
||||
import { Button, toast } from 'mono-svelte'
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { slide } from 'svelte/transition'
|
||||
|
||||
interface Props {
|
||||
image?: FileList | null
|
||||
preview?: boolean
|
||||
multiple?: boolean
|
||||
onupload?: (urls: string[]) => void
|
||||
}
|
||||
|
||||
let {
|
||||
image = $bindable(null),
|
||||
preview = true,
|
||||
multiple = true,
|
||||
onupload,
|
||||
}: Props = $props()
|
||||
let progress = $state(1)
|
||||
|
||||
let previewURLs = $derived(
|
||||
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined,
|
||||
)
|
||||
|
||||
async function upload() {
|
||||
if (!profile.current?.jwt || image == null) return
|
||||
|
||||
progress = 0
|
||||
|
||||
try {
|
||||
const uploaded = (
|
||||
await Promise.all(
|
||||
Array.from(image).map((i) =>
|
||||
uploadImage(i, profile.current.instance, profile.current.jwt!)
|
||||
.then((uploaded) => {
|
||||
progress += 1 / (image?.length ?? 0)
|
||||
return uploaded
|
||||
})
|
||||
.catch((err) => {
|
||||
toast({ content: errorMessage(err), type: 'error' })
|
||||
return 'Failed to upload'
|
||||
}),
|
||||
),
|
||||
)
|
||||
).filter((i) => i != undefined)
|
||||
|
||||
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||
|
||||
onupload?.(uploaded)
|
||||
progress = 1
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: errorMessage(err),
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
progress = 1
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if progress != 1}
|
||||
<div transition:slide={{ duration: 500, easing: expoOut }} class="w-full">
|
||||
<ProgressBar {progress} />
|
||||
</div>
|
||||
{/if}
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
upload()
|
||||
}}
|
||||
>
|
||||
<label
|
||||
for="image-input"
|
||||
class="p-4 border-2 border-dashed rounded-xl cursor-pointer transition-colors
|
||||
border-slate-300 dark:border-zinc-700 hover:border-primary-900 dark:hover:border-primary-100"
|
||||
>
|
||||
{#if previewURLs}
|
||||
<div
|
||||
class="grid gap-x-2 gap-y-px max-h-64 overflow-auto
|
||||
{multiple ? 'grid-cols-3 grid-rows-2' : 'grid-cols-1 grid-rows-1'}"
|
||||
>
|
||||
{#each previewURLs as file}
|
||||
<img
|
||||
src={file}
|
||||
onload={() => URL.revokeObjectURL(file)}
|
||||
alt={file}
|
||||
class="w-full rounded-md h-full object-cover transition-all
|
||||
border border-slate-200 dark:border-zinc-800 ring-1
|
||||
ring-slate-50 dark:ring-zinc-950 bg-white dark:bg-zinc-950"
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="flex flex-col justify-center w-full items-center gap-2
|
||||
text-slate-600 dark:text-zinc-400"
|
||||
>
|
||||
<Icon src={DocumentPlus} size="32" />
|
||||
<span class="font-medium text-sm">{$t('form.post.selectFile')}</span>
|
||||
</div>
|
||||
{/if}
|
||||
<input
|
||||
{multiple}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
class="hidden"
|
||||
id="image-input"
|
||||
bind:files={image}
|
||||
/>
|
||||
</label>
|
||||
<Button
|
||||
loading={progress != 1}
|
||||
disabled={progress != 1 || image == null}
|
||||
submit
|
||||
color="primary"
|
||||
size="lg"
|
||||
>
|
||||
Upload
|
||||
</Button>
|
||||
</form>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script lang="ts">
|
||||
import { Button, Modal, TextInput } from 'mono-svelte'
|
||||
import Switch from '../input/Switch.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import ImageAttachForm from './ImageAttachForm.svelte'
|
||||
|
||||
let {
|
||||
open = $bindable(),
|
||||
imageUrl: passedImageUrl = $bindable(),
|
||||
}: { open: boolean; imageUrl?: string } = $props()
|
||||
|
||||
let imageUrl = $derived(passedImageUrl)
|
||||
let customUrl = $state(false)
|
||||
</script>
|
||||
|
||||
<Modal bind:open title={$t('form.post.uploadImage')}>
|
||||
<div class="flex justify-between gap-1 flex-wrap">
|
||||
<Switch
|
||||
options={[false, true]}
|
||||
optionNames={[$t('common.attach'), $t('content.url')]}
|
||||
bind:selected={customUrl}
|
||||
/>
|
||||
|
||||
<Button
|
||||
onclick={() => {
|
||||
passedImageUrl = undefined
|
||||
open = false
|
||||
}}
|
||||
size="xs"
|
||||
rounding="xl"
|
||||
>
|
||||
{$t('common.remove')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{#if customUrl}
|
||||
<form
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
if (!imageUrl) throw new Error('missing imageurl')
|
||||
|
||||
if (URL.canParse != undefined) {
|
||||
if (!URL.canParse(imageUrl)) throw new Error('invalid URL')
|
||||
}
|
||||
|
||||
passedImageUrl = imageUrl
|
||||
open = false
|
||||
}}
|
||||
class="contents"
|
||||
>
|
||||
<TextInput
|
||||
label={$t('content.url')}
|
||||
bind:value={imageUrl}
|
||||
pattern="http(s)?:\/\/(.*).(png|jpg|gif|avif|webp|jpeg|jxl|svg|bmp)"
|
||||
/>
|
||||
<Button submit color="primary" size="lg">
|
||||
{$t('form.submit')}
|
||||
</Button>
|
||||
</form>
|
||||
{:else}
|
||||
<ImageAttachForm
|
||||
multiple={false}
|
||||
onupload={(uploaded) => {
|
||||
open = false
|
||||
passedImageUrl = uploaded[0]
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</Modal>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { Label } from 'mono-svelte'
|
||||
import { DocumentPlus, Icon, Plus } from 'svelte-hero-icons'
|
||||
import ImageInputModal from './ImageInputModal.svelte'
|
||||
|
||||
let {
|
||||
imageUrl: passedImageUrl = $bindable(),
|
||||
label,
|
||||
}: {
|
||||
imageUrl?: string
|
||||
label?: string
|
||||
} = $props()
|
||||
|
||||
let imageUrl = $derived(passedImageUrl)
|
||||
|
||||
let open = $state(false)
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<Label>{label}</Label>
|
||||
|
||||
<button
|
||||
class={[
|
||||
'flex flex-col items-center justify-center px-8 py-4 mx-auto w-full rounded-xl',
|
||||
'border border-slate-200 dark:border-zinc-800 border-dashed hover:border-slate-300 hover:dark:border-zinc-700',
|
||||
'cursor-pointer min-h-36 transition-colors bg-white dark:bg-zinc-950 relative',
|
||||
]}
|
||||
type="button"
|
||||
onclick={() => (open = !open)}
|
||||
>
|
||||
{#if imageUrl}
|
||||
<div>
|
||||
<Icon
|
||||
src={Plus}
|
||||
class="text-slate-400 dark:text-zinc-500 absolute top-0 left-0 m-2"
|
||||
size="20"
|
||||
micro
|
||||
/>
|
||||
</div>
|
||||
<img src={imageUrl} alt="" class="rounded-md mx-auto h-full" />
|
||||
{:else}
|
||||
<Icon
|
||||
src={DocumentPlus}
|
||||
class="text-slate-400 dark:text-zinc-500"
|
||||
size="36"
|
||||
solid
|
||||
/>
|
||||
<p class="text-slate-600 dark:text-zinc-400 font-medium">
|
||||
{$t('common.attach')}
|
||||
</p>
|
||||
{/if}
|
||||
<ImageInputModal bind:open bind:imageUrl={passedImageUrl} />
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,65 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import { Label, TextInput } from 'mono-svelte'
|
||||
|
||||
interface Props {
|
||||
accept?: string
|
||||
files?: FileList | undefined | null
|
||||
label?: string | undefined
|
||||
url?: string | undefined
|
||||
}
|
||||
|
||||
let {
|
||||
accept = 'image/*',
|
||||
files = $bindable(null),
|
||||
label = undefined,
|
||||
url = undefined,
|
||||
}: Props = $props()
|
||||
|
||||
let dragover = $state(false)
|
||||
|
||||
let previewURL = $derived(files ? URL.createObjectURL(files[0]) : undefined)
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<Label text={label} class="mb-1" />
|
||||
<label
|
||||
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-xl
|
||||
border border-slate-200 dark:border-zinc-800 bg-white dark:bg-black
|
||||
cursor-pointer min-h-36 transition-colors {dragover
|
||||
? 'border-sky-500 text-sky-500'
|
||||
: ''}
|
||||
{url != undefined ? 'rounded-b-none' : ''}
|
||||
"
|
||||
ondrop={preventDefault((event) => (files = event.dataTransfer?.files))}
|
||||
ondragover={preventDefault((event) => {
|
||||
if (event.dataTransfer) {
|
||||
event.dataTransfer.dropEffect = 'copy'
|
||||
dragover = true
|
||||
}
|
||||
})}
|
||||
ondragleave={preventDefault(() => (dragover = false))}
|
||||
>
|
||||
{#if files}
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={previewURL}
|
||||
onload={() => {
|
||||
if (previewURL) URL.revokeObjectURL(previewURL)
|
||||
}}
|
||||
class="w-full max-w-sm h-full rounded-lg"
|
||||
/>
|
||||
{:else if url}
|
||||
<img src={url} />
|
||||
{:else}
|
||||
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
||||
<p class="text-sm opacity-50">Attach a file</p>
|
||||
{/if}
|
||||
<input type="file" bind:files {accept} class="hidden" />
|
||||
</label>
|
||||
{#if url != undefined}
|
||||
<TextInput class="rounded-t-none border-t-0 rounded-xl" />
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script lang="ts" module>
|
||||
export const parseURL = (href: string) => {
|
||||
try {
|
||||
return new URL(href)
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { HTMLAnchorAttributes } from 'svelte/elements'
|
||||
|
||||
interface Props extends HTMLAnchorAttributes {
|
||||
href: string
|
||||
highlight?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
href,
|
||||
highlight = false,
|
||||
children,
|
||||
class: clazz = '',
|
||||
icon,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<a
|
||||
{...rest}
|
||||
{href}
|
||||
class={[
|
||||
'hover:underline max-w-full inline-flex items-center gap-1',
|
||||
highlight && 'text-blue-600 dark:text-blue-400',
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{@render icon?.()}
|
||||
{@render children?.()}
|
||||
</a>
|
||||
@@ -0,0 +1,125 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/ui/generic/Avatar.svelte'
|
||||
import { getClient } from '$lib/api/client.svelte'
|
||||
import type { Community, ListingType } from '$lib/api/types'
|
||||
import { MenuButton, Search } from 'mono-svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { Icon, ServerStack, XCircle } from 'svelte-hero-icons'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
interface Props {
|
||||
type?: 'community' | 'instance'
|
||||
q?: string
|
||||
instance?: string | undefined
|
||||
listing_type?: ListingType
|
||||
showWhenEmpty?: boolean
|
||||
placeholder?: string
|
||||
onselect?: (item: any) => void
|
||||
label?: string
|
||||
}
|
||||
|
||||
let {
|
||||
type = 'community',
|
||||
q = $bindable(''),
|
||||
instance = undefined,
|
||||
listing_type = 'Subscribed',
|
||||
showWhenEmpty = false,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: Community | undefined }>()
|
||||
let instances = $derived(
|
||||
type == 'instance' && getClient().getFederatedInstances(),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if type == 'community'}
|
||||
<Search
|
||||
search={async (q) => {
|
||||
const results = await getClient(instance).search({
|
||||
q: q || ' ',
|
||||
type_: 'Communities',
|
||||
limit: 20,
|
||||
listing_type: listing_type,
|
||||
sort: 'TopAll',
|
||||
})
|
||||
|
||||
return results.communities
|
||||
}}
|
||||
extractName={(c) =>
|
||||
`${c.community.name}@${new URL(c.community.actor_id).hostname}`}
|
||||
bind:query={q}
|
||||
{...rest}
|
||||
>
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton onclick={() => dispatcher('select', undefined)}>
|
||||
<Icon src={XCircle} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet children({ item, select })}
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton onclick={() => select(item)}>
|
||||
<Avatar
|
||||
url={item.community.icon}
|
||||
alt={item.community.title}
|
||||
width={24}
|
||||
/>
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.community.title}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.community.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
{:else if type == 'instance'}
|
||||
<Search
|
||||
search={async (q) => {
|
||||
const results = (await instances) || {}
|
||||
|
||||
return q
|
||||
? (results.federated_instances?.linked || []).filter(
|
||||
(i) => i.software === 'lemmy' && i.domain.includes(q),
|
||||
)
|
||||
: []
|
||||
}}
|
||||
extractName={(i) => `${i.domain}`}
|
||||
bind:query={q}
|
||||
{...rest}
|
||||
>
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton onclick={() => dispatcher('select', undefined)}>
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None (Start typing to search)</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet children({ item, select })}
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton onclick={() => select(item)}>
|
||||
<Icon src={ServerStack} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.domain}</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
{/if}
|
||||
@@ -0,0 +1,69 @@
|
||||
<script lang="ts">
|
||||
import TabButton from './TabButton.svelte'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
interface Props {
|
||||
options: T[]
|
||||
disabled?: boolean[]
|
||||
optionNames?: string[]
|
||||
selected: T
|
||||
children?: import('svelte').Snippet<[{ selected: T }]>
|
||||
onselect?: (item: T) => void
|
||||
}
|
||||
|
||||
let {
|
||||
options,
|
||||
disabled = [],
|
||||
optionNames = [],
|
||||
selected = $bindable(),
|
||||
children,
|
||||
onselect,
|
||||
}: Props = $props()
|
||||
|
||||
let selectedIndex = $state(0)
|
||||
let id = $props.id()
|
||||
|
||||
/* you see id like this to be a super simple
|
||||
|
||||
*/
|
||||
$effect(() => {
|
||||
const newIndex = options.findIndex((i) => i === selected)
|
||||
if (newIndex !== -1) {
|
||||
selectedIndex = newIndex
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
const newSelected = options[selectedIndex]
|
||||
if (newSelected !== undefined && newSelected !== selected) {
|
||||
selected = newSelected
|
||||
onselect?.(newSelected)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<fieldset
|
||||
class="flex items-center gap-1 w-max max-w-full z-0 relative overflow-auto"
|
||||
>
|
||||
{#each options as option, index}
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
bind:group={selectedIndex}
|
||||
value={index}
|
||||
name={id}
|
||||
id="{id}-{option?.toString()}"
|
||||
class="hidden"
|
||||
/>
|
||||
<TabButton
|
||||
selected={selectedIndex == index}
|
||||
disabled={disabled[index]}
|
||||
element="div"
|
||||
>
|
||||
{optionNames[index] || option}
|
||||
</TabButton>
|
||||
</label>
|
||||
{/each}
|
||||
</fieldset>
|
||||
{@render children?.({ selected })}
|
||||
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { HTMLButtonAttributes } from 'svelte/elements'
|
||||
|
||||
const sizes = {
|
||||
sm: 'px-2.5 py-1',
|
||||
md: 'py-1.5 px-3.5',
|
||||
}
|
||||
|
||||
interface Props extends HTMLButtonAttributes {
|
||||
selected?: boolean
|
||||
children: Snippet
|
||||
size?: keyof typeof sizes
|
||||
element?: 'div' | 'a' | 'button'
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
selected = false,
|
||||
onselect,
|
||||
disabled,
|
||||
children,
|
||||
href,
|
||||
size = 'sm',
|
||||
element = href ? 'a' : 'button',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={element}
|
||||
class={[
|
||||
sizes[size],
|
||||
'rounded-xl text-sm font-medium transition-colors duration-75 relative cursor-pointer border shadow-xs',
|
||||
selected
|
||||
? 'border-transparent bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-90 active:brightness-75'
|
||||
: ' dark:bg-zinc-900/50 bg-white border-slate-200 dark:border-zinc-800 hover:bg-slate-100 hover:dark:bg-zinc-800 active:bg-slate-200 active:dark:bg-zinc-900',
|
||||
]}
|
||||
onclick={href ? undefined : onselect}
|
||||
{disabled}
|
||||
{href}
|
||||
{...rest}
|
||||
>
|
||||
{@render children?.()}
|
||||
</svelte:element>
|
||||
@@ -0,0 +1,116 @@
|
||||
<script lang="ts">
|
||||
import { findClosestNumber } from '$lib/util.svelte.js'
|
||||
import { createAvatar } from '@dicebear/core'
|
||||
import * as initials from '@dicebear/initials'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
const sizes = [16, 24, 32, 48, 64, 96, 128, 256, 512]
|
||||
|
||||
const optimizeUrl = (
|
||||
url: string | undefined,
|
||||
res: number,
|
||||
): string | undefined => {
|
||||
if (url === undefined) return
|
||||
|
||||
try {
|
||||
const urlObj = new URL(url)
|
||||
urlObj.searchParams.append('format', 'webp')
|
||||
if (res > -1) {
|
||||
urlObj.searchParams.append(
|
||||
'thumbnail',
|
||||
findClosestNumber(sizes, res).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
return urlObj.toString()
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
url: string | undefined
|
||||
alt?: string
|
||||
title?: string
|
||||
circle?: boolean
|
||||
width: number
|
||||
res?: number | undefined
|
||||
style?: string
|
||||
class?: ClassValue
|
||||
}
|
||||
|
||||
let {
|
||||
url,
|
||||
alt = '',
|
||||
title = '',
|
||||
circle = true,
|
||||
width,
|
||||
res = undefined,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let optimizedURLs = $derived(
|
||||
[2, 3, 6, -1].map((n) => optimizeUrl(url, (res || width) * n)),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if optimizedURLs[0] != undefined}
|
||||
<img
|
||||
{...rest}
|
||||
loading="lazy"
|
||||
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
||||
src={optimizedURLs[0]}
|
||||
alt=""
|
||||
{width}
|
||||
{title}
|
||||
class={[
|
||||
'aspect-square object-cover overflow-hidden shrink-0 bg-slate-100 dark:bg-zinc-900',
|
||||
circle ? 'rounded-full' : 'rounded-lg',
|
||||
clazz,
|
||||
]}
|
||||
style="width: {width}px; height: {width}px; {style}"
|
||||
/>
|
||||
{:else}
|
||||
<div
|
||||
style="width: {width}px; height: {width}px;"
|
||||
class={[
|
||||
'aspect-square object-cover overflow-hidden shrink-0',
|
||||
circle ? 'rounded-full' : 'rounded-lg',
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{@html createAvatar(initials, {
|
||||
seed: alt,
|
||||
backgroundType: ['gradientLinear'],
|
||||
fontWeight: 800,
|
||||
randomizeIds: true,
|
||||
chars: 1,
|
||||
scale: 125,
|
||||
textColor: ['fff', '000'],
|
||||
backgroundColor: [
|
||||
'7B68EE',
|
||||
'FF6347',
|
||||
'20B2AA',
|
||||
'DDA0DD',
|
||||
'F0E68C',
|
||||
'FF1493',
|
||||
'4682B4',
|
||||
'32CD32',
|
||||
'FFB6C1',
|
||||
'8B4513',
|
||||
'00CED1',
|
||||
'9370DB',
|
||||
'FFA500',
|
||||
'2E8B57',
|
||||
'DC143C',
|
||||
'BA55D3',
|
||||
'708090',
|
||||
'ADFF2F',
|
||||
'CD853F',
|
||||
'48D1CC',
|
||||
],
|
||||
}).toString()}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,27 @@
|
||||
<script lang="ts">
|
||||
import Avatar from './Avatar.svelte'
|
||||
|
||||
interface Props {
|
||||
name: string
|
||||
label?: string | undefined
|
||||
icon?: string | undefined
|
||||
customIcon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
name,
|
||||
label = undefined,
|
||||
icon = undefined,
|
||||
customIcon,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
{#if customIcon}{@render customIcon()}{:else}
|
||||
<Avatar url={icon} width={32} alt={name} circle={false} />
|
||||
{/if}
|
||||
<div class="flex flex-col">
|
||||
<span class="font-semibold text-base">{name}</span>
|
||||
<span class="text-sm">{label}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,167 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import Markdown from '../../app/markdown/Markdown.svelte'
|
||||
import FormattedNumber from '../../components/util/FormattedNumber.svelte'
|
||||
import Avatar from './Avatar.svelte'
|
||||
import Expandable from '../shared/disclosure/Expandable.svelte'
|
||||
|
||||
interface Props {
|
||||
avatar?: string | undefined
|
||||
name: string
|
||||
bio?: string | undefined
|
||||
banner?: string | undefined
|
||||
url?: string | undefined
|
||||
stats?: {
|
||||
name: string
|
||||
value: string
|
||||
format?: boolean
|
||||
}[]
|
||||
center?: boolean
|
||||
class?: ClassValue
|
||||
nameDetail?: import('svelte').Snippet
|
||||
actions?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
compact?: 'always' | 'lg'
|
||||
avatarCircle?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
avatar = undefined,
|
||||
name,
|
||||
bio = undefined,
|
||||
banner = undefined,
|
||||
url = undefined,
|
||||
stats = [],
|
||||
center = false,
|
||||
class: clazz = '',
|
||||
nameDetail,
|
||||
actions,
|
||||
children,
|
||||
compact,
|
||||
avatarCircle = true,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div {...rest} class={['z-10 text-sm contents w-full', clazz]}>
|
||||
<div
|
||||
class={[
|
||||
compact == 'lg' && 'lg:hidden',
|
||||
compact == 'always' && 'hidden',
|
||||
'absolute inset-0 h-96 overflow-x-hidden -z-10',
|
||||
]}
|
||||
>
|
||||
<img
|
||||
src={banner || avatar}
|
||||
class="w-full h-64 object-cover blur-3xl opacity-30 dark:opacity-30"
|
||||
height="192"
|
||||
alt="User banner"
|
||||
/>
|
||||
</div>
|
||||
{#if banner}
|
||||
<div class="relative overflow-hidden rounded-xl">
|
||||
<img
|
||||
src={banner}
|
||||
class="w-full object-cover h-48 rounded-t-xl bg-white dark:bg-zinc-900 rounded-xl"
|
||||
height="192"
|
||||
alt="User banner"
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Avatar
|
||||
width={96}
|
||||
url={avatar}
|
||||
alt={name}
|
||||
circle={avatarCircle}
|
||||
class={[
|
||||
'ring-slate-25 bg-slate-25 dark:bg-zinc-925 ring-6 relative dark:ring-zinc-950',
|
||||
banner && '-mt-12 ml-4',
|
||||
!avatarCircle && 'rounded-3xl!',
|
||||
]}
|
||||
/>
|
||||
<div class="py-4 flex flex-col gap-4">
|
||||
<div class="flex flex-col flex-1">
|
||||
<svelte:element
|
||||
this={url ? 'a' : 'span'}
|
||||
href={url}
|
||||
class="text-2xl font-medium tracking-tight {url
|
||||
? 'hover:underline hover:text-primary-900 dark:hover:text-primary-100'
|
||||
: ''}"
|
||||
>
|
||||
{name}
|
||||
</svelte:element>
|
||||
<span
|
||||
class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400 max-w-full w-max"
|
||||
>
|
||||
{@render nameDetail?.()}
|
||||
</span>
|
||||
|
||||
{#if actions}
|
||||
<div class="flex flex-col mt-2">
|
||||
{@render actions?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if stats.length > 0}
|
||||
<div
|
||||
class={[
|
||||
compact == 'lg' && 'lg:hidden',
|
||||
compact == 'always' ? 'hidden' : 'flex',
|
||||
'text-sm flex-row flex-wrap overflow-hidden gap-4 h-full',
|
||||
]}
|
||||
>
|
||||
{#each stats as stat}
|
||||
<div class="">
|
||||
<div class="text-slate-600 dark:text-zinc-500 text-sm font-medium">
|
||||
{stat.name}
|
||||
</div>
|
||||
<div
|
||||
class="text-xl font-medium text-primary-900 dark:text-primary-100 text-right"
|
||||
>
|
||||
{#if stat.format ?? true}
|
||||
<FormattedNumber
|
||||
number={Number(stat.value)}
|
||||
options={{ notation: 'standard' }}
|
||||
/>
|
||||
{:else}
|
||||
{stat.value}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{#if bio}
|
||||
<div
|
||||
class={[
|
||||
compact == 'lg' && 'lg:hidden',
|
||||
compact == 'always' && 'hidden',
|
||||
'relative w-full mb-4 text-base',
|
||||
center ? 'text-center' : 'text-left',
|
||||
]}
|
||||
>
|
||||
{#if bio.length > 300}
|
||||
<Expandable>
|
||||
{#snippet title()}
|
||||
{$t('cards.site.about')}
|
||||
{/snippet}
|
||||
<Markdown source={bio} class="font-normal" />
|
||||
</Expandable>
|
||||
{:else}
|
||||
<Markdown source={bio} class="font-normal" />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="space-y-3 py-4 pt-0">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.banner-mask {
|
||||
mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,82 @@
|
||||
<script lang="ts" module>
|
||||
import { pushState } from '$app/navigation'
|
||||
|
||||
export function showImage(url: string) {
|
||||
pushState('', {
|
||||
openImage: url,
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import { Share, XMark } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fade, scale } from 'svelte/transition'
|
||||
import { trapFocus } from 'trap-focus-svelte'
|
||||
|
||||
interface Props {
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
alt?: string
|
||||
}
|
||||
|
||||
let { alt = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if page.state.openImage || '' != ''}
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="fixed top-0 left-0 w-screen h-svh overflow-auto bg-white/50 dark:bg-black/50
|
||||
flex flex-col z-100 backdrop-blur-xs"
|
||||
transition:fade={{ duration: 150 }}
|
||||
onclick={() => history.back()}
|
||||
onkeydown={(e) => {
|
||||
if (e.key == 'Escape') history.back()
|
||||
}}
|
||||
use:trapFocus
|
||||
>
|
||||
<img
|
||||
width={800}
|
||||
height={800}
|
||||
src={page.state.openImage}
|
||||
class={[
|
||||
'max-w-full mx-auto my-auto overscroll-contain bg-white dark:bg-zinc-900',
|
||||
]}
|
||||
transition:scale={{ start: 0.95, easing: expoOut, duration: 250 }}
|
||||
{alt}
|
||||
/>
|
||||
<div class="sticky z-10 bottom-4 left-1/2 -translate-x-1/2 w-max">
|
||||
<Material
|
||||
class="gap-1 p-0.5 px-1 flex flex-row items-center"
|
||||
rounding="full"
|
||||
padding="none"
|
||||
color="uniform"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<Button
|
||||
onclick={() => {
|
||||
navigator.clipboard.writeText(page.state?.openImage ?? '')
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
color="tertiary"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
aria-label={$t('post.actions.more.share')}
|
||||
icon={Share}
|
||||
></Button>
|
||||
<Button
|
||||
onclick={() => history.back()}
|
||||
color="tertiary"
|
||||
size="square-lg"
|
||||
rounding="pill"
|
||||
aria-label={$t('common.back')}
|
||||
icon={XMark}
|
||||
></Button>
|
||||
</Material>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,19 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
const placements = {
|
||||
top: 'top-6 lg:top-22',
|
||||
bottom: 'bottom-22 lg:bottom-6 mt-6',
|
||||
}
|
||||
|
||||
interface Props {
|
||||
placement: keyof typeof placements
|
||||
children?: Snippet
|
||||
}
|
||||
|
||||
let { placement, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class={['sticky z-30 mb-0', placements[placement]]}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/ui/generic/Avatar.svelte'
|
||||
import CommonList from '$comp/ui/layout/CommonList.svelte'
|
||||
import { Button } from 'mono-svelte'
|
||||
|
||||
interface Props {
|
||||
items: {
|
||||
avatar?: string
|
||||
name: string
|
||||
instance?: string
|
||||
id: number
|
||||
url: string
|
||||
}[]
|
||||
}
|
||||
|
||||
let { items }: Props = $props()
|
||||
</script>
|
||||
|
||||
<CommonList animate={false} class="px-1 py-0.5" size="xs" {items}>
|
||||
{#snippet item(item)}
|
||||
<Button
|
||||
class="font-normal w-full h-max block"
|
||||
color="none"
|
||||
alignment="left"
|
||||
href={item.url}
|
||||
>
|
||||
<div class="flex-none">
|
||||
<Avatar
|
||||
url={item.avatar}
|
||||
alt={item.name}
|
||||
title={item.name}
|
||||
width={24}
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col max-w-full break-words">
|
||||
<span>{item.name}</span>
|
||||
{#if item.instance}
|
||||
<span class="text-xs text-slate-600 dark:text-zinc-400">
|
||||
{item.instance}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</Button>
|
||||
{/snippet}
|
||||
</CommonList>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
width?: number
|
||||
}
|
||||
|
||||
let { width = 48 }: Props = $props()
|
||||
</script>
|
||||
|
||||
<svg
|
||||
{width}
|
||||
height={width}
|
||||
viewBox="0 0 100 100"
|
||||
fill="currentColor"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="inline hover:fill-slate-700 dark:hover:fill-zinc-300 transition-colors"
|
||||
>
|
||||
<path
|
||||
id="hexagon"
|
||||
d="M45.5 10.8868C48.594 9.10042 52.406 9.10042 55.5 10.8868L82.3061 26.3632C85.4001 28.1496 87.3061 31.4508 87.3061 35.0235V65.9765C87.3061 69.5492 85.4001 72.8504 82.3061 74.6368L55.5 90.1132C52.406 91.8996 48.594 91.8996 45.5 90.1132L18.6939 74.6368C15.5999 72.8504 13.6939 69.5492 13.6939 65.9765V35.0235C13.6939 31.4508 15.5999 28.1496 18.6939 26.3632L45.5 10.8868Z"
|
||||
/>
|
||||
</svg>
|
||||
@@ -0,0 +1,11 @@
|
||||
<div class="skeleton animate-pulse flex flex-col gap-2 w-full">
|
||||
<div
|
||||
class="w-2/3 h-6 bg-slate-200 dark:bg-zinc-800 animate-pulse rounded-md"
|
||||
></div>
|
||||
<div
|
||||
class="w-full h-20 bg-slate-200 dark:bg-zinc-800 animate-pulse rounded-md"
|
||||
></div>
|
||||
<div
|
||||
class="w-32 h-6 bg-slate-200 dark:bg-zinc-800 animate-pulse rounded-md"
|
||||
></div>
|
||||
</div>
|
||||
@@ -0,0 +1,67 @@
|
||||
<script lang="ts" module>
|
||||
interface PageScopedError {
|
||||
scope: string
|
||||
message: string
|
||||
}
|
||||
|
||||
let errors = $state<PageScopedError[]>([])
|
||||
|
||||
export function pushError(args: { scope: string; message: string }) {
|
||||
errors.push(args)
|
||||
}
|
||||
|
||||
export function clearErrorScope(scope: string | null | undefined) {
|
||||
errors = errors.filter((error) => error.scope != scope)
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { onDestroy } from 'svelte'
|
||||
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
|
||||
onDestroy(() => {
|
||||
clearErrorScope(scope)
|
||||
})
|
||||
interface Props {
|
||||
scope?: string | undefined | null
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { scope = undefined, class: clazz = '' }: Props = $props()
|
||||
|
||||
let scopedErrors = $derived(
|
||||
errors.filter((e) => e.scope == scope || e.scope == 'global'),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if scopedErrors.length > 0}
|
||||
<div
|
||||
class={['flex flex-col gap-4', clazz]}
|
||||
in:slide={{ duration: 400, easing: expoOut }}
|
||||
out:slide={{ duration: 400, delay: 400, easing: expoOut }}
|
||||
>
|
||||
<div
|
||||
in:fly|global={{
|
||||
y: -8,
|
||||
duration: 400,
|
||||
delay: 200,
|
||||
opacity: 0,
|
||||
easing: expoOut,
|
||||
}}
|
||||
out:fly={{ y: -8, duration: 400, opacity: 0, easing: expoOut }}
|
||||
class="bg-red-400/10 border border-red-500/30 text-red-900 dark:text-red-50 rounded-2xl p-4"
|
||||
>
|
||||
<Icon
|
||||
src={ExclamationTriangle}
|
||||
size="32"
|
||||
mini
|
||||
class="inline-block rounded-lg bg-red-500 p-1.5 text-white clear-both float-left mr-2"
|
||||
/>
|
||||
{#each scopedErrors as error}
|
||||
<p>{error.message}</p>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import FormattedNumber from '../../components/util/FormattedNumber.svelte'
|
||||
|
||||
interface Props {
|
||||
label: string
|
||||
content: string | number
|
||||
formatted?: boolean
|
||||
labelClass?: string
|
||||
contentClass?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
label,
|
||||
content,
|
||||
formatted = false,
|
||||
labelClass = '',
|
||||
contentClass = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if content != '-1'}
|
||||
<dl class={['flex flex-col', clazz]}>
|
||||
<dt class={['text-slate-600 dark:text-zinc-400 text-xs', labelClass]}>
|
||||
{label}
|
||||
</dt>
|
||||
<dd class={['text-base', contentClass]}>
|
||||
{#if formatted}
|
||||
<FormattedNumber number={Number(content)} />
|
||||
{:else}
|
||||
{content}
|
||||
{/if}
|
||||
</dd>
|
||||
</dl>
|
||||
{/if}
|
||||
@@ -0,0 +1,53 @@
|
||||
<script lang="ts">
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
interface Props {
|
||||
icon?: IconSource | undefined
|
||||
title: string
|
||||
description?: string | undefined
|
||||
class?: ClassValue
|
||||
children?: import('svelte').Snippet
|
||||
iconClass?: ClassValue
|
||||
}
|
||||
|
||||
let {
|
||||
icon = undefined,
|
||||
title,
|
||||
description = undefined,
|
||||
class: clazz = '',
|
||||
children,
|
||||
iconClass,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="text-slate-500 dark:text-zinc-500 contrast-more:text-slate-700 contrast-more:dark:text-zinc-300 flex flex-col w-max mx-auto items-center gap-4 {clazz}"
|
||||
>
|
||||
<div class="flex flex-col gap-2 items-center max-w-sm">
|
||||
{#if icon}
|
||||
<div
|
||||
class={[
|
||||
iconClass
|
||||
? iconClass
|
||||
: 'bg-slate-100 dark:bg-zinc-900 p-3 rounded-2xl text-primary-900 dark:text-primary-100',
|
||||
]}
|
||||
>
|
||||
<Icon src={icon} size="28" solid />
|
||||
</div>
|
||||
{/if}
|
||||
<div class={['space-y-2', clazz]}>
|
||||
<h1
|
||||
class="text-slate-900 dark:text-zinc-100 text-xl font-medium text-center"
|
||||
>
|
||||
{title}
|
||||
</h1>
|
||||
{#if description}
|
||||
<p class="text-center font-normal max-w-80 mx-auto text-balance">
|
||||
{description}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { Tween } from 'svelte/motion'
|
||||
|
||||
interface Props {
|
||||
progress?: number
|
||||
}
|
||||
|
||||
let { progress = 0 }: Props = $props()
|
||||
|
||||
let tween = new Tween(progress, { easing: expoOut })
|
||||
|
||||
$effect(() => {
|
||||
tween.set(progress)
|
||||
})
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="bg-primary-900 dark:bg-primary-100 h-1 rounded-full"
|
||||
style="width: {tween.current >= 0 ? tween.current * 100 : 0}%;"
|
||||
></div>
|
||||
@@ -0,0 +1,46 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import Avatar from '../Avatar.svelte'
|
||||
|
||||
interface Props {
|
||||
href?: string
|
||||
icon?: string
|
||||
title: string
|
||||
detail?: string
|
||||
orientation: 'vertical' | 'horizontal'
|
||||
children?: Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
href,
|
||||
icon,
|
||||
title,
|
||||
detail,
|
||||
children,
|
||||
orientation = 'horizontal',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={[
|
||||
'flex gap-2 p-5',
|
||||
orientation == 'horizontal'
|
||||
? 'flex-row items-center'
|
||||
: 'flex-col items-staRT',
|
||||
]}
|
||||
>
|
||||
<Avatar url={icon} alt={title} width={detail ? 32 : 24} circle={false} />
|
||||
<a class="flex-1 flex flex-col group" {href}>
|
||||
<h3
|
||||
class="font-medium text-base overflow-hidden text-ellipsis leading-5 group-hover:underline"
|
||||
>
|
||||
{title}
|
||||
</h3>
|
||||
<p class="text-sm text-slate-600 dark:text-zinc-400">
|
||||
{detail}
|
||||
</p>
|
||||
</a>
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,159 @@
|
||||
<script lang="ts" generics="T">
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
const sizeDelay: Record<'lg' | 'md' | 'sm' | 'xs', number> = {
|
||||
lg: 120,
|
||||
md: 80,
|
||||
sm: 40,
|
||||
xs: 0,
|
||||
}
|
||||
|
||||
interface Props {
|
||||
items?: T[]
|
||||
item?: Snippet<[T, number]>
|
||||
children?: Snippet
|
||||
animate?: boolean
|
||||
size?: 'lg' | 'md' | 'sm' | 'xs'
|
||||
class?: ClassValue
|
||||
selected?: (item: T) => boolean
|
||||
}
|
||||
|
||||
let {
|
||||
items,
|
||||
item: itemSnippet,
|
||||
children,
|
||||
animate = true,
|
||||
size = 'sm',
|
||||
class: clazz,
|
||||
selected,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<ul class="space-y-1">
|
||||
{#if items}
|
||||
{#each items as item, index (item)}
|
||||
<li
|
||||
class={[
|
||||
'group/li',
|
||||
animate && 'animate',
|
||||
size == 'xs' && 'xs',
|
||||
selected?.(item) && 'selected',
|
||||
clazz,
|
||||
]}
|
||||
style="--i: {index < 10 ? index * sizeDelay[size] : 0}ms;"
|
||||
>
|
||||
{@render itemSnippet?.(item, index)}
|
||||
</li>
|
||||
{/each}
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
|
||||
<style>
|
||||
ul > :global(li) {
|
||||
transition: background-color 0.1s;
|
||||
background-color: var(--color-white);
|
||||
container-type: inline-size;
|
||||
|
||||
border-radius: var(--radius-md) var(--radius-md);
|
||||
|
||||
&:first-child {
|
||||
border-top-left-radius: var(--radius-2xl);
|
||||
border-top-right-radius: var(--radius-2xl);
|
||||
}
|
||||
&:last-child {
|
||||
border-bottom-left-radius: var(--radius-2xl);
|
||||
border-bottom-right-radius: var(--radius-2xl);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: var(--color-slate-25);
|
||||
}
|
||||
}
|
||||
|
||||
ul > :global(li:not(.xs) > *) {
|
||||
padding-block: calc(var(--spacing) * 3);
|
||||
padding-inline: calc(var(--spacing) * 3.5);
|
||||
|
||||
@media screen and (min-width: 40rem) {
|
||||
padding-block: calc(var(--spacing) * 3);
|
||||
padding-inline: calc(var(--spacing) * 4);
|
||||
}
|
||||
}
|
||||
|
||||
ul > :global(li.xs > *) {
|
||||
padding-block: calc(var(--spacing) * 0.5);
|
||||
padding-block: calc(var(--spacing) * 1);
|
||||
}
|
||||
|
||||
ul > :global(li).selected {
|
||||
background-color: color-mix(
|
||||
in oklab,
|
||||
var(--color-white),
|
||||
var(--color-slate-100)
|
||||
);
|
||||
}
|
||||
|
||||
:global(.dark) ul > :global(li).selected {
|
||||
background-color: color-mix(
|
||||
in oklab,
|
||||
var(--color-zinc-925),
|
||||
var(--color-zinc-800)
|
||||
);
|
||||
}
|
||||
|
||||
:global(.dark) ul > :global(li) {
|
||||
background-color: color-mix(
|
||||
in oklab,
|
||||
var(--color-zinc-925),
|
||||
var(--color-zinc-900)
|
||||
);
|
||||
|
||||
&:hover {
|
||||
background-color: var(--color-zinc-900);
|
||||
}
|
||||
|
||||
&:active {
|
||||
background-color: var(--color-zinc-950);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes pop-in {
|
||||
from {
|
||||
transform: translateY(16px);
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
transform: translateY(0px);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.animate {
|
||||
--delay: var(--i, 0ms);
|
||||
}
|
||||
|
||||
:global(.animate > *:only-child) {
|
||||
animation: pop-in 1s forwards cubic-bezier(0.16, 1, 0.3, 1);
|
||||
animation-delay: var(--delay, 0ms);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
:global(.animate:not(:has(> * + *))) {
|
||||
animation: pop-in 1s forwards cubic-bezier(0.16, 1, 0.3, 1);
|
||||
animation-delay: var(--delay, 0ms);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
:global(.animate > *:only-child) {
|
||||
animation: none;
|
||||
opacity: 1;
|
||||
}
|
||||
:global(.animate:not(:has(> * + *))) {
|
||||
animation: none;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,71 @@
|
||||
<script lang="ts">
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
const sizes = {
|
||||
xs: 'text-xs',
|
||||
sm: 'text-sm',
|
||||
md: 'text-base',
|
||||
lg: 'text-lg',
|
||||
}
|
||||
|
||||
const margins = {
|
||||
none: '',
|
||||
sm: 'mt-3 mb-1 px-3',
|
||||
md: 'mt-4 mb-2',
|
||||
lg: 'mt-6 mb-2',
|
||||
'bottom-sm': 'mb-1 px-3',
|
||||
'bottom-md': 'mb-2',
|
||||
'bottom-lg': 'mb-3',
|
||||
}
|
||||
|
||||
const colors = {
|
||||
subtle: 'text-slate-600 dark:text-zinc-400',
|
||||
none: '',
|
||||
}
|
||||
|
||||
interface Props {
|
||||
class?: ClassValue
|
||||
size?: keyof typeof sizes
|
||||
color?: keyof typeof colors
|
||||
margin?: keyof typeof margins
|
||||
border?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
action?: import('svelte').Snippet
|
||||
element?: string
|
||||
}
|
||||
|
||||
let {
|
||||
class: clazz = '',
|
||||
children,
|
||||
action,
|
||||
border = true,
|
||||
size = 'sm',
|
||||
color = 'subtle',
|
||||
margin = 'none',
|
||||
element = 'h3',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={[
|
||||
'flex flex-row items-center gap-2 flex-wrap',
|
||||
sizes[size],
|
||||
colors[color],
|
||||
margins[margin],
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
<svelte:element
|
||||
this={element}
|
||||
class="font-medium text-left flex flex-row gap-1 items-center"
|
||||
>
|
||||
{@render children?.()}
|
||||
</svelte:element>
|
||||
<div
|
||||
class={[
|
||||
'flex-1 border-slate-200/70 dark:border-zinc-800 border-b',
|
||||
!border && 'opacity-0',
|
||||
]}
|
||||
></div>
|
||||
{@render action?.()}
|
||||
</div>
|
||||
@@ -0,0 +1,108 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { ChevronLeft, ChevronRight, Icon } from 'svelte-hero-icons'
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { fly } from 'svelte/transition'
|
||||
import { page as pageData } from '$app/state'
|
||||
import { invalidate } from '$app/navigation'
|
||||
import { SvelteURLSearchParams } from 'svelte/reactivity'
|
||||
|
||||
interface Props {
|
||||
page?: number
|
||||
cursor?: { next?: string; back?: string } | undefined
|
||||
hasMore?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
href?: (current: number | string) => string
|
||||
back?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
page = $bindable(0),
|
||||
cursor = undefined,
|
||||
hasMore = true,
|
||||
children,
|
||||
href,
|
||||
back = true,
|
||||
}: Props = $props()
|
||||
|
||||
let customHref = (href?: string) => {
|
||||
if (href?.startsWith('?')) {
|
||||
const current = new SvelteURLSearchParams(pageData.url.searchParams)
|
||||
const newParams = new SvelteURLSearchParams(href)
|
||||
|
||||
current.delete(Array.from(newParams.keys())[0])
|
||||
current.append(
|
||||
Array.from(newParams.entries())[0][0],
|
||||
Array.from(newParams.entries())[0][1],
|
||||
)
|
||||
|
||||
return `?${current.toString()}`
|
||||
} else return href
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if hasMore || page != 1}
|
||||
<nav
|
||||
aria-label={$t('aria.pagination.nav')}
|
||||
class={[
|
||||
'flex flex-row gap-2 items-center justify-center bg-white dark:bg-zinc-900',
|
||||
'border border-slate-200 dark:border-zinc-800 rounded-full overflow-hidden w-max mx-auto p-0.5',
|
||||
'shadow-md',
|
||||
]}
|
||||
>
|
||||
{#if children}
|
||||
<span class="text-sm text-slate-600 dark:text-zinc-400 font-medium">
|
||||
{@render children?.()}
|
||||
</span>
|
||||
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
||||
{/if}
|
||||
{#if back}
|
||||
<Button
|
||||
href={customHref(href?.(cursor?.back ?? page - 1))}
|
||||
color="tertiary"
|
||||
onclick={() => invalidate(pageData.url)}
|
||||
title={$t('common.back')}
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class="text-inherit dark:text-inherit p-1"
|
||||
disabled={(cursor?.back == undefined && cursor?.next != undefined) ||
|
||||
page <= 1}
|
||||
>
|
||||
{#snippet suffix()}
|
||||
<Icon src={ChevronLeft} size="24" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
{#if page}
|
||||
<div style="display: grid;">
|
||||
{#key page}
|
||||
<div
|
||||
in:fly={{ y: 8, easing: backOut, duration: 400, delay: 100 }}
|
||||
out:fly={{ y: 8, easing: backOut, duration: 400 }}
|
||||
class="text-lg font-medium"
|
||||
style="grid-column: 1; grid-row: 1;"
|
||||
>
|
||||
{page}
|
||||
</div>
|
||||
{/key}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Button
|
||||
href={customHref(href?.(cursor?.next ?? page + 1))}
|
||||
color="tertiary"
|
||||
onclick={() => invalidate(pageData.url)}
|
||||
title={$t('common.next')}
|
||||
size="custom"
|
||||
rounding="pill"
|
||||
class="text-inherit dark:text-inherit p-1"
|
||||
disabled={!hasMore}
|
||||
>
|
||||
{#snippet suffix()}
|
||||
<Icon src={ChevronRight} size="24" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
</nav>
|
||||
{/if}
|
||||
@@ -0,0 +1,35 @@
|
||||
<script lang="ts">
|
||||
import { navigating, page } from '$app/state'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { Button, TextInput } from 'mono-svelte'
|
||||
import { MagnifyingGlass } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
query?: string | null
|
||||
}
|
||||
|
||||
let { query = $bindable() }: Props = $props()
|
||||
|
||||
let searchElement = $state<HTMLInputElement>()
|
||||
</script>
|
||||
|
||||
<div class="flex gap-2 flex-row items-center w-full text-base h-10">
|
||||
<TextInput
|
||||
bind:value={query}
|
||||
bind:element={searchElement}
|
||||
name="q"
|
||||
placeholder={$t('routes.search.query')}
|
||||
size="lg"
|
||||
class="flex-1 rounded-full! h-full text-base!"
|
||||
/>
|
||||
<Button
|
||||
submit
|
||||
color="primary"
|
||||
size="custom"
|
||||
class="shrink-0 h-full aspect-square shadow-md"
|
||||
title="Search"
|
||||
rounding="pill"
|
||||
loading={navigating.to?.route.id == page.url.pathname}
|
||||
icon={MagnifyingGlass}
|
||||
></Button>
|
||||
</div>
|
||||
@@ -0,0 +1,109 @@
|
||||
<script lang="ts">
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type { Snippet } from 'svelte'
|
||||
import type {
|
||||
ClassValue,
|
||||
HTMLAttributes,
|
||||
UIEventHandler,
|
||||
} from 'svelte/elements'
|
||||
import { scrollY } from 'svelte/reactivity/window'
|
||||
|
||||
interface Props extends HTMLAttributes<HTMLDivElement> {
|
||||
children?: Snippet
|
||||
navbar?: Snippet<[{ class: ClassValue; style: string }]>
|
||||
sidebar?: Snippet<[{ class: ClassValue; style: string }]>
|
||||
main?: Snippet<[{ class: ClassValue; style: string }]>
|
||||
suffix?: Snippet<[{ class: ClassValue; style: string }]>
|
||||
}
|
||||
|
||||
let { children, navbar, sidebar, main, suffix }: Props = $props()
|
||||
|
||||
let previousTop = 0
|
||||
const onscroll: UIEventHandler<Window> = () => {
|
||||
if (!settings.dock.autoHide) {
|
||||
dockVisible = true
|
||||
return
|
||||
}
|
||||
|
||||
dockVisible = (scrollY?.current ?? 0) <= previousTop
|
||||
previousTop = scrollY?.current ?? 0
|
||||
}
|
||||
|
||||
let dockVisible = $state(true)
|
||||
</script>
|
||||
|
||||
<svelte:window {onscroll} />
|
||||
|
||||
{@render children?.()}
|
||||
<div class="min-h-screen flex flex-col">
|
||||
<div
|
||||
class={[
|
||||
'fixed md:sticky bottom-0 md:top-0',
|
||||
!dockVisible && 'max-md:-bottom-24',
|
||||
'w-full z-50 pointer-events-none',
|
||||
]}
|
||||
style="transition: bottom .4s cubic-bezier(0.075, 0.82, 0.165, 1);"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{@render navbar?.({
|
||||
class: [
|
||||
'bg-slate-100/70 dark:bg-zinc-950/90 border-slate-200/50 dark:border-zinc-900',
|
||||
'pointer-events-auto backdrop-blur-xl border md:border-t-0 md:border-x-0',
|
||||
],
|
||||
style: '',
|
||||
})}
|
||||
</div>
|
||||
<div class={['content flex-1', settings.newWidth && 'limit-width']}>
|
||||
{@render sidebar?.({
|
||||
class: `hidden md:flex sticky top-0 lg:top-16 left-0 max-h-[calc(100vh-4rem)] bg-slate-100 dark:bg-zinc-950 z-40`,
|
||||
style: 'grid-area: sidebar; width: 100% !important;',
|
||||
})}
|
||||
{@render main?.({
|
||||
class: `w-full bg-slate-50 dark:bg-zinc-925 justify-self-center border-x border-slate-200 dark:border-zinc-900 max-lg:pb-22 pb-3 lg:pb-6`,
|
||||
style: 'grid-area: main',
|
||||
})}
|
||||
{@render suffix?.({
|
||||
class: `max-lg:hidden flex w-full sticky top-0 lg:top-16 left-0 max-h-[calc(100vh-4rem)] overflow-auto bg-slate-100 dark:bg-zinc-950 z-40`,
|
||||
style: 'grid-area: suffix;',
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.content {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
height: 100%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
grid-area: content;
|
||||
grid-template-columns: 1fr;
|
||||
grid-template-areas: 'main';
|
||||
justify-items: start;
|
||||
}
|
||||
|
||||
.content.limit-width {
|
||||
max-width: 100rem;
|
||||
}
|
||||
|
||||
@media (min-width: 48rem) {
|
||||
.content {
|
||||
grid-template-columns: 16rem 1fr;
|
||||
justify-items: end start;
|
||||
grid-template-areas: 'sidebar main';
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 64rem) {
|
||||
.content {
|
||||
grid-template-columns: 20% 60% 20%;
|
||||
justify-items: end center start;
|
||||
grid-template-areas: 'sidebar main suffix';
|
||||
}
|
||||
|
||||
.content.limit-width {
|
||||
width: 100%;
|
||||
grid-template-columns: 2fr 5fr 2fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,7 @@
|
||||
export { default as Header } from './pages/Header.svelte'
|
||||
export { default as Tabs } from './pages/Tabs.svelte'
|
||||
export { default as CommonList } from './CommonList.svelte'
|
||||
export { default as SearchBar } from './SearchBar.svelte'
|
||||
export { default as Shell } from './Shell.svelte'
|
||||
export { default as Pageination } from './Pageination.svelte'
|
||||
export { default as PostListShell } from './pages/PostListShell.svelte'
|
||||
@@ -0,0 +1,56 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
|
||||
const sizes = {
|
||||
sm: 'text-2xl',
|
||||
md: 'text-3xl',
|
||||
lg: 'text-4xl',
|
||||
xl: 'text-6xl',
|
||||
}
|
||||
|
||||
interface Props {
|
||||
pageHeader?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
size?: keyof typeof sizes
|
||||
children?: import('svelte').Snippet
|
||||
extended?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
pageHeader = false,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
size = 'lg',
|
||||
children,
|
||||
extended,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<header
|
||||
class={[
|
||||
pageHeader &&
|
||||
`w-[calc(100%+1.5rem)] sm:w-[calc(100%+3rem)]
|
||||
bg-slate-100 dark:bg-zinc-950 -mx-3 sm:-mx-6 sm:px-6 sm:pb-6 px-4 pb-4 -mt-64 pt-64
|
||||
border-b border-slate-200 dark:border-zinc-900 margin z-0 mb-3 sm:mb-6`,
|
||||
]}
|
||||
{style}
|
||||
aria-label={$t('aria.element.pageHeader')}
|
||||
>
|
||||
{#if children}
|
||||
<h1
|
||||
class={[
|
||||
sizes[size],
|
||||
'flex gap-2 w-full tracking-tight font-medium',
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{@render children?.()}
|
||||
</h1>
|
||||
{/if}
|
||||
{#if extended}
|
||||
<div class="flex flex-col gap-3 mt-3">
|
||||
{@render extended?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</header>
|
||||
@@ -0,0 +1,114 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import { page } from '$app/state'
|
||||
import type { GetPosts, ListingType, PostView } from '$lib/api/types'
|
||||
import Location from '$lib/feature/filter/Location.svelte'
|
||||
import Sort from '$lib/feature/filter/Sort.svelte'
|
||||
import ViewSelect from '$lib/feature/filter/ViewSelect.svelte'
|
||||
import PostFeed from '$comp/lemmy/post/feed/PostFeed.svelte'
|
||||
import VirtualFeed from '$comp/lemmy/post/feed/VirtualFeed.svelte'
|
||||
import { Header } from '$comp/ui/layout'
|
||||
import Pageination from '$comp/ui/layout/Pageination.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import type { SortType } from 'lemmy-js-client'
|
||||
import Button from 'mono-svelte/button/Button.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { ArrowRight, Icon } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
cursor?: string
|
||||
params: {
|
||||
location?: ListingType
|
||||
sort?: SortType
|
||||
}
|
||||
title?: string
|
||||
extended?: Snippet
|
||||
getParams: GetPosts
|
||||
client: {
|
||||
lastSeen?: number
|
||||
itemHeights?: (number | null)[]
|
||||
}
|
||||
header?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
params,
|
||||
posts = $bindable(),
|
||||
cursor = $bindable(),
|
||||
title,
|
||||
extended: passedExtended,
|
||||
getParams,
|
||||
client = $bindable(),
|
||||
header = true,
|
||||
}: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
if (params.sort) settings.defaultSort.sort = params.sort
|
||||
})
|
||||
|
||||
const FeedComponent = $derived(
|
||||
settings.infiniteScroll && browser && !settings.posts.noVirtualize
|
||||
? VirtualFeed
|
||||
: PostFeed,
|
||||
)
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-2 max-w-full w-full min-w-0">
|
||||
{#if header}
|
||||
<Header pageHeader>
|
||||
{#if title}
|
||||
{title}
|
||||
{/if}
|
||||
{#snippet extended()}
|
||||
{@render passedExtended?.()}
|
||||
<form class="" method="get" action={page.url.pathname}>
|
||||
<div class="flex flex-row gap-2">
|
||||
{#if params.location}
|
||||
<Location name="type" navigate bind:selected={params.location} />
|
||||
{/if}
|
||||
{#if params.sort}
|
||||
<Sort
|
||||
placement="bottom"
|
||||
name="sort"
|
||||
navigate
|
||||
bind:selected={params.sort}
|
||||
/>
|
||||
{/if}
|
||||
<ViewSelect placement="bottom" />
|
||||
|
||||
<noscript>
|
||||
<Button
|
||||
class="self-end h-[34px] aspect-square"
|
||||
size="custom"
|
||||
submit
|
||||
>
|
||||
<Icon src={ArrowRight} size="16" micro />
|
||||
</Button>
|
||||
</noscript>
|
||||
</div>
|
||||
</form>
|
||||
{/snippet}
|
||||
</Header>
|
||||
{/if}
|
||||
|
||||
<FeedComponent
|
||||
bind:posts
|
||||
bind:lastSeen={() => client.lastSeen ?? 0, (v) => (client.lastSeen = v)}
|
||||
bind:params={getParams}
|
||||
virtualList={{ itemHeights: client?.itemHeights ?? [] }}
|
||||
/>
|
||||
<svelte:element
|
||||
this={settings.infiniteScroll && !settings.posts.noVirtualize
|
||||
? 'noscript'
|
||||
: 'div'}
|
||||
class="mt-auto flex flex-col"
|
||||
>
|
||||
<Pageination
|
||||
cursor={{ next: cursor }}
|
||||
href={(page) =>
|
||||
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
||||
back={false}
|
||||
/>
|
||||
</svelte:element>
|
||||
</div>
|
||||
@@ -0,0 +1,92 @@
|
||||
<script lang="ts">
|
||||
import { invalidateAll } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import TabButton from '$comp/input/TabButton.svelte'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
interface Props {
|
||||
routes: {
|
||||
href: string
|
||||
name: string
|
||||
}[]
|
||||
currentRoute?: SvelteURL | undefined
|
||||
buildUrl?: (currentRoute: SvelteURL | undefined, href: string) => string
|
||||
children?: import('svelte').Snippet
|
||||
style?: 'header' | 'subpage'
|
||||
margin?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
routes,
|
||||
currentRoute = undefined,
|
||||
buildUrl = (_, href) => href,
|
||||
children,
|
||||
style = 'header',
|
||||
margin = true,
|
||||
}: Props = $props()
|
||||
|
||||
let matchType = $derived<('search' | 'pathname')[]>(
|
||||
routes.map((i) =>
|
||||
new URL(`https://example.com${i.href}`)?.search != ''
|
||||
? 'search'
|
||||
: 'pathname',
|
||||
),
|
||||
)
|
||||
|
||||
// i am on 2 hours of sleep i apologize
|
||||
function isSelected(url: URL, href: SvelteURL, type: 'search' | 'pathname') {
|
||||
const currentSearch = new Set(url.searchParams.values())
|
||||
const hrefSearch = new Set(href.searchParams.values())
|
||||
// checks if there is any
|
||||
const usePathname = !routes.some(
|
||||
(i) =>
|
||||
new Set(
|
||||
new URL(`https://example.com${i.href}`).searchParams.values(),
|
||||
).intersection(currentSearch).size > 0,
|
||||
)
|
||||
|
||||
const hasSearchParam = hrefSearch.intersection(currentSearch).size > 0
|
||||
|
||||
if (hasSearchParam && !usePathname) return hasSearchParam
|
||||
else if ((url.search == '' || usePathname) && type == 'pathname')
|
||||
return href.pathname == url.pathname
|
||||
}
|
||||
</script>
|
||||
|
||||
<nav
|
||||
class={[
|
||||
'flex flex-row items-center sm:mt-0 flex-wrap z-20',
|
||||
style == 'header'
|
||||
? 'p-1 gap-x-8 gap-y-4 justify-center sm:justify-start'
|
||||
: 'gap-2',
|
||||
margin && 'my-2',
|
||||
margin && style == 'subpage' && 'mb-3',
|
||||
]}
|
||||
>
|
||||
{#each routes as route, index (route.href)}
|
||||
{@const selected = isSelected(
|
||||
page.url,
|
||||
new SvelteURL(`${page.url.origin}${route.href}`),
|
||||
matchType[index],
|
||||
)}
|
||||
{#if style == 'header'}
|
||||
<a
|
||||
onclick={() => invalidateAll()}
|
||||
href={buildUrl(currentRoute, route.href)}
|
||||
class={[
|
||||
'rounded-full font-medium transition-colors duration-100 relative z-0 shrink-0 hover:text-slate-900 hover:dark:text-zinc-100',
|
||||
selected
|
||||
? 'text-primary-900 dark:text-primary-100'
|
||||
: 'text-slate-500 dark:text-zinc-500',
|
||||
]}
|
||||
>
|
||||
{route.name}
|
||||
</a>
|
||||
{:else}
|
||||
<TabButton href={buildUrl(currentRoute, route.href)} {selected}>
|
||||
{route.name}
|
||||
</TabButton>
|
||||
{/if}
|
||||
{/each}
|
||||
{@render children?.()}
|
||||
</nav>
|
||||
@@ -0,0 +1,143 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { Button } from 'mono-svelte'
|
||||
import type { ButtonProps } from 'mono-svelte/button/Button.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
|
||||
interface Props extends ButtonProps {
|
||||
label: string
|
||||
icon?: IconSource | undefined
|
||||
href?: string | undefined
|
||||
adaptive?: boolean
|
||||
isSelectedFilter?: (path: string) => boolean
|
||||
class?: string
|
||||
customIcon?: Snippet<[{ size: number; isSelected?: boolean }]>
|
||||
children?: Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
label,
|
||||
icon,
|
||||
href,
|
||||
adaptive = true,
|
||||
isSelectedFilter = (path) => href != undefined && path == href,
|
||||
class: clazz = '',
|
||||
customIcon,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let isSelected = $derived(isSelectedFilter(page.url.pathname))
|
||||
</script>
|
||||
|
||||
<Button
|
||||
{...rest}
|
||||
color="none"
|
||||
rounding="none"
|
||||
class={[
|
||||
'nav-btn',
|
||||
adaptive && 'nav-btn-dynamic',
|
||||
isSelected && 'nav-btn-selected',
|
||||
clazz,
|
||||
]}
|
||||
shadow="none"
|
||||
size="custom"
|
||||
{href}
|
||||
title={label}
|
||||
aria-selected={isSelected}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<div class="prefix">
|
||||
{#if customIcon}
|
||||
{@render customIcon?.({ size: 16, isSelected })}
|
||||
{:else if icon}
|
||||
<div class="hidden md:block">
|
||||
<Icon src={icon} size="16" micro />
|
||||
</div>
|
||||
<div class="block md:hidden">
|
||||
<Icon src={icon} size="20" mini />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
<span class="hidden {adaptive ? 'md:block' : ''}">{label}</span>
|
||||
{@render children?.()}
|
||||
</Button>
|
||||
|
||||
<style>
|
||||
@reference '../../../../app.css';
|
||||
|
||||
:global {
|
||||
.prefix {
|
||||
@variant max-md {
|
||||
height: 100%;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
aspect-ratio: 1 / 1;
|
||||
border-radius: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
width: calc(var(--spacing) * 10);
|
||||
height: calc(var(--spacing) * 10);
|
||||
|
||||
color: var(--color-slate-500);
|
||||
|
||||
@variant dark {
|
||||
color: var(--color-zinc-400);
|
||||
}
|
||||
|
||||
@variant hover {
|
||||
color: var(--color-slate-900);
|
||||
@variant dark {
|
||||
color: var(--color-zinc-50);
|
||||
}
|
||||
}
|
||||
|
||||
transition-property: color;
|
||||
}
|
||||
|
||||
.nav-btn-dynamic {
|
||||
@variant md {
|
||||
width: max-content;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-btn-selected {
|
||||
color: var(--color-primary-900);
|
||||
@variant dark {
|
||||
color: var(--color-primary-100);
|
||||
}
|
||||
|
||||
@variant max-md {
|
||||
.prefix {
|
||||
background-color: var(--color-slate-200);
|
||||
@variant dark {
|
||||
background-color: var(--color-zinc-800);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@variant max-md {
|
||||
.nav-btn-sm-primary .prefix {
|
||||
background-color: var(--color-primary-900);
|
||||
color: var(--color-slate-50);
|
||||
|
||||
@variant hover {
|
||||
color: var(--color-slate-50);
|
||||
}
|
||||
|
||||
@variant dark {
|
||||
background-color: var(--color-primary-100);
|
||||
color: var(--color-zinc-900);
|
||||
@variant hover {
|
||||
color: var(--color-zinc-900);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,162 @@
|
||||
<script lang="ts">
|
||||
import { notifications, profile } from '$lib/app/auth.svelte.js'
|
||||
import { site } from '$lib/api/client.svelte'
|
||||
import { amModOfAny, isAdmin } from '$comp/lemmy/moderation/moderation.js'
|
||||
import Avatar from '$lib/ui/generic/Avatar.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/app/instance.svelte'
|
||||
import { Menu, Spinner } from 'mono-svelte'
|
||||
import {
|
||||
Bars3,
|
||||
GlobeAlt,
|
||||
Home,
|
||||
Icon,
|
||||
MagnifyingGlass,
|
||||
PencilSquare,
|
||||
ServerStack,
|
||||
ShieldCheck,
|
||||
} from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import Logo from '../Logo.svelte'
|
||||
import CommandsWrapper from './commands/CommandsWrapper.svelte'
|
||||
import NavButton from './NavButton.svelte'
|
||||
|
||||
let promptOpen: boolean = $state(false)
|
||||
interface Props {
|
||||
style?: string
|
||||
class?: ClassValue
|
||||
}
|
||||
|
||||
let { style = '', class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
<CommandsWrapper bind:open={promptOpen} />
|
||||
<nav
|
||||
class={[
|
||||
'w-full mx-auto z-50',
|
||||
'md:gap-5 gap-2 flex flex-row items-center justify-between p-2',
|
||||
'box-border p-0.5 duration-150 @container *:max-md:flex-1',
|
||||
clazz,
|
||||
]}
|
||||
{style}
|
||||
>
|
||||
<NavButton
|
||||
oncontextmenu={(e: Event) => {
|
||||
e.preventDefault()
|
||||
promptOpen = true
|
||||
return true
|
||||
}}
|
||||
icon={Home}
|
||||
href="/"
|
||||
label={$t('nav.home')}
|
||||
class="logo border-0 md:rounded-full! md:w-10! md:h-10 md:px-0! text-primary-900! dark:text-primary-100! -order-1"
|
||||
adaptive={false}
|
||||
>
|
||||
{#snippet customIcon()}
|
||||
{#if LINKED_INSTANCE_URL}
|
||||
{#if site.data}
|
||||
<Avatar
|
||||
alt={site.data.site_view.site.name}
|
||||
url={site.data.site_view.site.icon}
|
||||
width={32}
|
||||
circle={false}
|
||||
/>
|
||||
{:else}
|
||||
<Spinner width={32} />
|
||||
{/if}
|
||||
{:else}
|
||||
<Logo width={32} />
|
||||
{/if}
|
||||
{/snippet}
|
||||
</NavButton>
|
||||
<div class="hidden md:block md:flex-1"></div>
|
||||
<div class="sr-only md:not-sr-only md:contents">
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<NavButton
|
||||
href="/admin"
|
||||
label={$t('nav.admin')}
|
||||
icon={ServerStack}
|
||||
class="relative order-0"
|
||||
isSelectedFilter={(path) => path.startsWith('/admin')}
|
||||
/>
|
||||
{/if}
|
||||
{#if amModOfAny(profile.current?.user)}
|
||||
<NavButton
|
||||
href="/moderation"
|
||||
label={$t('nav.moderation')}
|
||||
class="relative order-0"
|
||||
icon={ShieldCheck}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
<NavButton
|
||||
href="/explore/communities"
|
||||
label={$t('routes.explore.title')}
|
||||
icon={GlobeAlt}
|
||||
isSelectedFilter={(path) => path.startsWith('/explore')}
|
||||
class="order-1"
|
||||
/>
|
||||
<NavButton
|
||||
href="/search"
|
||||
label={$t('nav.search')}
|
||||
icon={MagnifyingGlass}
|
||||
class="order-3 md:order-2"
|
||||
/>
|
||||
<NavButton
|
||||
label={$t('nav.create.label')}
|
||||
href="/create"
|
||||
isSelectedFilter={(path) => path.startsWith('/create')}
|
||||
icon={PencilSquare}
|
||||
class="order-2 md:order-3 nav-btn-sm-primary"
|
||||
alwaysShowIcon
|
||||
/>
|
||||
<Menu placement="bottom">
|
||||
{#snippet target(attachment)}
|
||||
<button
|
||||
{@attach attachment}
|
||||
class={[
|
||||
'w-10 h-10 rounded-full',
|
||||
'transition-all relative grid place-items-center',
|
||||
' group cursor-pointer order-4',
|
||||
]}
|
||||
title={$t('profile.profile')}
|
||||
>
|
||||
{#if profile.current?.user}
|
||||
<div
|
||||
class={[
|
||||
'h-full aspect-square object-cover rounded-full grid place-items-center',
|
||||
'border-slate-200 dark:border-zinc-700 hover:bg-slate-200 dark:hover:bg-zinc-700 bg-slate-50 dark:bg-zinc-900',
|
||||
]}
|
||||
>
|
||||
<Avatar
|
||||
url={profile.current.user.local_user_view.person.avatar}
|
||||
width={36}
|
||||
alt={profile.current.user.local_user_view.person.name}
|
||||
class="group-hover:scale-90 transition-transform group-active:scale-85"
|
||||
/>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="w-full h-full grid place-items-center">
|
||||
<Icon src={Bars3} micro size="18" />
|
||||
</div>
|
||||
{/if}
|
||||
{#if Math.max(...Object.values($notifications)) > 0}
|
||||
<div
|
||||
class="w-2 h-2 absolute top-0.5 right-0.5 bg-red-500 rounded-full"
|
||||
></div>
|
||||
{/if}
|
||||
</button>
|
||||
{/snippet}
|
||||
{#snippet children(open)}
|
||||
{#if open}
|
||||
{#await import('./Profile.svelte')}
|
||||
<div class="p-8 w-full h-full grid place-items-center">
|
||||
<Spinner width={20} />
|
||||
</div>
|
||||
{:then { default: Profile }}
|
||||
<Profile />
|
||||
{/await}
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Menu>
|
||||
</nav>
|
||||
@@ -0,0 +1,181 @@
|
||||
<script lang="ts">
|
||||
import { env } from '$env/dynamic/public'
|
||||
import { notifications, profile } from '$lib/app/auth.svelte'
|
||||
import { amModOfAny, isAdmin } from '$comp/lemmy/moderation/moderation'
|
||||
|
||||
import SiteCard from '$comp/lemmy/instance/InstanceCard.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { site } from '$lib/api/client.svelte'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { theme } from '$lib/app/theme/theme.svelte'
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
MenuButton,
|
||||
MenuDivider,
|
||||
modal,
|
||||
Option,
|
||||
Select,
|
||||
Spinner,
|
||||
toast,
|
||||
} from 'mono-svelte'
|
||||
import {
|
||||
ArrowLeftOnRectangle,
|
||||
Bookmark,
|
||||
BugAnt,
|
||||
CodeBracketSquare,
|
||||
Cog6Tooth,
|
||||
ComputerDesktop,
|
||||
Icon,
|
||||
Identification,
|
||||
Inbox,
|
||||
Moon,
|
||||
ServerStack,
|
||||
ShieldCheck,
|
||||
Sun,
|
||||
Swatch,
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
</script>
|
||||
|
||||
{#snippet siteSnippet()}
|
||||
{#if site.data}
|
||||
<SiteCard
|
||||
site={site.data.site_view}
|
||||
admins={site.data.admins}
|
||||
taglines={site.data.taglines}
|
||||
version={site.data.version}
|
||||
/>
|
||||
{:else}
|
||||
<Spinner />
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#snippet notifBadge(number: number)}
|
||||
{#if number > 0}
|
||||
<Badge
|
||||
color="red-subtle"
|
||||
class="min-w-5 h-5 p-0! px-0.5 grid place-items-center ml-auto"
|
||||
>
|
||||
{number > 99 ? '∞' : number}
|
||||
</Badge>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
{#if profile.current?.jwt}
|
||||
<MenuButton href="/inbox" icon={Inbox}>
|
||||
{$t('profile.inbox')}
|
||||
{#if $notifications.inbox > 0}
|
||||
<Badge color="red-subtle" class="text-xs ml-auto font-bold py-0.5!">
|
||||
{$notifications.inbox > 99 ? '∞' : $notifications.inbox}
|
||||
</Badge>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if amModOfAny(profile.current.user)}
|
||||
<MenuButton href="/moderation" icon={ShieldCheck}>
|
||||
{$t('routes.moderation.feed')}
|
||||
{#snippet suffix()}
|
||||
{@render notifBadge($notifications.reports)}
|
||||
{/snippet}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.current.user && isAdmin(profile.current.user)}
|
||||
<MenuButton href="/admin/applications" icon={ServerStack}>
|
||||
{$t('routes.admin.applications.title')}
|
||||
{#snippet suffix()}
|
||||
{@render notifBadge($notifications.applications)}
|
||||
{/snippet}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuDivider>{$t('profile.profile')}</MenuDivider>
|
||||
<MenuButton href="/profile" icon={UserCircle}>
|
||||
{$t('profile.profile')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/saved" icon={Bookmark}>
|
||||
{$t('profile.saved')}
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<MenuButton href="/accounts/login" icon={ArrowLeftOnRectangle}>
|
||||
{$t('account.login')}
|
||||
</MenuButton>
|
||||
<MenuButton href="/signup" icon={Identification}>
|
||||
{$t('account.signup')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton href="/accounts" icon={UserGroup}>
|
||||
{$t('account.accounts')}
|
||||
</MenuButton>
|
||||
<MenuDivider>{$t('nav.menu.app')}</MenuDivider>
|
||||
<MenuButton href="/settings" icon={Cog6Tooth}>
|
||||
{$t('nav.menu.settings')}
|
||||
</MenuButton>
|
||||
<Select bind:value={theme.colorScheme} size="sm" placement="bottom">
|
||||
{#snippet target(attachment)}
|
||||
<MenuButton
|
||||
{@attach attachment}
|
||||
icon={theme.colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
: theme.colorScheme == 'light'
|
||||
? Sun
|
||||
: Moon}
|
||||
class=" w-full"
|
||||
nest
|
||||
>
|
||||
{$t('nav.menu.colorscheme.label')}
|
||||
</MenuButton>
|
||||
<Option value="system" class="hidden" icon={ComputerDesktop}>
|
||||
{$t('nav.menu.colorscheme.system')}
|
||||
</Option>
|
||||
<Option value="light" class="hidden" icon={Sun}>
|
||||
{$t('nav.menu.colorscheme.light')}
|
||||
</Option>
|
||||
<Option value="dark" class="hidden" icon={Moon}>
|
||||
{$t('nav.menu.colorscheme.dark')}
|
||||
</Option>
|
||||
{/snippet}
|
||||
</Select>
|
||||
<MenuButton href="/theme" icon={Swatch}>
|
||||
{$t('nav.menu.theme')}
|
||||
</MenuButton>
|
||||
{#if settings.debugInfo}
|
||||
<MenuButton href="/util" icon={BugAnt}>Debug</MenuButton>
|
||||
{/if}
|
||||
<li class="flex flex-col px-2 py-1 mx-auto my-1 text-xs w-full">
|
||||
<div class="flex flex-row gap-2 w-full items-center">
|
||||
<div class="flex-1">
|
||||
<button
|
||||
class="hover:brightness-110 transition-all"
|
||||
onclick={() => {
|
||||
navigator?.clipboard?.writeText(__VERSION__)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
>
|
||||
<Badge color="blue-subtle">{__VERSION__}</Badge>
|
||||
</button>
|
||||
</div>
|
||||
<Button
|
||||
onclick={() => {
|
||||
modal({
|
||||
title: $t('nav.menu.instance'),
|
||||
snippet: siteSnippet,
|
||||
body: '',
|
||||
})
|
||||
}}
|
||||
color="tertiary"
|
||||
title={$t('nav.menu.instance')}
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={ServerStack} size="16" micro />
|
||||
</Button>
|
||||
{#if env.PUBLIC_XYLIGHT_MODE?.toLowerCase() == 'true'}
|
||||
<Button
|
||||
color="tertiary"
|
||||
href="https://github.com/Xyphyn/Photon"
|
||||
title={$t('nav.menu.source')}
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={CodeBracketSquare} size="16" micro />
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
</li>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { Button } from 'mono-svelte'
|
||||
import { ArrowUturnDown, Icon, QuestionMarkCircle } from 'svelte-hero-icons'
|
||||
import type { HTMLButtonAttributes } from 'svelte/elements'
|
||||
import Avatar from '../../Avatar.svelte'
|
||||
import type { Action } from './actions.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
interface Props {
|
||||
action: Action
|
||||
class?: string
|
||||
children?: Snippet
|
||||
onclick?: HTMLButtonAttributes['onclick']
|
||||
}
|
||||
|
||||
let { action, children, ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Button
|
||||
href={action.href}
|
||||
alignment="left"
|
||||
color="none"
|
||||
size="custom"
|
||||
class="block w-full"
|
||||
data-sveltekit-preload-code="viewport"
|
||||
data-sveltekit-preload-data="tap"
|
||||
{...rest}
|
||||
>
|
||||
{#if typeof action.icon === 'string'}
|
||||
<Avatar url={action.icon} width={20} />
|
||||
{:else}
|
||||
<Icon
|
||||
src={action.icon ?? QuestionMarkCircle}
|
||||
solid
|
||||
size="20"
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
<div class="inline-flex flex-col">
|
||||
<span>{action.name}</span>
|
||||
{#if action.detail}
|
||||
<span class="font-normal text-xs">{action.detail}</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex-1"></div>
|
||||
{#if action.shortcut}
|
||||
<div class="flex items-center gap-0.5 text-xs font-medium">
|
||||
⌘ {action.shortcut}
|
||||
</div>
|
||||
{/if}
|
||||
{#if action.subActions}
|
||||
<Icon src={ArrowUturnDown} size="16" micro class="" />
|
||||
{/if}
|
||||
</Button>
|
||||
@@ -0,0 +1,300 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { profile } from '$lib/app/auth.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { resumables } from '$lib/lemmy/item'
|
||||
import { theme } from '$lib/app/theme/theme.svelte'
|
||||
import { fuzzySearch } from '$lib/util.svelte'
|
||||
import { TextInput } from 'mono-svelte'
|
||||
import { createEventDispatcher, onMount } from 'svelte'
|
||||
import { Home, Icon, MagnifyingGlass } from 'svelte-hero-icons'
|
||||
import EndPlaceholder from '../../EndPlaceholder.svelte'
|
||||
import CommonList from '../../layout/CommonList.svelte'
|
||||
import { getGroups, type Action, type Group } from './actions.svelte'
|
||||
import CommandItem from './CommandItem.svelte'
|
||||
|
||||
interface Props {
|
||||
open?: boolean
|
||||
groups?: Group[]
|
||||
}
|
||||
|
||||
let { open = $bindable(false), groups = $bindable([]) }: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
groups = getGroups(
|
||||
$resumables,
|
||||
profile.current,
|
||||
profile.meta.profiles,
|
||||
theme.data,
|
||||
page.data.contextual?.actions,
|
||||
)
|
||||
})
|
||||
|
||||
let search = $state('')
|
||||
let container: HTMLElement | undefined = $state()
|
||||
const dispatch = createEventDispatcher()
|
||||
let selectedIndex = $state(0)
|
||||
let filteredGroups: Group[] = $state([])
|
||||
let breadcrumbs: Action[] = $state([])
|
||||
let input = $state<HTMLInputElement>()
|
||||
|
||||
const debounce = (fn: Function, ms = 300) => {
|
||||
let timeoutId: ReturnType<typeof setTimeout>
|
||||
return function (this: any, ...args: any[]) {
|
||||
clearTimeout(timeoutId)
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms)
|
||||
}
|
||||
}
|
||||
|
||||
function searchGroup(term: string) {
|
||||
if (term == '/kill @') {
|
||||
goto('/you_died')
|
||||
}
|
||||
|
||||
if (term.length < 1) {
|
||||
if (breadcrumbs.length <= 0) {
|
||||
filteredGroups = groups.map((group) => ({
|
||||
...group,
|
||||
actions: flattenActions(group.actions, false),
|
||||
}))
|
||||
}
|
||||
} else {
|
||||
filteredGroups = groups
|
||||
.map((group) => {
|
||||
const scoredActions = flattenActions(group.actions)
|
||||
.map((action) => ({
|
||||
...action,
|
||||
score: Math.max(
|
||||
fuzzySearch(action.name, term),
|
||||
fuzzySearch(group.name, term),
|
||||
action.detail ? fuzzySearch(action.detail, term) : -1,
|
||||
),
|
||||
}))
|
||||
.filter((action) => action.score > 0)
|
||||
.sort((a, b) => b.score - a.score)
|
||||
|
||||
return {
|
||||
...group,
|
||||
actions: scoredActions,
|
||||
score: Math.max(
|
||||
fuzzySearch(group.name, term),
|
||||
...scoredActions.map((a) => a.score),
|
||||
),
|
||||
}
|
||||
})
|
||||
.filter((group) => group.actions.length > 0)
|
||||
.sort((a, b) => b.score - a.score)
|
||||
}
|
||||
}
|
||||
|
||||
const debouncedSearch = debounce((term: string) => searchGroup(term), 50)
|
||||
|
||||
function updateFilteredGroups() {
|
||||
if (breadcrumbs.length === 0) {
|
||||
filteredGroups = groups
|
||||
} else {
|
||||
const lastAction = breadcrumbs[breadcrumbs.length - 1]
|
||||
filteredGroups = [
|
||||
{
|
||||
name: lastAction.name,
|
||||
actions: lastAction.subActions || [],
|
||||
},
|
||||
]
|
||||
}
|
||||
selectedIndex = 0
|
||||
search = ''
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
breadcrumbs.pop()
|
||||
updateFilteredGroups()
|
||||
}
|
||||
|
||||
function flattenActions(
|
||||
actions: Action[],
|
||||
subaction: boolean = true,
|
||||
): Action[] {
|
||||
return actions.flatMap((action) => [
|
||||
action,
|
||||
...(action.subActions && subaction
|
||||
? flattenActions(action.subActions)
|
||||
: []),
|
||||
])
|
||||
}
|
||||
|
||||
function togglePalette() {
|
||||
open = !open
|
||||
if (open) {
|
||||
search = ''
|
||||
selectedIndex = 0
|
||||
filteredGroups = groups
|
||||
breadcrumbs = []
|
||||
}
|
||||
}
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (event.ctrlKey) {
|
||||
const actions = groups
|
||||
.flatMap((g) => g.actions)
|
||||
.filter((a) => a.shortcut != undefined)
|
||||
|
||||
actions.forEach((a) => {
|
||||
if (event.key === a.shortcut) {
|
||||
event.preventDefault()
|
||||
if (a.href) goto(a.href)
|
||||
if (a.handle) a.handle()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (!open) return
|
||||
|
||||
switch (event.key) {
|
||||
case 'ArrowDown':
|
||||
event.preventDefault()
|
||||
selectedIndex = (selectedIndex + 1) % flattenedActions.length
|
||||
focusItem(selectedIndex)
|
||||
break
|
||||
case 'ArrowUp':
|
||||
event.preventDefault()
|
||||
selectedIndex =
|
||||
(selectedIndex - 1 + flattenedActions.length) %
|
||||
flattenedActions.length
|
||||
focusItem(selectedIndex)
|
||||
break
|
||||
case 'Enter':
|
||||
searchGroup(search)
|
||||
handleSelect(flattenedActions[selectedIndex])
|
||||
break
|
||||
case 'Escape':
|
||||
event.preventDefault()
|
||||
if (breadcrumbs.length > 0) {
|
||||
breadcrumbs.pop()
|
||||
updateFilteredGroups()
|
||||
} else {
|
||||
togglePalette()
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if (selectedIndex >= flattenedActions.length) selectedIndex = 0
|
||||
}
|
||||
|
||||
function focusItem(index: number) {
|
||||
if (!browser) return
|
||||
|
||||
const listItems = container?.querySelectorAll('li')
|
||||
if (!listItems) return
|
||||
listItems[index % listItems.length].focus()
|
||||
listItems[index % listItems.length].scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'center',
|
||||
})
|
||||
}
|
||||
|
||||
async function handleSelect(action: Action) {
|
||||
if (!action) return
|
||||
if (action.subActions && action.subActions.length > 0) {
|
||||
breadcrumbs = [...breadcrumbs, action]
|
||||
updateFilteredGroups()
|
||||
} else {
|
||||
if (action.href) goto(action.href)
|
||||
if (action.handle) action.handle()
|
||||
togglePalette()
|
||||
dispatch('select', action)
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (open) search = ''
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
debouncedSearch(search)
|
||||
})
|
||||
|
||||
onMount(() => {
|
||||
if (input) input.focus()
|
||||
})
|
||||
|
||||
let flattenedActions = $derived(
|
||||
filteredGroups.flatMap((group) => group.actions),
|
||||
)
|
||||
</script>
|
||||
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
<TextInput
|
||||
bind:value={search}
|
||||
class="sticky rounded-none! border-t-0 border-x-0 focus-within:border-inherit! focus-within:ring-0!"
|
||||
size="lg"
|
||||
placeholder={$t('nav.commands.prompt')}
|
||||
bind:element={input}
|
||||
/>
|
||||
<div class="h-128 overflow-auto border-slate-200 dark:border-zinc-800 p-5">
|
||||
{#if breadcrumbs.length > 0}
|
||||
<div class="flex items-center gap-2 my-1">
|
||||
<button
|
||||
class="text-[13px] font-medium text-slate-600 dark:text-zinc-400"
|
||||
onclick={goBack}
|
||||
>
|
||||
<Icon src={Home} size="16" mini />
|
||||
</button>
|
||||
{#each breadcrumbs as crumb}
|
||||
<span class="text-base text-slate-400 dark:text-zinc-600">/</span>
|
||||
<span class="text-[13px] font-medium">
|
||||
{crumb.name}
|
||||
</span>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<div class="space-y-1" bind:this={container}>
|
||||
{#each filteredGroups as group, groupIndex}
|
||||
<div class="space-y-1">
|
||||
<EndPlaceholder margin="md" size="sm">{group.name}</EndPlaceholder>
|
||||
<CommonList size="xs" class="p-0! sm:p-0! lg:p-0!">
|
||||
{#each group.actions as action, actionIndex}
|
||||
{@const globalIndex =
|
||||
filteredGroups
|
||||
.slice(0, groupIndex)
|
||||
.reduce((sum, g) => sum + g.actions.length, 0) + actionIndex}
|
||||
<li
|
||||
class={[
|
||||
'custom-size',
|
||||
globalIndex == selectedIndex &&
|
||||
'brightness-95 dark:brightness-125',
|
||||
]}
|
||||
>
|
||||
<CommandItem
|
||||
{action}
|
||||
onclick={(e) => {
|
||||
if (action.href) {
|
||||
togglePalette()
|
||||
return
|
||||
}
|
||||
e.stopPropagation()
|
||||
handleSelect(action)
|
||||
}}
|
||||
/>
|
||||
</li>
|
||||
{/each}
|
||||
</CommonList>
|
||||
</div>
|
||||
{/each}
|
||||
{#if search != ''}
|
||||
<CommandItem
|
||||
action={{
|
||||
name: search,
|
||||
href: `/search?q=${encodeURIComponent(search)}`,
|
||||
icon: MagnifyingGlass,
|
||||
}}
|
||||
>
|
||||
<span class="font-normal text-slate-600 dark:text-zinc-400">
|
||||
{$t('nav.commands.search', { default: '' })}
|
||||
</span>
|
||||
</CommandItem>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { Modal, TextLoader } from 'mono-svelte'
|
||||
|
||||
interface Props {
|
||||
open?: boolean
|
||||
}
|
||||
|
||||
let { open = $bindable(false) }: Props = $props()
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (
|
||||
(event.ctrlKey && event.key === 'p') ||
|
||||
(event.key == '/' && document.activeElement == document.body)
|
||||
) {
|
||||
event.preventDefault()
|
||||
open = !open
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onkeydown={handleKeydown} />
|
||||
|
||||
{#if open}
|
||||
<Modal bind:open title={null} class="p-0! gap-0!">
|
||||
{#await import('./Commands.svelte')}
|
||||
<div class="h-128 flex flex-col gap-2 items-center justify-center">
|
||||
<TextLoader>
|
||||
{$t('nav.commands.downloading')}
|
||||
</TextLoader>
|
||||
</div>
|
||||
{:then { default: Commands }}
|
||||
<Commands bind:open />
|
||||
{/await}
|
||||
</Modal>
|
||||
{/if}
|
||||
@@ -0,0 +1,414 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import {
|
||||
profile as currentProfile,
|
||||
type ProfileInfo,
|
||||
} from '$lib/app/auth.svelte'
|
||||
import { amModOfAny, isAdmin } from '$comp/lemmy/moderation/moderation'
|
||||
import { t } from '$lib/app/i18n/translations'
|
||||
import { type ResumableItem } from '$lib/lemmy/item'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
import { theme, type ThemeData } from '$lib/app/theme/theme.svelte'
|
||||
import { fullCommunityName } from '$lib/util.svelte'
|
||||
import {
|
||||
ArrowRightOnRectangle,
|
||||
ArrowTrendingDown,
|
||||
ArrowTrendingUp,
|
||||
Bookmark,
|
||||
ChartBar,
|
||||
ChatBubbleLeftRight,
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
Clock,
|
||||
Cog6Tooth,
|
||||
ComputerDesktop,
|
||||
Fire,
|
||||
GlobeAlt,
|
||||
GlobeAmericas,
|
||||
Home,
|
||||
Identification,
|
||||
Inbox,
|
||||
MapPin,
|
||||
Moon,
|
||||
Newspaper,
|
||||
PaintBrush,
|
||||
PencilSquare,
|
||||
Plus,
|
||||
Scale,
|
||||
ServerStack,
|
||||
ShieldCheck,
|
||||
Star,
|
||||
Sun,
|
||||
Swatch,
|
||||
Trophy,
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
ViewColumns,
|
||||
type IconSource,
|
||||
} from 'svelte-hero-icons'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
export interface Group {
|
||||
name: string
|
||||
actions: Action[]
|
||||
}
|
||||
|
||||
export interface Action {
|
||||
name: string
|
||||
desc?: string
|
||||
handle?: () => void
|
||||
href?: string
|
||||
shortcut?: string
|
||||
icon: string | IconSource
|
||||
subActions?: Action[]
|
||||
detail?: string
|
||||
}
|
||||
|
||||
export function getGroups(
|
||||
resumables: ResumableItem[],
|
||||
profile: ProfileInfo,
|
||||
profiles: ProfileInfo[],
|
||||
td: ThemeData,
|
||||
contextual?: Action[],
|
||||
) {
|
||||
return [
|
||||
{
|
||||
name: t.get('nav.commands.recents'),
|
||||
actions: resumables.map((r) => ({
|
||||
name: r.name,
|
||||
icon: r.avatar ?? PencilSquare,
|
||||
href: r.url,
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.contextual'),
|
||||
actions: contextual ?? [],
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.main'),
|
||||
actions: [
|
||||
{ href: '/', name: t.get('nav.home'), icon: Home, shortcut: 'h' },
|
||||
{
|
||||
href: '/communities',
|
||||
name: t.get('nav.communities'),
|
||||
icon: GlobeAlt,
|
||||
},
|
||||
...(amModOfAny(profile.user)
|
||||
? [
|
||||
{
|
||||
href: '/moderation',
|
||||
name: t.get('nav.moderation'),
|
||||
icon: ShieldCheck,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(profile.user && isAdmin(profile.user)
|
||||
? [
|
||||
{
|
||||
href: '/admin',
|
||||
name: t.get('nav.admin'),
|
||||
icon: ServerStack,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.feeds'),
|
||||
actions: [
|
||||
{
|
||||
name: t.get('filter.location.label'),
|
||||
icon: GlobeAmericas,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('filter.location.all'),
|
||||
icon: GlobeAmericas,
|
||||
href: '/?type=All',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.location.local'),
|
||||
icon: MapPin,
|
||||
href: '/?type=Local',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.location.subscribed'),
|
||||
icon: Newspaper,
|
||||
href: '/?type=Subscribed',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.label'),
|
||||
icon: ChartBar,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('filter.sort.top.label'),
|
||||
icon: Trophy,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('filter.sort.top.time.all'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopAll',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.9months'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopNineMonths',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.6months'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopSixMonths',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.3months'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopThreeMonths',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.month'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopMonth',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.week'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopWeek',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.day'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopDay',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.6hours'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopSixHour',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.top.time.hour'),
|
||||
icon: ChartBar,
|
||||
href: '/?sort=TopHour',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.active'),
|
||||
icon: ArrowTrendingUp,
|
||||
href: '/?sort=Active',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.hot'),
|
||||
icon: Fire,
|
||||
href: '/?sort=Hot',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.scaled'),
|
||||
icon: Scale,
|
||||
href: '/?sort=Scaled',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.new'),
|
||||
icon: Star,
|
||||
href: '/?sort=New',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.old'),
|
||||
icon: Clock,
|
||||
href: '/?sort=Old',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.controversial'),
|
||||
icon: ArrowTrendingDown,
|
||||
href: '/?sort=Controversial',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.mostcomments'),
|
||||
icon: ChatBubbleOvalLeftEllipsis,
|
||||
href: '/?sort=MostComments',
|
||||
},
|
||||
{
|
||||
name: t.get('filter.sort.newcomments'),
|
||||
icon: ChatBubbleLeftRight,
|
||||
href: '/?sort=NewComments',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('profile.profile'),
|
||||
actions: profile.jwt
|
||||
? [
|
||||
{
|
||||
href: '/profile/user',
|
||||
name: t.get('profile.profile'),
|
||||
icon: UserCircle,
|
||||
},
|
||||
{
|
||||
href: '/inbox',
|
||||
name: t.get('profile.inbox'),
|
||||
icon: Inbox,
|
||||
shortcut: 'i',
|
||||
},
|
||||
{
|
||||
href: '/saved',
|
||||
name: t.get('profile.saved'),
|
||||
icon: Bookmark,
|
||||
},
|
||||
{
|
||||
href: '/accounts',
|
||||
name: t.get('account.accounts'),
|
||||
icon: UserGroup,
|
||||
},
|
||||
{
|
||||
href: '/login',
|
||||
name: t.get('account.login'),
|
||||
icon: ArrowRightOnRectangle,
|
||||
},
|
||||
{
|
||||
href: '/signup',
|
||||
name: t.get('account.signup'),
|
||||
icon: Identification,
|
||||
},
|
||||
{
|
||||
href: '/login/guest',
|
||||
name: t.get('account.addGuest'),
|
||||
icon: Plus,
|
||||
},
|
||||
{
|
||||
href: '/accounts',
|
||||
name: t.get('account.accounts'),
|
||||
icon: UserGroup,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
href: '/login',
|
||||
name: t.get('account.login'),
|
||||
icon: ArrowRightOnRectangle,
|
||||
},
|
||||
{
|
||||
href: '/signup',
|
||||
name: t.get('account.signup'),
|
||||
icon: Identification,
|
||||
},
|
||||
{
|
||||
href: '/login/guest',
|
||||
name: t.get('account.addGuest'),
|
||||
icon: Plus,
|
||||
},
|
||||
{
|
||||
href: '/accounts',
|
||||
name: t.get('account.accounts'),
|
||||
icon: UserGroup,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('account.accounts'),
|
||||
actions: profiles.map((p) => ({
|
||||
name: p.username ?? t.get('account.guest'),
|
||||
icon: p.avatar ?? UserCircle,
|
||||
detail: p.instance,
|
||||
handle: async () => {
|
||||
if (profile.id != p.id) {
|
||||
currentProfile.meta.profile = p.id
|
||||
}
|
||||
|
||||
await goto(page.url, {
|
||||
invalidateAll: true,
|
||||
})
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: t.get('nav.menu.app'),
|
||||
actions: [
|
||||
{
|
||||
href: '/settings',
|
||||
name: t.get('nav.menu.settings'),
|
||||
icon: Cog6Tooth,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setView'),
|
||||
icon: ViewColumns,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('nav.commands.setViewTo', {
|
||||
default: t.get('filter.view.compact'),
|
||||
}),
|
||||
icon: ViewColumns,
|
||||
handle: () => (settings.view = 'compact'),
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setViewTo', {
|
||||
default: t.get('filter.view.cozy'),
|
||||
}),
|
||||
icon: ViewColumns,
|
||||
handle: () => (settings.view = 'cozy'),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColor'),
|
||||
icon: PaintBrush,
|
||||
subActions: [
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.system'),
|
||||
}),
|
||||
handle: () => (theme.colorScheme = 'system'),
|
||||
icon: ComputerDesktop,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.light'),
|
||||
}),
|
||||
handle: () => (theme.colorScheme = 'light'),
|
||||
icon: Sun,
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setColorTo', {
|
||||
default: t.get('nav.menu.colorscheme.dark'),
|
||||
}),
|
||||
handle: () => (theme.colorScheme = 'dark'),
|
||||
icon: Moon,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.setTheme'),
|
||||
icon: Swatch,
|
||||
subActions: td.themes.map((th) => ({
|
||||
name: t.get('nav.commands.setThemeTo', { default: th.name }),
|
||||
icon: Swatch,
|
||||
handle: () => (theme.data.currentTheme = th.id),
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('nav.commands.content'),
|
||||
actions: [
|
||||
{
|
||||
href: '/create/post',
|
||||
name: t.get('form.post.create'),
|
||||
icon: PencilSquare,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: t.get('profile.subscribed'),
|
||||
actions:
|
||||
profile.user?.follows.map((f) => ({
|
||||
icon: f.community.icon,
|
||||
name: f.community.title,
|
||||
href: `/c/${fullCommunityName(
|
||||
f.community.name,
|
||||
f.community.actor_id,
|
||||
)}`,
|
||||
detail: new SvelteURL(f.community.actor_id).hostname,
|
||||
})) ?? [],
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import { t } from '$lib/app/i18n/translations'
|
||||
import {
|
||||
type IconSource,
|
||||
Home,
|
||||
ChartBar,
|
||||
Cog6Tooth,
|
||||
Newspaper,
|
||||
GlobeAmericas,
|
||||
GlobeAlt,
|
||||
MagnifyingGlass,
|
||||
ShieldCheck,
|
||||
ServerStack,
|
||||
PencilSquare,
|
||||
MapPin,
|
||||
Fire,
|
||||
ArrowTrendingUp,
|
||||
Star,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export interface Link {
|
||||
url: string
|
||||
label?: string
|
||||
}
|
||||
|
||||
export const getDefaultLinks = (): Link[] => [
|
||||
{
|
||||
url: '/',
|
||||
label: t.get('nav.home'),
|
||||
},
|
||||
{
|
||||
url: '/?type=All',
|
||||
label: t.get('filter.location.all'),
|
||||
},
|
||||
{
|
||||
url: '/?type=Local',
|
||||
label: t.get('filter.location.local'),
|
||||
},
|
||||
{
|
||||
url: '/?type=Subscribed',
|
||||
label: t.get('filter.location.subscribed'),
|
||||
},
|
||||
{
|
||||
url: '/?type=All&sort=Hot',
|
||||
label: t.get('filter.sort.hot'),
|
||||
},
|
||||
{
|
||||
url: '/?type=All&sort=Active',
|
||||
label: t.get('filter.sort.active'),
|
||||
},
|
||||
{
|
||||
url: '/?type=All&sort=TopDay',
|
||||
label: t.get('filter.sort.top.time.day'),
|
||||
},
|
||||
{
|
||||
url: '/?type=All&sort=New',
|
||||
label: t.get('filter.sort.new'),
|
||||
},
|
||||
{
|
||||
url: '/communities',
|
||||
label: t.get('nav.communities'),
|
||||
},
|
||||
{
|
||||
url: '/search',
|
||||
label: t.get('nav.search'),
|
||||
},
|
||||
{
|
||||
url: '/moderation',
|
||||
label: t.get('moderation.label'),
|
||||
},
|
||||
{
|
||||
url: '/admin',
|
||||
label: t.get('admin.label'),
|
||||
},
|
||||
{
|
||||
url: '/settings',
|
||||
label: t.get('nav.menu.settings'),
|
||||
},
|
||||
{
|
||||
url: '/create/post',
|
||||
label: t.get('form.post.create'),
|
||||
},
|
||||
]
|
||||
|
||||
export const iconOfLink = (url: string): IconSource => {
|
||||
switch (url) {
|
||||
case '/':
|
||||
return Home
|
||||
case '/?type=All':
|
||||
return GlobeAmericas
|
||||
case '/?type=Subscribed':
|
||||
return Newspaper
|
||||
case '/?type=Local':
|
||||
return MapPin
|
||||
case '/?type=All&sort=Hot':
|
||||
return Fire
|
||||
case '/?type=All&sort=Active':
|
||||
return ArrowTrendingUp
|
||||
case '/?type=All&sort=TopDay':
|
||||
return ChartBar
|
||||
case '/?type=All&sort=New':
|
||||
return Star
|
||||
case '/communities':
|
||||
return GlobeAlt
|
||||
case '/search':
|
||||
return MagnifyingGlass
|
||||
case '/moderation':
|
||||
return ShieldCheck
|
||||
case '/admin':
|
||||
return ServerStack
|
||||
case '/settings':
|
||||
return Cog6Tooth
|
||||
case '/create/post':
|
||||
return PencilSquare
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<script lang="ts">
|
||||
const badgeColor = {
|
||||
'red-subtle':
|
||||
'bg-red-100 dark:bg-red-500/20 text-red-600 dark:text-red-400',
|
||||
'green-subtle': `bg-green-100 dark:bg-green-500/20 text-green-700 dark:text-green-400`,
|
||||
'yellow-subtle':
|
||||
'bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400',
|
||||
'gray-subtle':
|
||||
'bg-gray-100 dark:bg-gray-500/20 text-gray-700 dark:text-gray-300',
|
||||
'blue-subtle':
|
||||
'bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-300',
|
||||
custom: '',
|
||||
}
|
||||
|
||||
const badgeRoundness = {
|
||||
full: 'rounded-full',
|
||||
md: 'rounded-md',
|
||||
custom: '',
|
||||
}
|
||||
|
||||
type BadgeColor = keyof typeof badgeColor
|
||||
type BadgeRoundness = keyof typeof badgeRoundness
|
||||
|
||||
interface Props {
|
||||
label?: string
|
||||
color?: BadgeColor
|
||||
rounding?: BadgeRoundness
|
||||
allowIconOnly?: boolean
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
label = '',
|
||||
color = 'gray-subtle',
|
||||
rounding = 'full',
|
||||
allowIconOnly = false,
|
||||
class: clazz = '',
|
||||
icon,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<span
|
||||
{...rest}
|
||||
class={[
|
||||
allowIconOnly && 'max-md:px-1.5 max-md:py-1.5',
|
||||
'text-xs font-medium flex items-center gap-1 ring-1 ring-black/20 dark:ring-white/20 ring-inset px-2 py-1',
|
||||
badgeRoundness[rounding],
|
||||
badgeColor[color],
|
||||
clazz,
|
||||
]}
|
||||
title={label}
|
||||
>
|
||||
{@render icon?.()}
|
||||
<span class={allowIconOnly ? 'sr-only md:contents' : 'contents'}>
|
||||
{@render children?.()}
|
||||
</span>
|
||||
</span>
|
||||
@@ -0,0 +1,327 @@
|
||||
<script module lang="ts">
|
||||
export type ButtonColor = keyof typeof buttonColor
|
||||
export type ButtonAlignment = keyof typeof buttonAlignment
|
||||
export type ButtonShadow = keyof typeof buttonShadow
|
||||
|
||||
export const buttonAlignment = {
|
||||
left: 'justify-start text-left origin-left',
|
||||
center: 'justify-center',
|
||||
right: 'justify-end text-right origin-right',
|
||||
}
|
||||
|
||||
export const buttonColor = {
|
||||
primary: 'btn-primary',
|
||||
secondary: 'btn-secondary',
|
||||
tertiary: 'btn-tertiary',
|
||||
danger: 'btn-danger',
|
||||
ghost: 'btn-ghost',
|
||||
'danger-subtle': 'text-red-500 hover:bg-red-500 hover:text-inherit!',
|
||||
'success-subtle': 'text-green-500 hover:bg-green-500 hover:text-inherit!',
|
||||
'warning-subtle': 'text-yellow-500 hover:bg-yellow-500 hover:text-inherit!',
|
||||
'blue-subtle': `text-blue-500 hover:bg-blue-500 hover:text-inherit!`,
|
||||
|
||||
none: '',
|
||||
}
|
||||
|
||||
export const buttonShadow = {
|
||||
sm: 'shadow-xs',
|
||||
none: 'shadow-none',
|
||||
}
|
||||
|
||||
export type ButtonSize = keyof typeof buttonSize
|
||||
|
||||
export const buttonSize = {
|
||||
xs: 'btn-xs',
|
||||
sm: 'btn-sm',
|
||||
md: 'btn-md',
|
||||
lg: 'btn-lg',
|
||||
xl: 'btn-xl',
|
||||
'square-sm': 'btn-square-sm',
|
||||
'square-md': 'btn-square-md',
|
||||
'square-lg': 'btn-square-lg',
|
||||
'square-xl': 'btn-square-xl',
|
||||
custom: '',
|
||||
}
|
||||
|
||||
const buttonRounding = {
|
||||
pill: 'rounded-full',
|
||||
xl: 'rounded-xl',
|
||||
lg: 'rounded-lg',
|
||||
md: 'rounded-md',
|
||||
none: '',
|
||||
}
|
||||
type ButtonRoundness = keyof typeof buttonRounding
|
||||
|
||||
const buttonWeight = {
|
||||
md: 'font-medium',
|
||||
none: '',
|
||||
}
|
||||
type ButtonWeight = keyof typeof buttonWeight
|
||||
|
||||
interface Props
|
||||
extends Omit<HTMLButtonAttributes | HTMLAnchorAttributes, 'prefix'> {
|
||||
loading?: boolean
|
||||
submit?: boolean
|
||||
type?: 'button' | 'none'
|
||||
color?: ButtonColor
|
||||
size?: ButtonSize
|
||||
rounding?: ButtonRoundness
|
||||
alignment?: ButtonAlignment
|
||||
shadow?: ButtonShadow
|
||||
loaderWidth?: number | undefined
|
||||
href?: string | undefined
|
||||
class?: ClassValue
|
||||
prefix?: Snippet
|
||||
children?: Snippet
|
||||
suffix?: Snippet
|
||||
onclick?: HTMLButtonAttributes['onclick']
|
||||
icon?: IconSource
|
||||
weight?: ButtonWeight
|
||||
}
|
||||
|
||||
export type { Props as ButtonProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type {
|
||||
ClassValue,
|
||||
HTMLAnchorAttributes,
|
||||
HTMLButtonAttributes,
|
||||
} from 'svelte/elements'
|
||||
|
||||
import Spinner from '../loader/Spinner.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
|
||||
let {
|
||||
loading = false,
|
||||
submit = false,
|
||||
type = 'button',
|
||||
color = 'secondary',
|
||||
size = 'md',
|
||||
rounding = 'xl',
|
||||
alignment = 'center',
|
||||
shadow = color != 'tertiary' ? 'none' : 'none',
|
||||
disabled,
|
||||
loaderWidth = undefined,
|
||||
href = undefined,
|
||||
class: clazz = '',
|
||||
prefix,
|
||||
children,
|
||||
suffix,
|
||||
icon,
|
||||
weight = 'md',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={href ? 'a' : 'button'}
|
||||
role={href ? 'link' : 'button'}
|
||||
{href}
|
||||
{...rest}
|
||||
tabindex={disabled ? -1 : undefined}
|
||||
class={[
|
||||
type == 'button' && 'btn',
|
||||
buttonSize[size],
|
||||
buttonRounding[rounding],
|
||||
buttonShadow[shadow],
|
||||
buttonColor[color],
|
||||
buttonAlignment[alignment],
|
||||
buttonWeight[weight],
|
||||
(disabled || loading) && 'btn-disabled',
|
||||
alignment == 'center'
|
||||
? 'origin-center'
|
||||
: alignment == 'left'
|
||||
? 'origin-left'
|
||||
: 'origin-right',
|
||||
clazz,
|
||||
]}
|
||||
type={submit ? 'submit' : 'button'}
|
||||
>
|
||||
{#if loading}
|
||||
<Spinner width={loaderWidth ?? 16} />
|
||||
{:else if prefix}
|
||||
{@render prefix?.()}
|
||||
{:else if icon}
|
||||
<Icon
|
||||
src={icon}
|
||||
size="16"
|
||||
mini
|
||||
class={[color == 'secondary' && 'text-slate-600 dark:text-zinc-400']}
|
||||
/>
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
{@render suffix?.()}
|
||||
</svelte:element>
|
||||
|
||||
<!--
|
||||
@component
|
||||
|
||||
@slot `prefix` -- Will be replaced if `loading` is `true`.
|
||||
@slot `suffix`
|
||||
-->
|
||||
|
||||
<style>
|
||||
@reference "../../../app.css";
|
||||
|
||||
:global {
|
||||
.btn {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
font-size: var(--text-sm);
|
||||
gap: calc(var(--spacing) * 1.5);
|
||||
|
||||
transition: 75ms linear;
|
||||
|
||||
@variant hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
border: 1px solid transparent;
|
||||
background-color: var(--color-primary-900);
|
||||
color: var(--color-slate-50);
|
||||
|
||||
@variant dark {
|
||||
background-color: var(--color-primary-100) !important;
|
||||
color: var(--color-zinc-900);
|
||||
}
|
||||
|
||||
@variant hover {
|
||||
filter: brightness(120%);
|
||||
@variant dark {
|
||||
filter: brightness(90%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
border: 1px solid var(--color-slate-200);
|
||||
border-bottom-color: var(--color-slate-300);
|
||||
background-color: var(--color-white);
|
||||
|
||||
@variant dark {
|
||||
border: 1px solid var(--color-zinc-800);
|
||||
background-color: var(--color-zinc-900);
|
||||
}
|
||||
|
||||
@variant hover {
|
||||
background-color: var(--color-slate-50);
|
||||
@variant dark {
|
||||
background-color: var(--color-zinc-950);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-tertiary {
|
||||
background-color: transparent;
|
||||
@variant hover {
|
||||
background-color: --alpha(var(--color-slate-200) / 50%);
|
||||
@variant dark {
|
||||
background-color: --alpha(var(--color-zinc-700) / 30%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
/* border border-red-500 bg-red-500 hover:text-red-500 hover:bg-transparent text-white */
|
||||
|
||||
background-color: var(--color-red-600);
|
||||
color: var(--color-white);
|
||||
|
||||
@variant dark {
|
||||
background-color: var(--color-red-400);
|
||||
color: var(--color-black);
|
||||
}
|
||||
|
||||
@variant hover {
|
||||
filter: brightness(120%);
|
||||
@variant dark {
|
||||
filter: brightness(90%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-ghost {
|
||||
/* border border-slate-200 dark:border-zinc-800 bg-transparent
|
||||
hover:bg-slate-100 dark:hover:bg-zinc-800 dark:hover:border-zinc-700 dark:text-zinc-400 hover:text-inherit
|
||||
dark:hover:text-inherit */
|
||||
|
||||
border: 1px solid var(--color-slate-200);
|
||||
background-color: transparent;
|
||||
|
||||
@variant hover {
|
||||
background-color: var(--color-slate-100);
|
||||
}
|
||||
|
||||
@variant dark {
|
||||
border-color: var(--color-zinc-800);
|
||||
@variant hover {
|
||||
background-color: var(--color-zinc-800);
|
||||
border-color: var(--color-zinc-700);
|
||||
color: var(--color-zinc-200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn-xs {
|
||||
padding: calc(var(--spacing) * 1) calc(var(--spacing) * 2);
|
||||
font-size: var(--text-xs);
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 3);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.btn-md {
|
||||
padding-block: calc(var(--spacing) * 1.5);
|
||||
padding-inline: calc(var(--spacing) * 3);
|
||||
font-size: var(--text-sm);
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding-block: calc(var(--spacing) * 2);
|
||||
padding-inline: calc(var(--spacing) * 3);
|
||||
font-size: var(--text-sm);
|
||||
}
|
||||
|
||||
.btn-xl {
|
||||
padding: calc(var(--spacing) * 3) calc(var(--spacing) * 6);
|
||||
font-size: var(--text-base);
|
||||
}
|
||||
|
||||
.btn-square-sm {
|
||||
width: calc(var(--spacing) * 6);
|
||||
height: calc(var(--spacing) * 6);
|
||||
}
|
||||
|
||||
.btn-square-md {
|
||||
width: calc(var(--spacing) * 8);
|
||||
height: calc(var(--spacing) * 8);
|
||||
}
|
||||
|
||||
.btn-square-lg {
|
||||
width: calc(var(--spacing) * 10);
|
||||
height: calc(var(--spacing) * 10);
|
||||
}
|
||||
|
||||
.btn-square-xl {
|
||||
width: calc(var(--spacing) * 12);
|
||||
height: calc(var(--spacing) * 12);
|
||||
}
|
||||
|
||||
.btn-disabled {
|
||||
pointer-events: none;
|
||||
filter: brightness(90%);
|
||||
cursor: normal;
|
||||
|
||||
@variant dark {
|
||||
filter: brightness(70%);
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
interface Props {
|
||||
open?: boolean
|
||||
class?: ClassValue
|
||||
summary?: Snippet<[{ open: boolean }]>
|
||||
extended?: Snippet
|
||||
children?: Snippet<[{ open: boolean }]>
|
||||
}
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
class: clazz = '',
|
||||
summary,
|
||||
extended,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
const id = $props.id()
|
||||
</script>
|
||||
|
||||
<div {...rest} class={['w-full', clazz]}>
|
||||
<label for={id} class="w-full">
|
||||
{@render summary?.({ open })}
|
||||
</label>
|
||||
{@render extended?.()}
|
||||
<input {id} class="hidden input" type="checkbox" bind:checked={open} />
|
||||
<div class="expand">
|
||||
{@render children?.({ open })}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.expand {
|
||||
display: grid;
|
||||
grid-template-rows: 0fr;
|
||||
grid-template-columns: 100%;
|
||||
overflow: hidden;
|
||||
transition: grid-template-rows 0.5s cubic-bezier(0.19, 1, 0.22, 1);
|
||||
}
|
||||
|
||||
.input:checked + .expand {
|
||||
grid-template-rows: 1fr;
|
||||
}
|
||||
|
||||
.expand > :global(*) {
|
||||
min-height: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,61 @@
|
||||
<script lang="ts">
|
||||
import { Disclosure } from 'mono-svelte'
|
||||
import { Minus, Plus, Icon } from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
interface Props {
|
||||
open?: boolean
|
||||
icon?: boolean
|
||||
class?: ClassValue
|
||||
title?: import('svelte').Snippet<[boolean | undefined]>
|
||||
extended?: import('svelte').Snippet
|
||||
content?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
icon = true,
|
||||
class: clazz = '',
|
||||
title,
|
||||
extended,
|
||||
content,
|
||||
children,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Disclosure {extended} bind:open class={['gap-2', clazz]}>
|
||||
{#snippet summary()}
|
||||
<div
|
||||
class={[
|
||||
'font-medium w-full text-left flex flex-row items-center justify-between hover:text-primary-900',
|
||||
'dark:hover:text-primary-100 transition-colors z-0 group relative cursor-pointer',
|
||||
]}
|
||||
>
|
||||
<div class="flex flex-row gap-1 items-center w-full">
|
||||
{@render title?.(open)}
|
||||
</div>
|
||||
{#if icon}
|
||||
<div
|
||||
class={[
|
||||
'ml-auto',
|
||||
!open && 'rotate-90',
|
||||
'transition-transform duration-300 ease-out',
|
||||
]}
|
||||
>
|
||||
<Icon src={open ? Minus : Plus} size="15" micro class={[]} />
|
||||
</div>
|
||||
{/if}
|
||||
<div
|
||||
class="inset-0 -z-10 opacity-0 absolute bg-slate-200/50 dark:bg-zinc-900/50 rounded-full
|
||||
group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all"
|
||||
></div>
|
||||
</div>
|
||||
{/snippet}
|
||||
{#if content}
|
||||
{@render content()}
|
||||
{:else}
|
||||
<div class="text-slate-900 dark:text-zinc-100 *:mt-2">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</Disclosure>
|
||||
@@ -0,0 +1,80 @@
|
||||
<script lang="ts">
|
||||
import Button from '../button/Button.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
import { Label } from '../index.js'
|
||||
|
||||
interface Props {
|
||||
accept?: string
|
||||
id?: string
|
||||
files?: FileList | null
|
||||
multiple?: boolean
|
||||
preview?: boolean
|
||||
label?: string | undefined
|
||||
class?: string
|
||||
customLabel?: import('svelte').Snippet
|
||||
button?: import('svelte').Snippet
|
||||
choose?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
accept = '*',
|
||||
id = generateID(),
|
||||
files = $bindable(),
|
||||
multiple = false,
|
||||
preview = true,
|
||||
label = undefined,
|
||||
class: clazz = '',
|
||||
customLabel,
|
||||
button,
|
||||
choose,
|
||||
}: Props = $props()
|
||||
|
||||
let previewURLs = $derived(
|
||||
preview && files ? Array.from(files).map(URL.createObjectURL) : undefined,
|
||||
)
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1 {clazz}">
|
||||
{#if customLabel || label}
|
||||
<Label for={id} text={label}>
|
||||
{@render customLabel?.()}
|
||||
</Label>
|
||||
{/if}
|
||||
<label
|
||||
class="w-max relative cursor-pointer space-x-2 flex flex-row items-center"
|
||||
>
|
||||
{#if button}{@render button()}{:else}
|
||||
<Button>Browse</Button>
|
||||
{/if}
|
||||
{#if previewURLs}
|
||||
<div
|
||||
class="flex flex-row items-center -space-x-1 hover:space-x-1 z-20 h-8"
|
||||
>
|
||||
{#each previewURLs as file (file)}
|
||||
<img
|
||||
src={file}
|
||||
onload={() => URL.revokeObjectURL(file)}
|
||||
alt=""
|
||||
class="w-8 h-8 object-cover rounded-full hover:w-16
|
||||
hover:h-16 transition-all border border-slate-200 ring-1
|
||||
ring-slate-50 dark:ring-zinc-950 bg-white dark:bg-zinc-950"
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<span class="flex flex-row items-center text-slate-600 dark:text-zinc-400">
|
||||
{#if choose}{@render choose()}{:else if (files ?? []).length == 0}
|
||||
No file selected.
|
||||
{:else}
|
||||
{(files ?? []).length} files selected
|
||||
{/if}
|
||||
</span>
|
||||
<input
|
||||
type="file"
|
||||
bind:files
|
||||
{accept}
|
||||
{multiple}
|
||||
class="w-full h-full inset-0 opacity-0 absolute cursor-pointer"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { ClassValue, HTMLAttributes } from 'svelte/elements'
|
||||
|
||||
interface Props extends HTMLAttributes<HTMLSpanElement> {
|
||||
for?: string | undefined
|
||||
/**
|
||||
* The `text` prop will take precedence over the slot.
|
||||
*/
|
||||
text?: string | undefined
|
||||
class?: ClassValue
|
||||
customText?: Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
for: forID = undefined,
|
||||
text = undefined,
|
||||
class: clazz = '',
|
||||
customText,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={text || customText ? 'label' : 'h3'}
|
||||
{...rest}
|
||||
for={forID}
|
||||
class={['text-sm text-slate-800 dark:text-zinc-200 font-medium', clazz]}
|
||||
>
|
||||
{#if text}
|
||||
<div class="inline-block">{text}</div>
|
||||
{:else if customText}
|
||||
{@render customText?.()}
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
</svelte:element>
|
||||
@@ -0,0 +1,54 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
checked?: boolean
|
||||
labelClass?: string
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
description?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
checked = $bindable(),
|
||||
labelClass = '',
|
||||
class: clazz = '',
|
||||
children,
|
||||
description,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<label
|
||||
class="font-normal cursor-pointer flex flex-row items-center gap-4 group {clazz}"
|
||||
>
|
||||
<div
|
||||
class="w-11 h-6 rounded-full relative z-[inherit] cursor-pointer flex flex-row transition-colors shadow-xs
|
||||
{checked
|
||||
? 'bg-primary-900 dark:bg-primary-100'
|
||||
: 'bg-slate-200 dark:bg-zinc-800'}
|
||||
p-0.5 shrink-0"
|
||||
>
|
||||
<input
|
||||
bind:checked
|
||||
type="checkbox"
|
||||
class="peer appearance-none absolute top-0 left-0 w-full h-full cursor-pointer z-10"
|
||||
/>
|
||||
<div
|
||||
class="box-border w-5 h-full bg-white dark:peer-checked:bg-black rounded-full shadow-xs
|
||||
group-active:w-6 transition peer-checked:translate-x-5 peer-checked:group-active:translate-x-4
|
||||
peer-checked:rtl:-translate-x-5 peer-checked:group-active:rtl:-translate-x-4"
|
||||
></div>
|
||||
</div>
|
||||
<div class="flex flex-col {labelClass}">
|
||||
{@render children?.()}
|
||||
{#if description}
|
||||
<span class="font-normal text-sm text-slate-700 dark:text-zinc-300">
|
||||
{@render description?.()}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<style>
|
||||
.transition {
|
||||
transition: all 500ms cubic-bezier(0.075, 0.82, 0.165, 1);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,104 @@
|
||||
<script module lang="ts">
|
||||
export type Size = keyof typeof sizeClass
|
||||
|
||||
export const sizeClass = {
|
||||
sm: 'p-3',
|
||||
md: 'p-4',
|
||||
lg: 'p-5',
|
||||
}
|
||||
|
||||
interface Props extends HTMLTextareaAttributes {
|
||||
label?: string | undefined
|
||||
value?: string
|
||||
placeholder?: string
|
||||
disabled?: boolean
|
||||
required?: boolean
|
||||
size?: Size
|
||||
id?: string
|
||||
rows?: number
|
||||
element?: HTMLTextAreaElement | undefined
|
||||
class?: ClassValue
|
||||
customLabel?: import('svelte').Snippet
|
||||
suffix?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export type { Props as TextAreaProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { ClassValue, HTMLTextareaAttributes } from 'svelte/elements'
|
||||
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
const borderClass = `
|
||||
border border-slate-200 dark:border-zinc-800
|
||||
`
|
||||
|
||||
let {
|
||||
label = undefined,
|
||||
value = $bindable(),
|
||||
placeholder = '',
|
||||
disabled = false,
|
||||
required = false,
|
||||
size = 'md',
|
||||
id = generateID(),
|
||||
rows = 4,
|
||||
element = $bindable(),
|
||||
class: clazz = '',
|
||||
customLabel,
|
||||
suffix,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1 {clazz}">
|
||||
{#if customLabel || label}
|
||||
<Label
|
||||
for={id}
|
||||
text={label}
|
||||
class="peer-invalid:text-red-500 {required
|
||||
? "after:content-['*'] after:text-red-500 after:ml-1"
|
||||
: ''}"
|
||||
>
|
||||
{@render customLabel?.()}
|
||||
</Label>
|
||||
{/if}
|
||||
<div
|
||||
class="rounded-xl flex flex-col items-center text-sm bg-white dark:bg-zinc-950 {clazz}"
|
||||
>
|
||||
<textarea
|
||||
{id}
|
||||
{placeholder}
|
||||
{disabled}
|
||||
{rows}
|
||||
bind:value
|
||||
bind:this={element}
|
||||
{...rest}
|
||||
class={[
|
||||
sizeClass[size],
|
||||
borderClass,
|
||||
`focus:border-slate-800 dark:focus:border-zinc-200 bg-white dark:bg-zinc-950
|
||||
focus:outline-hidden focus:ring-2 ring-slate-800/50 rounded-xl dark:ring-zinc-200/50
|
||||
transition-all text-sm w-full disabled:bg-slate-100
|
||||
disabled:cursor-not-allowed dark:disabled:bg-zinc-900 invalid:border-red-500!
|
||||
peer invalid:text-red-500 z-10`,
|
||||
suffix && 'rounded-b-none border-b-0',
|
||||
clazz,
|
||||
]}
|
||||
></textarea>
|
||||
{#if suffix}
|
||||
<div
|
||||
class="{borderClass} {sizeClass[
|
||||
size
|
||||
]} w-full border-t-0 rounded-xl rounded-t-none
|
||||
flex items-center"
|
||||
>
|
||||
{@render suffix?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -0,0 +1,131 @@
|
||||
<script module lang="ts">
|
||||
export type Size = keyof typeof sizeClass
|
||||
export type Shadow = keyof typeof shadowClass
|
||||
|
||||
export const sizeClass = {
|
||||
sm: 'px-3 py-1',
|
||||
md: 'px-3.5 py-1.5',
|
||||
lg: 'px-5 py-3',
|
||||
}
|
||||
|
||||
export const shadowClass = {
|
||||
sm: 'shadow-xs',
|
||||
none: 'shadow-none',
|
||||
}
|
||||
|
||||
interface Props extends Omit<HTMLInputAttributes, 'size' | 'prefix'> {
|
||||
label?: string | undefined
|
||||
placeholder?: string
|
||||
disabled?: boolean
|
||||
required?: boolean
|
||||
size?: Size
|
||||
id?: string
|
||||
inlineAffixes?: boolean
|
||||
shadow?: Shadow
|
||||
element?: HTMLInputElement | undefined
|
||||
class?: string
|
||||
customLabel?: import('svelte').Snippet
|
||||
prefix?: import('svelte').Snippet
|
||||
suffix?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export type { Props as TextInputProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { HTMLInputAttributes } from 'svelte/elements'
|
||||
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
const borderClass = `border border-slate-200 border-b-slate-300 dark:border-zinc-800`
|
||||
|
||||
let {
|
||||
label = undefined,
|
||||
value = $bindable(),
|
||||
placeholder = '',
|
||||
disabled = false,
|
||||
required = false,
|
||||
size = 'md',
|
||||
id = generateID(),
|
||||
inlineAffixes = false,
|
||||
shadow = 'sm',
|
||||
element = $bindable(),
|
||||
class: clazz = '',
|
||||
customLabel: passedCustomLabel,
|
||||
prefix,
|
||||
suffix,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1 {clazz}">
|
||||
{#if passedCustomLabel || label}
|
||||
<Label
|
||||
for={id}
|
||||
text={label}
|
||||
class="peer-invalid:text-red-500 {required
|
||||
? "after:content-['*'] after:text-red-500 after:ml-1"
|
||||
: ''}"
|
||||
>
|
||||
{@render passedCustomLabel?.()}
|
||||
</Label>
|
||||
{/if}
|
||||
<div
|
||||
class={[
|
||||
shadowClass[shadow],
|
||||
borderClass,
|
||||
`border focus-within:border-primary-900 dark:focus-within:border-primary-100 focus-within:ring-2
|
||||
ring-slate-300 dark:ring-zinc-700
|
||||
transition-colors
|
||||
rounded-xl flex flex-row items-center text-sm`,
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{#if prefix}
|
||||
<div
|
||||
class={[
|
||||
'rounded-xl rounded-r-none text-slate-600 dark:text-zinc-400',
|
||||
inlineAffixes && 'bg-white dark:bg-zinc-900 pr-0 w-8',
|
||||
sizeClass[size],
|
||||
]}
|
||||
>
|
||||
{@render prefix?.()}
|
||||
</div>
|
||||
{/if}
|
||||
<input
|
||||
type="text"
|
||||
{id}
|
||||
{placeholder}
|
||||
{disabled}
|
||||
bind:value
|
||||
bind:this={element}
|
||||
{...rest}
|
||||
class={[
|
||||
sizeClass[size],
|
||||
`bg-white dark:bg-zinc-900
|
||||
focus:outline-hidden rounded-xl text-sm w-full disabled:bg-slate-100
|
||||
disabled:cursor-not-allowed dark:disabled:bg-zinc-800 invalid:border-red-500!
|
||||
peer invalid:text-red-500 z-10`,
|
||||
prefix && 'rounded-l-none',
|
||||
prefix && inlineAffixes && 'border-l-0',
|
||||
suffix && 'rounded-r-none',
|
||||
suffix && inlineAffixes && 'border-r-0',
|
||||
clazz,
|
||||
]}
|
||||
/>
|
||||
{#if suffix}
|
||||
<div
|
||||
class={[
|
||||
'rounded-xl rounded-l-none text-slate-600 dark:text-zinc-400',
|
||||
inlineAffixes && 'bg-white dark:bg-zinc-900 pl-0',
|
||||
]}
|
||||
>
|
||||
{@render suffix?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -0,0 +1 @@
|
||||
export const generateID = () => Math.floor(Math.random() * 1000000).toString()
|
||||
@@ -0,0 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { locale } from '$lib/app/i18n'
|
||||
import { getContext, onDestroy, type Snippet } from 'svelte'
|
||||
import type { IconSource } from 'svelte-hero-icons'
|
||||
import type { HTMLOptionAttributes } from 'svelte/elements'
|
||||
|
||||
interface Props extends Omit<HTMLOptionAttributes, 'prefix'> {
|
||||
children: Snippet
|
||||
icon?: IconSource
|
||||
}
|
||||
let { children, icon, ...rest }: Props = $props()
|
||||
|
||||
let optionElement = $state<HTMLOptionElement>()
|
||||
let option = $derived({
|
||||
value: optionElement?.value ?? '',
|
||||
label: optionElement?.innerText ?? '',
|
||||
icon: icon,
|
||||
disabled: optionElement?.disabled,
|
||||
isLabel: optionElement?.getAttribute('data-label') == 'true',
|
||||
})
|
||||
|
||||
interface SelectContext {
|
||||
options: {
|
||||
value: string
|
||||
label: string
|
||||
icon?: IconSource
|
||||
disabled?: boolean
|
||||
isLabel?: boolean
|
||||
}[]
|
||||
}
|
||||
|
||||
const context = getContext<SelectContext>('select')
|
||||
|
||||
$effect(() => {
|
||||
if ($locale || !context.options.find((v) => v == option)) {
|
||||
const index = context.options.findIndex((i) => i.value == option.value)
|
||||
|
||||
if (index != -1) {
|
||||
context.options.splice(index, 1, option)
|
||||
} else {
|
||||
context.options.push(option)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
const index = context.options.findIndex((i) => i.value == option.value)
|
||||
if (index != -1) {
|
||||
context.options.splice(index, 1)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
{#key $locale}
|
||||
<option {...rest} bind:this={optionElement}>
|
||||
{@render children()}
|
||||
</option>
|
||||
{/key}
|
||||
@@ -0,0 +1,182 @@
|
||||
<script lang="ts" module>
|
||||
interface Props<T> extends Omit<HTMLSelectAttributes, 'size'> {
|
||||
value?: T | string | undefined
|
||||
placeholder?: string | undefined
|
||||
label?: string | undefined
|
||||
size?: 'md' | 'sm'
|
||||
id?: string
|
||||
class?: ClassValue
|
||||
baseClass?: ClassValue
|
||||
selectClass?: ClassValue
|
||||
customLabel?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
customOption?: import('svelte').Snippet<
|
||||
[
|
||||
{
|
||||
option: {
|
||||
value: string
|
||||
label: string
|
||||
icon?: IconSource
|
||||
disabled?: boolean
|
||||
}
|
||||
selected: boolean
|
||||
},
|
||||
]
|
||||
>
|
||||
target?: Snippet<[Attachment]>
|
||||
oncontextmenu?: HTMLSelectAttributes['oncontextmenu']
|
||||
onchange?: HTMLSelectAttributes['onchange']
|
||||
placement?: Placement
|
||||
}
|
||||
|
||||
export type { Props as SelectProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts" generics="T">
|
||||
import { setContext, tick, type Snippet } from 'svelte'
|
||||
import type { Placement } from 'svelte-floating-ui/dom'
|
||||
import {
|
||||
CheckCircle,
|
||||
ChevronUpDown,
|
||||
Icon,
|
||||
type IconSource,
|
||||
} from 'svelte-hero-icons'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
import type { ClassValue, HTMLSelectAttributes } from 'svelte/elements'
|
||||
import { buttonSize } from '../../button/Button.svelte'
|
||||
import Menu from '../../popover/Menu.svelte'
|
||||
import MenuButton from '../../popover/MenuButton.svelte'
|
||||
import Label from '../Label.svelte'
|
||||
|
||||
let open = $state(false)
|
||||
let element: HTMLSelectElement | undefined = $state()
|
||||
|
||||
interface SelectContext {
|
||||
options: {
|
||||
value: string
|
||||
label: string
|
||||
icon?: IconSource
|
||||
disabled?: boolean
|
||||
isLabel?: boolean
|
||||
}[]
|
||||
}
|
||||
|
||||
const context = setContext<SelectContext>('select', {
|
||||
options: [],
|
||||
})
|
||||
|
||||
let {
|
||||
value = $bindable(undefined),
|
||||
placeholder = undefined,
|
||||
label = undefined,
|
||||
size = 'md',
|
||||
class: clazz = '',
|
||||
baseClass = '',
|
||||
selectClass = '',
|
||||
customLabel,
|
||||
children,
|
||||
customOption,
|
||||
oncontextmenu,
|
||||
onchange,
|
||||
placement = 'bottom',
|
||||
target: passedTarget,
|
||||
...rest
|
||||
}: Props<T> = $props()
|
||||
</script>
|
||||
|
||||
{#snippet selectTarget(attachment: Attachment)}
|
||||
<Label
|
||||
text={label}
|
||||
customText={customLabel}
|
||||
class={['space-y-1 relative max-w-full w-max min-w-0', baseClass]}
|
||||
>
|
||||
<div class="relative max-w-full" role="presentation">
|
||||
<select
|
||||
{@attach attachment}
|
||||
{...rest}
|
||||
bind:this={element}
|
||||
class={[
|
||||
buttonSize[size],
|
||||
'btn btn-secondary select rounded-xl appearance-none pr-6! w-full',
|
||||
selectClass,
|
||||
clazz,
|
||||
]}
|
||||
bind:value
|
||||
onmousedown={(e) => {
|
||||
e.preventDefault()
|
||||
}}
|
||||
onkeypress={(e) => {
|
||||
e.preventDefault()
|
||||
open = !open
|
||||
}}
|
||||
{onchange}
|
||||
{oncontextmenu}
|
||||
{placeholder}
|
||||
>
|
||||
{#if placeholder}
|
||||
<option disabled selected value="">{placeholder}</option>
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
</select>
|
||||
<Icon
|
||||
src={ChevronUpDown}
|
||||
micro
|
||||
size="16"
|
||||
class="absolute bottom-1/2 translate-y-1/2 right-1 box-border pointer-events-none z-10 text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</div>
|
||||
</Label>
|
||||
{/snippet}
|
||||
|
||||
<Menu bind:open {placement}>
|
||||
{#snippet target(attachment)}
|
||||
{@const render = passedTarget ?? selectTarget}
|
||||
{@render render?.(attachment)}
|
||||
{/snippet}
|
||||
{#each context.options as option (option)}
|
||||
{#if customOption}{@render customOption({
|
||||
option,
|
||||
selected: option.value == value,
|
||||
})}{:else}
|
||||
<MenuButton
|
||||
onclick={async () => {
|
||||
value = option.value
|
||||
await tick()
|
||||
element?.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
}}
|
||||
size="custom"
|
||||
disabled={option.disabled}
|
||||
color="none"
|
||||
class={[
|
||||
'min-h-0! py-1 hover:bg-slate-100 dark:hover:bg-zinc-800',
|
||||
option.value == value &&
|
||||
'bg-slate-100 dark:bg-zinc-800 text-primary-900 dark:text-primary-100 font-medium',
|
||||
option.disabled &&
|
||||
'pointer-events-none text-slate-600 dark:text-zinc-400',
|
||||
option.isLabel && 'text-xs mt-2',
|
||||
]}
|
||||
>
|
||||
{#if option.value == value}
|
||||
<Icon
|
||||
src={CheckCircle}
|
||||
size="16"
|
||||
micro
|
||||
class="text-primary-900 dark:text-primary-100"
|
||||
/>
|
||||
{:else if option.icon}
|
||||
<Icon
|
||||
src={option.icon}
|
||||
size="16"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
{/if}
|
||||
{@html option.label}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{/each}
|
||||
</Menu>
|
||||
|
||||
<style>
|
||||
@reference '../../../../app.css';
|
||||
</style>
|
||||
@@ -0,0 +1,33 @@
|
||||
// Reexport your entry components here
|
||||
|
||||
export { default as Button } from './button/Button.svelte'
|
||||
export { buttonColor, buttonSize, buttonShadow } from './button/Button.svelte'
|
||||
export { default as Spinner } from './loader/Spinner.svelte'
|
||||
export { default as TextLoader } from './loader/TextLoader.svelte'
|
||||
export { default as Material } from './materials/Material.svelte'
|
||||
|
||||
export { default as Label } from './forms/Label.svelte'
|
||||
export { default as FileInput } from './forms/FileInput.svelte'
|
||||
export { default as TextInput } from './forms/TextInput.svelte'
|
||||
export { default as TextArea } from './forms/TextArea.svelte'
|
||||
export { default as Select } from './forms/select/Select.svelte'
|
||||
export { default as Option } from './forms/select/Option.svelte'
|
||||
|
||||
export { default as Switch } from './forms/Switch.svelte'
|
||||
|
||||
export { default as Popover } from './popover/Popover.svelte'
|
||||
export { default as Menu } from './popover/Menu.svelte'
|
||||
export { default as MenuDivider } from './popover/MenuDivider.svelte'
|
||||
export { default as MenuButton } from './popover/MenuButton.svelte'
|
||||
export { default as Disclosure } from './disclosure/Disclosure.svelte'
|
||||
export { default as Expandable } from './disclosure/Expandable.svelte'
|
||||
export { default as Modal } from './modal/Modal.svelte'
|
||||
export { modal, action } from './modal/modal.js'
|
||||
export { default as ModalContainer } from './modal/ModalContainer.svelte'
|
||||
|
||||
export { toast, removeToast, toasts, toastColors } from './toast/toasts.js'
|
||||
export { default as ToastContainer } from './toast/ToastContainer.svelte'
|
||||
|
||||
export { default as Note } from './note/Note.svelte'
|
||||
export { default as Badge } from './badge/Badge.svelte'
|
||||
export { default as Search } from './search/Search.svelte'
|
||||
@@ -0,0 +1,43 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
width?: number
|
||||
}
|
||||
|
||||
let { width = 16, ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<svg
|
||||
{...rest}
|
||||
{width}
|
||||
height={width}
|
||||
stroke="currentColor"
|
||||
fill="none"
|
||||
stroke-width="2"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
class="animate-spin"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
aria-live="polite"
|
||||
role="status"
|
||||
>
|
||||
<line x1="12" y1="2" x2="12" y2="6"></line>
|
||||
<line x1="12" y1="18" x2="12" y2="22"></line>
|
||||
<line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line>
|
||||
<line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line>
|
||||
<line x1="2" y1="12" x2="6" y2="12"></line>
|
||||
<line x1="18" y1="12" x2="22" y2="12"></line>
|
||||
<line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line>
|
||||
<line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line>
|
||||
</svg>
|
||||
|
||||
<style>
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
.animate-spin {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,46 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
interface Props {
|
||||
children: Snippet
|
||||
}
|
||||
|
||||
let { children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="text-loader font-medium text-lg tracking-tight"
|
||||
aria-busy="true"
|
||||
aria-live="polite"
|
||||
>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.text-loader {
|
||||
color: transparent;
|
||||
background: linear-gradient(
|
||||
to right,
|
||||
var(--color-zinc-500),
|
||||
var(--color-zinc-50),
|
||||
var(--color-zinc-500)
|
||||
);
|
||||
background-size: 200%;
|
||||
background-clip: text;
|
||||
display: inline;
|
||||
width: max-content;
|
||||
animation: pulse 1s infinite linear;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0% {
|
||||
background-position: 100%;
|
||||
}
|
||||
50% {
|
||||
background-position: 0%;
|
||||
}
|
||||
100% {
|
||||
background-position: -100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,84 @@
|
||||
<script lang="ts">
|
||||
import type { ClassValue, HTMLAttributes } from 'svelte/elements'
|
||||
|
||||
type Elevation = keyof typeof elevationClass
|
||||
type Padding = keyof typeof paddingClass
|
||||
type Rounding = keyof typeof roundedClass
|
||||
type Color = keyof typeof colorClass
|
||||
|
||||
const elevationClass = {
|
||||
flat: '',
|
||||
low: 'shadow-2xs',
|
||||
medium: 'shadow-xs',
|
||||
high: 'shadow-md',
|
||||
xhigh: 'shadow-lg',
|
||||
max: 'shadow-xl',
|
||||
}
|
||||
|
||||
const paddingClass = {
|
||||
none: 'p-0',
|
||||
sm: 'p-2',
|
||||
md: 'p-4',
|
||||
lg: 'p-5',
|
||||
xl: 'p-6',
|
||||
}
|
||||
|
||||
const roundedClass = {
|
||||
none: '',
|
||||
sm: 'rounded-xs',
|
||||
md: 'rounded-md',
|
||||
lg: 'rounded-lg',
|
||||
xl: 'rounded-xl',
|
||||
'2xl': 'rounded-2xl',
|
||||
full: 'rounded-full',
|
||||
}
|
||||
|
||||
const colorClass = {
|
||||
default:
|
||||
'bg-white dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 border-b-slate-300 dark:border-t-zinc-700',
|
||||
distinct:
|
||||
'bg-white dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 border-b-slate-300 dark:border-t-zinc-700',
|
||||
transparent:
|
||||
'border border-slate-200 dark:border-zinc-900 border-b-slate-300 dark:border-t-zinc-800',
|
||||
uniform:
|
||||
'bg-white dark:bg-zinc-950 border border-slate-200 dark:border-zinc-900',
|
||||
none: '',
|
||||
}
|
||||
|
||||
interface Props extends HTMLAttributes<HTMLElement> {
|
||||
elevation?: Elevation
|
||||
padding?: Padding
|
||||
rounding?: Rounding
|
||||
color?: Color
|
||||
element?: string
|
||||
class?: ClassValue
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
elevation = 'flat',
|
||||
padding = 'md',
|
||||
rounding = 'xl',
|
||||
color = 'uniform',
|
||||
element = 'div',
|
||||
class: clazz = '',
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={element}
|
||||
{...rest}
|
||||
class={[
|
||||
elevationClass[elevation],
|
||||
paddingClass[padding],
|
||||
roundedClass[rounding],
|
||||
colorClass[color],
|
||||
'text-sm',
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{@render children?.()}
|
||||
</svelte:element>
|
||||
@@ -0,0 +1,150 @@
|
||||
<script lang="ts">
|
||||
import { pushState, replaceState } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import type { Snippet } from 'svelte'
|
||||
import { XMark } from 'svelte-hero-icons'
|
||||
import { backOut } from 'svelte/easing'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import { fade, scale } from 'svelte/transition'
|
||||
import { trapFocus } from 'trap-focus-svelte'
|
||||
import { Button } from '../index.js'
|
||||
import Portal from '../popover/Portal.svelte'
|
||||
|
||||
interface Props {
|
||||
action?: string | undefined
|
||||
open?: boolean
|
||||
title?: string | undefined | null
|
||||
dismissable?: boolean
|
||||
class?: ClassValue
|
||||
customTitle?: Snippet
|
||||
children?: Snippet
|
||||
actions?: Snippet<[{ action: string }]>
|
||||
ondismissed?: () => void
|
||||
onaction?: () => void
|
||||
}
|
||||
|
||||
let {
|
||||
action = undefined,
|
||||
open = $bindable(false),
|
||||
title = undefined,
|
||||
dismissable = true,
|
||||
customTitle,
|
||||
children,
|
||||
actions,
|
||||
ondismissed,
|
||||
onaction,
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
const modalId = crypto.randomUUID()
|
||||
|
||||
let el = $state<HTMLElement>()
|
||||
let hasHistoryEntry = false
|
||||
|
||||
$effect(() => {
|
||||
if (open && modalId && !hasHistoryEntry) {
|
||||
pushState('', {
|
||||
openModals: [...(page.state.openModals ?? []), modalId],
|
||||
})
|
||||
hasHistoryEntry = true
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (modalId && hasHistoryEntry) {
|
||||
const currentModals = page.state.openModals ?? []
|
||||
const isInHistory = currentModals.includes(modalId)
|
||||
|
||||
if (!isInHistory && open) {
|
||||
replaceState('', {
|
||||
openModals: currentModals.filter((id) => id !== modalId),
|
||||
})
|
||||
hasHistoryEntry = false
|
||||
open = false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function onclose() {
|
||||
open = false
|
||||
|
||||
if ((page.state.openModals ?? []).includes(modalId)) history.back()
|
||||
hasHistoryEntry = false
|
||||
|
||||
ondismissed?.()
|
||||
}
|
||||
</script>
|
||||
|
||||
<Portal>
|
||||
{#if open}
|
||||
<!--svelte-ignore a11y_interactive_supports_focus-->
|
||||
<!--svelte-ignore a11y_click_events_have_key_events-->
|
||||
<div
|
||||
role="dialog"
|
||||
class={[
|
||||
'overflow-hidden fixed top-0 left-0 w-screen h-screen z-100',
|
||||
'flex flex-col items-center justify-center backdrop-blur-xs',
|
||||
'bg-white/50 dark:bg-black/50 box-border p-4',
|
||||
]}
|
||||
transition:fade|global={{ duration: 100 }}
|
||||
onclick={(e) => {
|
||||
// @ts-expect-error html node hell
|
||||
if (!el.contains(e.target)) onclose()
|
||||
}}
|
||||
>
|
||||
<div
|
||||
bind:this={el}
|
||||
use:trapFocus
|
||||
transition:scale|global={{
|
||||
start: 0.97,
|
||||
easing: backOut,
|
||||
duration: 300,
|
||||
}}
|
||||
class={[
|
||||
'w-full border border-slate-200 border-b-slate-300 dark:border-zinc-900',
|
||||
'rounded-2xl max-w-lg box-border mx-auto overscroll-contain shadow-lg overflow-auto',
|
||||
'p-5 flex flex-col gap-2 dark:bg-zinc-950 bg-slate-50 relative',
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{#if dismissable}
|
||||
<Button
|
||||
class="absolute top-0 right-0 m-2 text-slate-600 dark:text-zinc-400"
|
||||
color="tertiary"
|
||||
size="square-sm"
|
||||
onclick={onclose}
|
||||
icon={XMark}
|
||||
></Button>
|
||||
{/if}
|
||||
{#if title !== null}
|
||||
<h1 class="font-medium tracking-tight text-xl leading-5 max-w-full">
|
||||
{#if customTitle}
|
||||
{@render customTitle?.()}
|
||||
{:else if title}
|
||||
{title}
|
||||
{/if}
|
||||
</h1>
|
||||
{/if}
|
||||
{@render children?.()}
|
||||
{#if action}
|
||||
<div class="mt-2 flex w-full">
|
||||
{#if actions}{@render actions({ action })}{:else}
|
||||
<Button
|
||||
class="w-full"
|
||||
onclick={() => {
|
||||
onaction?.()
|
||||
onclose()
|
||||
}}
|
||||
color="primary"
|
||||
size="lg"
|
||||
rounding="xl"
|
||||
>
|
||||
{action}
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</Portal>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import Button from '../button/Button.svelte'
|
||||
import Modal from '../modal/Modal.svelte'
|
||||
import { Icon } from 'svelte-hero-icons'
|
||||
import { shownModal } from './modal.js'
|
||||
|
||||
let open = $state(false)
|
||||
|
||||
// reactivity hack
|
||||
run(() => {
|
||||
open = $shownModal ? true : false
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if $shownModal}
|
||||
<Modal
|
||||
title={$shownModal.title}
|
||||
dismissable={$shownModal.dismissable}
|
||||
ondismissed={() => shownModal.set(undefined)}
|
||||
bind:open
|
||||
>
|
||||
{#if $shownModal.snippet}
|
||||
{@render $shownModal.snippet()}
|
||||
{/if}
|
||||
{#if $shownModal.body}
|
||||
<p>{$shownModal.body}</p>
|
||||
{/if}
|
||||
{#if $shownModal.actions}
|
||||
<div
|
||||
class="flex items-center gap-2 {$shownModal.actions.length >= 3
|
||||
? 'flex-col'
|
||||
: 'flex-row'}"
|
||||
>
|
||||
{#each $shownModal.actions as action (action)}
|
||||
<Button
|
||||
size="lg"
|
||||
class="flex-1 w-full"
|
||||
onclick={action.action}
|
||||
color={action.type}
|
||||
>
|
||||
{#if action.icon}
|
||||
<Icon src={action.icon} mini size="16" />
|
||||
{/if}
|
||||
{action.content}
|
||||
</Button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</Modal>
|
||||
{/if}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { t } from '$lib/app/i18n/translations'
|
||||
import { type Snippet } from 'svelte'
|
||||
import type { IconSource } from 'svelte-hero-icons'
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
export const shownModal = writable<Modal | undefined>()
|
||||
|
||||
interface Modal {
|
||||
actions: Action[]
|
||||
title: string
|
||||
body?: string
|
||||
/**
|
||||
* Whether the modal has a close button or not
|
||||
*/
|
||||
dismissable: boolean
|
||||
snippet?: Snippet
|
||||
type: 'error' | 'info' | 'success'
|
||||
}
|
||||
|
||||
type Action = {
|
||||
/**
|
||||
* What function to run when this action is clicked. If undefined, it'll close the window.
|
||||
*/
|
||||
action: () => void
|
||||
type: 'danger' | 'secondary' | 'primary'
|
||||
content: string
|
||||
icon?: IconSource
|
||||
close: boolean
|
||||
}
|
||||
|
||||
export const action = (action?: {
|
||||
action?: () => void
|
||||
type?: 'danger' | 'secondary' | 'primary'
|
||||
content?: string
|
||||
icon?: IconSource
|
||||
close?: boolean
|
||||
}): Action => ({
|
||||
action: action?.action
|
||||
? () => {
|
||||
action?.action?.()
|
||||
if (action.close) shownModal.set(undefined)
|
||||
}
|
||||
: () => shownModal.set(undefined),
|
||||
type: action?.type ?? 'secondary',
|
||||
content: action?.content || t.get('common.back'),
|
||||
close: action?.close ?? true,
|
||||
})
|
||||
|
||||
export function modal(inputModal: {
|
||||
actions?: Action[]
|
||||
title: string
|
||||
body?: string
|
||||
/**
|
||||
* Whether the modal has a close button or not
|
||||
*/
|
||||
dismissable?: boolean
|
||||
snippet?: Snippet
|
||||
type?: 'error' | 'info' | 'success'
|
||||
}) {
|
||||
const modal: Modal = {
|
||||
actions: inputModal.actions ?? [action()],
|
||||
dismissable: inputModal.dismissable ?? true,
|
||||
title: inputModal.title,
|
||||
body: inputModal.body,
|
||||
type: inputModal.type ?? 'info',
|
||||
snippet: inputModal.snippet,
|
||||
}
|
||||
|
||||
shownModal.set(modal)
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<script lang="ts">
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import { Material } from '../index.js'
|
||||
import { Icon, InformationCircle } from 'svelte-hero-icons'
|
||||
|
||||
interface Props {
|
||||
content?: string | undefined
|
||||
children?: import('svelte').Snippet
|
||||
class?: ClassValue
|
||||
}
|
||||
|
||||
let { content = undefined, children, class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Material
|
||||
padding="none"
|
||||
color="uniform"
|
||||
class="flex flex-row space-x-2 items-center px-4 py-3 rounded-3xl! {clazz}"
|
||||
>
|
||||
<Icon
|
||||
src={InformationCircle}
|
||||
size="20"
|
||||
mini
|
||||
class="text-primary-900 dark:text-primary-100"
|
||||
/>
|
||||
<div class="flex flex-col md:flex-row items-center w-full">
|
||||
{#if children}
|
||||
{@render children?.()}
|
||||
{:else if content}
|
||||
<p>
|
||||
{content}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
</Material>
|
||||
@@ -0,0 +1,60 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
flip,
|
||||
offset,
|
||||
shift,
|
||||
type Middleware,
|
||||
type Placement,
|
||||
type Strategy,
|
||||
} from '@floating-ui/core'
|
||||
import Popover from '../popover/Popover.svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
|
||||
interface Props {
|
||||
openOnHover?: boolean
|
||||
open?: boolean
|
||||
placement?: Placement
|
||||
middleware?: Middleware[]
|
||||
strategy?: Strategy
|
||||
class?: string
|
||||
target?: Snippet<[Attachment]>
|
||||
children?: import('svelte').Snippet<[boolean]>
|
||||
}
|
||||
|
||||
let {
|
||||
openOnHover = false,
|
||||
open = $bindable(false),
|
||||
placement = 'bottom-start',
|
||||
middleware = [offset(6), shift({ padding: 6 }), flip()],
|
||||
strategy = 'absolute',
|
||||
target,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Popover
|
||||
{openOnHover}
|
||||
{placement}
|
||||
{middleware}
|
||||
{strategy}
|
||||
{target}
|
||||
{...rest}
|
||||
bind:open
|
||||
popoverClass="rounded-xl w-full backdrop-blur-md max-w-72"
|
||||
>
|
||||
{#snippet popover()}
|
||||
<div
|
||||
class="w-full max-w-sm max-h-128 overflow-auto list-none shadow-lg rounded-xl"
|
||||
>
|
||||
<div
|
||||
class="flex flex-col p-1 list-none bg-white/80 dark:bg-zinc-900/90 rounded-xl
|
||||
border border-slate-200 dark:border-zinc-800 gap-px"
|
||||
role="menu"
|
||||
>
|
||||
{@render children?.(open)}
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Popover>
|
||||
@@ -0,0 +1,79 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import Button, {
|
||||
type ButtonAlignment,
|
||||
type ButtonColor,
|
||||
type ButtonProps,
|
||||
} from '../button/Button.svelte'
|
||||
import { ChevronRight, Icon, type IconSource } from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
interface Props extends ButtonProps {
|
||||
color?: ButtonColor
|
||||
alignment?: ButtonAlignment
|
||||
href?: string | undefined
|
||||
disabled?: boolean
|
||||
class?: ClassValue
|
||||
icon?: IconSource
|
||||
prefix?: Snippet
|
||||
children?: Snippet
|
||||
suffix?: Snippet
|
||||
nest?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
color = 'tertiary',
|
||||
alignment = 'left',
|
||||
href = undefined,
|
||||
disabled = false,
|
||||
class: clazz = '',
|
||||
icon,
|
||||
prefix: passedPrefix,
|
||||
children,
|
||||
suffix: passedSuffix,
|
||||
nest,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Button
|
||||
{...rest}
|
||||
{color}
|
||||
type="none"
|
||||
size="custom"
|
||||
rounding="none"
|
||||
class={[
|
||||
'w-full px-3 py-1.5 min-h-7 duration-75 hover:cursor-default font-normal rounded-lg flex items-center gap-1 text-sm',
|
||||
disabled && 'opacity-70 pointer-events-none cursor-not-allowed',
|
||||
color == 'tertiary' && 'dark:hover:bg-zinc-800/70',
|
||||
clazz,
|
||||
]}
|
||||
{alignment}
|
||||
{href}
|
||||
{disabled}
|
||||
data-autoclose={nest ? 'false' : 'true'}
|
||||
shadow="none"
|
||||
role="menuitem"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<div
|
||||
class={[
|
||||
'contents shrink-0',
|
||||
color == 'tertiary' && 'text-slate-600 dark:text-zinc-400',
|
||||
]}
|
||||
>
|
||||
{#if icon}
|
||||
<Icon src={icon} micro size="16" />
|
||||
{:else}
|
||||
{@render passedPrefix?.()}
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
{@render children?.()}
|
||||
{#snippet suffix()}
|
||||
{@render passedSuffix?.()}
|
||||
{#if nest}
|
||||
<Icon src={ChevronRight} size="16" micro class="ml-auto" />
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Button>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
|
||||
let {
|
||||
showLabel = false,
|
||||
children,
|
||||
}: { showLabel?: boolean; children: Snippet } = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="text-slate-800 dark:text-zinc-200 text-xs font-medium mx-3 my-1.5 flex items-center gap-1"
|
||||
>
|
||||
<div class={[!showLabel && 'sr-only']}>{@render children?.()}</div>
|
||||
<hr
|
||||
class={[
|
||||
'shrink flex-1 border-slate-100 dark:border-zinc-800',
|
||||
!showLabel && '-mx-4',
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
@@ -0,0 +1,158 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
flip,
|
||||
offset,
|
||||
shift,
|
||||
type Middleware,
|
||||
type Placement,
|
||||
type Strategy,
|
||||
} from '@floating-ui/core'
|
||||
import { createFloatingActions } from 'svelte-floating-ui'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { scale } from 'svelte/transition'
|
||||
import { trapFocus } from 'trap-focus-svelte'
|
||||
import { Material } from '../index'
|
||||
import Portal from './Portal.svelte'
|
||||
|
||||
interface Props {
|
||||
openOnHover?: boolean
|
||||
open?: boolean
|
||||
autoClose?: boolean
|
||||
placement?: Placement
|
||||
middleware?: Middleware[]
|
||||
strategy?: Strategy
|
||||
popoverClass?: string
|
||||
target?: import('svelte').Snippet<[Attachment]>
|
||||
popover?: import('svelte').Snippet<[boolean]>
|
||||
children?: import('svelte').Snippet<[boolean]>
|
||||
}
|
||||
|
||||
let {
|
||||
openOnHover = false,
|
||||
open = $bindable(false),
|
||||
autoClose = true,
|
||||
placement = 'bottom-start',
|
||||
middleware = [offset(6), shift(), flip()],
|
||||
strategy = 'fixed',
|
||||
popoverClass = '',
|
||||
target,
|
||||
popover,
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
let popoverEl = $state<HTMLElement>()
|
||||
|
||||
let origins: Record<Placement, string> = {
|
||||
bottom: 'top',
|
||||
'bottom-end': 'top right',
|
||||
'bottom-start': 'top left',
|
||||
left: 'left',
|
||||
'left-end': 'left',
|
||||
'left-start': 'left',
|
||||
right: 'right',
|
||||
'right-end': 'right',
|
||||
'right-start': 'right',
|
||||
top: 'bottom',
|
||||
'top-end': 'bottom right',
|
||||
'top-start': 'bottom',
|
||||
}
|
||||
|
||||
const [floatingRef, floatingContent] = createFloatingActions({
|
||||
strategy: strategy,
|
||||
placement: placement,
|
||||
middleware: middleware,
|
||||
onComputed: ({ placement }) => {
|
||||
if (popoverEl) {
|
||||
popoverEl.style.transformOrigin = origins[placement]
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const menuAttach: Attachment = (element) => {
|
||||
const e = element as HTMLButtonElement
|
||||
|
||||
function toggle(force?: boolean) {
|
||||
if (!open && force == false) return
|
||||
|
||||
const newOpen = force ?? !open
|
||||
|
||||
if (!newOpen) {
|
||||
e.focus()
|
||||
}
|
||||
|
||||
open = newOpen
|
||||
}
|
||||
|
||||
const mouseLeave = () => openOnHover && toggle(false)
|
||||
const focus = () => openOnHover && toggle(true)
|
||||
const focusout = () => openOnHover && toggle(false)
|
||||
const click = () => {
|
||||
toggle()
|
||||
|
||||
if (autoClose) {
|
||||
const clickHandler = (event: Event) => {
|
||||
if (!e) return
|
||||
|
||||
const target = event.target as Element | null
|
||||
|
||||
if (!e?.contains(event.target as Element | null)) {
|
||||
if (target?.closest("[data-autoclose='false']") == null) {
|
||||
toggle(false)
|
||||
document.removeEventListener('click', clickHandler)
|
||||
}
|
||||
}
|
||||
}
|
||||
document.addEventListener('click', clickHandler)
|
||||
}
|
||||
}
|
||||
const keydown = (event: KeyboardEvent) => {
|
||||
if (event.key === 'Escape') {
|
||||
toggle(false)
|
||||
}
|
||||
}
|
||||
|
||||
e.addEventListener('mouseleave', mouseLeave)
|
||||
e.addEventListener('focus', focus)
|
||||
e.addEventListener('focusout', focusout)
|
||||
e.addEventListener('click', click)
|
||||
popoverEl?.addEventListener('keydown', keydown)
|
||||
|
||||
floatingRef(e)
|
||||
|
||||
return () => {
|
||||
e.removeEventListener('mouseleave', mouseLeave)
|
||||
e.removeEventListener('focus', focus)
|
||||
e.removeEventListener('focusout', focusout)
|
||||
e.removeEventListener('click', click)
|
||||
popoverEl?.removeEventListener('keydown', keydown)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
{@render target?.(menuAttach)}
|
||||
|
||||
{#if open}
|
||||
<Portal class="z-150">
|
||||
<div
|
||||
transition:scale={{
|
||||
duration: 175,
|
||||
start: 0.95,
|
||||
opacity: 0,
|
||||
easing: expoOut,
|
||||
}}
|
||||
class={['z-150', popoverClass]}
|
||||
use:floatingContent
|
||||
use:trapFocus
|
||||
bind:this={popoverEl}
|
||||
>
|
||||
{#if popover}
|
||||
{@render popover(open)}
|
||||
{:else}
|
||||
<Material elevation="high" color="distinct" class="flex flex-col">
|
||||
{@render children?.(open)}
|
||||
</Material>
|
||||
{/if}
|
||||
</div>
|
||||
</Portal>
|
||||
{/if}
|
||||
@@ -0,0 +1,42 @@
|
||||
<script lang="ts">
|
||||
import { browser } from '$app/environment'
|
||||
|
||||
// https://github.com/sveltejs/svelte/issues/3088#issuecomment-505785516
|
||||
import { onMount, onDestroy, createEventDispatcher } from 'svelte'
|
||||
let slottedElements = $state<HTMLDivElement>(),
|
||||
portal: HTMLDivElement
|
||||
|
||||
const dispatch = createEventDispatcher<{ mounted: void }>()
|
||||
|
||||
onMount(() => {
|
||||
if (!browser) return
|
||||
portal = document?.createElement('div')
|
||||
if (portal) portal.className = 'portal-mount'
|
||||
document?.body.appendChild(portal)
|
||||
if (slottedElements) portal?.appendChild(slottedElements)
|
||||
dispatch('mounted')
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
portal.remove()
|
||||
})
|
||||
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="portal-initial-mount-point">
|
||||
<div bind:this={slottedElements} class="portal-content {clazz || ''}">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.portal-initial-mount-point {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,118 @@
|
||||
<script lang="ts" module>
|
||||
interface Props<T> extends Omit<TextInputProps, 'onselect' | 'children'> {
|
||||
query?: string
|
||||
selected?: T | undefined
|
||||
search: (query: string) => Promise<T[]>
|
||||
extractName: (item: T) => string
|
||||
select?: (item: T) => void
|
||||
input?: import('svelte').Snippet
|
||||
noresults?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet<
|
||||
[
|
||||
{
|
||||
select: (item?: T) => void
|
||||
item: T
|
||||
extractName: (item: T) => string
|
||||
},
|
||||
]
|
||||
>
|
||||
onselect?: (value?: T) => void
|
||||
oninput?: TextInputProps['oninput']
|
||||
}
|
||||
|
||||
export type { Props as SearchProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts" generics="T">
|
||||
import type { TextInputProps } from 'mono-svelte/forms/TextInput.svelte'
|
||||
import { Menu, TextInput, Spinner, MenuButton } from '../index.js'
|
||||
import { debounce } from '../util/time.js'
|
||||
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
|
||||
|
||||
let items: T[] = $state([])
|
||||
|
||||
/**
|
||||
* This is here so that the menu doesn't open as soon as it's mounted.
|
||||
*/
|
||||
let openMenu = $state(false)
|
||||
let searching = $state(false)
|
||||
|
||||
let {
|
||||
query = $bindable(''),
|
||||
selected = $bindable(undefined),
|
||||
search,
|
||||
extractName,
|
||||
select = (item: T) => {
|
||||
selected = item
|
||||
query = extractName(item)
|
||||
onselect?.(item)
|
||||
},
|
||||
input,
|
||||
noresults,
|
||||
children,
|
||||
onselect,
|
||||
oninput,
|
||||
...rest
|
||||
}: Props<T> = $props()
|
||||
|
||||
const debounceFunc = debounce(async () => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
items = await search(query)
|
||||
searching = false
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="relative">
|
||||
<Menu bind:open={openMenu}>
|
||||
{#snippet target(attachment)}
|
||||
{#if input}{@render input()}{:else}
|
||||
<TextInput
|
||||
{@attach attachment}
|
||||
bind:value={query}
|
||||
oninput={(e) => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
oninput?.(e)
|
||||
debounceFunc()
|
||||
}}
|
||||
onfocus={(e) => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
oninput?.(e)
|
||||
debounceFunc()
|
||||
}}
|
||||
{...rest}
|
||||
inlineAffixes
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<div class="h-5 flex items-center">
|
||||
<Icon src={MagnifyingGlass} mini size="16" />
|
||||
</div>
|
||||
{/snippet}
|
||||
</TextInput>
|
||||
{/if}
|
||||
{/snippet}
|
||||
{#if searching}
|
||||
<div class="w-full h-24 grid place-items-center">
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
{:else if items.length == 0}
|
||||
<div class="text-center h-24 grid place-items-center">
|
||||
{#if noresults}{@render noresults()}{:else}No results found.{/if}
|
||||
</div>
|
||||
{:else}
|
||||
{#each items as item (item)}
|
||||
{#if children}{@render children({
|
||||
extractName,
|
||||
item,
|
||||
select,
|
||||
})}{:else}
|
||||
<MenuButton onclick={() => select(item)}>
|
||||
{extractName(item)}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
</Menu>
|
||||
</div>
|
||||
@@ -0,0 +1,88 @@
|
||||
<script lang="ts">
|
||||
import { Spinner } from '../index.js'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { type Toast, toasts, toastColors } from './toasts.js'
|
||||
import {
|
||||
InformationCircle,
|
||||
ExclamationTriangle,
|
||||
ExclamationCircle,
|
||||
CheckCircle,
|
||||
Icon,
|
||||
XMark,
|
||||
Check,
|
||||
} from 'svelte-hero-icons'
|
||||
import { fly } from 'svelte/transition'
|
||||
import Markdown from '$lib/app/markdown/Markdown.svelte'
|
||||
|
||||
interface Props {
|
||||
toast: Toast
|
||||
}
|
||||
|
||||
let { toast }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={[
|
||||
toastColors[toast.type],
|
||||
'relative rounded-xl overflow-hidden flex flex-row items-center gap-2 px-3 py-3 border border-slate-200 dark:border-zinc-800',
|
||||
'bg-white dark:bg-zinc-925 shadow-lg',
|
||||
toast.long ? 'w-full max-w-lg' : 'w-80',
|
||||
]}
|
||||
transition:fly={{
|
||||
duration: 600,
|
||||
y: 8,
|
||||
opacity: 0,
|
||||
easing: expoOut,
|
||||
}}
|
||||
>
|
||||
{#if toast.loading}
|
||||
<div class="relative m-2 ml-4 shrink-0">
|
||||
<Spinner width={20} />
|
||||
</div>
|
||||
{:else}
|
||||
<Icon
|
||||
size="28"
|
||||
mini
|
||||
class={['relative self-center shrink-0 p-1 rounded-lg']}
|
||||
src={toast.type == 'info'
|
||||
? InformationCircle
|
||||
: toast.type == 'success'
|
||||
? CheckCircle
|
||||
: toast.type == 'warning'
|
||||
? ExclamationTriangle
|
||||
: toast.type == 'error'
|
||||
? ExclamationCircle
|
||||
: ExclamationCircle}
|
||||
/>
|
||||
{/if}
|
||||
<div class="flex flex-col break-words max-w-full text-inherit">
|
||||
{#if toast.title}
|
||||
<h1 class="text-base font-semibold">{toast.title}</h1>
|
||||
{/if}
|
||||
<Markdown
|
||||
source={toast.content}
|
||||
class={toast.long ? 'text-[15px]' : 'text-sm font-medium'}
|
||||
/>
|
||||
</div>
|
||||
<div class="absolute top-0 right-0 flex items-center gap-1 m-1">
|
||||
{#if toast.action}
|
||||
<button
|
||||
onclick={() => {
|
||||
toast.action?.()
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-slate-100 dark:hover:bg-zinc-800 p-1 cursor-pointer"
|
||||
>
|
||||
<Icon src={Check} size="20" micro />
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
onclick={() => {
|
||||
toasts.update((toasts) => toasts.filter((t) => t.id != toast.id))
|
||||
}}
|
||||
class="rounded-lg w-max transition-colors hover:bg-slate-100 dark:hover:bg-zinc-800 p-1 cursor-pointer text-slate-600 dark:text-zinc-400"
|
||||
>
|
||||
<Icon src={XMark} size="16" micro />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
import Toast from './Toast.svelte'
|
||||
import { flip } from 'svelte/animate'
|
||||
import { toasts } from './toasts.js'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="fixed right-0 bottom-0 flex flex-col items-end justify-end z-200 p-4
|
||||
group overflow-hidden h-screen min-w-96 pointer-events-none gap-4"
|
||||
>
|
||||
{#each $toasts as toast (toast.id)}
|
||||
<div
|
||||
animate:flip={{ duration: 300, easing: expoOut }}
|
||||
class="pointer-events-auto transition-all
|
||||
duration-300"
|
||||
>
|
||||
<Toast {toast} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -0,0 +1,68 @@
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
type ToastType = keyof typeof toastColors
|
||||
|
||||
export const toastColors = {
|
||||
error: 'text-red-600 dark:text-red-400',
|
||||
warning: 'text-yellow-600 dark:text-yellow-400',
|
||||
success: 'text-green-600 dark:text-green-400',
|
||||
info: '',
|
||||
}
|
||||
|
||||
export interface Toast {
|
||||
id: number
|
||||
title?: string
|
||||
content: string
|
||||
type: ToastType
|
||||
loading?: boolean
|
||||
long?: boolean
|
||||
action?: () => void
|
||||
}
|
||||
|
||||
export const toasts = writable<Toast[]>([])
|
||||
|
||||
export function toast({
|
||||
title,
|
||||
content,
|
||||
type = 'info',
|
||||
duration = 5000,
|
||||
loading = false,
|
||||
long = false,
|
||||
action,
|
||||
}: {
|
||||
title?: string
|
||||
content: string
|
||||
type?: ToastType
|
||||
duration?: number
|
||||
loading?: boolean
|
||||
long?: boolean
|
||||
action?: () => void
|
||||
}) {
|
||||
let id = 0
|
||||
|
||||
toasts.update((toasts) => {
|
||||
id = Math.max(0, ...toasts.map((t) => t.id)) + 1
|
||||
|
||||
return [
|
||||
...toasts,
|
||||
{
|
||||
id: id,
|
||||
content: content,
|
||||
title: title,
|
||||
type: type,
|
||||
loading: loading,
|
||||
long: long,
|
||||
action: action,
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||
}, duration)
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
export const removeToast = (id: number) =>
|
||||
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||
@@ -0,0 +1,7 @@
|
||||
export const debounce = (fn: Function, ms = 300) => {
|
||||
let timeoutId: ReturnType<typeof setTimeout>
|
||||
return function (this: any, ...args: any[]) {
|
||||
clearTimeout(timeoutId)
|
||||
timeoutId = setTimeout(() => fn.apply(this, args), ms)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<script lang="ts">
|
||||
import { notifications, profile } from '$lib/app/auth.svelte.js'
|
||||
import ItemList from '$lib/ui/generic/ItemList.svelte'
|
||||
import Expandable from 'mono-svelte/disclosure/Expandable.svelte'
|
||||
import SidebarButton from '$comp/ui/sidebar/SidebarButton.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { communityLink } from '$lib/util.svelte'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { theme } from '$lib/app/theme/theme.svelte'
|
||||
import { Badge, Option, Select } from 'mono-svelte'
|
||||
import {
|
||||
ArrowLeftOnRectangle,
|
||||
Bookmark,
|
||||
ChevronUpDown,
|
||||
Cog6Tooth,
|
||||
ComputerDesktop,
|
||||
Icon,
|
||||
Identification,
|
||||
Inbox,
|
||||
Moon,
|
||||
Sun,
|
||||
Swatch,
|
||||
UserCircle,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
import EndPlaceholder from '../EndPlaceholder.svelte'
|
||||
import ProfileSelection from './ProfileSelection.svelte'
|
||||
import Logo from '../Logo.svelte'
|
||||
import { env } from '$env/dynamic/public'
|
||||
import Link from '$comp/input/Link.svelte'
|
||||
|
||||
interface Props {
|
||||
style?: string
|
||||
class?: ClassValue
|
||||
}
|
||||
|
||||
let { style = '', class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
<nav
|
||||
aria-label={$t('aria.sidebar.title')}
|
||||
class={['flex flex-col overflow-auto gap-1', clazz]}
|
||||
{style}
|
||||
>
|
||||
<ProfileSelection profiles={profile.meta.profiles} />
|
||||
<EndPlaceholder margin="sm" size="xs">{$t('profile.profile')}</EndPlaceholder>
|
||||
{#if profile.current?.jwt}
|
||||
<SidebarButton
|
||||
icon={UserCircle}
|
||||
href="/profile"
|
||||
label={$t('profile.profile')}
|
||||
/>
|
||||
<SidebarButton icon={Inbox} href="/inbox" label={$t('profile.inbox')}>
|
||||
{#if $notifications.inbox}
|
||||
<Badge
|
||||
class="min-w-5 h-5 p-0! px-0.5 grid place-items-center ml-auto"
|
||||
color="red-subtle"
|
||||
>
|
||||
{$notifications.inbox > 99 ? '∞' : $notifications.inbox}
|
||||
</Badge>
|
||||
{/if}
|
||||
</SidebarButton>
|
||||
<SidebarButton icon={Bookmark} href="/saved" label={$t('profile.saved')} />
|
||||
{:else}
|
||||
<SidebarButton
|
||||
href="/login"
|
||||
label={$t('account.login')}
|
||||
icon={ArrowLeftOnRectangle}
|
||||
/>
|
||||
<SidebarButton
|
||||
href="/signup"
|
||||
label={$t('account.signup')}
|
||||
icon={Identification}
|
||||
/>
|
||||
<SidebarButton
|
||||
href="/accounts"
|
||||
label={$t('account.accounts')}
|
||||
icon={UserGroup}
|
||||
/>
|
||||
{/if}
|
||||
<EndPlaceholder margin="sm" size="xs">{$t('nav.menu.app')}</EndPlaceholder>
|
||||
<SidebarButton
|
||||
href="/settings"
|
||||
label={$t('nav.menu.settings')}
|
||||
icon={Cog6Tooth}
|
||||
/>
|
||||
<Select bind:value={theme.colorScheme} size="sm">
|
||||
{#snippet target(attachment)}
|
||||
<SidebarButton
|
||||
{@attach attachment}
|
||||
label={$t('nav.menu.colorscheme.label')}
|
||||
icon={theme.colorScheme == 'system'
|
||||
? ComputerDesktop
|
||||
: theme.colorScheme == 'light'
|
||||
? Sun
|
||||
: Moon}
|
||||
class="w-full relative"
|
||||
>
|
||||
<Option value="system" class="hidden" icon={ComputerDesktop}>
|
||||
{$t('nav.menu.colorscheme.system')}
|
||||
</Option>
|
||||
<Option value="light" class="hidden" icon={Sun}>
|
||||
{$t('nav.menu.colorscheme.light')}
|
||||
</Option>
|
||||
<Option value="dark" class="hidden" icon={Moon}>
|
||||
{$t('nav.menu.colorscheme.dark')}
|
||||
</Option>
|
||||
<Icon micro size="16" src={ChevronUpDown} class="ml-auto" />
|
||||
</SidebarButton>
|
||||
{/snippet}
|
||||
</Select>
|
||||
<SidebarButton href="/theme" label={$t('nav.menu.theme')} icon={Swatch} />
|
||||
{#if profile.current?.user}
|
||||
<EndPlaceholder margin="sm" size="xs">
|
||||
{$t('content.communities')}
|
||||
</EndPlaceholder>
|
||||
|
||||
<div class="space-y-3">
|
||||
{#if profile.current?.user.moderates.length > 0}
|
||||
<Expandable class="px-1.5" bind:open={settings.expand.moderates}>
|
||||
{#snippet title()}
|
||||
<span class="px-2 py-1 w-full">
|
||||
<EndPlaceholder border={false}>
|
||||
{$t('routes.profile.moderates')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{profile.current.user?.moderates.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={profile.current.user.moderates.map((i) => ({
|
||||
id: i.community.id,
|
||||
name: i.community.title,
|
||||
url: communityLink(i.community),
|
||||
avatar: i.community.icon,
|
||||
instance: new URL(i.community.actor_id).hostname,
|
||||
}))}
|
||||
/>
|
||||
</Expandable>
|
||||
{/if}
|
||||
|
||||
<Expandable class="px-1.5" bind:open={settings.expand.communities}>
|
||||
{#snippet title()}
|
||||
<span class="px-2 py-1 w-full">
|
||||
<EndPlaceholder border={false}>
|
||||
{$t('profile.subscribed')}
|
||||
{#snippet action()}
|
||||
<span class="dark:text-white text-black">
|
||||
{profile.current.user?.follows.length}
|
||||
</span>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</span>
|
||||
{/snippet}
|
||||
|
||||
<ItemList
|
||||
items={profile.current.user.follows.map((i) => ({
|
||||
id: i.community.id,
|
||||
name: i.community.title,
|
||||
url: communityLink(i.community),
|
||||
avatar: i.community.icon,
|
||||
instance: new URL(i.community.actor_id).hostname,
|
||||
}))}
|
||||
/>
|
||||
</Expandable>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex-1 h-full mt-auto"></div>
|
||||
|
||||
<footer
|
||||
class="flex gap-6 flex-col xl:flex-row text-sm text-slate-600 dark:text-zinc-300 flex-wrap"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<Logo width={16} />
|
||||
<span class="font-medium">
|
||||
{__VERSION__}
|
||||
</span>
|
||||
</div>
|
||||
{#if env.PUBLIC_XYLIGHT_MODE?.toLowerCase() == 'true'}
|
||||
<Link highlight href="https://github.com/xyphyn/photon">
|
||||
{$t('nav.menu.source')}
|
||||
</Link>
|
||||
<Link highlight href="https://buymeacoffee.com/xylight">
|
||||
{$t('nav.menu.donate')}
|
||||
</Link>
|
||||
{/if}
|
||||
</footer>
|
||||
</nav>
|
||||
@@ -0,0 +1,54 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state'
|
||||
import { Button } from 'mono-svelte'
|
||||
import type { ButtonProps } from 'mono-svelte/button/Button.svelte'
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
|
||||
interface Props extends ButtonProps {
|
||||
href?: string | undefined
|
||||
icon?: IconSource | undefined
|
||||
class?: string
|
||||
label?: string
|
||||
customIcon?: import('svelte').Snippet<[{ selected: boolean }]>
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
href = undefined,
|
||||
icon = undefined,
|
||||
class: clazz = '',
|
||||
customIcon,
|
||||
children,
|
||||
label,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let selected = $derived(page.url.pathname == href)
|
||||
</script>
|
||||
|
||||
<Button
|
||||
color="tertiary"
|
||||
alignment="left"
|
||||
rounding="xl"
|
||||
{...rest}
|
||||
{href}
|
||||
weight="none"
|
||||
class={[
|
||||
'hover:text-slate-900 hover:dark:text-zinc-50',
|
||||
selected
|
||||
? 'text-primary-900 dark:text-primary-100'
|
||||
: 'text-slate-600 dark:text-zinc-400',
|
||||
clazz,
|
||||
]}
|
||||
shadow="none"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
{#if customIcon}
|
||||
{@render customIcon({ selected })}
|
||||
{:else if icon}
|
||||
<Icon src={icon} solid size="18" />
|
||||
{/if}
|
||||
{/snippet}
|
||||
{label}
|
||||
{@render children?.()}
|
||||
</Button>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script lang="ts" module>
|
||||
const wrapClass = {
|
||||
wrap: '',
|
||||
'no-wrap': 'overflow-hidden text-ellipsis whitespace-nowrap',
|
||||
force: 'break-words',
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
wrap?: keyof typeof wrapClass
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { wrap = 'wrap', class: clazz = '', children }: Props = $props()
|
||||
|
||||
let classes = $derived(`${wrapClass[wrap]} ${clazz ?? ''}`)
|
||||
</script>
|
||||
|
||||
<span class={classes}>
|
||||
{@render children?.()}
|
||||
</span>
|
||||
@@ -1,222 +0,0 @@
|
||||
import { env } from '$env/dynamic/public'
|
||||
import type { Theme, ThemeColors } from './theme.svelte'
|
||||
|
||||
const PHOTON_DEFAULT = {
|
||||
slate: {
|
||||
25: '252 253 254',
|
||||
50: '248 250 252',
|
||||
100: '241 245 249',
|
||||
200: '226 232 240',
|
||||
300: '203 213 225',
|
||||
400: '148 163 184',
|
||||
500: '100 116 139',
|
||||
600: '71 85 105',
|
||||
700: '51 65 85',
|
||||
800: '30 41 59',
|
||||
900: '15 23 42',
|
||||
950: '2 6 23',
|
||||
},
|
||||
zinc: {
|
||||
'50': '252 252 254',
|
||||
'100': '248 248 251',
|
||||
'200': '235 235 240',
|
||||
'300': '222 222 228',
|
||||
'400': '175 175 185',
|
||||
'500': '128 128 138',
|
||||
'600': '98 98 108',
|
||||
'700': '68 68 76',
|
||||
'800': '47 47 54',
|
||||
'900': '34 34 39',
|
||||
'925': '28 28 32',
|
||||
'950': '25 25 29',
|
||||
},
|
||||
primary: {
|
||||
100: '241 245 249',
|
||||
900: '15 23 42',
|
||||
},
|
||||
other: {
|
||||
black: '0 0 0',
|
||||
white: '255 255 255',
|
||||
},
|
||||
}
|
||||
|
||||
export function getDefaultColors(): ThemeColors {
|
||||
return env.PUBLIC_THEME ? JSON.parse(env.PUBLIC_THEME) : PHOTON_DEFAULT
|
||||
}
|
||||
|
||||
export function getDefaultTheme(): Theme {
|
||||
return {
|
||||
id: 0,
|
||||
colors: getDefaultColors(),
|
||||
name: env.PUBLIC_THEME ? 'Instance Default' : 'Mono',
|
||||
}
|
||||
}
|
||||
|
||||
export const presets: Theme[] = [
|
||||
getDefaultTheme(),
|
||||
...(env.PUBLIC_THEME
|
||||
? [{ colors: PHOTON_DEFAULT, id: -10, name: 'Mono' }]
|
||||
: []),
|
||||
{
|
||||
colors: {
|
||||
slate: {
|
||||
25: '252 253 254',
|
||||
50: '248 250 252',
|
||||
100: '241 245 249',
|
||||
200: '226 232 240',
|
||||
300: '203 213 225',
|
||||
400: '148 163 184',
|
||||
500: '100 116 139',
|
||||
600: '71 85 105',
|
||||
700: '51 65 85',
|
||||
800: '30 41 59',
|
||||
900: '15 23 42',
|
||||
950: '2 6 23',
|
||||
},
|
||||
zinc: {
|
||||
50: '250 250 250',
|
||||
100: '244 244 245',
|
||||
200: '228 228 231',
|
||||
300: '212 212 216',
|
||||
400: '161 161 170',
|
||||
500: '113 113 122',
|
||||
600: '82 82 91',
|
||||
700: '52 52 59',
|
||||
800: '31 31 36',
|
||||
900: '18 18 21',
|
||||
925: '12 12 14',
|
||||
950: '9 9 11',
|
||||
},
|
||||
primary: {
|
||||
100: '241 245 249',
|
||||
900: '15 23 42',
|
||||
},
|
||||
other: {
|
||||
black: '0 0 0',
|
||||
white: '255 255 255',
|
||||
},
|
||||
},
|
||||
id: -1,
|
||||
name: 'Classic',
|
||||
},
|
||||
{
|
||||
colors: {
|
||||
slate: {
|
||||
25: '252 253 254',
|
||||
50: '248 250 252',
|
||||
100: '241 245 249',
|
||||
200: '226 232 240',
|
||||
300: '203 213 225',
|
||||
400: '148 163 184',
|
||||
500: '100 116 139',
|
||||
600: '71 85 105',
|
||||
700: '51 65 85',
|
||||
800: '30 41 59',
|
||||
900: '15 23 42',
|
||||
950: '2 6 23',
|
||||
},
|
||||
zinc: {
|
||||
50: `249 250 251`,
|
||||
100: `243 244 246`,
|
||||
200: `229 231 235`,
|
||||
300: `209 213 219`,
|
||||
400: `156 163 175`,
|
||||
500: `107 114 128`,
|
||||
600: `75 85 99`,
|
||||
700: '30 30 30',
|
||||
800: '22 22 22',
|
||||
900: '10 10 10',
|
||||
925: '0 0 0',
|
||||
950: `0 0 0`,
|
||||
},
|
||||
primary: {
|
||||
100: '241 245 249',
|
||||
900: '15 23 42',
|
||||
},
|
||||
other: {
|
||||
black: `0 0 0`,
|
||||
white: `255 255 255`,
|
||||
},
|
||||
},
|
||||
id: -2,
|
||||
name: 'AMOLED',
|
||||
},
|
||||
{
|
||||
colors: {
|
||||
zinc: {
|
||||
'50': '205 214 244',
|
||||
'100': '186 194 222',
|
||||
'200': '166 173 200',
|
||||
'300': '147 153 178',
|
||||
'400': '127 132 156',
|
||||
'500': '108 112 134',
|
||||
'600': '88 91 112',
|
||||
'700': '69 71 90',
|
||||
'800': '49 50 68',
|
||||
'900': '30 30 46',
|
||||
'925': '24 24 37',
|
||||
'950': '17 17 27',
|
||||
},
|
||||
primary: { '100': '166 227 161', '900': '114 135 253' },
|
||||
other: { white: '239 241 245' },
|
||||
slate: {
|
||||
'25': '239 241 245',
|
||||
'50': '230 233 239',
|
||||
'100': '220 224 232',
|
||||
'200': '204 208 218',
|
||||
'300': '188 192 204',
|
||||
'400': '172 176 190',
|
||||
'500': '140 143 161',
|
||||
'600': '124 127 147',
|
||||
'700': '108 111 133',
|
||||
'800': '92 95 119',
|
||||
'900': '76 79 105',
|
||||
'950': '76 79 105',
|
||||
},
|
||||
},
|
||||
id: -3,
|
||||
name: 'Catppuccin',
|
||||
},
|
||||
{
|
||||
colors: {
|
||||
slate: {
|
||||
25: '251 251 251',
|
||||
50: '242 242 242',
|
||||
100: '229 229 229',
|
||||
200: '226 226 226',
|
||||
300: '222 222 222',
|
||||
400: '154 153 150',
|
||||
500: '102 102 102',
|
||||
600: '51 51 51',
|
||||
700: '85 85 85',
|
||||
800: '51 51 51',
|
||||
900: '51 51 51',
|
||||
950: '7 7 7',
|
||||
},
|
||||
zinc: {
|
||||
50: '253 253 253',
|
||||
100: '244 244 244',
|
||||
200: '226 226 226',
|
||||
300: '213 213 213',
|
||||
400: '163 163 163',
|
||||
500: '114 114 114',
|
||||
600: '85 85 85',
|
||||
700: '78 78 78',
|
||||
800: '59 59 59',
|
||||
900: '42 42 42',
|
||||
925: '34 34 34',
|
||||
950: '29 29 29',
|
||||
},
|
||||
primary: {
|
||||
100: '241 245 249',
|
||||
900: '15 23 42',
|
||||
},
|
||||
other: {
|
||||
black: '0 0 0',
|
||||
white: '255 255 255',
|
||||
},
|
||||
},
|
||||
id: -4,
|
||||
name: 'Neutral',
|
||||
},
|
||||
]
|
||||
@@ -1,190 +0,0 @@
|
||||
import { browser } from '$app/environment'
|
||||
import { env } from '$env/dynamic/public'
|
||||
import { getDefaultTheme, presets } from './presets'
|
||||
|
||||
type ColorScheme = 'system' | 'light' | 'dark'
|
||||
|
||||
export interface ThemeData {
|
||||
scheme: ColorScheme
|
||||
themes: Theme[]
|
||||
currentTheme: number
|
||||
}
|
||||
|
||||
export interface Theme {
|
||||
id: number
|
||||
colors: ThemeColors
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface ThemeColors {
|
||||
[scheme: string]: {
|
||||
[key: string]: string
|
||||
}
|
||||
}
|
||||
|
||||
export function hexToRgb(value: string) {
|
||||
// Regular expression to match valid hex color codes
|
||||
const hexRegex = /^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
|
||||
|
||||
if (!hexRegex.test(value)) {
|
||||
return value // Not a valid hex color
|
||||
}
|
||||
|
||||
// Remove # if present
|
||||
let hex = value.replace('#', '')
|
||||
|
||||
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
||||
if (hex.length === 3) {
|
||||
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
|
||||
}
|
||||
|
||||
// Convert to RGB values
|
||||
const r = parseInt(hex.substring(0, 2), 16)
|
||||
const g = parseInt(hex.substring(2, 4), 16)
|
||||
const b = parseInt(hex.substring(4, 6), 16)
|
||||
|
||||
return `${r} ${g} ${b}`
|
||||
}
|
||||
|
||||
export function rgbToHex(rgbString: string): string {
|
||||
const rgb = rgbString.split(' ')
|
||||
|
||||
if (rgb.length !== 3) {
|
||||
return rgbString
|
||||
}
|
||||
|
||||
const [r, g, b] = rgb.map((val) => {
|
||||
const num = parseInt(val, 10)
|
||||
if (isNaN(num) || num < 0 || num > 255) {
|
||||
return 0
|
||||
}
|
||||
return num
|
||||
})
|
||||
|
||||
// Convert to hex and pad with zeros if necessary
|
||||
const toHex = (n: number) => n.toString(16).padStart(2, '0')
|
||||
|
||||
// Return the hex color code
|
||||
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
|
||||
}
|
||||
|
||||
$effect.root(() => {
|
||||
$effect(() => {
|
||||
if (browser) {
|
||||
const filteredThemes = theme.data.themes.filter((t) => t.id > 0)
|
||||
localStorage.setItem(
|
||||
'theme.data',
|
||||
JSON.stringify({
|
||||
...theme.data,
|
||||
themes: filteredThemes,
|
||||
}),
|
||||
)
|
||||
}
|
||||
})
|
||||
$effect(() => {
|
||||
if (browser) {
|
||||
const prefersDark = window.matchMedia(
|
||||
'(prefers-color-scheme: dark)',
|
||||
).matches
|
||||
|
||||
const html = document.querySelector('html')
|
||||
|
||||
if (theme.colorScheme == 'system')
|
||||
html?.classList.toggle('dark', prefersDark)
|
||||
else html?.classList.toggle('dark', theme.colorScheme === 'dark')
|
||||
|
||||
localStorage.setItem('colorScheme', theme.colorScheme)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const configuredColorScheme = env.PUBLIC_COLORSCHEME ?? 'system'
|
||||
|
||||
class ThemeState {
|
||||
constructor() {
|
||||
const localColorScheme: ColorScheme = browser
|
||||
? (localStorage.getItem('colorScheme') as ColorScheme) ||
|
||||
configuredColorScheme
|
||||
: (configuredColorScheme as ColorScheme)
|
||||
|
||||
this.#colorScheme = localColorScheme
|
||||
}
|
||||
|
||||
#data = $state<ThemeData>(
|
||||
loadTheme() ?? {
|
||||
scheme: 'system',
|
||||
themes: presets,
|
||||
currentTheme: 0,
|
||||
},
|
||||
)
|
||||
#current = $derived(
|
||||
this.#data.themes.find((i) => i.id == this.#data.currentTheme) ??
|
||||
getDefaultTheme(),
|
||||
)
|
||||
#colorScheme = $state<ColorScheme>(configuredColorScheme as ColorScheme)
|
||||
#vars = $derived(calculateVars(this.#current))
|
||||
|
||||
get current() {
|
||||
return this.#current
|
||||
}
|
||||
set current(value) {
|
||||
if (!value) return
|
||||
const index = this.#data.themes.findIndex((i) => i.id == value?.id)
|
||||
this.#data.themes[index] = value
|
||||
}
|
||||
|
||||
get colorScheme() {
|
||||
return this.#colorScheme
|
||||
}
|
||||
set colorScheme(value) {
|
||||
this.#colorScheme = value
|
||||
}
|
||||
|
||||
get vars() {
|
||||
return this.#vars
|
||||
}
|
||||
|
||||
get data() {
|
||||
return this.#data
|
||||
}
|
||||
set data(value) {
|
||||
this.#data = value
|
||||
}
|
||||
}
|
||||
|
||||
export const theme = new ThemeState()
|
||||
|
||||
export function calculateVars(theme: Theme) {
|
||||
let cssVariables = ''
|
||||
|
||||
for (const [scheme, colors] of Object.entries(theme.colors)) {
|
||||
for (const [key, value] of Object.entries(colors)) {
|
||||
cssVariables += `--c-${scheme[0]}-${key}:${hexToRgb(value)}; `
|
||||
}
|
||||
}
|
||||
|
||||
return cssVariables.trim()
|
||||
}
|
||||
|
||||
export const inDarkColorScheme = (): boolean => {
|
||||
if (browser) {
|
||||
return theme.colorScheme == 'system'
|
||||
? window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
: theme.colorScheme == 'dark'
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function loadTheme() {
|
||||
if (!browser) return
|
||||
const localTheme = localStorage.getItem('theme.data')
|
||||
|
||||
if (localTheme) {
|
||||
const data = JSON.parse(localTheme)
|
||||
if (!data) return
|
||||
data.themes = [...presets, ...data.themes]
|
||||
return data
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<script lang="ts">
|
||||
import { locale } from '$lib/app/i18n'
|
||||
|
||||
interface Props {
|
||||
number: number
|
||||
locale?: string
|
||||
options?: Intl.NumberFormatOptions
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
number,
|
||||
locale: localeToUse = $locale,
|
||||
options = {
|
||||
notation: 'compact',
|
||||
},
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<span class={clazz ?? ''}>
|
||||
{Intl.NumberFormat(localeToUse, options).format(number)}
|
||||
</span>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script lang="ts" module>
|
||||
export function formatRelativeDate(
|
||||
date: Date,
|
||||
options: Intl.RelativeTimeFormatOptions,
|
||||
locale?: string,
|
||||
relativeTo?: Date,
|
||||
) {
|
||||
try {
|
||||
const now = relativeTo?.getTime() ?? Date.now()
|
||||
|
||||
const diffInMillis = now - date.getTime()
|
||||
|
||||
const thresholds = [
|
||||
{ unit: 'second', threshold: 1000 },
|
||||
{ unit: 'minute', threshold: 60 * 1000 },
|
||||
{ unit: 'hour', threshold: 60 * 60 * 1000 },
|
||||
{ unit: 'day', threshold: 24 * 60 * 60 * 1000 },
|
||||
{ unit: 'week', threshold: 7 * 24 * 60 * 60 * 1000 },
|
||||
{ unit: 'month', threshold: 30 * 24 * 60 * 60 * 1000 },
|
||||
{ unit: 'year', threshold: 365 * 24 * 60 * 60 * 1000 },
|
||||
]
|
||||
|
||||
for (let i = thresholds.length - 1; i >= 0; i--) {
|
||||
if (diffInMillis >= thresholds[i].threshold) {
|
||||
const value = Math.round(diffInMillis / thresholds[i].threshold)
|
||||
|
||||
let language = locale ?? 'en'
|
||||
|
||||
if (settings.absoluteDates) {
|
||||
const rtf = new Intl.DateTimeFormat(language, {
|
||||
...options,
|
||||
timeStyle: 'short',
|
||||
dateStyle: 'short',
|
||||
})
|
||||
return rtf.format(date)
|
||||
} else {
|
||||
const rtf = new Intl.RelativeTimeFormat(language, options)
|
||||
return rtf.format(-value, thresholds[i].unit as 'second')
|
||||
}
|
||||
}
|
||||
}
|
||||
return 'Now'
|
||||
} catch {
|
||||
return 'Invalid Date'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { locale } from '$lib/app/i18n'
|
||||
import { settings } from '$lib/settings.svelte'
|
||||
|
||||
const toLocaleDateString = (date: Date): string => {
|
||||
try {
|
||||
return date.toLocaleString()
|
||||
} catch {
|
||||
return 'Invalid Date'
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
date: Date
|
||||
relativeTo?: Date | undefined
|
||||
options?: Intl.RelativeTimeFormatOptions
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
date,
|
||||
relativeTo = undefined,
|
||||
options = {
|
||||
numeric: 'always',
|
||||
style: 'narrow',
|
||||
},
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let dateTime = $derived(toLocaleDateString(date))
|
||||
</script>
|
||||
|
||||
<time datetime={dateTime} title={dateTime} class={clazz} {style}>
|
||||
{formatRelativeDate(date, options, $locale, relativeTo)}
|
||||
</time>
|
||||
@@ -0,0 +1,2 @@
|
||||
export const publishedToDate = (published: string): Date =>
|
||||
published.endsWith('Z') ? new Date(published) : new Date(`${published}Z`)
|
||||
@@ -0,0 +1,21 @@
|
||||
<script lang="ts">
|
||||
import DebugTree from '$lib/ui/util/debug/DebugTree.svelte'
|
||||
import { Modal } from 'mono-svelte'
|
||||
|
||||
interface Props {
|
||||
object: any
|
||||
open?: boolean
|
||||
title?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { object, open = $bindable(false), title }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
{#snippet customTitle()}
|
||||
<span>
|
||||
{#if title}{@render title()}{:else}Debug{/if}
|
||||
</span>
|
||||
{/snippet}
|
||||
<DebugTree {object} isParent={true} />
|
||||
</Modal>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script lang="ts">
|
||||
import DebugTree from './DebugTree.svelte'
|
||||
interface Props {
|
||||
object: any
|
||||
isParent?: boolean
|
||||
}
|
||||
|
||||
let { object, isParent = false }: Props = $props()
|
||||
</script>
|
||||
|
||||
<ul class:ml-4={!isParent} class="leading-8">
|
||||
{#each Object.keys(object) as key}
|
||||
<details open={false}>
|
||||
<summary class="cursor-pointer">
|
||||
<code>{key}</code>
|
||||
</summary>
|
||||
{#if typeof object[key] === 'object'}
|
||||
<DebugTree object={object[key]} isParent={false} />
|
||||
{:else}
|
||||
<pre class="break-words">{object[key]}</pre>
|
||||
{/if}
|
||||
</details>
|
||||
{/each}
|
||||
</ul>
|
||||
Reference in new issue
Block a user