migrate: convert most components to svelte 5
This commit is contained in:
1 parent
d670f39f0a
commit
10ef4123da
225 files changed
+5441
-3341
No files matched your search
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
interface PageScopedError {
|
||||
@@ -24,17 +24,19 @@
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { onDestroy } from 'svelte'
|
||||
|
||||
export let scope: string | undefined | null = undefined
|
||||
|
||||
$: scopedErrors = $errors.filter(
|
||||
(e) => e.scope == scope || e.scope == 'global'
|
||||
)
|
||||
|
||||
onDestroy(() => {
|
||||
clearErrorScope(scope)
|
||||
})
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
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}
|
||||
|
||||
@@ -1 +1,11 @@
|
||||
<slot {...$$restProps} />
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet<[any]>} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props & { [key: string]: any }} */
|
||||
let { children, ...rest } = $props()
|
||||
</script>
|
||||
|
||||
{@render children?.({ ...rest })}
|
||||
@@ -1,14 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { browser } from '$app/environment'
|
||||
import { tick } from 'svelte'
|
||||
|
||||
export let label: string | undefined = undefined
|
||||
export let value: string
|
||||
export let required: boolean = false
|
||||
let textarea: HTMLTextAreaElement = $state()
|
||||
|
||||
let textarea: HTMLTextAreaElement
|
||||
|
||||
$: adjustHeight(value)
|
||||
async function adjustHeight(value: string) {
|
||||
await tick()
|
||||
if (textarea) {
|
||||
@@ -16,8 +13,25 @@
|
||||
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
|
||||
}
|
||||
}
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
label?: string | undefined
|
||||
value: string
|
||||
required?: boolean
|
||||
class?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
label = undefined,
|
||||
value = $bindable(),
|
||||
required = false,
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
run(() => {
|
||||
adjustHeight(value)
|
||||
})
|
||||
</script>
|
||||
|
||||
<label class="w-full">
|
||||
@@ -31,11 +45,11 @@
|
||||
{/if}
|
||||
<textarea
|
||||
bind:this={textarea}
|
||||
on:input={() => adjustHeight(value)}
|
||||
oninput={() => adjustHeight(value)}
|
||||
bind:value
|
||||
{required}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
rows={1}
|
||||
class="font-semibold text-2xl focus:outline-none w-full bg-transparent resize-none {clazz}"
|
||||
/>
|
||||
></textarea>
|
||||
</label>
|
||||
@@ -13,9 +13,7 @@
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<Label text={label} class="mb-1">
|
||||
<slot name="label" />
|
||||
</Label>
|
||||
<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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
export const parseURL = (href: string) => {
|
||||
try {
|
||||
return new URL(href)
|
||||
@@ -9,25 +9,38 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export let href: string
|
||||
export let highlight: boolean = false
|
||||
export let nowrap: boolean = false
|
||||
interface Props {
|
||||
href: string
|
||||
highlight?: boolean
|
||||
nowrap?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
$: richURL = $$slots.default ? undefined : parseURL(href)
|
||||
let {
|
||||
href,
|
||||
highlight = false,
|
||||
nowrap = false,
|
||||
children,
|
||||
class: clazz = '',
|
||||
icon,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let richURL = $derived(children ? undefined : parseURL(href))
|
||||
</script>
|
||||
|
||||
<a
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
{href}
|
||||
class="{highlight
|
||||
? 'text-blue-500'
|
||||
: ''} hover:underline max-w-full inline-flex items-center gap-1 {clazz}"
|
||||
>
|
||||
<slot name="icon" />
|
||||
<slot>
|
||||
{@render icon?.()}
|
||||
{#if children}{@render children()}{:else}
|
||||
<span
|
||||
class="flex relative gap-0 {nowrap
|
||||
? 'w-full whitespace-nowrap overflow-hidden text-ellipsis text-xs'
|
||||
@@ -52,5 +65,5 @@
|
||||
{href}
|
||||
{/if}
|
||||
</span>
|
||||
</slot>
|
||||
{/if}
|
||||
</a>
|
||||
@@ -1,8 +1,15 @@
|
||||
<script lang="ts">
|
||||
export let value: number
|
||||
export let min: number = 0
|
||||
export let max: number = 100
|
||||
export let step: number = 1
|
||||
import { createBubbler } from 'svelte/legacy'
|
||||
|
||||
const bubble = createBubbler()
|
||||
interface Props {
|
||||
value: number
|
||||
min?: number
|
||||
max?: number
|
||||
step?: number
|
||||
}
|
||||
|
||||
let { value = $bindable(), min = 0, max = 100, step = 1 }: Props = $props()
|
||||
</script>
|
||||
|
||||
<input
|
||||
@@ -11,10 +18,10 @@
|
||||
{min}
|
||||
{max}
|
||||
{step}
|
||||
on:change
|
||||
on:click
|
||||
on:keydown
|
||||
on:keypress
|
||||
onchange={bubble('change')}
|
||||
onclick={bubble('click')}
|
||||
onkeydown={bubble('keydown')}
|
||||
onkeypress={bubble('keypress')}
|
||||
class="w-full appearance-none h-2 cursor-pointer bg-slate-100 dark:bg-zinc-800
|
||||
rounded-full range"
|
||||
/>
|
||||
|
||||
@@ -1,24 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
||||
import { Button } from 'mono-svelte'
|
||||
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
type T = $$Generic
|
||||
export let options: T[]
|
||||
export let disabled: boolean[] = []
|
||||
export let optionNames: string[] = []
|
||||
export let selected: T
|
||||
export let headless: boolean = false
|
||||
|
||||
let clazz: string = ''
|
||||
export let buttonClazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
options: T[]
|
||||
disabled?: boolean[]
|
||||
optionNames?: string[]
|
||||
selected: T
|
||||
headless?: boolean
|
||||
class?: string
|
||||
buttonClazz?: string
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
let {
|
||||
options,
|
||||
disabled = [],
|
||||
optionNames = [],
|
||||
selected = $bindable(),
|
||||
headless = false,
|
||||
class: clazz = '',
|
||||
buttonClazz = '',
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: T }>()
|
||||
|
||||
$: {
|
||||
run(() => {
|
||||
dispatcher('select', selected)
|
||||
}
|
||||
})
|
||||
|
||||
let containerClass = `
|
||||
flex flex-row rtl:flex-row-reverse items-center w-max max-w-full overflow-auto
|
||||
@@ -57,7 +72,7 @@
|
||||
{#each options as option, index}
|
||||
<button
|
||||
class={buttonClass(selected == option)}
|
||||
on:click|preventDefault={() => (selected = option)}
|
||||
onclick={preventDefault(() => (selected = option))}
|
||||
disabled={disabled[index] ?? false}
|
||||
type="button"
|
||||
>
|
||||
@@ -65,9 +80,9 @@
|
||||
{#if headless && option == selected}
|
||||
<div
|
||||
class="absolute -bottom-1 left-0 w-full border-b-2 rounded-t-sm border-black dark:border-white"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<slot {selected} />
|
||||
{@render children?.({ selected })}
|
||||
@@ -7,15 +7,28 @@
|
||||
import { Icon, XCircle, ServerStack } from 'svelte-hero-icons'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let type: 'community' | 'instance' = 'community'
|
||||
export let q: string = ''
|
||||
interface Props {
|
||||
type?: 'community' | 'instance'
|
||||
q?: string
|
||||
instance?: string | undefined
|
||||
listing_type?: ListingType
|
||||
showWhenEmpty?: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let instance: string | undefined = undefined
|
||||
export let listing_type: ListingType = 'Subscribed'
|
||||
export let showWhenEmpty: boolean = false
|
||||
let {
|
||||
type = 'community',
|
||||
q = $bindable(''),
|
||||
instance = undefined,
|
||||
listing_type = 'Subscribed',
|
||||
showWhenEmpty = false,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: Community | undefined }>()
|
||||
$: instances = type == 'instance' && getClient().getFederatedInstances()
|
||||
let instances = $derived(
|
||||
type == 'instance' && getClient().getFederatedInstances(),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if type == 'community'}
|
||||
@@ -35,33 +48,35 @@
|
||||
on:select
|
||||
bind:query={q}
|
||||
{showWhenEmpty}
|
||||
{...$$restProps}
|
||||
let:item
|
||||
let:select
|
||||
{...rest}
|
||||
>
|
||||
<div class="w-full h-full" slot="noresults">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton on:click={() => dispatcher('select', undefined)}>
|
||||
<Icon src={XCircle} size="16" mini />
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton on:click={() => 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 on:click={() => select(item)}>
|
||||
<Avatar url={item.icon} alt={item.title} width={24} />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None</span>
|
||||
<span>{item.title}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton on:click={() => select(item)}>
|
||||
<Avatar url={item.icon} alt={item.title} width={24} />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.title}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
{:else if type == 'instance'}
|
||||
<Search
|
||||
@@ -70,7 +85,7 @@
|
||||
|
||||
return q
|
||||
? (results.federated_instances?.linked || []).filter(
|
||||
(i) => i.software === 'lemmy' && i.domain.includes(q)
|
||||
(i) => i.software === 'lemmy' && i.domain.includes(q),
|
||||
)
|
||||
: []
|
||||
}}
|
||||
@@ -78,28 +93,30 @@
|
||||
on:select
|
||||
bind:query={q}
|
||||
{showWhenEmpty}
|
||||
{...$$restProps}
|
||||
let:item
|
||||
let:select
|
||||
{...rest}
|
||||
>
|
||||
<div class="w-full h-full" slot="noresults">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton on:click={() => dispatcher('select', undefined)}>
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton on:click={() => 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 on:click={() => select(item)}>
|
||||
<Icon src={ServerStack} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None (Start typing to search)</span>
|
||||
<span>{item.domain}</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton on:click={() => select(item)}>
|
||||
<Icon src={ServerStack} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.domain}</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
{/if}
|
||||
@@ -22,12 +22,21 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { optimizeImageURL } from './post/helpers'
|
||||
|
||||
export let site: SiteView
|
||||
export let taglines: Tagline[] | undefined = undefined
|
||||
export let admins: PersonView[] | undefined = undefined
|
||||
export let version: string | undefined = undefined
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
site: SiteView
|
||||
taglines?: Tagline[] | undefined
|
||||
admins?: PersonView[] | undefined
|
||||
version?: string | undefined
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
site,
|
||||
taglines = undefined,
|
||||
admins = undefined,
|
||||
version = undefined,
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<StickyCard class="w-full {clazz} text-slate-600 dark:text-zinc-400">
|
||||
@@ -45,13 +54,14 @@
|
||||
</div>
|
||||
{/if}
|
||||
<Entity name={site.site.name} label={new URL(site.site.actor_id).hostname}>
|
||||
<Avatar
|
||||
width={32}
|
||||
url={site.site.icon}
|
||||
alt={site.site.name}
|
||||
circle={false}
|
||||
slot="icon"
|
||||
/>
|
||||
{#snippet customIcon()}
|
||||
<Avatar
|
||||
width={32}
|
||||
url={site.site.icon}
|
||||
alt={site.site.name}
|
||||
circle={false}
|
||||
/>
|
||||
{/snippet}
|
||||
</Entity>
|
||||
<div class="flex flex-row gap-1 !border-0">
|
||||
<Button
|
||||
@@ -91,21 +101,25 @@
|
||||
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.about}>
|
||||
<span class="flex items-center gap-1 py-1 px-2" slot="title">
|
||||
<Icon src={InformationCircle} size="16" mini />
|
||||
{$t('cards.site.about')}
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span class="flex items-center gap-1 py-1 px-2">
|
||||
<Icon src={InformationCircle} size="16" mini />
|
||||
{$t('cards.site.about')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<Markdown source={site.site.description} />
|
||||
<div class="my-4" />
|
||||
<div class="my-4"></div>
|
||||
<Markdown source={site.site.sidebar} />
|
||||
</Expandable>
|
||||
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.stats}>
|
||||
<span class="flex items-center gap-1 py-1 px-2" slot="title">
|
||||
<Icon src={ChartBar} size="16" mini />
|
||||
{$t('cards.site.stats')}
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span class="flex items-center gap-1 py-1 px-2">
|
||||
<Icon src={ChartBar} size="16" mini />
|
||||
{$t('cards.site.stats')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<div class="flex flex-row gap-4 flex-wrap">
|
||||
<LabelStat
|
||||
label={$t('content.users')}
|
||||
@@ -128,10 +142,12 @@
|
||||
{#if admins}
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.team}>
|
||||
<span class="flex items-center gap-1 py-1 px-2" slot="title">
|
||||
<Icon src={UserGroup} size="16" mini />
|
||||
{$t('cards.site.admins')}
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span class="flex items-center gap-1 py-1 px-2">
|
||||
<Icon src={UserGroup} size="16" mini />
|
||||
{$t('cards.site.admins')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={admins.map((a) => ({
|
||||
id: a.person.id,
|
||||
@@ -146,7 +162,7 @@
|
||||
|
||||
{#if version}
|
||||
<div class="w-max">
|
||||
<Badge title="Lemmy version">
|
||||
<Badge label="Lemmy version">
|
||||
<Icon src={ServerStack} micro size="14" />
|
||||
{version}
|
||||
</Badge>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import {
|
||||
ArrowUp,
|
||||
Bookmark,
|
||||
@@ -30,25 +32,38 @@
|
||||
import { expoInOut, expoOut } from 'svelte/easing'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
|
||||
export let node: CommentNodeI
|
||||
export let postId: number
|
||||
export let op: boolean = false
|
||||
interface Props {
|
||||
node: CommentNodeI
|
||||
postId: number
|
||||
op?: boolean
|
||||
actions?: boolean
|
||||
meta?: boolean
|
||||
open?: boolean
|
||||
replying?: boolean
|
||||
contentClass?: string
|
||||
class?: string
|
||||
metaSuffix?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export let actions: boolean = true
|
||||
export let meta: boolean = true
|
||||
let {
|
||||
node = $bindable(),
|
||||
postId,
|
||||
op = false,
|
||||
actions = true,
|
||||
meta = true,
|
||||
open = $bindable(true),
|
||||
replying = $bindable(false),
|
||||
contentClass = '',
|
||||
class: clazz = '',
|
||||
metaSuffix,
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
export let open = true
|
||||
let editing = $state(false)
|
||||
let newComment = $state(node.comment_view.comment.content)
|
||||
|
||||
export let replying = false
|
||||
|
||||
let editing = false
|
||||
let newComment = node.comment_view.comment.content
|
||||
|
||||
let editingLoad = false
|
||||
|
||||
export let contentClass: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let editingLoad = $state(false)
|
||||
|
||||
async function save() {
|
||||
if (!$profile?.jwt || newComment.length <= 0) return
|
||||
@@ -84,13 +99,15 @@
|
||||
}
|
||||
})
|
||||
|
||||
let highlight = ''
|
||||
let highlight = $state('')
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
<Modal bind:open={editing}>
|
||||
<span slot="title">{$t('form.edit')}</span>
|
||||
<form on:submit|preventDefault={save} class="contents">
|
||||
{#snippet customTitle()}
|
||||
<span>{$t('form.edit')}</span>
|
||||
{/snippet}
|
||||
<form onsubmit={preventDefault(save)} class="contents">
|
||||
<CommentForm
|
||||
postId={node.comment_view.comment.id}
|
||||
bind:value={newComment}
|
||||
@@ -120,11 +137,11 @@
|
||||
>
|
||||
{#if meta}
|
||||
<button
|
||||
on:click={() => (open = !open)}
|
||||
onclick={() => (open = !open)}
|
||||
class="flex flex-row cursor-pointer gap-2 items-center group text-[13px] flex-wrap w-full
|
||||
z-0 group relative"
|
||||
>
|
||||
<slot name="meta-suffix" />
|
||||
{@render metaSuffix?.()}
|
||||
<div
|
||||
class="absolute opacity-0 -z-10 inset-0 group-hover:block group-hover:opacity-100
|
||||
bg-slate-100 dark:bg-zinc-900 group-hover:-inset-1 group-hover:-inset-x-2 rounded-full transition-all
|
||||
@@ -154,14 +171,14 @@
|
||||
avatar
|
||||
user={node.comment_view.creator}
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
{#snippet extraBadges()}
|
||||
{#if node.comment_view.creator_is_moderator}
|
||||
<ShieldIcon filled width={14} class="text-green-500" />
|
||||
{/if}
|
||||
{#if node.comment_view.creator_is_admin}
|
||||
<ShieldIcon filled width={14} class="text-red-500" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</UserLink>
|
||||
{#if op}
|
||||
<Icon mini size="16" src={Microphone} class="text-sky-600" />
|
||||
@@ -254,7 +271,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
<div class="bg-transparent dark:bg-transparent">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -30,14 +30,22 @@
|
||||
import { text } from '$lib/components/translate/translation'
|
||||
import { userSettings } from '$lib/settings'
|
||||
|
||||
export let comment: CommentView
|
||||
export let replying: boolean = false
|
||||
export let disabled = false
|
||||
interface Props {
|
||||
comment: CommentView
|
||||
replying?: boolean
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
comment = $bindable(),
|
||||
replying = $bindable(false),
|
||||
disabled = false,
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ edit: CommentView }>()
|
||||
|
||||
let reply = ''
|
||||
let translating = false
|
||||
let translating = $state(false)
|
||||
</script>
|
||||
|
||||
{#if translating}
|
||||
@@ -69,22 +77,19 @@
|
||||
<CommentModerationMenu bind:item={comment} />
|
||||
{/if}
|
||||
<Menu placement="bottom">
|
||||
<Button
|
||||
slot="target"
|
||||
title={$t('comment.actions.label')}
|
||||
color="tertiary"
|
||||
rounding="pill"
|
||||
size="square-sm"
|
||||
class="text-slate-700 dark:text-zinc-300"
|
||||
>
|
||||
<Icon
|
||||
src={EllipsisHorizontal}
|
||||
width={16}
|
||||
height={16}
|
||||
mini
|
||||
slot="prefix"
|
||||
/>
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
title={$t('comment.actions.label')}
|
||||
color="tertiary"
|
||||
rounding="pill"
|
||||
size="square-sm"
|
||||
class="text-slate-700 dark:text-zinc-300"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} width={16} height={16} mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('comment.actions.label')}</MenuDivider>
|
||||
<MenuButton
|
||||
on:click={() => {
|
||||
@@ -104,7 +109,9 @@
|
||||
translating = !translating
|
||||
}}
|
||||
>
|
||||
<Icon src={Language} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Language} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.translate')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -134,7 +141,7 @@
|
||||
comment.comment.deleted = await deleteItem(
|
||||
comment,
|
||||
!comment.comment.deleted,
|
||||
$profile.jwt
|
||||
$profile.jwt,
|
||||
)
|
||||
}}
|
||||
>
|
||||
@@ -154,5 +161,5 @@
|
||||
{/if}
|
||||
{/if}
|
||||
</Menu>
|
||||
<div class="flex-1 w-full" />
|
||||
<div class="flex-1 w-full"></div>
|
||||
</div>
|
||||
@@ -12,26 +12,39 @@
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Icon, XMark } from 'svelte-hero-icons'
|
||||
|
||||
export let postId: number
|
||||
export let parentId: number | undefined = undefined
|
||||
export let locked: boolean = false
|
||||
export let banned: boolean = false
|
||||
export let rows: number = 7
|
||||
export let placeholder: string | undefined = undefined
|
||||
|
||||
const dispatch = createEventDispatcher<{
|
||||
comment: CommentResponse
|
||||
confirm: string
|
||||
cancel: boolean
|
||||
}>()
|
||||
|
||||
export let value = ''
|
||||
export let actions = true
|
||||
interface Props {
|
||||
postId: number
|
||||
parentId?: number | undefined
|
||||
locked?: boolean
|
||||
banned?: boolean
|
||||
rows?: number
|
||||
placeholder?: string | undefined
|
||||
value?: string
|
||||
actions?: boolean
|
||||
preview?: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let previewAction = true
|
||||
export { previewAction as preview }
|
||||
let {
|
||||
postId,
|
||||
parentId = undefined,
|
||||
locked = false,
|
||||
banned = false,
|
||||
rows = 7,
|
||||
placeholder = undefined,
|
||||
value = $bindable(''),
|
||||
actions = true,
|
||||
preview: previewAction = true,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
let loading = $state(false)
|
||||
let preview = false
|
||||
|
||||
async function submit() {
|
||||
@@ -70,7 +83,7 @@
|
||||
</div>
|
||||
{:else}
|
||||
<MarkdownEditor
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
{rows}
|
||||
placeholder={locked
|
||||
? $t('comment.locked')
|
||||
@@ -88,7 +101,7 @@
|
||||
on:focus
|
||||
previewButton={previewAction}
|
||||
>
|
||||
<div class="flex-1" />
|
||||
<div class="flex-1"></div>
|
||||
{#if actions}
|
||||
<Button
|
||||
size="custom"
|
||||
|
||||
@@ -9,13 +9,23 @@
|
||||
import { Button, Material } from 'mono-svelte'
|
||||
import { ArrowUturnUp, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let comment: CommentView
|
||||
export let view = $userSettings.view
|
||||
export let community = false
|
||||
interface Props {
|
||||
comment: CommentView
|
||||
view?: any
|
||||
community?: boolean
|
||||
meta?: boolean
|
||||
class?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let meta: boolean = true
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
comment,
|
||||
view = $userSettings.view,
|
||||
community = false,
|
||||
meta = true,
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Material
|
||||
@@ -68,7 +78,7 @@
|
||||
node={{ children: [], comment_view: comment, depth: 1, ui: {} }}
|
||||
replying={false}
|
||||
{meta}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
/>
|
||||
</div>
|
||||
</Material>
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import type { CommentNodeI } from './comments'
|
||||
import { createWindowVirtualizer } from '@tanstack/svelte-virtual'
|
||||
@@ -6,31 +8,37 @@
|
||||
import { browser } from '$app/environment'
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
export let nodes: CommentNodeI[]
|
||||
export let post: Post
|
||||
export let scrollTo: string | undefined
|
||||
interface Props {
|
||||
nodes: CommentNodeI[]
|
||||
post: Post
|
||||
scrollTo: string | undefined
|
||||
}
|
||||
|
||||
let virtualListEl: HTMLElement | undefined = undefined
|
||||
let { nodes, post, scrollTo }: Props = $props()
|
||||
|
||||
$: virtualizer = createWindowVirtualizer({
|
||||
count: nodes.length,
|
||||
estimateSize: () => 30,
|
||||
scrollMargin: virtualListEl?.offsetTop,
|
||||
initialRect: {
|
||||
height: 1500,
|
||||
width: 99999,
|
||||
},
|
||||
overscan: 5,
|
||||
})
|
||||
let virtualListEl: HTMLElement | undefined = $state(undefined)
|
||||
|
||||
let virtualItemEls: HTMLElement[] = []
|
||||
let virtualizer = $derived(
|
||||
createWindowVirtualizer({
|
||||
count: nodes.length,
|
||||
estimateSize: () => 30,
|
||||
scrollMargin: virtualListEl?.offsetTop,
|
||||
initialRect: {
|
||||
height: 1500,
|
||||
width: 99999,
|
||||
},
|
||||
overscan: 5,
|
||||
}),
|
||||
)
|
||||
|
||||
$: items = $virtualizer.getVirtualItems()
|
||||
let virtualItemEls: HTMLElement[] = $state([])
|
||||
|
||||
$: {
|
||||
let items = $derived($virtualizer.getVirtualItems())
|
||||
|
||||
run(() => {
|
||||
if (virtualItemEls.length)
|
||||
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
|
||||
}
|
||||
})
|
||||
|
||||
onMount(() => {
|
||||
if (scrollTo) {
|
||||
|
||||
@@ -18,10 +18,19 @@
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
export let vote: number = 0
|
||||
export let upvotes: number
|
||||
export let downvotes: number
|
||||
export let commentId: number
|
||||
interface Props {
|
||||
vote?: number
|
||||
upvotes: number
|
||||
downvotes: number
|
||||
commentId: number
|
||||
}
|
||||
|
||||
let {
|
||||
vote = $bindable(0),
|
||||
upvotes = $bindable(),
|
||||
downvotes = $bindable(),
|
||||
commentId,
|
||||
}: Props = $props()
|
||||
|
||||
const castVote = async (newVote: number) => {
|
||||
if (!$profile?.jwt) {
|
||||
@@ -42,7 +51,7 @@
|
||||
class="h-full flex items-center overflow-hidden {buttonColor.ghost} rounded-full hover:bg-transparent"
|
||||
>
|
||||
<button
|
||||
on:click={() => castVote(vote == 1 ? 0 : 1)}
|
||||
onclick={() => castVote(vote == 1 ? 0 : 1)}
|
||||
class="flex items-center gap-0.5 transition-colors px-1.5 h-full
|
||||
{vote == 1
|
||||
? shouldShowVoteColor(vote, 'upvotes')
|
||||
@@ -65,7 +74,7 @@
|
||||
class="border-l h-4 w-0 !p-0 border-slate-200 dark:border-zinc-800"
|
||||
></div>
|
||||
<button
|
||||
on:click={() => castVote(vote == -1 ? 0 : -1)}
|
||||
onclick={() => castVote(vote == -1 ? 0 : -1)}
|
||||
class="flex flex-row-reverse items-center gap-0.5 h-full transition-colors border-0 px-1.5
|
||||
{vote == -1
|
||||
? shouldShowVoteColor(vote, 'downvotes')
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import Comments from './Comments.svelte'
|
||||
import Comment from './Comment.svelte'
|
||||
import { buildCommentsTree, type CommentNodeI } from './comments'
|
||||
import { page } from '$app/stores'
|
||||
@@ -22,11 +23,15 @@
|
||||
import { t } from '$lib/translations'
|
||||
import { browser } from '$app/environment'
|
||||
|
||||
export let nodes: CommentNodeI[]
|
||||
export let isParent: boolean
|
||||
export let post: Post
|
||||
interface Props {
|
||||
nodes: CommentNodeI[]
|
||||
isParent: boolean
|
||||
post: Post
|
||||
}
|
||||
|
||||
let hydrated = false
|
||||
let { nodes = $bindable(), isParent, post }: Props = $props()
|
||||
|
||||
let hydrated = $state(false)
|
||||
|
||||
onMount(() => {
|
||||
hydrated = true
|
||||
@@ -74,7 +79,7 @@
|
||||
// 0.18.2 -> 0.18.3 broke this
|
||||
// so i'm adding this check
|
||||
const treeParent = tree.find(
|
||||
(c) => c.comment_view.comment.id == parent.comment_view.comment.id
|
||||
(c) => c.comment_view.comment.id == parent.comment_view.comment.id,
|
||||
)
|
||||
|
||||
if (treeParent) {
|
||||
@@ -113,10 +118,10 @@
|
||||
? 'divide-y dark:divide-zinc-900 divide-slate-100'
|
||||
: ' border-slate-200 dark:border-zinc-800 my-1'}
|
||||
>
|
||||
{#each nodes as node (node.comment_view.comment.id)}
|
||||
{#each nodes as node, index (node.comment_view.comment.id)}
|
||||
<Comment
|
||||
postId={post.id}
|
||||
bind:node
|
||||
bind:node={nodes[index]}
|
||||
bind:open={node.ui.open}
|
||||
op={post.creator_id == node.comment_view.creator.id}
|
||||
contentClass="pl-3 {node.children.length > 0 ||
|
||||
@@ -125,7 +130,7 @@
|
||||
: ''} ml-3 border-slate-200 dark:border-zinc-800"
|
||||
>
|
||||
{#if node.children?.length > 0}
|
||||
<svelte:self {post} bind:nodes={node.children} isParent={false} />
|
||||
<Comments {post} bind:nodes={nodes[index].children} isParent={false} />
|
||||
{/if}
|
||||
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
|
||||
<svelte:element
|
||||
@@ -143,7 +148,7 @@
|
||||
on:click={() => {
|
||||
if (node.depth > 4) {
|
||||
goto(
|
||||
`/comment/${$page.params.instance}/${node.comment_view.comment.id}#comments`
|
||||
`/comment/${$page.params.instance}/${node.comment_view.comment.id}#comments`,
|
||||
)
|
||||
} else {
|
||||
node.loading = true
|
||||
@@ -151,13 +156,14 @@
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Icon
|
||||
src={ArrowDownCircle}
|
||||
micro
|
||||
size="16"
|
||||
slot="prefix"
|
||||
class="text-primary-900 dark:text-primary-100"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={ArrowDownCircle}
|
||||
micro
|
||||
size="16"
|
||||
class="text-primary-900 dark:text-primary-100"
|
||||
/>
|
||||
{/snippet}
|
||||
{$t('comment.more', {
|
||||
// @ts-ignore
|
||||
comments: node.comment_view.counts.child_count,
|
||||
|
||||
@@ -28,7 +28,7 @@ function getDepthFromComment(comment?: Comment): number | undefined {
|
||||
export function buildCommentsTree(
|
||||
comments: CommentView[],
|
||||
baseDepth: number = 0,
|
||||
filter: (c: CommentView) => boolean = (c) => true
|
||||
filter: (c: CommentView) => boolean = (c) => true,
|
||||
): CommentNodeI[] {
|
||||
const start = performance.now()
|
||||
const map = new Map<number, CommentNodeI>()
|
||||
@@ -81,7 +81,7 @@ export function buildCommentsTree(
|
||||
|
||||
export function searchCommentTree(
|
||||
tree: CommentNodeI[],
|
||||
id: number
|
||||
id: number,
|
||||
): CommentNodeI | undefined {
|
||||
for (const node of tree) {
|
||||
if (node.comment_view.comment.id === id) {
|
||||
@@ -102,7 +102,7 @@ export function searchCommentTree(
|
||||
export function insertCommentIntoTree(
|
||||
tree: CommentNodeI[],
|
||||
cv: CommentView,
|
||||
parentComment: boolean
|
||||
parentComment: boolean,
|
||||
) {
|
||||
// Building a fake node to be used for later
|
||||
const node: CommentNodeI = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
export async function block(id: number, block: boolean) {
|
||||
try {
|
||||
const loading = toast({
|
||||
@@ -111,13 +111,10 @@
|
||||
import Entity from '$lib/components/ui/Entity.svelte'
|
||||
import { userSettings } from '$lib/settings'
|
||||
|
||||
export let community_view: CommunityView
|
||||
export let moderators: CommunityModeratorView[] = []
|
||||
|
||||
let loading = {
|
||||
let loading = $state({
|
||||
blocking: false,
|
||||
subscribing: false,
|
||||
}
|
||||
})
|
||||
|
||||
async function subscribe() {
|
||||
if (!$profile?.jwt) return
|
||||
@@ -140,8 +137,17 @@
|
||||
|
||||
loading.subscribing = false
|
||||
}
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
community_view: CommunityView
|
||||
moderators?: CommunityModeratorView[]
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
community_view = $bindable(),
|
||||
moderators = [],
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<StickyCard class="min-w-full pt-0 text-slate-600 dark:text-zinc-400 {clazz}">
|
||||
@@ -149,34 +155,39 @@
|
||||
name={community_view.community.title}
|
||||
label="!{fullCommunityName(
|
||||
community_view.community.name,
|
||||
community_view.community.actor_id
|
||||
community_view.community.actor_id,
|
||||
)}"
|
||||
>
|
||||
<Avatar
|
||||
width={32}
|
||||
url={community_view.community.icon}
|
||||
alt={community_view.community.name}
|
||||
circle={false}
|
||||
slot="icon"
|
||||
/>
|
||||
{#snippet customIcon()}
|
||||
<Avatar
|
||||
width={32}
|
||||
url={community_view.community.icon}
|
||||
alt={community_view.community.name}
|
||||
circle={false}
|
||||
/>
|
||||
{/snippet}
|
||||
</Entity>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.about} class="!pt-0">
|
||||
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
|
||||
<Icon src={InformationCircle} size="15" mini />
|
||||
{$t('cards.site.about')}
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span class="py-1 px-1 flex gap-1 items-center">
|
||||
<Icon src={InformationCircle} size="15" mini />
|
||||
{$t('cards.site.about')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<Markdown source={community_view.community.description} />
|
||||
</Expandable>
|
||||
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.stats}>
|
||||
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
|
||||
<Icon src={ChartBar} size="15" mini />
|
||||
{$t('cards.site.stats')}
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span class="py-1 px-1 flex gap-1 items-center">
|
||||
<Icon src={ChartBar} size="15" mini />
|
||||
{$t('cards.site.stats')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<div class="flex flex-row gap-4 flex-wrap">
|
||||
<LabelStat
|
||||
label={$t('cards.community.members')}
|
||||
@@ -194,10 +205,12 @@
|
||||
{#if moderators && moderators.length > 0}
|
||||
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
|
||||
<Expandable bind:open={$userSettings.expand.team}>
|
||||
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
|
||||
<ShieldIcon width={15} filled />
|
||||
{$t('cards.community.moderators')}
|
||||
</span>
|
||||
{#snippet title()}
|
||||
<span class="py-1 px-1 flex gap-1 items-center">
|
||||
<ShieldIcon width={15} filled />
|
||||
{$t('cards.community.moderators')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={moderators.map((m) => ({
|
||||
id: m.moderator.id,
|
||||
@@ -224,12 +237,13 @@
|
||||
on:click={subscribe}
|
||||
class="flex-1 relative z-[inherit]"
|
||||
>
|
||||
<Icon
|
||||
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
||||
mini
|
||||
size="16"
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
|
||||
mini
|
||||
size="16"
|
||||
/>
|
||||
{/snippet}
|
||||
{community_view.subscribed == 'Subscribed' ||
|
||||
community_view.subscribed == 'Pending'
|
||||
? $t('cards.community.subscribed')
|
||||
@@ -240,17 +254,23 @@
|
||||
<Button
|
||||
href="/c/{fullCommunityName(
|
||||
community_view.community.name,
|
||||
community_view.community.actor_id
|
||||
community_view.community.actor_id,
|
||||
)}/settings"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Cog6Tooth} mini size="16" slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Cog6Tooth} mini size="16" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
<Menu placement="top-end">
|
||||
<Button size="square-md" slot="target" class="ml-auto">
|
||||
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button size="square-md" class="ml-auto">
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuButton href="/modlog?community={community_view.community.id}">
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
{$t('cards.community.modlog')}
|
||||
@@ -262,7 +282,9 @@
|
||||
on:click={() =>
|
||||
block(community_view.community.id, !community_view.blocked)}
|
||||
>
|
||||
<Icon src={NoSymbol} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={NoSymbol} size="16" mini />
|
||||
{/snippet}
|
||||
{community_view.blocked
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
@@ -273,7 +295,9 @@
|
||||
size="lg"
|
||||
on:click={() => blockInstance(community_view.community.instance_id)}
|
||||
>
|
||||
<Icon src={BuildingOffice2} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={BuildingOffice2} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -301,7 +325,9 @@
|
||||
type: 'error',
|
||||
})}
|
||||
>
|
||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
@@ -15,31 +17,39 @@
|
||||
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
|
||||
import Select from 'mono-svelte/forms/Select.svelte'
|
||||
|
||||
/**
|
||||
* The community ID to edit.
|
||||
*/
|
||||
export let edit: number | undefined = undefined
|
||||
|
||||
export let formData: {
|
||||
name: string
|
||||
displayName: string
|
||||
icon?: string
|
||||
banner?: string
|
||||
sidebar?: string
|
||||
nsfw: boolean
|
||||
postsLockedToModerators: boolean
|
||||
submitting: boolean
|
||||
visibility: 'Public' | 'LocalOnly'
|
||||
} = {
|
||||
name: '',
|
||||
displayName: '',
|
||||
sidebar: '',
|
||||
nsfw: false,
|
||||
postsLockedToModerators: false,
|
||||
submitting: false,
|
||||
visibility: 'Public',
|
||||
interface Props {
|
||||
/**
|
||||
* The community ID to edit.
|
||||
*/
|
||||
edit?: number | undefined
|
||||
formData?: {
|
||||
name: string
|
||||
displayName: string
|
||||
icon?: string
|
||||
banner?: string
|
||||
sidebar?: string
|
||||
nsfw: boolean
|
||||
postsLockedToModerators: boolean
|
||||
submitting: boolean
|
||||
visibility: 'Public' | 'LocalOnly'
|
||||
}
|
||||
formtitle?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
edit = undefined,
|
||||
formData = $bindable({
|
||||
name: '',
|
||||
displayName: '',
|
||||
sidebar: '',
|
||||
nsfw: false,
|
||||
postsLockedToModerators: false,
|
||||
submitting: false,
|
||||
visibility: 'Public',
|
||||
}),
|
||||
formtitle,
|
||||
}: Props = $props()
|
||||
|
||||
async function submit() {
|
||||
if (!$profile?.jwt) return
|
||||
if ((!edit && formData.name == '') || formData.displayName == '') return
|
||||
@@ -103,7 +113,7 @@
|
||||
goto(
|
||||
`/c/${res.community_view.community.name}@${
|
||||
new URL(res.community_view.community.actor_id).hostname
|
||||
}`
|
||||
}`,
|
||||
)
|
||||
} catch (err) {
|
||||
toast({
|
||||
@@ -115,19 +125,19 @@
|
||||
formData.submitting = false
|
||||
}
|
||||
|
||||
let uploading = {
|
||||
let uploading = $state({
|
||||
banner: false,
|
||||
icon: false,
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<form
|
||||
on:submit|preventDefault={submit}
|
||||
onsubmit={preventDefault(submit)}
|
||||
class="flex flex-col gap-4 h-full w-full"
|
||||
>
|
||||
<slot name="formtitle">
|
||||
{#if formtitle}{@render formtitle()}{:else}
|
||||
<Header>{$t('routes.createCommunity')}</Header>
|
||||
</slot>
|
||||
{/if}
|
||||
<TextInput
|
||||
required
|
||||
label={$t('form.name')}
|
||||
@@ -147,7 +157,7 @@
|
||||
<Label>{$t('routes.admin.config.icon')}</Label>
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => (uploading.icon = !uploading.icon)}
|
||||
onclick={() => (uploading.icon = !uploading.icon)}
|
||||
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
||||
>
|
||||
{#if formData.icon}
|
||||
@@ -175,7 +185,7 @@
|
||||
<Label>{$t('routes.admin.config.banner')}</Label>
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => (uploading.banner = !uploading.banner)}
|
||||
onclick={() => (uploading.banner = !uploading.banner)}
|
||||
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
||||
>
|
||||
{#if formData.banner}
|
||||
|
||||
@@ -31,13 +31,23 @@
|
||||
import { isAdmin } from '../moderation/moderation'
|
||||
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
|
||||
|
||||
export let community: Community
|
||||
export let subscribed: SubscribedType
|
||||
export let counts: CommunityAggregates | undefined = undefined
|
||||
export let moderators: CommunityModeratorView[] = []
|
||||
export let blocked: boolean = false
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
community: Community
|
||||
subscribed: SubscribedType
|
||||
counts?: CommunityAggregates | undefined
|
||||
moderators?: CommunityModeratorView[]
|
||||
blocked?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
community = $bindable(),
|
||||
subscribed = $bindable(),
|
||||
counts = undefined,
|
||||
moderators = [],
|
||||
blocked = false,
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<EntityHeader
|
||||
@@ -71,27 +81,28 @@
|
||||
bio={community.description}
|
||||
class={clazz}
|
||||
>
|
||||
<button
|
||||
on:click={() => {
|
||||
navigator?.clipboard?.writeText?.(
|
||||
`!${fullCommunityName(community.name, community.actor_id)}`
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="text-sm flex gap-0 items-center"
|
||||
slot="nameDetail"
|
||||
>
|
||||
!{fullCommunityName(community.name, community.actor_id)}
|
||||
</button>
|
||||
{#snippet nameDetail()}
|
||||
<button
|
||||
onclick={() => {
|
||||
navigator?.clipboard?.writeText?.(
|
||||
`!${fullCommunityName(community.name, community.actor_id)}`,
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="text-sm flex gap-0 items-center"
|
||||
>
|
||||
!{fullCommunityName(community.name, community.actor_id)}
|
||||
</button>
|
||||
{/snippet}
|
||||
{#if moderators.length > 0}
|
||||
<Expandable
|
||||
class="border rounded-xl bg-white/50 dark:bg-zinc-900/50 w-full p-3 px-4
|
||||
dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text-zinc-300 transition-colors"
|
||||
>
|
||||
<svelte:fragment slot="title">
|
||||
{#snippet title()}
|
||||
<ShieldIcon width={15} filled />
|
||||
{$t('cards.community.moderators')}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
<ItemList
|
||||
items={moderators.map((m) => ({
|
||||
id: m.moderator.id,
|
||||
@@ -114,30 +125,32 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
counts: counts ?? {},
|
||||
subscribed: subscribed,
|
||||
}}
|
||||
let:subscribe
|
||||
let:subscribing
|
||||
>
|
||||
<Button
|
||||
disabled={subscribing}
|
||||
loading={subscribing}
|
||||
size="lg"
|
||||
color={subscribed == 'NotSubscribed' ? 'primary' : 'secondary'}
|
||||
on:click={async () => {
|
||||
subscribed =
|
||||
(await subscribe())?.community_view.subscribed ?? 'NotSubscribed'
|
||||
}}
|
||||
class="flex-1 relative z-[inherit]"
|
||||
>
|
||||
<Icon
|
||||
src={subscribed != 'NotSubscribed' ? Check : Plus}
|
||||
micro
|
||||
size="16"
|
||||
slot="prefix"
|
||||
/>
|
||||
{subscribed == 'Subscribed' || subscribed == 'Pending'
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
{#snippet children({ subscribe, subscribing })}
|
||||
<Button
|
||||
disabled={subscribing}
|
||||
loading={subscribing}
|
||||
size="lg"
|
||||
color={subscribed == 'NotSubscribed' ? 'primary' : 'secondary'}
|
||||
on:click={async () => {
|
||||
subscribed =
|
||||
(await subscribe())?.community_view.subscribed ??
|
||||
'NotSubscribed'
|
||||
}}
|
||||
class="flex-1 relative z-[inherit]"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={subscribed != 'NotSubscribed' ? Check : Plus}
|
||||
micro
|
||||
size="16"
|
||||
/>
|
||||
{/snippet}
|
||||
{subscribed == 'Subscribed' || subscribed == 'Pending'
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Subscribe>
|
||||
{/if}
|
||||
|
||||
@@ -150,7 +163,7 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
rounding="xl"
|
||||
href="/c/{fullCommunityName(
|
||||
community.name,
|
||||
community.actor_id
|
||||
community.actor_id,
|
||||
)}/settings"
|
||||
style="height: 38px; width: 38px;"
|
||||
>
|
||||
@@ -158,14 +171,13 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
</Button>
|
||||
{/if}
|
||||
<Menu placement="top-end">
|
||||
<Button
|
||||
rounding="xl"
|
||||
size="custom"
|
||||
slot="target"
|
||||
style="height: 38px; width: 38px;"
|
||||
>
|
||||
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button rounding="xl" size="custom" style="height: 38px; width: 38px;">
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuButton href="/modlog?community={community.id}">
|
||||
<Icon src={Newspaper} size="16" mini />
|
||||
{$t('cards.community.modlog')}
|
||||
@@ -176,7 +188,9 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
size="lg"
|
||||
on:click={() => block(community.id, !blocked)}
|
||||
>
|
||||
<Icon src={NoSymbol} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={NoSymbol} size="16" mini />
|
||||
{/snippet}
|
||||
{blocked
|
||||
? $t('cards.community.unblock')
|
||||
: $t('cards.community.block')}
|
||||
@@ -187,7 +201,9 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
size="lg"
|
||||
on:click={() => blockInstance(community.instance_id)}
|
||||
>
|
||||
<Icon src={BuildingOffice2} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={BuildingOffice2} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('cards.community.blockInstance')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -215,7 +231,9 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
|
||||
type: 'error',
|
||||
})}
|
||||
>
|
||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -23,13 +23,22 @@
|
||||
import { t } from '$lib/translations'
|
||||
import Entity from '$lib/components/ui/Entity.svelte'
|
||||
|
||||
export let community: CommunityView
|
||||
export let view: 'cozy' | 'compact' = 'compact'
|
||||
export let showCounts: boolean = true
|
||||
let showInfo = $state(false)
|
||||
interface Props {
|
||||
community: CommunityView
|
||||
view?: 'cozy' | 'compact'
|
||||
showCounts?: boolean
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let showInfo = false
|
||||
let clazz: string = 'py-4 flex flex-col gap-4 text-sm max-w-full relative'
|
||||
export { clazz as class }
|
||||
let {
|
||||
community = $bindable(),
|
||||
view = 'compact',
|
||||
showCounts = true,
|
||||
class: clazz = 'py-4 flex flex-col gap-4 text-sm max-w-full relative',
|
||||
icon,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if showInfo}
|
||||
@@ -48,7 +57,7 @@
|
||||
<a
|
||||
href="/c/{fullCommunityName(
|
||||
community.community.name,
|
||||
community.community.actor_id
|
||||
community.community.actor_id,
|
||||
)}"
|
||||
class="flex-1 w-full overflow-hidden"
|
||||
data-sveltekit-preload-data="tap"
|
||||
@@ -58,13 +67,13 @@
|
||||
? 'flex-col gap-2'
|
||||
: 'flex-row'} gap-2 items-center"
|
||||
>
|
||||
<slot name="icon">
|
||||
{#if icon}{@render icon()}{:else}
|
||||
<Avatar
|
||||
url={community.community.icon}
|
||||
width={32}
|
||||
alt={community.community.name}
|
||||
/>
|
||||
</slot>
|
||||
{/if}
|
||||
<div
|
||||
class="flex flex-col overflow-hidden whitespace-nowrap flex-1 min-w-0 flex-shrink"
|
||||
>
|
||||
@@ -92,50 +101,55 @@
|
||||
<Button size="square-md" on:click={() => (showInfo = !showInfo)}>
|
||||
<Icon src={InformationCircle} size="16" micro />
|
||||
</Button>
|
||||
<Subscribe {community} let:subscribe let:subscribing>
|
||||
<Button
|
||||
disabled={subscribing || !$profile?.jwt}
|
||||
loading={subscribing}
|
||||
on:click={async () => {
|
||||
const res = await subscribe()
|
||||
<Subscribe {community}>
|
||||
{#snippet children({ subscribe, subscribing })}
|
||||
<Button
|
||||
disabled={subscribing || !$profile?.jwt}
|
||||
loading={subscribing}
|
||||
on:click={async () => {
|
||||
const res = await subscribe()
|
||||
|
||||
if (res) {
|
||||
const newSubscribed =
|
||||
res.community_view.subscribed != 'NotSubscribed'
|
||||
? 'Subscribed'
|
||||
: 'NotSubscribed'
|
||||
if (res) {
|
||||
const newSubscribed =
|
||||
res.community_view.subscribed != 'NotSubscribed'
|
||||
? 'Subscribed'
|
||||
: 'NotSubscribed'
|
||||
|
||||
community.subscribed = newSubscribed
|
||||
addSubscription(
|
||||
community.community,
|
||||
newSubscribed == 'Subscribed'
|
||||
)
|
||||
}
|
||||
}}
|
||||
size="custom"
|
||||
title={isSubscribed(community.subscribed)
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
color={isSubscribed(community.subscribed) ? 'elevatedLow' : 'primary'}
|
||||
class="{isSubscribed(community.subscribed)
|
||||
? 'text-slate-600 dark:text-zinc-400'
|
||||
: ''}
|
||||
aspect-square h-8 @md:px-2 @md:min-w-32 @md:aspect-auto"
|
||||
>
|
||||
<Icon
|
||||
src={isSubscribed(community.subscribed) ? Check : Plus}
|
||||
size="16"
|
||||
micro
|
||||
slot="prefix"
|
||||
/>
|
||||
<span class="hidden @md:block">
|
||||
{#if isSubscribed(community.subscribed)}
|
||||
{$t('cards.community.subscribed')}
|
||||
{:else}
|
||||
{$t('cards.community.subscribe')}
|
||||
{/if}
|
||||
</span>
|
||||
</Button>
|
||||
community.subscribed = newSubscribed
|
||||
addSubscription(
|
||||
community.community,
|
||||
newSubscribed == 'Subscribed',
|
||||
)
|
||||
}
|
||||
}}
|
||||
size="custom"
|
||||
title={isSubscribed(community.subscribed)
|
||||
? $t('cards.community.subscribed')
|
||||
: $t('cards.community.subscribe')}
|
||||
color={isSubscribed(community.subscribed)
|
||||
? 'elevatedLow'
|
||||
: 'primary'}
|
||||
class="{isSubscribed(community.subscribed)
|
||||
? 'text-slate-600 dark:text-zinc-400'
|
||||
: ''}
|
||||
aspect-square h-8 @md:px-2 @md:min-w-32 @md:aspect-auto"
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon
|
||||
src={isSubscribed(community.subscribed) ? Check : Plus}
|
||||
size="16"
|
||||
micro
|
||||
/>
|
||||
{/snippet}
|
||||
<span class="hidden @md:block">
|
||||
{#if isSubscribed(community.subscribed)}
|
||||
{$t('cards.community.subscribed')}
|
||||
{:else}
|
||||
{$t('cards.community.subscribe')}
|
||||
{/if}
|
||||
</span>
|
||||
</Button>
|
||||
{/snippet}
|
||||
</Subscribe>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,25 +5,37 @@
|
||||
import type { Community } from 'lemmy-js-client'
|
||||
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let community: Community
|
||||
|
||||
export let avatar: boolean = false
|
||||
export let name: boolean = true
|
||||
export let avatarSize: number = 24
|
||||
export let showInstance: boolean = $userSettings.showInstances.community
|
||||
export let displayName: boolean = true
|
||||
|
||||
export let badges = {
|
||||
nsfw: false,
|
||||
interface Props {
|
||||
community: Community
|
||||
avatar?: boolean
|
||||
name?: boolean
|
||||
avatarSize?: number
|
||||
showInstance?: boolean
|
||||
displayName?: boolean
|
||||
badges?: any
|
||||
class?: string
|
||||
instanceClass?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let clazz: string = ''
|
||||
export let instanceClass: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
community,
|
||||
avatar = false,
|
||||
name = true,
|
||||
avatarSize = 24,
|
||||
showInstance = $userSettings.showInstances.community,
|
||||
displayName = true,
|
||||
badges = {
|
||||
nsfw: false,
|
||||
},
|
||||
class: clazz = '',
|
||||
instanceClass = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<a
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class="items-center flex flex-row gap-2 hover:underline max-w-full min-w-0 {clazz}"
|
||||
href="/c/{community.name}@{new URL(community.actor_id).hostname}"
|
||||
data-sveltekit-preload-data="tap"
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import type { Community } from 'lemmy-js-client'
|
||||
|
||||
export let community: Community
|
||||
interface Props {
|
||||
community: Community
|
||||
}
|
||||
|
||||
let { community }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row gap-3 items-center">
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { page } from '$app/stores'
|
||||
import { profile } from '$lib/auth'
|
||||
import { userSettings } from '$lib/settings'
|
||||
@@ -14,36 +16,51 @@
|
||||
import { amModOfAny } from '../moderation/moderation'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
export let selected: string
|
||||
export let navigate: boolean = true
|
||||
export let changeDefault: boolean = false
|
||||
export let showLabel: boolean = true
|
||||
interface Props {
|
||||
selected: string
|
||||
navigate?: boolean
|
||||
changeDefault?: boolean
|
||||
showLabel?: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let feed: string = selected
|
||||
$: feed = selected
|
||||
$: changeDefault
|
||||
? ($userSettings.defaultSort.feed = selected as
|
||||
| 'All'
|
||||
| 'Subscribed'
|
||||
| 'Local')
|
||||
: undefined
|
||||
let {
|
||||
selected,
|
||||
navigate = true,
|
||||
changeDefault = false,
|
||||
showLabel = true,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let feed: string = $state(selected)
|
||||
run(() => {
|
||||
feed = selected
|
||||
})
|
||||
run(() => {
|
||||
changeDefault
|
||||
? ($userSettings.defaultSort.feed = selected as
|
||||
| 'All'
|
||||
| 'Subscribed'
|
||||
| 'Local')
|
||||
: undefined
|
||||
})
|
||||
</script>
|
||||
|
||||
<Select
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
bind:value={feed}
|
||||
on:change={() => {
|
||||
if (navigate) searchParam($page.url, 'type', feed, 'page', 'cursor')
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="label">
|
||||
{#snippet customLabel()}
|
||||
{#if showLabel}
|
||||
<span class="flex items-center gap-1">
|
||||
<Icon src={GlobeAmericas} size="16" micro />
|
||||
{$t('filter.location.label')}
|
||||
</span>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
<option value="All">
|
||||
<Icon
|
||||
src={GlobeAmericas}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { page } from '$app/stores'
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { t } from '$lib/translations'
|
||||
@@ -25,26 +27,40 @@
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
|
||||
export let selected: string
|
||||
export let navigate: boolean = true
|
||||
export let changeDefault: boolean = false
|
||||
|
||||
let sort: string = selected?.startsWith('Top') ? 'TopAll' : selected
|
||||
$: if (selected) {
|
||||
sort = selected?.startsWith('Top') ? 'TopAll' : selected
|
||||
interface Props {
|
||||
selected: string
|
||||
navigate?: boolean
|
||||
changeDefault?: boolean
|
||||
class?: string
|
||||
[key: string]: any
|
||||
}
|
||||
const setSelected = () => (selected = sort)
|
||||
$: changeDefault
|
||||
? ($userSettings.defaultSort.sort = selected as SortType)
|
||||
: undefined
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
selected = $bindable(),
|
||||
navigate = true,
|
||||
changeDefault = false,
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
let sort: string = $state(selected?.startsWith('Top') ? 'TopAll' : selected)
|
||||
const setSelected = () => (selected = sort)
|
||||
|
||||
run(() => {
|
||||
if (selected) {
|
||||
sort = selected?.startsWith('Top') ? 'TopAll' : selected
|
||||
}
|
||||
})
|
||||
run(() => {
|
||||
changeDefault
|
||||
? ($userSettings.defaultSort.sort = selected as SortType)
|
||||
: undefined
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row {clazz}">
|
||||
<Select
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class={selected?.startsWith('Top') ? 'rounded-r-none' : ''}
|
||||
bind:value={sort}
|
||||
on:change={(e) => {
|
||||
@@ -52,10 +68,12 @@
|
||||
if (navigate) searchParam($page.url, 'sort', selected, 'page', 'cursor')
|
||||
}}
|
||||
>
|
||||
<span slot="label" class="flex items-center gap-1">
|
||||
<Icon src={ChartBar} size="13" micro />
|
||||
{$t('filter.sort.label')}
|
||||
</span>
|
||||
{#snippet label()}
|
||||
<span class="flex items-center gap-1">
|
||||
<Icon src={ChartBar} size="13" micro />
|
||||
{$t('filter.sort.label')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<option value="Active">
|
||||
<Icon
|
||||
src={ArrowTrendingUp}
|
||||
@@ -149,10 +167,12 @@
|
||||
searchParam($page.url, 'sort', selected, 'page', 'cursor')
|
||||
}}
|
||||
>
|
||||
<span slot="label" class="flex items-center gap-1">
|
||||
<Icon src={Clock} size="15" micro />
|
||||
{$t('filter.sort.top.time.label')}
|
||||
</span>
|
||||
{#snippet label()}
|
||||
<span class="flex items-center gap-1">
|
||||
<Icon src={Clock} size="15" micro />
|
||||
{$t('filter.sort.top.time.label')}
|
||||
</span>
|
||||
{/snippet}
|
||||
<option value="TopAll">
|
||||
<Icon
|
||||
src={PlusCircle}
|
||||
|
||||
@@ -13,18 +13,23 @@
|
||||
ViewColumns,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export let showLabel = true
|
||||
interface Props {
|
||||
showLabel?: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { showLabel = true, ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Select {...$$restProps} bind:value={$userSettings.view}>
|
||||
<svelte:fragment slot="label">
|
||||
<Select {...rest} bind:value={$userSettings.view}>
|
||||
{#snippet customLabel()}
|
||||
{#if showLabel}
|
||||
<span class="flex items-center gap-1">
|
||||
<Icon src={ViewColumns} size="14" micro />
|
||||
{$t('filter.view.label')}
|
||||
</span>
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
<option value="cozy">
|
||||
<Icon
|
||||
src={RectangleGroup}
|
||||
|
||||
@@ -5,13 +5,17 @@
|
||||
import { flip } from 'svelte/animate'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
|
||||
export let items: {
|
||||
avatar?: string
|
||||
name: string
|
||||
instance?: string
|
||||
id: number
|
||||
url: string
|
||||
}[]
|
||||
interface Props {
|
||||
items: {
|
||||
avatar?: string
|
||||
name: string
|
||||
instance?: string
|
||||
id: number
|
||||
url: string
|
||||
}[]
|
||||
}
|
||||
|
||||
let { items }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#each items.sort((a, b) => a.name.localeCompare(b.name)) as item (item.id)}
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import type { PrivateMessageView } from 'lemmy-js-client'
|
||||
|
||||
export let message: PrivateMessageView
|
||||
export let meta: boolean = true
|
||||
interface Props {
|
||||
message: PrivateMessageView
|
||||
meta?: boolean
|
||||
style?: string
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let { message, meta = true, style = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-2 text-sm" {style}>
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import type { Person } from 'lemmy-js-client'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
|
||||
export let open: boolean = false
|
||||
export let user: Person
|
||||
interface Props {
|
||||
open?: boolean
|
||||
user: Person
|
||||
denying: boolean
|
||||
denyReason?: string
|
||||
}
|
||||
|
||||
export let denying: boolean
|
||||
|
||||
export let denyReason: string = ''
|
||||
let {
|
||||
open = $bindable(false),
|
||||
user,
|
||||
denying = $bindable(),
|
||||
denyReason = $bindable(''),
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
|
||||
@@ -21,10 +30,12 @@
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
<h1 class="text-2xl font-bold" slot="title">
|
||||
{$t('routes.admin.applications.modalTitle')}
|
||||
</h1>
|
||||
<form on:submit|preventDefault={() => deny()} class="flex flex-col gap-4">
|
||||
{#snippet title()}
|
||||
<h1 class="text-2xl font-bold">
|
||||
{$t('routes.admin.applications.modalTitle')}
|
||||
</h1>
|
||||
{/snippet}
|
||||
<form onsubmit={preventDefault(() => deny())} class="flex flex-col gap-4">
|
||||
<UserLink avatar {user} />
|
||||
<MarkdownEditor
|
||||
bind:value={denyReason}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.js'
|
||||
import ProgressBar from '$lib/components/ui/ProgressBar.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
@@ -11,14 +13,24 @@
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { slide } from 'svelte/transition'
|
||||
|
||||
export let open: boolean
|
||||
export let image: FileList | null = null
|
||||
export let preview: boolean = true
|
||||
export let multiple: boolean = true
|
||||
let progress = 1
|
||||
interface Props {
|
||||
open: boolean
|
||||
image?: FileList | null
|
||||
preview?: boolean
|
||||
multiple?: boolean
|
||||
}
|
||||
|
||||
$: previewURLs =
|
||||
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined
|
||||
let {
|
||||
open = $bindable(),
|
||||
image = $bindable(null),
|
||||
preview = true,
|
||||
multiple = true,
|
||||
}: Props = $props()
|
||||
let progress = $state(1)
|
||||
|
||||
let previewURLs = $derived(
|
||||
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined,
|
||||
)
|
||||
|
||||
const dispatcher = createEventDispatcher<{ upload: string[] }>()
|
||||
|
||||
@@ -39,8 +51,8 @@
|
||||
.catch((err) => {
|
||||
toast({ content: errorMessage(err), type: 'error' })
|
||||
return 'Failed to upload'
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
)
|
||||
).filter((i) => i != undefined)
|
||||
|
||||
@@ -61,13 +73,15 @@
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
<div slot="title" class="flex items-center gap-2">Upload image</div>
|
||||
{#snippet title()}
|
||||
<div class="flex items-center gap-2">Upload image</div>
|
||||
{/snippet}
|
||||
{#if progress != 1}
|
||||
<div transition:slide={{ duration: 500, easing: expoOut }} class="w-full">
|
||||
<ProgressBar {progress} />
|
||||
</div>
|
||||
{/if}
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={upload}>
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(upload)}>
|
||||
<label
|
||||
for="image-input"
|
||||
class="p-4 border-2 border-dashed rounded-xl cursor-pointer transition-colors
|
||||
@@ -79,10 +93,10 @@
|
||||
{multiple ? 'grid-cols-3 grid-rows-2' : 'grid-cols-1 grid-rows-1'}"
|
||||
>
|
||||
{#each previewURLs as file}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={file}
|
||||
on:load={() => URL.revokeObjectURL(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
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.js'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
@@ -8,12 +10,16 @@
|
||||
import { Button, Modal, toast } from 'mono-svelte'
|
||||
import { Icon, PaperAirplane } from 'svelte-hero-icons'
|
||||
|
||||
export let open: boolean = false
|
||||
export let user: Person
|
||||
interface Props {
|
||||
open?: boolean
|
||||
user: Person
|
||||
}
|
||||
|
||||
let message = ''
|
||||
let { open = $bindable(false), user }: Props = $props()
|
||||
|
||||
let loading = false
|
||||
let message = $state('')
|
||||
|
||||
let loading = $state(false)
|
||||
|
||||
async function sendMessage() {
|
||||
if (!$profile?.jwt || message == '') return
|
||||
@@ -44,8 +50,10 @@
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
<h1 class="text-2xl font-bold" slot="title">Message</h1>
|
||||
<form on:submit|preventDefault={sendMessage} class="flex flex-col gap-4">
|
||||
{#snippet title()}
|
||||
<h1 class="text-2xl font-bold">Message</h1>
|
||||
{/snippet}
|
||||
<form onsubmit={preventDefault(sendMessage)} class="flex flex-col gap-4">
|
||||
<p class="inline-flex flex-row gap-2 items-center">
|
||||
<Icon src={PaperAirplane} size="16" mini />
|
||||
<UserLink avatar {user} />
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import type { Community, Person, PersonView } from 'lemmy-js-client'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
@@ -9,17 +11,25 @@
|
||||
import { t } from '$lib/translations'
|
||||
import CommunityLink from '../community/CommunityLink.svelte'
|
||||
|
||||
export let open = false
|
||||
let item: Person | undefined
|
||||
export { item as user }
|
||||
export let community: Community | undefined
|
||||
export let banned: boolean
|
||||
interface Props {
|
||||
open?: boolean
|
||||
user: Person | undefined
|
||||
community: Community | undefined
|
||||
banned: boolean
|
||||
}
|
||||
|
||||
let reason = ''
|
||||
let deleteData = false
|
||||
let expires = ''
|
||||
let {
|
||||
open = $bindable(false),
|
||||
user: item = $bindable(),
|
||||
community,
|
||||
banned,
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
let reason = $state('')
|
||||
let deleteData = $state(false)
|
||||
let expires = $state('')
|
||||
|
||||
let loading = $state(false)
|
||||
|
||||
// hack due to svelte's reactive declarations
|
||||
const resetReason = () => {
|
||||
@@ -28,7 +38,9 @@
|
||||
expires = ''
|
||||
}
|
||||
|
||||
$: if (item) resetReason()
|
||||
run(() => {
|
||||
if (item) resetReason()
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (!item || !$profile?.user || !$profile?.jwt) return
|
||||
@@ -105,7 +117,7 @@
|
||||
title={banned ? $t('moderation.ban.unbanning') : $t('moderation.ban.banning')}
|
||||
>
|
||||
{#if item}
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={submit}>
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(submit)}>
|
||||
<div class="flex items-center gap-1">
|
||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||
<span class="font-bold">{item.name}</span>
|
||||
@@ -121,9 +133,9 @@
|
||||
{#if !banned}
|
||||
<Checkbox bind:checked={deleteData}>
|
||||
{$t('moderation.ban.deleteData')}
|
||||
<svelte:fragment slot="description">
|
||||
{#snippet description()}
|
||||
{$t('moderation.ban.warning')}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</Checkbox>
|
||||
<TextInput
|
||||
bind:value={expires}
|
||||
|
||||
@@ -14,19 +14,25 @@
|
||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
export let item: PostView | CommentView
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom" class="top-0 h-[26px] w-[26px] ">
|
||||
<Button
|
||||
class="w-[26px] h-[26px] hover:!text-green-500 dark:text-zinc-400 text-slate-600"
|
||||
size="square-md"
|
||||
slot="target"
|
||||
color="tertiary"
|
||||
{...$$restProps}
|
||||
>
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
class="w-[26px] h-[26px] hover:!text-green-500 dark:text-zinc-400 text-slate-600"
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod($profile.user, item.community)}
|
||||
@@ -36,7 +42,9 @@
|
||||
{/if}
|
||||
</MenuDivider>
|
||||
<MenuButton color="danger-subtle" on:click={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{/snippet}
|
||||
{#if isCommentView(item)}
|
||||
{item.comment.removed
|
||||
? $t('moderation.restore')
|
||||
@@ -52,7 +60,9 @@
|
||||
on:click={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
>
|
||||
<Icon src={ShieldExclamation} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
{/snippet}
|
||||
{item.creator_banned_from_community
|
||||
? $t('moderation.ban.unbanFromCommunity')
|
||||
: $t('moderation.ban.banFromCommunity')}
|
||||
@@ -67,12 +77,14 @@
|
||||
await feature(
|
||||
!item.comment.distinguished,
|
||||
item.comment,
|
||||
$profile.jwt
|
||||
$profile.jwt,
|
||||
)
|
||||
).comment_view.comment
|
||||
}}
|
||||
>
|
||||
<Icon src={Megaphone} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Megaphone} size="16" micro />
|
||||
{/snippet}
|
||||
{item.comment.distinguished
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
@@ -83,7 +95,9 @@
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
<MenuDivider>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton color="danger-subtle" on:click={() => remove(item, true)}>
|
||||
<Icon src={Fire} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{/snippet}
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -18,12 +18,17 @@
|
||||
import { t } from '$lib/translations'
|
||||
import ShieldIcon from './ShieldIcon.svelte'
|
||||
|
||||
export let item: PostView | CommentView
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let locking = false
|
||||
let pinning = false
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
|
||||
$: acting = locking || pinning
|
||||
let locking = $state(false)
|
||||
let pinning = $state(false)
|
||||
|
||||
let acting = $derived(locking || pinning)
|
||||
|
||||
async function lock(lock: boolean) {
|
||||
if (!$profile?.jwt || !isPostView(item)) return
|
||||
@@ -71,16 +76,17 @@
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
<Button
|
||||
class="hover:!text-green-500"
|
||||
slot="target"
|
||||
size="square-md"
|
||||
color="ghost"
|
||||
loading={acting}
|
||||
{...$$restProps}
|
||||
>
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
class="hover:!text-green-500"
|
||||
size="square-md"
|
||||
color="ghost"
|
||||
loading={acting}
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={16} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
|
||||
<MenuDivider>
|
||||
{#if !item.community.local && !amMod($profile.user, item.community)}
|
||||
@@ -95,12 +101,9 @@
|
||||
loading={locking}
|
||||
disabled={locking}
|
||||
>
|
||||
<Icon
|
||||
src={item.post.locked ? LockOpen : LockClosed}
|
||||
size="16"
|
||||
mini
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={item.post.locked ? LockOpen : LockClosed} size="16" mini />
|
||||
{/snippet}
|
||||
{item.post.locked ? $t('moderation.unlock') : $t('moderation.lock')}
|
||||
</MenuButton>
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import { Select, Switch, toast } from 'mono-svelte'
|
||||
@@ -16,21 +18,31 @@
|
||||
import { Button, Checkbox, Modal } from 'mono-svelte'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | undefined = undefined
|
||||
export let purge: boolean = false
|
||||
interface Props {
|
||||
open: boolean
|
||||
item?: PostView | CommentView | undefined
|
||||
purge?: boolean
|
||||
}
|
||||
|
||||
let reason = ''
|
||||
let commentReason: boolean = false
|
||||
let privateMessage: boolean = false
|
||||
let loading = false
|
||||
let preset = $userSettings.moderation.presets[0]?.content ?? ''
|
||||
let {
|
||||
open = $bindable(),
|
||||
item = $bindable(undefined),
|
||||
purge = false,
|
||||
}: Props = $props()
|
||||
|
||||
$: removed = item
|
||||
? isCommentView(item)
|
||||
? item.comment.removed
|
||||
: item.post.removed
|
||||
: false
|
||||
let reason = $state('')
|
||||
let commentReason: boolean = $state(false)
|
||||
let privateMessage: boolean = $state(false)
|
||||
let loading = $state(false)
|
||||
let preset = $state($userSettings.moderation.presets[0]?.content ?? '')
|
||||
|
||||
let removed = $derived(
|
||||
item
|
||||
? isCommentView(item)
|
||||
? item.comment.removed
|
||||
: item.post.removed
|
||||
: false,
|
||||
)
|
||||
|
||||
const getReplyReason = (reason: string, preset: string) => {
|
||||
if (!item) return `no template`
|
||||
@@ -38,7 +50,7 @@
|
||||
return removalTemplate(preset, {
|
||||
communityLink: `!${fullCommunityName(
|
||||
item!.community.name,
|
||||
item!.community.actor_id
|
||||
item!.community.actor_id,
|
||||
)}`,
|
||||
postTitle: item.post.name,
|
||||
reason: reason,
|
||||
@@ -46,7 +58,10 @@
|
||||
})
|
||||
}
|
||||
|
||||
$: replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||
let replyReason
|
||||
run(() => {
|
||||
replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||
})
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
@@ -151,11 +166,11 @@
|
||||
commentReason = false
|
||||
}
|
||||
|
||||
$: {
|
||||
run(() => {
|
||||
if (item) {
|
||||
resetText()
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
@@ -168,7 +183,7 @@
|
||||
>
|
||||
{#if item}
|
||||
<form
|
||||
on:submit|preventDefault={remove}
|
||||
onsubmit={preventDefault(remove)}
|
||||
class="flex flex-col gap-4 list-none"
|
||||
>
|
||||
{#if isCommentView(item)}
|
||||
@@ -212,16 +227,18 @@
|
||||
placeholder={replyReason}
|
||||
rows={3}
|
||||
>
|
||||
<div class="flex justify-between items-end mb-1" slot="label">
|
||||
{$t('comment.reply')}
|
||||
<Select bind:value={preset} placeholder="No preset">
|
||||
{#each $userSettings.moderation.presets as preset}
|
||||
<option value={preset.content}>
|
||||
{preset.title}
|
||||
</option>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
{#snippet label()}
|
||||
<div class="flex justify-between items-end mb-1">
|
||||
{$t('comment.reply')}
|
||||
<Select bind:value={preset} placeholder="No preset">
|
||||
{#each $userSettings.moderation.presets as preset}
|
||||
<option value={preset.content}>
|
||||
{preset.title}
|
||||
</option>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
{/snippet}
|
||||
</MarkdownEditor>
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -233,7 +250,9 @@
|
||||
disabled={loading}
|
||||
submit
|
||||
>
|
||||
<Icon src={purge ? Fire : Trash} mini size="16" slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={purge ? Fire : Trash} mini size="16" />
|
||||
{/snippet}
|
||||
{#if purge}
|
||||
{$t('admin.purge')}
|
||||
{:else}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import { toast } from 'mono-svelte'
|
||||
@@ -16,24 +18,27 @@
|
||||
import { t } from '$lib/translations'
|
||||
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | PrivateMessageView | undefined =
|
||||
undefined
|
||||
interface Props {
|
||||
open: boolean
|
||||
item?: PostView | CommentView | PrivateMessageView | undefined
|
||||
}
|
||||
|
||||
let { open = $bindable(), item = undefined }: Props = $props()
|
||||
|
||||
const isComment = (
|
||||
item: PostView | CommentView | PrivateMessageView
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is CommentView => 'comment' in item
|
||||
|
||||
const isPost = (
|
||||
item: PostView | CommentView | PrivateMessageView
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is PostView => !isComment(item) && 'post' in item
|
||||
|
||||
const isPrivateMessage = (
|
||||
item: PostView | CommentView | PrivateMessageView
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is PrivateMessageView => !isComment(item) && 'private_message' in item
|
||||
|
||||
let loading = false
|
||||
let reason = ''
|
||||
let loading = $state(false)
|
||||
let reason = $state('')
|
||||
|
||||
async function report() {
|
||||
if (!item || !$profile?.jwt || reason == '') return
|
||||
@@ -70,15 +75,15 @@
|
||||
|
||||
const resetText = () => (reason = '')
|
||||
|
||||
$: {
|
||||
run(() => {
|
||||
if (item) {
|
||||
resetText()
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Modal bind:open title={$t('moderation.reportModal.title')}>
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={report}>
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(report)}>
|
||||
{#if item}
|
||||
<div class="pointer-events-none list-none">
|
||||
{#if isComment(item)}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let width: number = 16
|
||||
export let filled: boolean = false
|
||||
interface Props {
|
||||
width?: number
|
||||
filled?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let { width = 16, filled = false, class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if filled}
|
||||
|
||||
@@ -106,7 +106,7 @@ export const removalTemplate = (
|
||||
communityLink?: string
|
||||
username?: string
|
||||
reason?: string
|
||||
}
|
||||
},
|
||||
) => {
|
||||
if (content.postTitle) input = input.replaceAll('{{post}}', content.postTitle)
|
||||
if (content.communityLink)
|
||||
|
||||
@@ -31,26 +31,6 @@
|
||||
import { profile } from '$lib/auth'
|
||||
import { goto } from '$app/navigation'
|
||||
|
||||
export let post: PostView
|
||||
export let actions: boolean = true
|
||||
export let hideCommunity = false
|
||||
export let view = $userSettings.view
|
||||
|
||||
$: tags = parseTags(post.post.name)
|
||||
$: type = mediaType(post.post.url, view)
|
||||
$: rule = getTagRule(tags.tags)
|
||||
|
||||
$: hideTitle =
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_title == post.post.name &&
|
||||
view != 'compact' &&
|
||||
type != 'iframe'
|
||||
|
||||
$: hideBody =
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_description == post.post.body &&
|
||||
view != 'compact'
|
||||
|
||||
function getTagRule(tags: Tag[]): 'blur' | 'hide' | undefined {
|
||||
const tagContent = tags.map((t) => t.content.toLowerCase())
|
||||
|
||||
@@ -75,9 +55,40 @@
|
||||
}
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
post: PostView
|
||||
actions?: boolean
|
||||
hideCommunity?: boolean
|
||||
view?: any
|
||||
style?: string
|
||||
class?: string
|
||||
badges?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
post,
|
||||
actions = true,
|
||||
hideCommunity = false,
|
||||
view = $userSettings.view,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
badges,
|
||||
}: Props = $props()
|
||||
|
||||
let tags = $derived(parseTags(post.post.name))
|
||||
let type = $derived(mediaType(post.post.url, view))
|
||||
let rule = $derived(getTagRule(tags.tags))
|
||||
let hideTitle = $derived(
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_title == post.post.name &&
|
||||
view != 'compact' &&
|
||||
type != 'iframe',
|
||||
)
|
||||
let hideBody = $derived(
|
||||
$userSettings.posts.deduplicateEmbed &&
|
||||
post.post.embed_description == post.post.body &&
|
||||
view != 'compact',
|
||||
)
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -85,9 +96,9 @@
|
||||
This is the sole component for displaying posts.
|
||||
It adapts to all kinds of form factors for different contexts, such as feeds, full post view, and crosspost list.
|
||||
-->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<div
|
||||
class="post relative max-w-full min-w-0 w-full cursor-pointer outline-none
|
||||
group
|
||||
@@ -97,10 +108,10 @@
|
||||
{view == 'cozy' ? 'py-5 flex flex-col gap-2' : ''}
|
||||
{clazz ?? ''}"
|
||||
id={post.post.id.toString()}
|
||||
on:click={(e) => {
|
||||
onclick={(e) => {
|
||||
onClick(e)
|
||||
}}
|
||||
on:keydown={(e) => {
|
||||
onkeydown={(e) => {
|
||||
// @ts-ignore
|
||||
if (e.key == 'Enter') onClick(e)
|
||||
}}
|
||||
@@ -135,7 +146,9 @@
|
||||
tags={tags?.tags}
|
||||
{view}
|
||||
>
|
||||
<slot name="badges" slot="badges" />
|
||||
{#snippet extraBadges()}
|
||||
{@render badges?.()}
|
||||
{/snippet}
|
||||
</PostMeta>
|
||||
{#key post.post.url}
|
||||
<div
|
||||
@@ -178,11 +191,15 @@
|
||||
{:else if view == 'compact'}
|
||||
<div class="flex flex-row items-center gap-2 text-sm">
|
||||
<Badge>
|
||||
<Icon src={ArrowUp} slot="icon" size="14" micro />
|
||||
{#snippet icon()}
|
||||
<Icon src={ArrowUp} size="14" micro />
|
||||
{/snippet}
|
||||
{post.counts.score}
|
||||
</Badge>
|
||||
<Badge>
|
||||
<Icon src={ChatBubbleOvalLeft} slot="icon" size="14" micro />
|
||||
{#snippet icon()}
|
||||
<Icon src={ChatBubbleOvalLeft} size="14" micro />
|
||||
{/snippet}
|
||||
{post.counts.comments}
|
||||
</Badge>
|
||||
</div>
|
||||
@@ -194,7 +211,7 @@
|
||||
group-hover:inset-y-0.5 group-hover:-inset-x-4 group-hover:sm:-inset-x-5 group-hover:opacity-100
|
||||
group-focus:inset-y-0.5 group-focus:-inset-x-4 group-focus:sm:-inset-x-5 group-focus:opacity-100
|
||||
duration-150"
|
||||
/>
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<style lang="postcss">
|
||||
|
||||
@@ -67,28 +67,37 @@
|
||||
formatRelativeDate,
|
||||
} from '$lib/components/util/RelativeDate.svelte'
|
||||
|
||||
export let post: PostView
|
||||
export let view: View = 'cozy'
|
||||
export let debug: boolean = false
|
||||
|
||||
const dispatcher = createEventDispatcher<{ edit: PostView; hide: boolean }>()
|
||||
|
||||
let editing = false
|
||||
let saving = false
|
||||
let editing = $state(false)
|
||||
let saving = $state(false)
|
||||
|
||||
let translating = false
|
||||
let translating = $state(false)
|
||||
|
||||
let localShare = false
|
||||
let localShare = $state(false)
|
||||
|
||||
$: buttonHeight = view == 'compact' ? 'h-7' : 'h-8'
|
||||
$: buttonSquare = view == 'compact' ? 'w-7 h-7' : 'w-8 h-8'
|
||||
interface Props {
|
||||
post: PostView
|
||||
view?: View
|
||||
debug?: boolean
|
||||
style?: string
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let {
|
||||
post = $bindable(),
|
||||
view = 'cozy',
|
||||
debug = $bindable(false),
|
||||
style = '',
|
||||
}: Props = $props()
|
||||
let buttonHeight = $derived(view == 'compact' ? 'h-7' : 'h-8')
|
||||
let buttonSquare = $derived(view == 'compact' ? 'w-7 h-7' : 'w-8 h-8')
|
||||
</script>
|
||||
|
||||
{#if editing}
|
||||
<Modal bind:open={editing}>
|
||||
<h1 slot="title" class="text-2xl font-bold">Editing post</h1>
|
||||
{#snippet customTitle()}
|
||||
<h1 class="text-2xl font-bold">Editing post</h1>
|
||||
{/snippet}
|
||||
{#await import('./form/PostForm.svelte')}
|
||||
<div class="mx-auto h-96 flex justify-center items-center">
|
||||
<Spinner width={32} />
|
||||
@@ -103,10 +112,10 @@
|
||||
dispatcher('edit', e.detail)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="formtitle">
|
||||
{#snippet formtitle()}
|
||||
<!-- Have the title not exist at all -->
|
||||
{''}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</PostForm>
|
||||
{/await}
|
||||
</Modal>
|
||||
@@ -152,7 +161,7 @@
|
||||
/>
|
||||
<FormattedNumber number={post.counts.comments} />
|
||||
</Button>
|
||||
<div class="flex-1" />
|
||||
<div class="flex-1"></div>
|
||||
|
||||
{#if $userSettings.debugInfo}
|
||||
{#if debug}
|
||||
@@ -169,7 +178,9 @@
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon src={BugAnt} micro size="16" slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={BugAnt} micro size="16" />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))}
|
||||
@@ -200,12 +211,9 @@
|
||||
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon
|
||||
src={post.saved ? BookmarkSlash : Bookmark}
|
||||
size="16"
|
||||
mini
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
@@ -216,21 +224,26 @@
|
||||
targetClass="h-full"
|
||||
title={$t('post.actions.more.label')}
|
||||
>
|
||||
<Button
|
||||
slot="target"
|
||||
title={$t('post.actions.more.label')}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
<Icon slot="prefix" src={EllipsisHorizontal} width={16} micro />
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
title={$t('post.actions.more.label')}
|
||||
color="ghost"
|
||||
rounding="pill"
|
||||
size="custom"
|
||||
class={buttonSquare}
|
||||
animations={{ scale: true, large: true }}
|
||||
>
|
||||
{#snippet prefix()}
|
||||
<Icon src={EllipsisHorizontal} width={16} micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('cards.site.stats')}</MenuDivider>
|
||||
<div class="flex flex-row gap-1 items-center">
|
||||
<MenuButton class="flex-1">
|
||||
<Icon src={Clock} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Clock} size="16" micro />
|
||||
{/snippet}
|
||||
<span>
|
||||
{publishedToDate(post.post.published).toLocaleDateString(undefined, {
|
||||
dateStyle: 'short',
|
||||
@@ -242,10 +255,12 @@
|
||||
publishedToDate(post.post.updated),
|
||||
{
|
||||
style: 'long',
|
||||
}
|
||||
},
|
||||
)}
|
||||
<MenuButton class="flex-1" aria-label={editedTime}>
|
||||
<Icon src={Pencil} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Pencil} size="16" micro />
|
||||
{/snippet}
|
||||
<RelativeDate date={publishedToDate(post.post.updated)} />
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -256,7 +271,9 @@
|
||||
<MenuButton
|
||||
aria-label={$t('aria.vote.score', { default: post.counts.score })}
|
||||
>
|
||||
<Icon src={ArrowsUpDown} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowsUpDown} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.vote.score')}
|
||||
•
|
||||
<FormattedNumber
|
||||
@@ -276,25 +293,17 @@
|
||||
{/if}
|
||||
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
|
||||
<MenuButton link href={userLink(post.creator)}>
|
||||
<Icon
|
||||
src={UserCircle}
|
||||
size="16"
|
||||
micro
|
||||
slot="prefix"
|
||||
class="flex-shrink-0"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={UserCircle} size="16" micro class="flex-shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.creator.name}
|
||||
</TextProps>
|
||||
</MenuButton>
|
||||
<MenuButton link href={communityLink(post.community)}>
|
||||
<Icon
|
||||
src={Newspaper}
|
||||
size="16"
|
||||
micro
|
||||
slot="prefix"
|
||||
class="flex-shrink-0"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Icon src={Newspaper} size="16" micro class="flex-shrink-0" />
|
||||
{/snippet}
|
||||
<TextProps wrap="no-wrap">
|
||||
{post.community.title}
|
||||
</TextProps>
|
||||
@@ -304,7 +313,9 @@
|
||||
</MenuDivider>
|
||||
{#if $profile?.user && $profile?.jwt && $profile.user.local_user_view.person.id == post.creator.id}
|
||||
<MenuButton on:click={() => (editing = true)}>
|
||||
<Icon src={PencilSquare} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.edit')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -315,7 +326,9 @@
|
||||
post.read = await markAsRead(post.post, !post.read, $profile.jwt)
|
||||
}}
|
||||
>
|
||||
<Icon slot="prefix" src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{#snippet prefix()}
|
||||
<Icon src={post.read ? EyeSlash : Eye} size="16" micro />
|
||||
{/snippet}
|
||||
{post.read
|
||||
? $t('post.actions.more.markUnread')
|
||||
: $t('post.actions.more.markRead')}
|
||||
@@ -331,15 +344,17 @@
|
||||
navigator.clipboard.writeText(
|
||||
localShare
|
||||
? `${instanceToURL(getInstance())}/post/${post.post.id}`
|
||||
: post.post.ap_id
|
||||
: post.post.ap_id,
|
||||
)
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
class="flex-1 !py-0"
|
||||
>
|
||||
<Icon src={Share} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
<div class="flex-1" />
|
||||
<div class="flex-1"></div>
|
||||
{#if !post.post.local}
|
||||
<div class="flex">
|
||||
<Button
|
||||
@@ -371,7 +386,9 @@
|
||||
translating = !translating
|
||||
}}
|
||||
>
|
||||
<Icon src={Language} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Language} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.translate')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
@@ -399,7 +416,9 @@
|
||||
goto('/create/post?crosspost=true')
|
||||
}}
|
||||
>
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={ArrowTopRightOnSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.crosspost')}
|
||||
</MenuButton>
|
||||
{#if $profile.user && post.creator.id == $profile.user.local_user_view.person.id}
|
||||
@@ -409,12 +428,14 @@
|
||||
post.post.deleted = await deleteItem(
|
||||
post,
|
||||
!post.post.deleted,
|
||||
$profile.jwt
|
||||
$profile.jwt,
|
||||
)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
<Icon src={Trash} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Trash} size="16" micro />
|
||||
{/snippet}
|
||||
{post.post.deleted
|
||||
? $t('post.actions.more.restore')
|
||||
: $t('post.actions.more.delete')}
|
||||
@@ -428,7 +449,7 @@
|
||||
const hidden = await hidePost(
|
||||
post.post.id,
|
||||
!post.hidden,
|
||||
$profile?.jwt
|
||||
$profile?.jwt,
|
||||
)
|
||||
post.hidden = hidden
|
||||
if (hidden) {
|
||||
@@ -437,14 +458,18 @@
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
<Icon slot="prefix" src={XMark} size="16" micro />
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="16" micro />
|
||||
{/snippet}
|
||||
{post.hidden
|
||||
? $t('post.actions.more.unhide')
|
||||
: $t('post.actions.more.hide')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton on:click={() => report(post)} color="danger-subtle">
|
||||
<Icon src={Flag} width={16} micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Flag} width={16} micro />
|
||||
{/snippet}
|
||||
{$t('moderation.report')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
@@ -4,15 +4,8 @@
|
||||
import { Button } from 'mono-svelte'
|
||||
import { ChevronDown, Icon } from 'svelte-hero-icons'
|
||||
|
||||
export let body: string
|
||||
export let view: View = 'cozy'
|
||||
export let clickThrough = false
|
||||
let htmlElement = 'div'
|
||||
|
||||
export { htmlElement as element }
|
||||
|
||||
let expanded = false
|
||||
let element: Element
|
||||
let expanded = $state(false)
|
||||
let element: Element = $state()
|
||||
|
||||
function isOverflown(element: Element, body: string = '') {
|
||||
if (!element) return
|
||||
@@ -26,11 +19,25 @@
|
||||
return overflows
|
||||
}
|
||||
|
||||
$: overflows = isOverflown(element, body)
|
||||
interface Props {
|
||||
body: string
|
||||
view?: View
|
||||
clickThrough?: boolean
|
||||
element?: string
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
body,
|
||||
view = 'cozy',
|
||||
clickThrough = false,
|
||||
element: htmlElement = 'div',
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let overflows = $derived(isOverflown(element, body))
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
export interface Tag {
|
||||
content: string
|
||||
color?: string
|
||||
@@ -12,7 +12,7 @@
|
||||
])
|
||||
|
||||
export const parseTags = (
|
||||
title?: string
|
||||
title?: string,
|
||||
): { tags: Tag[]; title?: string } => {
|
||||
if (!title) return { tags: [] }
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
extracted.push(
|
||||
textToTag.get(content) ?? {
|
||||
content: content,
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
return ''
|
||||
@@ -43,6 +43,8 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { stopPropagation } from 'svelte/legacy'
|
||||
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { Badge, Popover } from 'mono-svelte'
|
||||
@@ -70,37 +72,53 @@
|
||||
import CommunityHeader from '../community/CommunityHeader.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
|
||||
export let community: Community | undefined = undefined
|
||||
export let showCommunity: boolean = true
|
||||
export let subscribed: SubscribedType | undefined = undefined
|
||||
let popoverOpen = $state(false)
|
||||
|
||||
export let user: Person | undefined = undefined
|
||||
export let published: Date | undefined = undefined
|
||||
export let title: string | undefined = undefined
|
||||
export let id: number | undefined = undefined
|
||||
export let read: boolean = false
|
||||
export let edited: string | undefined = undefined
|
||||
|
||||
export let view: View = 'cozy'
|
||||
|
||||
// Badges
|
||||
export let badges = {
|
||||
nsfw: false,
|
||||
saved: false,
|
||||
featured: false,
|
||||
deleted: false,
|
||||
removed: false,
|
||||
locked: false,
|
||||
moderator: false,
|
||||
admin: false,
|
||||
interface Props {
|
||||
community?: Community | undefined
|
||||
showCommunity?: boolean
|
||||
subscribed?: SubscribedType | undefined
|
||||
user?: Person | undefined
|
||||
published?: Date | undefined
|
||||
title?: string | undefined
|
||||
id?: number | undefined
|
||||
read?: boolean
|
||||
edited?: string | undefined
|
||||
view?: View
|
||||
// Badges
|
||||
badges?: any
|
||||
tags?: Tag[]
|
||||
style?: string
|
||||
titleClass?: string
|
||||
extraBadges?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export let tags: Tag[] = []
|
||||
|
||||
let popoverOpen = false
|
||||
|
||||
export let style: string = ''
|
||||
export let titleClass: string = ''
|
||||
let {
|
||||
community = $bindable(undefined),
|
||||
showCommunity = true,
|
||||
subscribed = $bindable(undefined),
|
||||
user = undefined,
|
||||
published = undefined,
|
||||
title = undefined,
|
||||
id = undefined,
|
||||
read = false,
|
||||
edited = undefined,
|
||||
view = 'cozy',
|
||||
badges = {
|
||||
nsfw: false,
|
||||
saved: false,
|
||||
featured: false,
|
||||
deleted: false,
|
||||
removed: false,
|
||||
locked: false,
|
||||
moderator: false,
|
||||
admin: false,
|
||||
},
|
||||
tags = [],
|
||||
style = '',
|
||||
titleClass = '',
|
||||
extraBadges,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -114,32 +132,36 @@
|
||||
class:compact={view == 'compact'}
|
||||
{style}
|
||||
>
|
||||
{#if showCommunity && community && subscribed && showCommunity}
|
||||
{#if showCommunity && community != undefined && subscribed}
|
||||
<Popover bind:open={popoverOpen} manual>
|
||||
<button
|
||||
on:click={() => (popoverOpen = !popoverOpen)}
|
||||
class="relative cursor-pointer row-span-2 flex-shrink-0 pr-2 group/community"
|
||||
slot="target"
|
||||
>
|
||||
<Avatar
|
||||
url={community.icon}
|
||||
width={view == 'compact' ? 24 : 32}
|
||||
alt={community.name}
|
||||
class="group-hover/community:ring-2 transition-all ring-offset-0 ring-primary-900 dark:ring-primary-100"
|
||||
/>
|
||||
</button>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<div
|
||||
slot="popover"
|
||||
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
||||
on:click|stopPropagation={() => {}}
|
||||
>
|
||||
<CommunityHeader bind:community bind:subscribed />
|
||||
</div>
|
||||
{#snippet target()}
|
||||
<button
|
||||
onclick={() => (popoverOpen = !popoverOpen)}
|
||||
class="relative cursor-pointer row-span-2 flex-shrink-0 pr-2 group/community"
|
||||
>
|
||||
<Avatar
|
||||
url={community?.icon}
|
||||
width={view == 'compact' ? 24 : 32}
|
||||
alt={community?.name}
|
||||
class="group-hover/community:ring-2 transition-all ring-offset-0 ring-primary-900 dark:ring-primary-100"
|
||||
/>
|
||||
</button>
|
||||
{/snippet}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
{#snippet popover()}
|
||||
{#if community && subscribed}
|
||||
<div
|
||||
class="max-w-md rounded-2xl bg-white dark:bg-zinc-950"
|
||||
onclick={stopPropagation(() => {})}
|
||||
>
|
||||
<CommunityHeader bind:community bind:subscribed />
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Popover>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
{/if}
|
||||
{#if showCommunity && community}
|
||||
<CommunityLink
|
||||
@@ -174,14 +196,14 @@
|
||||
avatar={!showCommunity}
|
||||
class="flex-shrink "
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
{#snippet extraBadges()}
|
||||
{#if badges.moderator}
|
||||
<ShieldIcon filled width={14} class="text-green-500" />
|
||||
{/if}
|
||||
{#if badges.admin}
|
||||
<ShieldIcon filled width={14} class="text-red-500" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</UserLink>
|
||||
</address>
|
||||
{/if}
|
||||
@@ -213,13 +235,13 @@
|
||||
style={tag.color ? `--tag-color: ${tag.color};` : ''}
|
||||
>
|
||||
<Badge class={tag.color ? 'badge-tag-color' : ''}>
|
||||
<svelte:fragment slot="icon">
|
||||
{#snippet icon()}
|
||||
{#if tag.icon}
|
||||
<Icon src={tag.icon} micro size="14" />
|
||||
{:else}
|
||||
<Icon src={Tag} micro size="14" />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
{tag.content}
|
||||
</Badge>
|
||||
</a>
|
||||
@@ -227,7 +249,9 @@
|
||||
{/if}
|
||||
{#if badges.nsfw}
|
||||
<Badge label={$t('post.badges.nsfw')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={ExclamationTriangle} size="14" micro slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={ExclamationTriangle} size="14" micro />
|
||||
{/snippet}
|
||||
{$t('post.badges.nsfw')}
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -237,7 +261,9 @@
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={Bookmark} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Bookmark} micro size="14" />
|
||||
{/snippet}
|
||||
{$t('post.badges.saved')}
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -247,19 +273,25 @@
|
||||
color="yellow-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={LockClosed} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={LockClosed} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.locked')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.removed}
|
||||
<Badge label={$t('post.badges.removed')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={Trash} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.removed')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
{#if badges.deleted}
|
||||
<Badge label={$t('post.badges.deleted')} color="red-subtle" allowIconOnly>
|
||||
<Icon src={Trash} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Trash} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.deleted')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
@@ -269,11 +301,13 @@
|
||||
color="green-subtle"
|
||||
allowIconOnly
|
||||
>
|
||||
<Icon src={Megaphone} micro size="14" slot="icon" />
|
||||
{#snippet icon()}
|
||||
<Icon src={Megaphone} micro size="14" />
|
||||
{/snippet}
|
||||
<span class="max-md:hidden">{$t('post.badges.featured')}</span>
|
||||
</Badge>
|
||||
{/if}
|
||||
<slot name="badges" />
|
||||
{@render extraBadges?.()}
|
||||
</div>
|
||||
</header>
|
||||
{#if title && id}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
export const voteColor = (vote: number, border: boolean = false) =>
|
||||
vote == 1
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
export const shouldShowVoteColor = (
|
||||
vote: number,
|
||||
type: 'upvotes' | 'downvotes'
|
||||
type: 'upvotes' | 'downvotes',
|
||||
): string =>
|
||||
(vote == -1 && type == 'downvotes') || (vote == 1 && type == 'upvotes')
|
||||
? voteColor(vote)
|
||||
@@ -29,15 +29,27 @@
|
||||
import { t } from '$lib/translations'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
|
||||
export let post: Post
|
||||
export let vote: number = 0
|
||||
export let score: number
|
||||
export let upvotes: number = 0
|
||||
export let downvotes: number = 0
|
||||
interface Props {
|
||||
post: Post
|
||||
vote?: number
|
||||
score: number
|
||||
upvotes?: number
|
||||
downvotes?: number
|
||||
showCounts?: boolean
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
export let showCounts: boolean = true
|
||||
let {
|
||||
post,
|
||||
vote = $bindable(0),
|
||||
score = $bindable(),
|
||||
upvotes = $bindable(0),
|
||||
downvotes = $bindable(0),
|
||||
showCounts = true,
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
let loading = $state(false)
|
||||
|
||||
let oldScore = score
|
||||
|
||||
@@ -58,7 +70,7 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<slot {vote} {score}>
|
||||
{#if children}{@render children({ vote, score })}{:else}
|
||||
<div
|
||||
class="{buttonColor.ghost} rounded-full h-full font-medium flex items-center *:p-2
|
||||
hover:bg-white hover:dark:bg-zinc-900 overflow-hidden transition-colors flex-shrink-0
|
||||
@@ -70,7 +82,7 @@
|
||||
aria-label={$t('aria.vote.group')}
|
||||
>
|
||||
<button
|
||||
on:click={() => castVote(vote == 1 ? 0 : 1)}
|
||||
onclick={() => castVote(vote == 1 ? 0 : 1)}
|
||||
class="flex items-center gap-0.5 transition-colors relative z-0
|
||||
{vote == 1
|
||||
? shouldShowVoteColor(vote, 'upvotes')
|
||||
@@ -96,7 +108,7 @@
|
||||
</button>
|
||||
{#if $site?.site_view.local_site.enable_downvotes ?? true}
|
||||
<button
|
||||
on:click={() => castVote(vote == -1 ? 0 : -1)}
|
||||
onclick={() => castVote(vote == -1 ? 0 : -1)}
|
||||
class="flex items-center flex-row-reverse gap-0.5 transition-colors
|
||||
{vote == -1
|
||||
? shouldShowVoteColor(vote, 'downvotes')
|
||||
@@ -122,4 +134,4 @@
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</slot>
|
||||
{/if}
|
||||
@@ -9,14 +9,26 @@
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
import { combineCrossposts } from './crosspost'
|
||||
|
||||
export let posts: PostView[]
|
||||
export let community: boolean = false
|
||||
export let feedData: any
|
||||
let etc = $$restProps
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
community?: boolean
|
||||
feedData: any
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
$: combinedPosts = combineCrossposts(posts)
|
||||
let {
|
||||
posts = $bindable(),
|
||||
community = false,
|
||||
feedData,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
let etc = rest
|
||||
|
||||
let viewPost: number = -1
|
||||
let combinedPosts = $derived(combineCrossposts(posts))
|
||||
|
||||
let viewPost: number = $state(-1)
|
||||
</script>
|
||||
|
||||
<ul
|
||||
@@ -32,7 +44,9 @@
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
@@ -53,10 +67,10 @@
|
||||
posts = posts.toSpliced(index, 1)
|
||||
}}
|
||||
>
|
||||
<svelte:fragment slot="badges">
|
||||
{#snippet badges()}
|
||||
{#if post.withCrossposts}
|
||||
<button
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
if (viewPost == post.post.id) viewPost = -1
|
||||
else viewPost = post.post.id
|
||||
}}
|
||||
@@ -76,7 +90,7 @@
|
||||
: 's'}
|
||||
</Badge>
|
||||
</button>{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</Post>
|
||||
{#if post.withCrossposts && viewPost == post.post.id}
|
||||
<div
|
||||
@@ -104,5 +118,5 @@
|
||||
{/if}
|
||||
{/each}
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
@@ -20,7 +22,7 @@
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly, slide } from 'svelte/transition'
|
||||
import { browser } from '$app/environment'
|
||||
import { afterUpdate, onMount, tick, type SvelteComponent } from 'svelte'
|
||||
import { onMount, tick, type SvelteComponent } from 'svelte'
|
||||
import {
|
||||
createVirtualizer,
|
||||
createWindowVirtualizer,
|
||||
@@ -39,12 +41,28 @@
|
||||
import type { Readable } from 'svelte/motion'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
|
||||
export let posts: PostView[]
|
||||
export let community: boolean = false
|
||||
export let feedId: PostFeedID
|
||||
let virtualItemEls: HTMLElement[] = $state([])
|
||||
let virtualListEl: HTMLElement | undefined = $state(undefined)
|
||||
|
||||
let virtualItemEls: HTMLElement[] = []
|
||||
let virtualListEl: HTMLElement | undefined = undefined
|
||||
afterNavigate(() => {
|
||||
$virtualizer.scrollToIndex($postFeeds[feedId]?.lastSeen ?? 0)
|
||||
})
|
||||
|
||||
interface Props {
|
||||
posts: PostView[]
|
||||
community?: boolean
|
||||
feedId: PostFeedID
|
||||
feedData: PostFeed['data']
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
posts = $bindable(),
|
||||
community = false,
|
||||
feedId,
|
||||
feedData = $bindable(),
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
const virtualizer = createWindowVirtualizer({
|
||||
count: posts.length,
|
||||
@@ -55,27 +73,9 @@
|
||||
},
|
||||
})
|
||||
|
||||
$: items = $virtualizer.getVirtualItems()
|
||||
|
||||
$: if (virtualItemEls.length) {
|
||||
virtualItemEls.forEach($virtualizer.measureElement)
|
||||
}
|
||||
|
||||
$: if (posts.length && virtualListEl)
|
||||
$virtualizer.setOptions({
|
||||
scrollMargin: virtualListEl?.offsetTop,
|
||||
count: posts.length,
|
||||
})
|
||||
|
||||
afterNavigate(() => {
|
||||
$virtualizer.scrollToIndex($postFeeds[feedId]?.lastSeen ?? 0)
|
||||
})
|
||||
|
||||
export let feedData: PostFeed['data']
|
||||
|
||||
let error: any = undefined
|
||||
let loading = false
|
||||
let hasMore = true
|
||||
let error: any = $state(undefined)
|
||||
let loading = $state(false)
|
||||
let hasMore = $state(true)
|
||||
|
||||
async function loadMore() {
|
||||
if (!hasMore || loading) return
|
||||
@@ -181,6 +181,19 @@
|
||||
await tick()
|
||||
$virtualizer.measure()
|
||||
})
|
||||
let items = $derived($virtualizer.getVirtualItems())
|
||||
run(() => {
|
||||
if (virtualItemEls.length) {
|
||||
virtualItemEls.forEach($virtualizer.measureElement)
|
||||
}
|
||||
})
|
||||
run(() => {
|
||||
if (posts.length && virtualListEl)
|
||||
$virtualizer.setOptions({
|
||||
scrollMargin: virtualListEl?.offsetTop,
|
||||
count: posts.length,
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<!-- <svelte:window on:keydown={handleKeydown} /> -->
|
||||
@@ -198,7 +211,9 @@
|
||||
description="There are no posts that match this filter."
|
||||
>
|
||||
<Button href="/communities">
|
||||
<Icon src={Plus} size="16" mini slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" mini />
|
||||
{/snippet}
|
||||
<span>Follow some communities</span>
|
||||
</Button>
|
||||
</Placeholder>
|
||||
@@ -284,16 +299,20 @@
|
||||
// @ts-ignore
|
||||
community_name: feedData.community_name ?? 'undefined',
|
||||
})}
|
||||
<Button slot="action" color="tertiary">
|
||||
<Icon src={ChevronDoubleUp} size="16" micro slot="prefix" />
|
||||
{$t('routes.post.scrollToTop')}
|
||||
</Button>
|
||||
{#snippet action()}
|
||||
<Button color="tertiary">
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChevronDoubleUp} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('routes.post.scrollToTop')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</EndPlaceholder>
|
||||
</div>
|
||||
{/if}
|
||||
<InfiniteScroll window threshold={1000} on:loadMore={loadMore} />
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
|
||||
<style lang="postcss">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { userSettings } from "$lib/settings"
|
||||
import type { PostView } from "lemmy-js-client"
|
||||
import { get } from "svelte/store"
|
||||
import { userSettings } from '$lib/settings.svelte'
|
||||
import type { PostView } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export type PostViewWithCrossposts = PostView & {
|
||||
withCrossposts: true
|
||||
@@ -54,4 +54,4 @@ export const combineCrossposts = (
|
||||
})
|
||||
|
||||
return results
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
||||
import { client, site } from '$lib/lemmy.js'
|
||||
import type { Community, Post, PostView } from 'lemmy-js-client'
|
||||
@@ -33,46 +35,56 @@
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import FreeTextInput from '$lib/components/input/FreeTextInput.svelte'
|
||||
|
||||
export let edit = false
|
||||
|
||||
/**
|
||||
* The post to edit
|
||||
*/
|
||||
export let editingPost: Post | undefined = undefined
|
||||
|
||||
export let passedCommunity: Community | undefined = undefined
|
||||
|
||||
export let data: {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
thumbnail?: string
|
||||
url?: string
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
alt_text?: string
|
||||
language_id?: number
|
||||
} = {
|
||||
community: null,
|
||||
title: '',
|
||||
body: '',
|
||||
image: null,
|
||||
thumbnail: undefined,
|
||||
url: undefined,
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
language_id: undefined,
|
||||
interface Props {
|
||||
edit?: boolean
|
||||
/**
|
||||
* The post to edit
|
||||
*/
|
||||
editingPost?: Post | undefined
|
||||
passedCommunity?: Community | undefined
|
||||
data?: {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
thumbnail?: string
|
||||
url?: string
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
alt_text?: string
|
||||
language_id?: number
|
||||
}
|
||||
formtitle?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
edit = false,
|
||||
editingPost = undefined,
|
||||
passedCommunity = undefined,
|
||||
data = $bindable({
|
||||
community: null,
|
||||
title: '',
|
||||
body: '',
|
||||
image: null,
|
||||
thumbnail: undefined,
|
||||
url: undefined,
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
language_id: undefined,
|
||||
}),
|
||||
formtitle,
|
||||
}: Props = $props()
|
||||
// weird select menu language handling
|
||||
// @ts-ignore
|
||||
$: if (data.language_id === '') data.language_id = undefined
|
||||
run(() => {
|
||||
if (data.language_id === '') data.language_id = undefined
|
||||
})
|
||||
|
||||
let saveDraft = edit ? false : true
|
||||
let communitySearch = passedCommunity?.name ?? ''
|
||||
let communitySearch = $state(passedCommunity?.name ?? '')
|
||||
|
||||
let communities: Community[] = []
|
||||
let communities: Community[] = $state([])
|
||||
|
||||
const dispatcher = createEventDispatcher<{ submit: PostView }>()
|
||||
|
||||
@@ -179,7 +191,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
let uploadingImage = false
|
||||
let uploadingImage = $state(false)
|
||||
|
||||
const generateTitle = async (url: string | undefined) => {
|
||||
if (!url) return
|
||||
@@ -224,15 +236,17 @@
|
||||
return true
|
||||
}
|
||||
|
||||
let generation = {
|
||||
let generation = $state({
|
||||
loading: false,
|
||||
generatable: false,
|
||||
title: '',
|
||||
}
|
||||
})
|
||||
|
||||
let addAltText = false
|
||||
let addAltText = $state(false)
|
||||
|
||||
$: generation.generatable = canGenerateTitle(data.url)
|
||||
run(() => {
|
||||
generation.generatable = canGenerateTitle(data.url)
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if uploadingImage}
|
||||
@@ -248,12 +262,12 @@
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
<form on:submit|preventDefault={submit} class="flex flex-col gap-4 h-full">
|
||||
<slot name="formtitle">
|
||||
<form onsubmit={preventDefault(submit)} class="flex flex-col gap-4 h-full">
|
||||
{#if formtitle}{@render formtitle()}{:else}
|
||||
<Header class="font-bold text-xl">
|
||||
{edit ? $t('form.post.edit') : $t('form.post.create')}
|
||||
</Header>
|
||||
</slot>
|
||||
{/if}
|
||||
<ErrorContainer scope="post-form" />
|
||||
{#if !edit && data}
|
||||
{#if !data.community}
|
||||
@@ -285,12 +299,13 @@
|
||||
alignment="left"
|
||||
size="sm"
|
||||
>
|
||||
<Avatar
|
||||
url={data.community.icon}
|
||||
alt={data.community.name}
|
||||
width={24}
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Avatar
|
||||
url={data.community.icon}
|
||||
alt={data.community.name}
|
||||
width={24}
|
||||
/>
|
||||
{/snippet}
|
||||
<div class="flex flex-col gap-0">
|
||||
<span class="text-xs">{data.community.name}</span>
|
||||
<span class="text-[10px] leading-3">
|
||||
@@ -326,7 +341,9 @@
|
||||
<div
|
||||
class="border border-slate-100 rounded-xl h-6 w-6 grid place-items-center"
|
||||
>
|
||||
<Icon src={Plus} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" micro />
|
||||
{/snippet}
|
||||
</div>
|
||||
{#if data.url}
|
||||
<Button
|
||||
@@ -336,12 +353,9 @@
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon
|
||||
src={ChatBubbleBottomCenterText}
|
||||
size="15"
|
||||
micro
|
||||
slot="prefix"
|
||||
/>{$t('form.post.altText')}
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChatBubbleBottomCenterText} size="15" micro />
|
||||
{/snippet}{$t('form.post.altText')}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
@@ -351,7 +365,9 @@
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Photo} size="15" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Photo} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.uploadImage')}
|
||||
</Button>
|
||||
{#if generation.generatable}
|
||||
@@ -363,7 +379,9 @@
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Sparkles} size="15" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Sparkles} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.generateTitle')}
|
||||
</Button>
|
||||
{/if}
|
||||
@@ -433,7 +451,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
<div class="mt-auto" />
|
||||
<div class="mt-auto"></div>
|
||||
<div class="flex flex-row items-center gap-2 w-full">
|
||||
<Button
|
||||
submit
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { client, getInstance } from '$lib/lemmy.js'
|
||||
import type { View } from '$lib/settings'
|
||||
import type { View } from '$lib/settings.svelte'
|
||||
import { isImage, isVideo } from '$lib/ui/image'
|
||||
import { canParseUrl, findClosestNumber } from '$lib/util'
|
||||
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
|
||||
@@ -10,7 +10,7 @@ export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||
export const bestImageURL = (
|
||||
post: Post,
|
||||
compact: boolean = true,
|
||||
width: number = 1024
|
||||
width: number = 1024,
|
||||
) => {
|
||||
if (post.thumbnail_url) return optimizeImageURL(post.thumbnail_url, width)
|
||||
else if (post.url) return optimizeImageURL(post.url, width)
|
||||
@@ -20,7 +20,7 @@ export const bestImageURL = (
|
||||
|
||||
export const optimizeImageURL = (
|
||||
urlStr: string,
|
||||
width: number = 1024
|
||||
width: number = 1024,
|
||||
): string => {
|
||||
try {
|
||||
const url = new URL(urlStr)
|
||||
@@ -32,8 +32,8 @@ export const optimizeImageURL = (
|
||||
'thumbnail',
|
||||
findClosestNumber(
|
||||
[128, 196, 256, 512, 728, 1024, 1536],
|
||||
width
|
||||
).toString()
|
||||
width,
|
||||
).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ export const iframeType = (url: string): IframeType => {
|
||||
export async function hidePost(
|
||||
id: number,
|
||||
hide: boolean,
|
||||
jwt: string
|
||||
jwt: string,
|
||||
): Promise<boolean> {
|
||||
const res = await client({ auth: jwt }).hidePost({
|
||||
hide: hide,
|
||||
|
||||
@@ -12,14 +12,25 @@
|
||||
import { t } from '$lib/translations'
|
||||
import type { View } from '$lib/settings'
|
||||
|
||||
export let url: string
|
||||
export let thumbnail_url: string | undefined = undefined
|
||||
export let nsfw: boolean = false
|
||||
export let embed_title: string | undefined = undefined
|
||||
export let embed_description: string | undefined = undefined
|
||||
export let view: View = 'cozy'
|
||||
interface Props {
|
||||
url: string
|
||||
thumbnail_url?: string | undefined
|
||||
nsfw?: boolean
|
||||
embed_title?: string | undefined
|
||||
embed_description?: string | undefined
|
||||
view?: View
|
||||
}
|
||||
|
||||
$: richURL = parseURL(url)
|
||||
let {
|
||||
url,
|
||||
thumbnail_url = undefined,
|
||||
nsfw = false,
|
||||
embed_title = undefined,
|
||||
embed_description = undefined,
|
||||
view = 'cozy',
|
||||
}: Props = $props()
|
||||
|
||||
let richURL = $derived(parseURL(url))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -105,37 +116,39 @@
|
||||
rounded-full flex p-1 relative -top-7 min-[384px]:mx-3 mt-8 min-[384px]:mt-0 mx-auto -mb-7 w-max max-w-full overflow-auto"
|
||||
>
|
||||
<PostLinkSources {url}>
|
||||
<Button
|
||||
color="tertiary"
|
||||
slot="target"
|
||||
size="sm"
|
||||
class="w-max text-slate-600 dark:text-zinc-400 block
|
||||
text-xs flex-shrink-0"
|
||||
rounding="pill"
|
||||
>
|
||||
<Icon src={LinkIcon} size="16" micro class="flex-shrink-0" />
|
||||
{$t('post.actions.link.actions')}
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
color="tertiary"
|
||||
size="sm"
|
||||
class="w-max text-slate-600 dark:text-zinc-400 block
|
||||
text-xs flex-shrink-0"
|
||||
rounding="pill"
|
||||
>
|
||||
<Icon src={LinkIcon} size="16" micro class="flex-shrink-0" />
|
||||
{$t('post.actions.link.actions')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</PostLinkSources>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex space-x-1">
|
||||
<PostLinkSources {url}>
|
||||
<Button
|
||||
color="ghost"
|
||||
slot="target"
|
||||
size="xs"
|
||||
rounding="pill"
|
||||
class="p-0.5 px-1 w-max mt-auto text-slate-600 dark:text-zinc-400 block
|
||||
text-xs"
|
||||
>
|
||||
<div class="mr-0.5" style="width: 8px;">
|
||||
<Icon src={LinkIcon} size="16" micro />
|
||||
</div>
|
||||
<div class="mr-1" style="width: 8px;">
|
||||
<Icon src={ChevronDown} size="16" micro />
|
||||
</div>
|
||||
</Button>
|
||||
{#snippet target()}
|
||||
<Button
|
||||
color="ghost"
|
||||
size="xs"
|
||||
rounding="pill"
|
||||
class="p-0.5 px-1 w-max mt-auto text-slate-600 dark:text-zinc-400 block
|
||||
text-xs"
|
||||
>
|
||||
<div class="mr-0.5" style="width: 8px;">
|
||||
<Icon src={LinkIcon} size="16" micro />
|
||||
</div>
|
||||
<div class="mr-1" style="width: 8px;">
|
||||
<Icon src={ChevronDown} size="16" micro />
|
||||
</div>
|
||||
</Button>
|
||||
{/snippet}
|
||||
</PostLinkSources>
|
||||
<Button
|
||||
href={url}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
const sources: {
|
||||
getLink: (url: string) => string
|
||||
name: string
|
||||
@@ -43,12 +43,20 @@
|
||||
import type { MediaType } from '../helpers'
|
||||
import { Icon, Share } from 'svelte-hero-icons'
|
||||
|
||||
export let url: string
|
||||
export let type: MediaType = 'embed'
|
||||
interface Props {
|
||||
url: string
|
||||
type?: MediaType
|
||||
target?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { url, type = 'embed', target, ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Menu {...$$restProps}>
|
||||
<slot name="target" slot="target" />
|
||||
<Menu {...rest}>
|
||||
{#snippet target()}
|
||||
{@render target?.()}
|
||||
{/snippet}
|
||||
|
||||
<MenuDivider>{$t('post.actions.link.title')}</MenuDivider>
|
||||
{#each sources as source}
|
||||
@@ -66,7 +74,9 @@
|
||||
toast({ content: $t('toast.copied') })
|
||||
}}
|
||||
>
|
||||
<Icon src={Share} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('post.actions.more.share')}
|
||||
</MenuButton>
|
||||
</Menu>
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
const youtubeDomain = (place: 'youtube' | 'invidious' | 'piped') => {
|
||||
switch (place) {
|
||||
case 'youtube': {
|
||||
@@ -37,12 +37,6 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export let type: IframeType = 'none'
|
||||
export let thumbnail: string | undefined = undefined
|
||||
export let url: string
|
||||
export let opened = !$userSettings.embeds.clickToView
|
||||
export let autoplay: boolean = $userSettings.embeds.clickToView
|
||||
|
||||
const urlToEmbed = (inputUrl: string) => {
|
||||
if (type == 'video') {
|
||||
return inputUrl
|
||||
@@ -56,7 +50,7 @@
|
||||
if (autoplay) url.searchParams.set('autoplay', '1')
|
||||
|
||||
return `https://${youtubeDomain(
|
||||
$userSettings.embeds.youtube
|
||||
$userSettings.embeds.youtube,
|
||||
)}/embed/${videoID}?${url.searchParams.toString()}`
|
||||
}
|
||||
|
||||
@@ -64,7 +58,7 @@
|
||||
}
|
||||
|
||||
const typeData = (
|
||||
type: IframeType
|
||||
type: IframeType,
|
||||
): {
|
||||
icon: IconSource
|
||||
text: string
|
||||
@@ -91,11 +85,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: data = typeData(type)
|
||||
$: embedUrl = urlToEmbed(url)
|
||||
interface Props {
|
||||
type?: IframeType
|
||||
thumbnail?: string | undefined
|
||||
url: string
|
||||
opened?: any
|
||||
autoplay?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
type = 'none',
|
||||
thumbnail = undefined,
|
||||
url,
|
||||
opened = $bindable(!$userSettings.embeds.clickToView),
|
||||
autoplay = $userSettings.embeds.clickToView,
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let data = $derived(typeData(type))
|
||||
let embedUrl = $derived(urlToEmbed(url))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -104,7 +113,7 @@
|
||||
-->
|
||||
{#if opened}
|
||||
{#if type == 'video'}
|
||||
<!-- svelte-ignore a11y-media-has-caption -->
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video {autoplay} controls class="rounded-xl aspect-video {clazz}">
|
||||
<source src={url} />
|
||||
</video>
|
||||
@@ -116,11 +125,11 @@
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
allowfullscreen
|
||||
class="aspect-video rounded-xl dark:bg-zinc-900 {clazz ?? ''}"
|
||||
/>
|
||||
></iframe>
|
||||
{/if}
|
||||
{:else}
|
||||
<button
|
||||
on:click={() => (opened = true)}
|
||||
onclick={() => (opened = true)}
|
||||
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center text-white"
|
||||
>
|
||||
{#if thumbnail}
|
||||
@@ -132,7 +141,7 @@
|
||||
{:else}
|
||||
<div
|
||||
class="absolute blur-3xl -z-10 top-0 left-0 w-full h-full bg-gradient-to-br from-green-800 via-blue-900 via-20% to-red-700"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
<Icon src={data.icon} solid size="48" />
|
||||
<h1 class="font-bold text-xl">{data.text}</h1>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { stopPropagation } from 'svelte/legacy'
|
||||
|
||||
import { userSettings, type View } from '$lib/settings'
|
||||
import type { Post } from 'lemmy-js-client'
|
||||
import { bestImageURL, postLink } from '../helpers'
|
||||
@@ -6,10 +8,14 @@
|
||||
import { Button, modal } from 'mono-svelte'
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
export let post: Post
|
||||
export let blur: boolean = false
|
||||
interface Props {
|
||||
post: Post
|
||||
blur?: boolean
|
||||
}
|
||||
|
||||
let imageLoaded: boolean | null = null
|
||||
let { post, blur = false }: Props = $props()
|
||||
|
||||
let imageLoaded: boolean | null = $state(null)
|
||||
|
||||
onMount(() => {
|
||||
imageLoaded = false
|
||||
@@ -23,11 +29,11 @@
|
||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.name}
|
||||
on:click={() => showImage(bestImageURL(post, false, -1))}
|
||||
onclick={() => showImage(bestImageURL(post, false, -1))}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
loading="lazy"
|
||||
fetchpriority="auto"
|
||||
@@ -52,7 +58,7 @@
|
||||
srcset={bestImageURL(post, false, 1512)}
|
||||
media="(max-width: 1512px)"
|
||||
/>
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={bestImageURL(post, false, -1)}
|
||||
loading="lazy"
|
||||
@@ -63,16 +69,16 @@
|
||||
height={300}
|
||||
class:blur-[64px]={blur}
|
||||
alt={post.alt_text ?? ''}
|
||||
on:load={() => (imageLoaded = true)}
|
||||
onload={() => (imageLoaded = true)}
|
||||
/>
|
||||
</picture>
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
class="absolute bottom-0 left-0 right-0 flex justify-between items-center
|
||||
rounded-full ml-auto w-max m-2 p-0 gap-1
|
||||
*:bg-white *:border *:border-slate-200 *:dark:border-zinc-800 *:dark:bg-zinc-900"
|
||||
on:click|stopPropagation={() => {}}
|
||||
onclick={stopPropagation(() => {})}
|
||||
>
|
||||
{#if post.alt_text}
|
||||
<Button
|
||||
|
||||
@@ -18,11 +18,21 @@
|
||||
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||
import PostImage from './PostImage.svelte'
|
||||
|
||||
export let view: 'card' | 'cozy' | 'list' | 'compact' = 'cozy'
|
||||
export let post: Post
|
||||
export let type: MediaType = 'none'
|
||||
export let opened: boolean | undefined = undefined
|
||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||
interface Props {
|
||||
view?: 'card' | 'cozy' | 'list' | 'compact'
|
||||
post: Post
|
||||
type?: MediaType
|
||||
opened?: boolean | undefined
|
||||
blur?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
view = 'cozy',
|
||||
post,
|
||||
type = 'none',
|
||||
opened = undefined,
|
||||
blur = post.nsfw && $userSettings.nsfwBlur,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<!--
|
||||
|
||||
@@ -18,19 +18,28 @@
|
||||
ExclamationTriangle,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
export let post: Post
|
||||
export let type: MediaType = 'none'
|
||||
export let view: View = 'cozy'
|
||||
export let blur: boolean = post.nsfw && $userSettings.nsfwBlur
|
||||
|
||||
const thumbnailSize = (view: View) =>
|
||||
view == 'compact' ? 'w-22 h-22 sm:w-28' : 'w-24 h-24 sm:w-32'
|
||||
|
||||
$: size = thumbnailSize(view)
|
||||
interface Props {
|
||||
post: Post
|
||||
type?: MediaType
|
||||
view?: View
|
||||
blur?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
post,
|
||||
type = 'none',
|
||||
view = 'cozy',
|
||||
blur = post.nsfw && $userSettings.nsfwBlur,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
let size = $derived(thumbnailSize(view))
|
||||
</script>
|
||||
|
||||
<!--
|
||||
@@ -43,15 +52,16 @@
|
||||
openOnHover
|
||||
placement={$userSettings.leftAlign ? 'bottom-start' : 'bottom-end'}
|
||||
>
|
||||
<Material
|
||||
slot="target"
|
||||
padding="none"
|
||||
rounding="full"
|
||||
elevation="high"
|
||||
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
|
||||
>
|
||||
ALT
|
||||
</Material>
|
||||
{#snippet target()}
|
||||
<Material
|
||||
padding="none"
|
||||
rounding="full"
|
||||
elevation="high"
|
||||
class="w-max absolute bottom-0 left-0 py-0.5 px-1.5 m-1 font-bold"
|
||||
>
|
||||
ALT
|
||||
</Material>
|
||||
{/snippet}
|
||||
<div class="max-w-sm">
|
||||
{post.alt_text}
|
||||
</div>
|
||||
@@ -60,7 +70,7 @@
|
||||
<svelte:element
|
||||
this={!$userSettings.expandImages || type != 'image' ? 'a' : 'button'}
|
||||
href={postLink(post)}
|
||||
on:click={() => {
|
||||
onclick={() => {
|
||||
if (type == 'image') {
|
||||
showImage(bestImageURL(post, false, -1))
|
||||
}
|
||||
|
||||
@@ -7,11 +7,21 @@
|
||||
import { Icon, XCircle } from 'svelte-hero-icons'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let q: string = ''
|
||||
interface Props {
|
||||
q?: string
|
||||
instance?: string | undefined
|
||||
listing_type?: ListingType
|
||||
showWhenEmpty?: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let instance: string | undefined = undefined
|
||||
export let listing_type: ListingType = 'Subscribed'
|
||||
export let showWhenEmpty: boolean = false
|
||||
let {
|
||||
q = $bindable(''),
|
||||
instance = undefined,
|
||||
listing_type = 'Subscribed',
|
||||
showWhenEmpty = false,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: Person | undefined }>()
|
||||
</script>
|
||||
@@ -32,31 +42,33 @@
|
||||
on:select
|
||||
bind:query={q}
|
||||
{showWhenEmpty}
|
||||
{...$$restProps}
|
||||
let:item
|
||||
let:select
|
||||
{...rest}
|
||||
>
|
||||
<div class="w-full h-full" slot="noresults">
|
||||
{#if showWhenEmpty}
|
||||
<MenuButton on:click={() => dispatcher('select', undefined)}>
|
||||
<Icon src={XCircle} size="16" mini />
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if showWhenEmpty}
|
||||
<MenuButton on:click={() => 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 on:click={() => select(item)}>
|
||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None</span>
|
||||
<span>{item.name}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton on:click={() => select(item)}>
|
||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.name}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
@@ -11,12 +11,21 @@
|
||||
import { userLink } from '$lib/lemmy/generic'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
|
||||
export let user: PersonView
|
||||
export let view: 'cozy' | 'compact' = 'compact'
|
||||
export let showCounts: boolean = true
|
||||
interface Props {
|
||||
user: PersonView
|
||||
view?: 'cozy' | 'compact'
|
||||
showCounts?: boolean
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let clazz: string = 'py-4 flex flex-col gap-4 text-sm max-w-full relative'
|
||||
export { clazz as class }
|
||||
let {
|
||||
user,
|
||||
view = 'compact',
|
||||
showCounts = true,
|
||||
class: clazz = 'py-4 flex flex-col gap-4 text-sm max-w-full relative',
|
||||
icon,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class={clazz}>
|
||||
@@ -32,9 +41,9 @@
|
||||
? 'flex-col gap-2'
|
||||
: 'flex-row'} gap-2 items-center"
|
||||
>
|
||||
<slot name="icon">
|
||||
{#if icon}{@render icon()}{:else}
|
||||
<Avatar url={user.person.avatar} width={32} alt={user.person.name} />
|
||||
</slot>
|
||||
{/if}
|
||||
<div class="flex flex-col">
|
||||
<div class="font-medium text-base">
|
||||
{user.person.display_name ?? user.person.name}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { env } from '$env/dynamic/public'
|
||||
|
||||
import type { IconSource } from 'svelte-hero-icons'
|
||||
@@ -18,7 +18,7 @@
|
||||
const badges = parseBadge()
|
||||
|
||||
const getEnvBadge = (
|
||||
actor_id: string
|
||||
actor_id: string,
|
||||
):
|
||||
| {
|
||||
classes: string
|
||||
@@ -54,21 +54,36 @@
|
||||
import type { Person } from 'lemmy-js-client'
|
||||
import { Icon, Language, NoSymbol } from 'svelte-hero-icons'
|
||||
|
||||
export let user: Person
|
||||
export let avatar: boolean = false
|
||||
export let avatarSize: number = 24
|
||||
export let badges: boolean = true
|
||||
export let inComment: boolean = false
|
||||
export let showInstance: boolean =
|
||||
$userSettings.showInstances.user ||
|
||||
($userSettings.showInstances.comments && inComment)
|
||||
export let displayName = $userSettings.displayNames
|
||||
interface Props {
|
||||
user: Person
|
||||
avatar?: boolean
|
||||
avatarSize?: number
|
||||
badges?: boolean
|
||||
inComment?: boolean
|
||||
showInstance?: boolean
|
||||
displayName?: any
|
||||
instanceClass?: string
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
extraBadges?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
$: envBadge = getEnvBadge(user.actor_id)
|
||||
let {
|
||||
user,
|
||||
avatar = false,
|
||||
avatarSize = 24,
|
||||
badges = true,
|
||||
inComment = false,
|
||||
showInstance = $userSettings.showInstances.user ||
|
||||
($userSettings.showInstances.comments && inComment),
|
||||
displayName = $userSettings.displayNames,
|
||||
instanceClass = '',
|
||||
class: clazz = '',
|
||||
children,
|
||||
extraBadges,
|
||||
}: Props = $props()
|
||||
|
||||
export let instanceClass: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let envBadge = $derived(getEnvBadge(user.actor_id))
|
||||
</script>
|
||||
|
||||
<a
|
||||
@@ -76,7 +91,7 @@
|
||||
href="/u/{user.name}@{new URL(user.actor_id).hostname}"
|
||||
data-sveltekit-preload-data="tap"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
{#if avatar}
|
||||
<Avatar
|
||||
url={user.avatar}
|
||||
@@ -125,7 +140,7 @@
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
<slot name="badges" />
|
||||
{@render extraBadges?.()}
|
||||
{/if}
|
||||
</a>
|
||||
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { goto } from '$app/navigation'
|
||||
import { t } from '$lib/translations'
|
||||
import { TextInput } from 'mono-svelte'
|
||||
|
||||
let query: string = ''
|
||||
let loading = false
|
||||
let query: string = $state('')
|
||||
let loading = $state(false)
|
||||
|
||||
function search() {
|
||||
loading = true
|
||||
goto(`/search?q=${query}`).then(() => (loading = false))
|
||||
}
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
let { class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<form on:submit|preventDefault={search} class="w-full h-full {clazz}">
|
||||
<form onsubmit={preventDefault(search)} class="w-full h-full {clazz}">
|
||||
<TextInput
|
||||
bind:value={query}
|
||||
class="w-full h-full {clazz}"
|
||||
@@ -22,4 +28,4 @@
|
||||
autofocus
|
||||
/>
|
||||
</form>
|
||||
<slot {search} {loading} />
|
||||
{@render children?.({ search, loading })}
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { marked } from 'marked'
|
||||
import {
|
||||
MdCode,
|
||||
@@ -88,20 +88,32 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import SvelteMarkdown from 'svelte-markdown'
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
export let source: string = ''
|
||||
export let inline: boolean = false
|
||||
import SvelteMarkdown from 'svelte-markdown'
|
||||
|
||||
options.inline = inline
|
||||
|
||||
export let noStyle: boolean = false
|
||||
interface Props {
|
||||
source?: string
|
||||
inline?: boolean
|
||||
noStyle?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
$: tokens = marked.lexer(source)
|
||||
let {
|
||||
source = '',
|
||||
inline = false,
|
||||
noStyle = false,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let tokens
|
||||
run(() => {
|
||||
tokens = marked.lexer(source)
|
||||
})
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.js'
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
@@ -22,30 +24,21 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import ImageUploadModal from '../lemmy/modal/ImageUploadModal.svelte'
|
||||
|
||||
export let images: boolean = true
|
||||
export let value: string = ''
|
||||
export let label: string | undefined = undefined
|
||||
export let previewButton: boolean = true
|
||||
export let tools: boolean = true
|
||||
export let disabled: boolean = false
|
||||
export let rows: number = 2
|
||||
|
||||
export let beforePreview: (input: string) => string = (input) => input
|
||||
|
||||
const dispatcher = createEventDispatcher<{ confirm: string }>()
|
||||
|
||||
let textArea: HTMLTextAreaElement
|
||||
let textArea: HTMLTextAreaElement | undefined = $state()
|
||||
|
||||
function replaceTextAtIndices(
|
||||
str: string,
|
||||
startIndex: number,
|
||||
endIndex: number,
|
||||
replacement: string
|
||||
replacement: string,
|
||||
) {
|
||||
return str.substring(0, startIndex) + replacement + str.substring(endIndex)
|
||||
}
|
||||
|
||||
function wrapSelection(start: string, end: string) {
|
||||
if (!textArea) return
|
||||
const startPos = textArea.selectionStart
|
||||
const endPos = textArea.selectionEnd
|
||||
|
||||
@@ -56,7 +49,7 @@
|
||||
textArea.value,
|
||||
startPos,
|
||||
endPos,
|
||||
newText
|
||||
newText,
|
||||
)
|
||||
|
||||
textArea.focus()
|
||||
@@ -66,10 +59,8 @@
|
||||
value = textArea.value
|
||||
}
|
||||
|
||||
let uploadingImage = false
|
||||
let image: any
|
||||
|
||||
export let previewing = false
|
||||
let uploadingImage = $state(false)
|
||||
let image: any = $state()
|
||||
|
||||
const shortcuts = {
|
||||
KeyB: () => wrapSelection('**', '**'),
|
||||
@@ -92,10 +83,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: if (!previewing && value) adjustHeight()
|
||||
interface Props {
|
||||
images?: boolean
|
||||
value?: string
|
||||
label?: string | undefined
|
||||
previewButton?: boolean
|
||||
tools?: boolean
|
||||
disabled?: boolean
|
||||
rows?: number
|
||||
beforePreview?: (input: string) => string
|
||||
previewing?: boolean
|
||||
class?: string
|
||||
customLabel?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
images = true,
|
||||
value = $bindable(''),
|
||||
label = undefined,
|
||||
previewButton = true,
|
||||
tools = true,
|
||||
disabled = false,
|
||||
rows = 2,
|
||||
beforePreview = (input) => input,
|
||||
previewing = $bindable(false),
|
||||
class: clazz = '',
|
||||
customLabel,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
run(() => {
|
||||
if (!previewing && value) adjustHeight()
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if uploadingImage && images}
|
||||
@@ -111,12 +133,12 @@
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
{#if label || $$slots.label}
|
||||
{#if label || customLabel}
|
||||
<Label>
|
||||
{#if label}
|
||||
{label}
|
||||
{:else if $$slots.label}
|
||||
<slot name="label" />
|
||||
{:else if customLabel}
|
||||
{@render customLabel?.()}
|
||||
{/if}
|
||||
</Label>
|
||||
{/if}
|
||||
@@ -264,7 +286,7 @@ overflow-hidden transition-colors {clazz}"
|
||||
}
|
||||
}}
|
||||
{rows}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -279,7 +301,7 @@ overflow-hidden transition-colors {clazz}"
|
||||
optionNames={[$t('form.edit'), $t('form.preview')]}
|
||||
/>
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import { Icon, ClipboardDocument } from 'svelte-hero-icons'
|
||||
|
||||
export let raw: string
|
||||
interface Props {
|
||||
raw: string
|
||||
}
|
||||
|
||||
let { raw }: Props = $props()
|
||||
|
||||
function parseCodeblock(src: string): {
|
||||
code: string
|
||||
@@ -21,7 +25,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: codeblock = parseCodeblock(raw)
|
||||
let codeblock = $derived(parseCodeblock(raw))
|
||||
</script>
|
||||
|
||||
<Material
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
<script lang="ts">
|
||||
export let depth: number = 0
|
||||
export let raw: string | undefined = undefined
|
||||
interface Props {
|
||||
depth?: number
|
||||
raw?: string | undefined
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { depth = 0, raw = undefined, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if depth === 1}
|
||||
<h1 class="font-bold text-4xl"><slot></slot></h1>
|
||||
<h1 class="font-bold text-4xl">{@render children?.()}</h1>
|
||||
{:else if depth === 2}
|
||||
<h2 class="font-bold text-3xl"><slot></slot></h2>
|
||||
<h2 class="font-bold text-3xl">{@render children?.()}</h2>
|
||||
{:else if depth === 3}
|
||||
<h3 class="font-bold text-2xl"><slot></slot></h3>
|
||||
<h3 class="font-bold text-2xl">{@render children?.()}</h3>
|
||||
{:else if depth === 4}
|
||||
<h4 class="font-semibold text-xl"><slot></slot></h4>
|
||||
<h4 class="font-semibold text-xl">{@render children?.()}</h4>
|
||||
{:else if depth === 5}
|
||||
<h5 class="font-semibold text-lg"><slot></slot></h5>
|
||||
<h5 class="font-semibold text-lg">{@render children?.()}</h5>
|
||||
{:else if depth === 6}
|
||||
<h6 class="font-semibold text-base"><slot></slot></h6>
|
||||
<h6 class="font-semibold text-base">{@render children?.()}</h6>
|
||||
{:else}
|
||||
{raw}
|
||||
{/if}
|
||||
@@ -1,5 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
interface Props {
|
||||
text: string
|
||||
}
|
||||
|
||||
let { text }: Props = $props()
|
||||
</script>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -7,11 +7,15 @@
|
||||
} from '$lib/components/lemmy/post/helpers'
|
||||
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
|
||||
|
||||
export let href: string
|
||||
export let title: string | undefined = undefined
|
||||
export let text: string = ''
|
||||
interface Props {
|
||||
href: string
|
||||
title?: string | undefined
|
||||
text?: string
|
||||
}
|
||||
|
||||
$: type = mediaType(href, 'cozy')
|
||||
let { href, title = undefined, text = '' }: Props = $props()
|
||||
|
||||
let type = $derived(mediaType(href, 'cozy'))
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -29,7 +33,7 @@
|
||||
{:else}
|
||||
<button
|
||||
class="inline"
|
||||
on:click={() => showImage(optimizeImageURL(href, -1), text)}
|
||||
onclick={() => showImage(optimizeImageURL(href, -1), text)}
|
||||
>
|
||||
<img
|
||||
src={optimizeImageURL(href, 1024)}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { photonify } from './plugins'
|
||||
|
||||
export let href = ''
|
||||
export let title = undefined
|
||||
interface Props {
|
||||
href?: string
|
||||
title?: any
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { href = '', title = undefined, children }: Props = $props()
|
||||
|
||||
export const parseURL = (href: string) => {
|
||||
try {
|
||||
@@ -12,7 +17,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: photonified = photonify(href)
|
||||
let photonified = $derived(photonify(href))
|
||||
</script>
|
||||
|
||||
<a
|
||||
@@ -20,5 +25,5 @@
|
||||
{title}
|
||||
class="hover:underline text-sky-600 dark:text-sky-500"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</a>
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let ordered: boolean
|
||||
export let start: number
|
||||
interface Props {
|
||||
ordered: boolean
|
||||
start: number
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { ordered, start, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if ordered}
|
||||
@@ -8,12 +13,12 @@
|
||||
{start}
|
||||
class="pl-5 list-decimal *:marker:font-medium *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ol>
|
||||
{:else}
|
||||
<ul
|
||||
class="list-disc pl-4 *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
{/if}
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
export let tokens
|
||||
let { tokens, children } = $props()
|
||||
</script>
|
||||
|
||||
<li>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</li>
|
||||
@@ -1,9 +1,16 @@
|
||||
<script>
|
||||
import { options } from '../Markdown.svelte'
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<p class="leading-[1.5] {options.inline ? '' : 'max-w'}">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</p>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<blockquote class="border-l-2 dark:border-zinc-700 border-slate-300 p-1 px-3">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</blockquote>
|
||||
@@ -6,7 +6,11 @@
|
||||
import { Icon } from 'svelte-hero-icons'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
|
||||
export let raw: string
|
||||
interface Props {
|
||||
raw: string
|
||||
}
|
||||
|
||||
let { raw }: Props = $props()
|
||||
|
||||
function extractTitle(text: string) {
|
||||
const spoilerRegex = /^::: ?spoiler (.+)\n([\s\S]+?)\n:::/gm
|
||||
@@ -25,12 +29,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: data = extractTitle(raw)
|
||||
let data = $derived(extractTitle(raw))
|
||||
</script>
|
||||
|
||||
<Expandable class="border-y border-slate-200 dark:border-zinc-800 py-2">
|
||||
<div slot="title" class="text-left">
|
||||
<SvelteMarkdown source={data.title} {renderers} {options} isInline />
|
||||
</div>
|
||||
{#snippet title()}
|
||||
<div class="text-left">
|
||||
<SvelteMarkdown source={data.title} {renderers} {options} isInline />
|
||||
</div>
|
||||
{/snippet}
|
||||
<SvelteMarkdown source={data.content} {renderers} {options} />
|
||||
</Expandable>
|
||||
@@ -1,5 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
interface Props {
|
||||
text: string
|
||||
}
|
||||
|
||||
let { text }: Props = $props()
|
||||
</script>
|
||||
|
||||
<sub>{text}</sub>
|
||||
@@ -1,5 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
interface Props {
|
||||
text: string
|
||||
}
|
||||
|
||||
let { text }: Props = $props()
|
||||
</script>
|
||||
|
||||
<sup>{text}</sup>
|
||||
@@ -1 +1,11 @@
|
||||
<slot />
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
{@render children?.()}
|
||||
@@ -37,7 +37,7 @@ export const linkify = markedLinkifyIt(
|
||||
|
||||
if (!self.re.community) {
|
||||
self.re.community = new RegExp(
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i,
|
||||
)
|
||||
}
|
||||
if (self.re.community.test(tail)) {
|
||||
@@ -63,7 +63,7 @@ export const linkify = markedLinkifyIt(
|
||||
|
||||
if (!self.re.user) {
|
||||
self.re.user = new RegExp(
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i,
|
||||
)
|
||||
}
|
||||
if (self.re.user.test(tail)) {
|
||||
@@ -86,7 +86,7 @@ export const linkify = markedLinkifyIt(
|
||||
},
|
||||
{
|
||||
fuzzyEmail: false,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
const regexes = {
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<table class="overflow-auto w-full table-fixed rounded-xl">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</table>
|
||||
@@ -1 +1,11 @@
|
||||
<tbody><slot /></tbody>
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<tbody>{@render children?.()}</tbody>
|
||||
@@ -1,13 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let header: boolean
|
||||
export let align:
|
||||
| 'left'
|
||||
| 'center'
|
||||
| 'right'
|
||||
| 'justify'
|
||||
| 'char'
|
||||
| null
|
||||
| undefined = undefined
|
||||
interface Props {
|
||||
header: boolean
|
||||
align?: 'left' | 'center' | 'right' | 'justify' | 'char' | null | undefined
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { header, align = undefined, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if header}
|
||||
@@ -15,13 +13,13 @@
|
||||
class="bg-slate-50 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 py-2 px-3"
|
||||
{align}
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</th>
|
||||
{:else}
|
||||
<td
|
||||
class="bg-slate-25 dark:bg-zinc-950 border border-slate-200 dark:border-zinc-800 py-2 px-3"
|
||||
{align}
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</td>
|
||||
{/if}
|
||||
@@ -1 +1,11 @@
|
||||
<thead><slot /></thead>
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<thead>{@render children?.()}</thead>
|
||||
@@ -1 +1,11 @@
|
||||
<tr><slot /></tr>
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<tr>{@render children?.()}</tr>
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { Button, Modal, Select, Spinner, TextArea } from 'mono-svelte'
|
||||
import { text } from './translation'
|
||||
import { locale, t } from '$lib/translations'
|
||||
@@ -10,16 +12,22 @@
|
||||
translatedText: string
|
||||
}
|
||||
|
||||
export let open: boolean = false
|
||||
interface Props {
|
||||
open?: boolean
|
||||
}
|
||||
|
||||
let { open = $bindable(false) }: Props = $props()
|
||||
let error = false
|
||||
|
||||
const opened = () => translate($text)
|
||||
|
||||
$: if (open) opened()
|
||||
run(() => {
|
||||
if (open) opened()
|
||||
})
|
||||
|
||||
let result: Promise<TranslateResponse> | undefined = undefined
|
||||
let from = 'auto'
|
||||
let to = $locale
|
||||
let result: Promise<TranslateResponse> | undefined = $state(undefined)
|
||||
let from = $state('auto')
|
||||
let to = $state($locale)
|
||||
|
||||
async function translate(text: string) {
|
||||
const url = $userSettings.translator
|
||||
@@ -53,9 +61,11 @@
|
||||
|
||||
<Modal title={$t('post.actions.more.translate')} bind:open>
|
||||
<TextArea bind:value={$text} rows={2}>
|
||||
<Button on:click={() => translate($text)} slot="suffix" color="primary">
|
||||
{$t('post.actions.more.translate')}
|
||||
</Button>
|
||||
{#snippet suffix()}
|
||||
<Button on:click={() => translate($text)} color="primary">
|
||||
{$t('post.actions.more.translate')}
|
||||
</Button>
|
||||
{/snippet}
|
||||
</TextArea>
|
||||
<div class="flex items-center gap-2 w-full">
|
||||
<Select bind:value={from} class="flex-1">
|
||||
|
||||
@@ -5,17 +5,9 @@
|
||||
|
||||
const sizes = [16, 24, 32, 48, 64, 96, 128, 256, 512]
|
||||
|
||||
export let url: string | undefined
|
||||
export let alt: string = ''
|
||||
export let title: string = ''
|
||||
export let circle: boolean = true
|
||||
|
||||
export let width: number
|
||||
export let res: number | undefined = undefined
|
||||
|
||||
const optimizeUrl = (
|
||||
url: string | undefined,
|
||||
res: number
|
||||
res: number,
|
||||
): string | undefined => {
|
||||
if (url === undefined) return
|
||||
|
||||
@@ -25,7 +17,7 @@
|
||||
if (res > -1) {
|
||||
urlObj.searchParams.append(
|
||||
'thumbnail',
|
||||
findClosestNumber(sizes, res).toString()
|
||||
findClosestNumber(sizes, res).toString(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -35,17 +27,38 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: optimizedURLs = [2, 3, 6, -1].map((n) =>
|
||||
optimizeUrl(url, (res || width) * n)
|
||||
interface Props {
|
||||
url: string | undefined
|
||||
alt?: string
|
||||
title?: string
|
||||
circle?: boolean
|
||||
width: number
|
||||
res?: number | undefined
|
||||
style?: string
|
||||
class?: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
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)),
|
||||
)
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
</script>
|
||||
|
||||
{#if optimizedURLs[0] != undefined}
|
||||
<img
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
loading="lazy"
|
||||
srcset="{optimizedURLs[0]} 1x, {optimizedURLs[1]} 2x, {optimizedURLs[2]} 4x, {optimizedURLs[3]} 6x"
|
||||
src={optimizedURLs[0]}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
action?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { class: clazz = '', children, action }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -8,8 +13,8 @@
|
||||
text-sm text-slate-600 dark:text-zinc-400 gap-2 flex-wrap {clazz}"
|
||||
>
|
||||
<span class="font-medium text-left">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</span>
|
||||
<hr class="border-slate-200 flex-1 w-full dark:border-zinc-800" />
|
||||
<slot name="action" />
|
||||
{@render action?.()}
|
||||
</div>
|
||||
@@ -1,15 +1,25 @@
|
||||
<script lang="ts">
|
||||
import Avatar from './Avatar.svelte'
|
||||
|
||||
export let name: string
|
||||
export let label: string | undefined = undefined
|
||||
export let icon: string | undefined = undefined
|
||||
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">
|
||||
<slot name="icon">
|
||||
{#if customIcon}{@render customIcon()}{:else}
|
||||
<Avatar url={icon} width={32} />
|
||||
</slot>
|
||||
{/if}
|
||||
<div class="flex flex-col">
|
||||
<span class="font-semibold text-base">{name}</span>
|
||||
<span class="text-sm">{label}</span>
|
||||
|
||||
@@ -6,28 +6,46 @@
|
||||
import { optimizeImageURL } from '../lemmy/post/helpers'
|
||||
import FormattedNumber from '../util/FormattedNumber.svelte'
|
||||
|
||||
export let avatar: string | undefined = undefined
|
||||
export let name: string
|
||||
export let bio: string | undefined = undefined
|
||||
export let banner: string | undefined = undefined
|
||||
export let url: string | undefined = undefined
|
||||
export let stats: {
|
||||
interface Props {
|
||||
avatar?: string | undefined
|
||||
name: string
|
||||
value: string
|
||||
format?: boolean
|
||||
}[] = []
|
||||
bio?: string | undefined
|
||||
banner?: string | undefined
|
||||
url?: string | undefined
|
||||
stats?: {
|
||||
name: string
|
||||
value: string
|
||||
format?: boolean
|
||||
}[]
|
||||
center?: boolean
|
||||
class?: string
|
||||
nameDetail?: import('svelte').Snippet
|
||||
actions?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let center: boolean = false
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
avatar = undefined,
|
||||
name,
|
||||
bio = undefined,
|
||||
banner = undefined,
|
||||
url = undefined,
|
||||
stats = [],
|
||||
center = false,
|
||||
class: clazz = '',
|
||||
nameDetail,
|
||||
actions,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<Material
|
||||
color="transparent"
|
||||
padding="none"
|
||||
rounding="xl"
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class="z-10 relative border-slate-200 dark:border-zinc-700 {clazz}"
|
||||
>
|
||||
{#if banner || avatar}
|
||||
@@ -72,12 +90,12 @@
|
||||
<span
|
||||
class="flex items-center gap-0 text-sm text-slate-600 dark:text-zinc-400 max-w-full w-max"
|
||||
>
|
||||
<slot name="nameDetail" />
|
||||
{@render nameDetail?.()}
|
||||
</span>
|
||||
|
||||
{#if $$slots.actions}
|
||||
{#if actions}
|
||||
<div class="flex flex-col mt-2">
|
||||
<slot name="actions" />
|
||||
{@render actions?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -118,7 +136,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</Material>
|
||||
|
||||
|
||||
@@ -1,40 +1,58 @@
|
||||
<script lang="ts">
|
||||
import { Disclosure } from 'mono-svelte'
|
||||
import { Minus, Plus, Icon } from 'svelte-hero-icons'
|
||||
export let open: boolean = false
|
||||
export let icon: boolean = true
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
open?: boolean
|
||||
icon?: boolean
|
||||
class?: string
|
||||
title?: import('svelte').Snippet
|
||||
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 bind:open class="items-start justify-items-start gap-2 {clazz}">
|
||||
<div
|
||||
slot="summary"
|
||||
class="font-medium w-full text-left flex flex-row items-center justify-between hover:text-primary-900
|
||||
hover:dark:text-primary-100 transition-colors h-full z-0 group relative"
|
||||
>
|
||||
<div class="flex flex-row gap-1 items-center w-full">
|
||||
<slot name="title" />
|
||||
</div>
|
||||
{#if icon}
|
||||
<Icon
|
||||
src={open ? Minus : Plus}
|
||||
size="16"
|
||||
micro
|
||||
class="{open
|
||||
? ''
|
||||
: 'rotate-90'} transition-transform duration-300 ease-out"
|
||||
/>
|
||||
{/if}
|
||||
{#snippet summary()}
|
||||
<div
|
||||
class="inset-0 -z-10 opacity-0 absolute bg-slate-100 dark:bg-zinc-900 rounded-full
|
||||
group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all"
|
||||
/>
|
||||
</div>
|
||||
<slot name="extended" slot="extended" />
|
||||
<slot name="content">
|
||||
<div class="pt-2 text-slate-900 dark:text-zinc-100">
|
||||
<slot />
|
||||
class="font-medium w-full text-left flex flex-row items-center justify-between hover:text-primary-900
|
||||
hover:dark:text-primary-100 transition-colors h-full z-0 group relative"
|
||||
>
|
||||
<div class="flex flex-row gap-1 items-center w-full">
|
||||
{@render title?.()}
|
||||
</div>
|
||||
{#if icon}
|
||||
<Icon
|
||||
src={open ? Minus : Plus}
|
||||
size="16"
|
||||
micro
|
||||
class="{open
|
||||
? ''
|
||||
: 'rotate-90'} transition-transform duration-300 ease-out"
|
||||
/>
|
||||
{/if}
|
||||
<div
|
||||
class="inset-0 -z-10 opacity-0 absolute bg-slate-100 dark:bg-zinc-900 rounded-full
|
||||
group-hover:opacity-100 group-hover:-inset-1 group-hover:-inset-x-2 transition-all"
|
||||
></div>
|
||||
</div>
|
||||
</slot>
|
||||
{/snippet}
|
||||
{#snippet extended()}
|
||||
{@render extended?.()}
|
||||
{/snippet}
|
||||
{#if content}{@render content()}{:else}
|
||||
<div class="pt-2 text-slate-900 dark:text-zinc-100">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</Disclosure>
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { pushState } from '$app/navigation'
|
||||
|
||||
export function showImage(url: string, alt: string = '') {
|
||||
@@ -24,13 +24,8 @@
|
||||
import { focusTrap } from 'svelte-focus-trap'
|
||||
import { t } from '$lib/translations'
|
||||
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
export let alt: string = ''
|
||||
|
||||
let zoomed = false
|
||||
let sharing = false
|
||||
let zoomed = $state(false)
|
||||
let sharing = $state(false)
|
||||
|
||||
async function downloadImage(url: string) {
|
||||
sharing = true
|
||||
@@ -43,21 +38,29 @@
|
||||
sharing = false
|
||||
return file
|
||||
}
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
/**
|
||||
* The full-resolution image URL
|
||||
*/
|
||||
alt?: string
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { alt = '', class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if $page.state.openImage || '' != ''}
|
||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||
<!-- svelte-ignore a11y-positive-tabindex -->
|
||||
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- svelte-ignore a11y_positive_tabindex -->
|
||||
<div
|
||||
class="fixed top-0 left-0 w-screen h-[100svh] overflow-auto bg-white/50 dark:bg-black/50
|
||||
flex flex-col z-[100] backdrop-blur-sm"
|
||||
transition:fade={{ duration: 150 }}
|
||||
on:click={() => history.back()}
|
||||
on:keydown={(e) => {
|
||||
onclick={() => history.back()}
|
||||
onkeydown={(e) => {
|
||||
if (e.key == 'Escape') history.back()
|
||||
}}
|
||||
use:focusTrap
|
||||
@@ -117,7 +120,9 @@
|
||||
title={$t('post.actions.more.share')}
|
||||
loading={sharing}
|
||||
>
|
||||
<Icon src={Share} size="20" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Share} size="20" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => {
|
||||
@@ -141,13 +146,15 @@
|
||||
rounding="pill"
|
||||
title={$t('post.image.close')}
|
||||
>
|
||||
<Icon src={XMark} size="20" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={XMark} size="20" micro />
|
||||
{/snippet}
|
||||
</Button>
|
||||
</Material>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button on:click={() => history.back()} class="contents {clazz}">
|
||||
<slot />
|
||||
<button onclick={() => history.back()} class="contents {clazz}">
|
||||
{@render children?.()}
|
||||
</button>
|
||||
@@ -1,14 +1,23 @@
|
||||
<script lang="ts">
|
||||
import FormattedNumber from '../util/FormattedNumber.svelte'
|
||||
|
||||
export let label: string
|
||||
export let content: string
|
||||
export let formatted: boolean = false
|
||||
interface Props {
|
||||
label: string
|
||||
content: string
|
||||
formatted?: boolean
|
||||
labelClass?: string
|
||||
contentClass?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
export let labelClass: string = ''
|
||||
export let contentClass: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
label,
|
||||
content,
|
||||
formatted = false,
|
||||
labelClass = '',
|
||||
contentClass = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col {clazz}">
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<script lang="ts">
|
||||
import { userSettings } from '$lib/settings'
|
||||
|
||||
export let width = 48
|
||||
interface Props {
|
||||
width?: number
|
||||
}
|
||||
|
||||
let { width = 48 }: Props = $props()
|
||||
|
||||
const monthColors: {
|
||||
[x: number]: string
|
||||
@@ -20,7 +24,7 @@
|
||||
12: '--hover-color-1: #228B22; --hover-color-2: #FFFFFF;',
|
||||
}
|
||||
|
||||
$: monthColor = monthColors[new Date().getMonth() + 1]
|
||||
let monthColor = $derived(monthColors[new Date().getMonth() + 1])
|
||||
</script>
|
||||
|
||||
<svg
|
||||
|
||||
@@ -12,9 +12,19 @@
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let page: number = 0
|
||||
export let cursor: { next?: string; back?: string } | undefined = undefined
|
||||
export let hasMore: boolean = true
|
||||
interface Props {
|
||||
page?: number;
|
||||
cursor?: { next?: string; back?: string } | undefined;
|
||||
hasMore?: boolean;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
let {
|
||||
page = $bindable(0),
|
||||
cursor = undefined,
|
||||
hasMore = true,
|
||||
children
|
||||
}: Props = $props();
|
||||
|
||||
const dispatcher = createEventDispatcher<{ change: number; cursor: string }>()
|
||||
</script>
|
||||
@@ -23,9 +33,9 @@
|
||||
aria-label={$t('aria.pagination.nav')}
|
||||
class="flex flex-row w-full gap-4 items-center justify-center"
|
||||
>
|
||||
{#if $$slots.default}
|
||||
{#if children}
|
||||
<span class="text-sm text-slate-600 dark:text-zinc-400 font-medium">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</span>
|
||||
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
||||
{/if}
|
||||
@@ -41,7 +51,9 @@
|
||||
class="text-inherit dark:text-inherit disabled:!opacity-20 disabled:!bg-transparent"
|
||||
disabled={(!cursor?.back && cursor?.next) || page <= 1}
|
||||
>
|
||||
<Icon src={ChevronLeft} size="24" mini slot="suffix" />
|
||||
{#snippet suffix()}
|
||||
<Icon src={ChevronLeft} size="24" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
|
||||
{#if page}
|
||||
@@ -71,6 +83,8 @@
|
||||
class="text-inherit dark:text-inherit"
|
||||
disabled={!hasMore}
|
||||
>
|
||||
<Icon src={ChevronRight} size="24" mini slot="suffix" />
|
||||
{#snippet suffix()}
|
||||
<Icon src={ChevronRight} size="24" mini />
|
||||
{/snippet}
|
||||
</Button>
|
||||
</nav>
|
||||
@@ -1,13 +1,25 @@
|
||||
<script lang="ts">
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
|
||||
export let icon: IconSource | undefined = undefined
|
||||
|
||||
export let title: string
|
||||
export let description: string | undefined = undefined
|
||||
export let center: boolean = false
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
icon?: IconSource | undefined;
|
||||
title: string;
|
||||
description?: string | undefined;
|
||||
center?: boolean;
|
||||
class?: string;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
let {
|
||||
icon = undefined,
|
||||
title,
|
||||
description = undefined,
|
||||
center = false,
|
||||
class: clazz = '',
|
||||
children
|
||||
}: Props = $props();
|
||||
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -32,5 +44,5 @@
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -1,15 +1,23 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy';
|
||||
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { tweened } from 'svelte/motion'
|
||||
|
||||
export let progress: number = 0
|
||||
interface Props {
|
||||
progress?: number;
|
||||
}
|
||||
|
||||
let { progress = 0 }: Props = $props();
|
||||
|
||||
let tween = tweened(progress, { easing: expoOut })
|
||||
|
||||
$: tween.set(progress)
|
||||
run(() => {
|
||||
tween.set(progress)
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="bg-primary-900 dark:bg-primary-100 h-1 rounded-full"
|
||||
style="width: {$tween * 100}%;"
|
||||
/>
|
||||
></div>
|
||||
@@ -1,12 +1,18 @@
|
||||
<script lang="ts">
|
||||
export let small: boolean = false
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
small?: boolean;
|
||||
class?: string;
|
||||
children?: import('svelte').Snippet;
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let { small = false, class: clazz = '', children, ...rest }: Props = $props();
|
||||
|
||||
</script>
|
||||
|
||||
<span
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class="{!small ? 'text-lg' : 'text-xs'} font-semibold {clazz}"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</span>
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
class?: string;
|
||||
children?: import('svelte').Snippet;
|
||||
}
|
||||
|
||||
let { class: clazz = '', children }: Props = $props();
|
||||
|
||||
</script>
|
||||
|
||||
<aside
|
||||
@@ -8,5 +13,5 @@
|
||||
flex-col gap-4 px-6 pt-4 max-w-full w-full h-full
|
||||
overflow-auto text-sm border-slate-200 dark:border-zinc-800 {clazz}"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</aside>
|
||||
@@ -1,10 +1,12 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { derived as derivedStore } from 'svelte/store'
|
||||
|
||||
const calculateDockProperties = (
|
||||
settings: {
|
||||
top: boolean | null
|
||||
noGap: boolean | null
|
||||
},
|
||||
screenWidth: number
|
||||
screenWidth: number,
|
||||
): {
|
||||
noGap: boolean
|
||||
top: boolean
|
||||
@@ -35,7 +37,7 @@
|
||||
export const calculatePadding = (
|
||||
panel: boolean,
|
||||
top: boolean,
|
||||
content: boolean
|
||||
content: boolean,
|
||||
): {
|
||||
top: number
|
||||
bottom: number
|
||||
@@ -63,12 +65,15 @@
|
||||
|
||||
export let screenWidth = writable(1000)
|
||||
export let dockProps: Readable<ReturnType<typeof calculateDockProperties>> =
|
||||
derived([userSettings, screenWidth], ([$settings, $screenWidth], set) => {
|
||||
set(calculateDockProperties($settings.dock, $screenWidth))
|
||||
})
|
||||
derivedStore(
|
||||
[userSettings, screenWidth],
|
||||
([$settings, $screenWidth], set) => {
|
||||
set(calculateDockProperties($settings.dock, $screenWidth))
|
||||
},
|
||||
)
|
||||
export let contentPadding: Readable<ReturnType<typeof calculatePadding>> =
|
||||
derived(dockProps, ($dockProps, set) =>
|
||||
set(calculatePadding($dockProps.noGap, $dockProps.top, true))
|
||||
derivedStore(dockProps, ($dockProps, set) =>
|
||||
set(calculatePadding($dockProps.noGap, $dockProps.top, true)),
|
||||
)
|
||||
</script>
|
||||
|
||||
@@ -76,27 +81,47 @@
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { themeVars } from '$lib/ui/colors'
|
||||
import { routes } from '$lib/util.js'
|
||||
import { derived, writable, type Readable, type Writable } from 'svelte/store'
|
||||
import { writable, type Readable, type Writable } from 'svelte/store'
|
||||
|
||||
export let route: { id: string | null } | undefined = undefined
|
||||
interface Props {
|
||||
route?: { id: string | null } | undefined
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
navbar?: import('svelte').Snippet<[any]>
|
||||
sidebar?: import('svelte').Snippet<[any]>
|
||||
main?: import('svelte').Snippet<[any]>
|
||||
suffix?: import('svelte').Snippet<[any]>
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
$: title = route ? routes[(route.id as keyof typeof routes) ?? ''] : ''
|
||||
let {
|
||||
route = undefined,
|
||||
class: clazz = '',
|
||||
children,
|
||||
navbar,
|
||||
sidebar,
|
||||
main,
|
||||
suffix,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
$: sidePadding = calculatePadding($dockProps.noGap, $dockProps.top, false)
|
||||
$: topPanel = $dockProps.noGap && $dockProps.top
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let title = $derived(
|
||||
route ? routes[(route.id as keyof typeof routes) ?? ''] : '',
|
||||
)
|
||||
let sidePadding = $derived(
|
||||
calculatePadding($dockProps.noGap, $dockProps.top, false),
|
||||
)
|
||||
let topPanel = $derived($dockProps.noGap && $dockProps.top)
|
||||
</script>
|
||||
|
||||
<svelte:window bind:innerWidth={$screenWidth} />
|
||||
|
||||
<div
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
class="shell bg-slate-50 dark:bg-zinc-950 {clazz}"
|
||||
style={$themeVars}
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
<div
|
||||
class="
|
||||
{$dockProps.noGap ? '' : 'p-4 max-w-3xl left-1/2 -translate-x-1/2'}
|
||||
@@ -108,47 +133,48 @@
|
||||
transition-duration: 250ms;
|
||||
transition-timing-function: cubic-bezier(0.075, 0.82, 0.165, 1);"
|
||||
>
|
||||
<slot
|
||||
name="navbar"
|
||||
class="
|
||||
{$dockProps.noGap
|
||||
? $dockProps.top
|
||||
? 'border-b shadow-none rounded-none'
|
||||
: 'border-t rounded-none'
|
||||
: 'border rounded-full'}
|
||||
{@render navbar?.({
|
||||
class: `
|
||||
${
|
||||
$dockProps.noGap
|
||||
? $dockProps.top
|
||||
? 'border-b shadow-none rounded-none'
|
||||
: 'border-t rounded-none'
|
||||
: 'border rounded-full'
|
||||
}
|
||||
|
||||
dark:bg-transparent transition-colors duration-500
|
||||
pointer-events-auto backdrop-blur-xl {topPanel
|
||||
? 'bg-slate-50/50 dark:bg-zinc-950/90 border-slate-100 dark:border-zinc-900'
|
||||
: `border-slate-200 dark:border-zinc-800 shadow-2xl
|
||||
bg-white/50 dark:bg-zinc-950/70`}"
|
||||
{title}
|
||||
style="transition: border-radius 250ms;"
|
||||
/>
|
||||
pointer-events-auto backdrop-blur-xl ${
|
||||
topPanel
|
||||
? 'bg-slate-50/50 dark:bg-zinc-950/90 border-slate-100 dark:border-zinc-900'
|
||||
: `border-slate-200 dark:border-zinc-800 shadow-2xl
|
||||
bg-white/50 dark:bg-zinc-950/70`
|
||||
}`,
|
||||
title,
|
||||
style: 'transition: border-radius 250ms;',
|
||||
})}
|
||||
</div>
|
||||
<div
|
||||
class="content divide-x divide-slate-100 dark:divide-zinc-900 min-h-screen {$userSettings.newWidth
|
||||
? 'limit-width'
|
||||
: ''}"
|
||||
>
|
||||
<slot
|
||||
name="sidebar"
|
||||
class="hidden md:flex sticky top-0 left-0 h-max bg-slate-50 dark:bg-zinc-950
|
||||
{@render sidebar?.({
|
||||
class: `hidden md:flex sticky top-0 left-0 h-max bg-slate-50 dark:bg-zinc-950
|
||||
z-40
|
||||
{sidePadding.class}"
|
||||
style="grid-area: sidebar; width: 100% !important;"
|
||||
/>
|
||||
<slot
|
||||
name="main"
|
||||
class="w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
|
||||
{$contentPadding.class} main"
|
||||
style="grid-area: main"
|
||||
/>
|
||||
<slot
|
||||
name="suffix"
|
||||
class="max-xl:hidden w-full sticky top-0 left-0 max-h-screen bg-slate-50 dark:bg-zinc-950 z-40 {sidePadding.class}"
|
||||
style="grid-area: suffix;"
|
||||
/>
|
||||
${sidePadding.class}`,
|
||||
style: 'grid-area: sidebar; width: 100% !important;',
|
||||
})}
|
||||
{@render main?.({
|
||||
class: `w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-sm z-0
|
||||
${$contentPadding.class} main`,
|
||||
style: 'grid-area: main',
|
||||
})}
|
||||
{@render suffix?.({
|
||||
class:
|
||||
'max-xl:hidden w-full sticky top-0 left-0 max-h-screen bg-slate-50 dark:bg-zinc-950 z-40 {sidePadding.class}',
|
||||
style: 'grid-area: suffix;',
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,11 +2,21 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { contentPadding } from '../Shell.svelte'
|
||||
|
||||
export let pageHeader = false
|
||||
interface Props {
|
||||
pageHeader?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
extended?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
pageHeader = false,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
children,
|
||||
extended,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -27,11 +37,11 @@
|
||||
class="text-3xl font-medium flex gap-2 w-full
|
||||
{$userSettings.font == 'satoshi/nunito' ? 'font-display' : ''} {clazz ?? ''}"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</h1>
|
||||
{#if $$slots.extended}
|
||||
{#if extended}
|
||||
<div class="mt-4">
|
||||
<slot name="extended" />
|
||||
{@render extended?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -3,25 +3,34 @@
|
||||
import { page } from '$app/stores'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let routes: {
|
||||
href: string
|
||||
name: string
|
||||
}[]
|
||||
export let currentRoute: string | undefined = undefined
|
||||
export let isSelected: (
|
||||
url: URL,
|
||||
currentRoute: string | undefined,
|
||||
route: string,
|
||||
defaultRoute?: string
|
||||
) => boolean = (url, currentRoute, route) =>
|
||||
(currentRoute ?? url.pathname) == route
|
||||
export let buildUrl: (
|
||||
currentRoute: string | undefined,
|
||||
href: string
|
||||
) => string = (route, href) => href
|
||||
export let defaultRoute: string | undefined = undefined
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
routes: {
|
||||
href: string
|
||||
name: string
|
||||
}[]
|
||||
currentRoute?: string | undefined
|
||||
isSelected?: (
|
||||
url: URL,
|
||||
currentRoute: string | undefined,
|
||||
route: string,
|
||||
defaultRoute?: string,
|
||||
) => boolean
|
||||
buildUrl?: (currentRoute: string | undefined, href: string) => string
|
||||
defaultRoute?: string | undefined
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
routes,
|
||||
currentRoute = undefined,
|
||||
isSelected = (url, currentRoute, route) =>
|
||||
(currentRoute ?? url.pathname) == route,
|
||||
buildUrl = (route, href) => href,
|
||||
defaultRoute = undefined,
|
||||
class: clazz = '',
|
||||
children,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<nav
|
||||
@@ -32,7 +41,7 @@
|
||||
>
|
||||
{#each routes as route}
|
||||
<a
|
||||
on:click={() => invalidate(route.href)}
|
||||
onclick={() => invalidate(route.href)}
|
||||
href={buildUrl(currentRoute, route.href)}
|
||||
class="font-medium rounded-full px-4 py-1 hover:bg-slate-200/40 hover:dark:bg-zinc-700/40
|
||||
transition-colors duration-100 relative z-0 flex-shrink-0"
|
||||
@@ -46,5 +55,5 @@
|
||||
{/if}
|
||||
</a>
|
||||
{/each}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</nav>
|
||||
@@ -8,12 +8,16 @@
|
||||
function action(detail: any) {
|
||||
dispatcher('action', detail)
|
||||
}
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
let { class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<ul
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-900 flex flex-col {clazz}"
|
||||
>
|
||||
<slot {action} />
|
||||
{@render children?.({ action })}
|
||||
</ul>
|
||||
@@ -1,3 +1,13 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<div class="p-2 flex flex-row">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -4,24 +4,41 @@
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
import { dockProps } from '../layout/Shell.svelte'
|
||||
|
||||
export let label: string
|
||||
export let icon: IconSource | undefined = undefined
|
||||
export let href: string | undefined = undefined
|
||||
|
||||
export let adaptive: boolean = true
|
||||
|
||||
export let isSelectedFilter: (path: string) => boolean = (path) =>
|
||||
href != undefined && path == href
|
||||
|
||||
$: isSelected = isSelectedFilter($page.url.pathname)
|
||||
$: isPanel = adaptive ? $dockProps.noGap : false
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
interface Props {
|
||||
label: string;
|
||||
icon?: IconSource | undefined;
|
||||
href?: string | undefined;
|
||||
adaptive?: boolean;
|
||||
isSelectedFilter?: (path: string) => boolean;
|
||||
class?: string;
|
||||
customIcon?: import('svelte').Snippet<[any]>;
|
||||
children?: import('svelte').Snippet;
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
label,
|
||||
icon = undefined,
|
||||
href = undefined,
|
||||
adaptive = true,
|
||||
isSelectedFilter = (path) =>
|
||||
href != undefined && path == href,
|
||||
class: clazz = '',
|
||||
customIcon,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props();
|
||||
|
||||
let isSelected = $derived(isSelectedFilter($page.url.pathname))
|
||||
let isPanel = $derived(adaptive ? $dockProps.noGap : false)
|
||||
</script>
|
||||
|
||||
<Button
|
||||
color={isPanel ? 'secondary' : 'tertiary'}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
on:click
|
||||
on:contextmenu
|
||||
class="rounded-full w-10 h-10 flex-shrink-0 {adaptive
|
||||
@@ -43,8 +60,8 @@
|
||||
size={isPanel ? '16' : '18'}
|
||||
/>
|
||||
{:else}
|
||||
<slot size={isPanel ? 16 : 18} {isSelected} name="icon" />
|
||||
{@render customIcon?.({ size: isPanel ? 16 : 18, isSelected, })}
|
||||
{/if}
|
||||
<span class="hidden {adaptive ? '@3xl:block' : ''}">{label}</span>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</Button>
|
||||
@@ -39,10 +39,13 @@
|
||||
import { userSettings } from '$lib/settings'
|
||||
import { dockProps } from '../layout/Shell.svelte'
|
||||
|
||||
let promptOpen: boolean = false
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let promptOpen: boolean = $state(false)
|
||||
interface Props {
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { style = '', class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
<CommandsWrapper bind:open={promptOpen} />
|
||||
@@ -64,7 +67,7 @@
|
||||
class="ml-2 logo"
|
||||
adaptive={false}
|
||||
>
|
||||
<svelte:fragment slot="icon">
|
||||
{#snippet icon()}
|
||||
{#if LINKED_INSTANCE_URL}
|
||||
{#if $site}
|
||||
<Avatar
|
||||
@@ -79,13 +82,13 @@
|
||||
{:else}
|
||||
<Logo width={32} />
|
||||
{/if}
|
||||
</svelte:fragment>
|
||||
{/snippet}
|
||||
</NavButton>
|
||||
<div
|
||||
class="flex flex-row gap-2 py-2 px-2 items-center w-full overflow-auto"
|
||||
style="border-radius: inherit;"
|
||||
>
|
||||
<div class="ml-auto" />
|
||||
<div class="ml-auto"></div>
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
<NavButton
|
||||
href="/admin"
|
||||
@@ -97,7 +100,7 @@
|
||||
{#if ($notifications.applications ?? 0) > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
</NavButton>
|
||||
{/if}
|
||||
@@ -110,15 +113,11 @@
|
||||
{#if ($notifications.reports ?? 0) > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
></div>
|
||||
{/if}
|
||||
<ShieldIcon
|
||||
let:size
|
||||
let:isSelected
|
||||
slot="icon"
|
||||
filled={isSelected}
|
||||
width={size}
|
||||
/>
|
||||
{#snippet customIcon({ size, isSelected })}
|
||||
<ShieldIcon filled={isSelected} width={size} />
|
||||
{/snippet}
|
||||
</NavButton>
|
||||
{/if}
|
||||
<NavButton
|
||||
@@ -128,16 +127,19 @@
|
||||
/>
|
||||
<NavButton href="/search" label={$t('nav.search')} icon={MagnifyingGlass} />
|
||||
<Menu placement="top">
|
||||
<NavButton
|
||||
class="relative"
|
||||
color="primary"
|
||||
slot="target"
|
||||
label={$t('nav.create.label')}
|
||||
icon={Plus}
|
||||
/>
|
||||
{#snippet target()}
|
||||
<NavButton
|
||||
class="relative"
|
||||
color="primary"
|
||||
label={$t('nav.create.label')}
|
||||
icon={Plus}
|
||||
/>
|
||||
{/snippet}
|
||||
<MenuDivider>{$t('nav.create.label')}</MenuDivider>
|
||||
<MenuButton link href="/create/post" disabled={!$profile?.jwt}>
|
||||
<Icon src={PencilSquare} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={PencilSquare} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('nav.create.post')}
|
||||
</MenuButton>
|
||||
<MenuButton
|
||||
@@ -148,7 +150,9 @@
|
||||
($site?.site_view.local_site.community_creation_admin_only &&
|
||||
!isAdmin($profile.user))}
|
||||
>
|
||||
<Icon src={Newspaper} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Newspaper} size="16" micro />
|
||||
{/snippet}
|
||||
{$t('nav.create.community')}
|
||||
</MenuButton>
|
||||
{#if !$profile?.jwt}
|
||||
@@ -166,7 +170,7 @@
|
||||
<img
|
||||
src={optimizeImageURL(
|
||||
$profile?.user?.local_user_view.person.avatar ?? '',
|
||||
32
|
||||
32,
|
||||
)}
|
||||
class="blur-2xl -z-10 object-cover w-48 h-48 opacity-20 dark:opacity-50 ml-auto"
|
||||
alt=""
|
||||
|
||||
Loaded 100 of 225 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user