fix: Fix lint errors (#559)

* cleanup: postactions styling

* misc: fix first round of errors

* pkg: remove vitest

* fix: fix lint errors stage 2

* fix: fix lint errors stage 3

* fix: fix lint errors, stage 3

* misc: update eslint rules to warn for writable derived
This commit is contained in:
Xylight authored and GitHub committed 2025-06-09 16:34:06 -07:00
1 parent 1824245f13
commit 76c581123a
225 files changed
+1553 -2352

No files matched your search

+42 -46
View File
@@ -1,22 +1,23 @@
import { browser } from '$app/environment'
import { env } from '$env/dynamic/public'
import {
amModOfAny,
isAdmin,
} from '$lib/components/lemmy/moderation/moderation.js'
import { toast } from 'mono-svelte'
import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js'
import { client, getClient } from '$lib/lemmy.svelte.js'
import { site } from './lemmy.svelte'
import { instanceToURL, moveItem } from '$lib/util.svelte'
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
import {
type Community,
type GetSiteResponse,
type MyUserInfo,
type Community,
} from 'lemmy-js-client'
import { toast } from 'mono-svelte'
import { writable } from 'svelte/store'
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
import { browser } from '$app/environment'
import { env } from '$env/dynamic/public'
import { t } from './i18n/translations'
import { site } from './lemmy.svelte'
import { errorMessage } from './lemmy/error'
const getDefaultProfile = (): Profile => ({
id: -1,
@@ -31,6 +32,7 @@ function getFromStorage<T>(key: string): T | undefined {
return JSON.parse(lc)
}
// eslint-disable-next-line
function setFromStorage(key: string, item: any, stringify: boolean = true) {
if (typeof localStorage == 'undefined') return
return localStorage.setItem(key, stringify ? JSON.stringify(item) : item)
@@ -40,7 +42,7 @@ export interface Profile {
id: number
instance: string
jwt?: string
user?: PersonData
user?: MyUserInfo
username?: string
avatar?: string
favorites?: Community[]
@@ -56,8 +58,6 @@ interface ProfileData {
defaultInstance?: string
}
interface PersonData extends MyUserInfo {}
interface Notifications {
inbox: number
reports: number
@@ -71,12 +71,12 @@ const getCookie = (key: string): string | undefined => {
// ask chatgpt or something to explain this for you
return document?.cookie
?.split(';')
.map((c) => c.trim())
.find((c) => c.split('=')?.[0] == key)
.map(c => c.trim())
.find(c => c.split('=')?.[0] == key)
?.split('=')?.[1]
}
export let profileData = $state<ProfileData>(
export const profileData = $state<ProfileData>(
getFromStorage<ProfileData>('profileData') ?? {
profiles: [
{
@@ -92,7 +92,7 @@ export let profileData = $state<ProfileData>(
class CurrentProfile {
#data = $derived(
profileData.profiles.find((i) => i.id == profileData.profile) ??
profileData.profiles.find(i => i.id == profileData.profile) ??
getDefaultProfile(),
)
@@ -101,12 +101,12 @@ class CurrentProfile {
}
set data(value) {
if (!value) return
const index = profileData.profiles.findIndex((i) => i.id == value?.id)
const index = profileData.profiles.findIndex(i => i.id == value?.id)
profileData.profiles[index] = value
}
}
export let profile = new CurrentProfile()
export const profile = new CurrentProfile()
async function fetchUserData(profile: CurrentProfile) {
if (profile.data.jwt) {
@@ -132,14 +132,14 @@ async function fetchUserData(profile: CurrentProfile) {
site.data = undefined
client({ instanceURL: profile.data.instance })
.getSite()
.then((res) => (site.data = res))
.then(res => (site.data = res))
}
}
return profile
}
export let notifications = writable<Notifications>({
export const notifications = writable<Notifications>({
applications: 0,
inbox: 0,
reports: 0,
@@ -149,7 +149,7 @@ $effect.root(() => {
$effect(() => {
const serialized = {
...profileData,
profiles: profileData.profiles.map((p) => serializeUser(p)),
profiles: profileData.profiles.map(p => serializeUser(p)),
}
setFromStorage('profileData', serialized)
@@ -167,7 +167,7 @@ $effect.root(() => {
$effect(() => {
if (profile.data.id || profileData)
fetchUserData(profile).then((res) => {
fetchUserData(profile).then(() => {
checkInbox()
})
})
@@ -180,15 +180,11 @@ if (
) {
const jwt = getCookie('jwt')
if (jwt) {
new Promise(async () => {
;(async () => {
const user = await userFromJwt(jwt, env.PUBLIC_INSTANCE_URL ?? '')
if (!user) return
const result = await setUser(
jwt,
env.PUBLIC_INSTANCE_URL ?? '',
user?.user?.local_user_view.person.name,
)
const result = await setUser(jwt, env.PUBLIC_INSTANCE_URL ?? '')
if (result)
toast({
@@ -196,21 +192,21 @@ if (
'Your instance migrated to Photon, and you were logged in using a leftover cookie.',
type: 'success',
})
})
})()
}
}
export async function setUser(jwt: string, inst: string, username?: string) {
export async function setUser(jwt: string, inst: string) {
try {
new URL(instanceToURL(inst))
} catch (err) {
} catch {
return
}
const user = await userFromJwt(jwt, inst)
.then((u) => u)
.catch((err) => {
toast({ content: err as any, type: 'error' })
.then(u => u)
.catch(err => {
toast({ content: errorMessage(err as string), type: 'error' })
})
if (!user?.user) {
toast({
@@ -219,7 +215,7 @@ export async function setUser(jwt: string, inst: string, username?: string) {
})
}
const id = Math.max(...profileData.profiles.map((p) => p.id)) + 1
const id = Math.max(...profileData.profiles.map(p => p.id)) + 1
profileData.profile = id
profileData.profiles.push({
id: id,
@@ -236,11 +232,11 @@ async function userFromJwt(
jwt: string,
instance: string,
): Promise<
{ user: PersonData | undefined; site: GetSiteResponse } | undefined
{ user: MyUserInfo | undefined; site: GetSiteResponse } | undefined
> {
const sitePromise = client({ instanceURL: instance, auth: jwt }).getSite()
let timer = setTimeout(
const timer = setTimeout(
() =>
toast({
content: `Still loading your user data...`,
@@ -251,11 +247,11 @@ async function userFromJwt(
)
const site = await sitePromise
.then((r) => {
.then(r => {
clearTimeout(timer)
return r
})
.catch((e) => {
.catch(e => {
toast({ content: `Failed to contact the instance. ${e}` })
})
@@ -282,7 +278,7 @@ export function resetProfile() {
export function deleteProfile(id: number) {
profileData.profiles.splice(
profileData.profiles.findIndex((p) => p.id == id),
profileData.profiles.findIndex(p => p.id == id),
1,
)
if (id == profileData.profile) resetProfile()
@@ -296,48 +292,48 @@ function serializeUser(user: Profile): Profile {
}
export async function setUserID(id: number) {
if (!profileData.profiles.find((p) => p.id == id)) return -1
if (!profileData.profiles.find(p => p.id == id)) return -1
profileData.profile = id
return profile
}
export function moveProfile(id: number, up: boolean) {
try {
const index = profileData.profiles.findIndex((i) => i.id == id)
const index = profileData.profiles.findIndex(i => i.id == id)
profileData.profiles = moveItem(
profileData.profiles,
index,
index + (up ? -1 : 1),
)
} catch (err) {
// we dont care
} catch {
/* empty */
}
}
async function getNotificationCount(jwt: string, mod: boolean, admin: boolean) {
const unreadsPromise = getClient()
.getUnreadCount()
.then((res) => res.mentions + res.private_messages + res.replies)
.then(res => res.mentions + res.private_messages + res.replies)
.catch(() => 0)
const reportsPromise = mod
? getClient()
.getReportCount({})
.then(
(res) =>
res =>
res.comment_reports +
res.post_reports +
(res.private_message_reports ?? 0),
)
.catch(() => 0)
: new Promise<number>((res) => res(0))
: new Promise<number>(res => res(0))
const applicationsPromise = admin
? getClient()
.getUnreadRegistrationApplicationCount()
.then((res) => res.registration_applications)
.then(res => res.registration_applications)
.catch(() => 0)
: new Promise<number>((res) => res(0))
: new Promise<number>(res => res(0))
const [unreads, reports, applications] = await Promise.all([
unreadsPromise,
@@ -1,6 +1,4 @@
<script lang="ts" module>
import { writable } from 'svelte/store'
interface PageScopedError {
scope: string
message: string
@@ -13,16 +11,16 @@
}
export function clearErrorScope(scope: string | null | undefined) {
errors = errors.filter((error) => error.scope != scope)
errors = errors.filter(error => error.scope != scope)
}
</script>
<script lang="ts">
import { Button } from 'mono-svelte'
import { ExclamationCircle, Icon, XCircle, XMark } from 'svelte-hero-icons'
import { fly, slide } from 'svelte/transition'
import { expoOut } from 'svelte/easing'
import { onDestroy } from 'svelte'
import { Icon, XMark } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition'
onDestroy(() => {
clearErrorScope(scope)
@@ -35,7 +33,7 @@
let { scope = undefined, class: clazz = '' }: Props = $props()
let scopedErrors = $derived(
errors.filter((e) => e.scope == scope || e.scope == 'global'),
errors.filter(e => e.scope == scope || e.scope == 'global'),
)
</script>
+1 -10
View File
@@ -1,7 +1,6 @@
<script lang="ts">
import { t } from '$lib/i18n/translations'
import { TextInput, Select, Option } from 'mono-svelte'
import type { Snippet } from 'svelte'
const multipliers = {
minute: 60,
@@ -22,17 +21,9 @@
value: number
max?: number
min?: number
number?: Snippet<[number]>
duration?: Snippet<[Duration]>
}
let {
value = $bindable(),
max,
min = 0,
number: numberSnippet,
duration: durationSnippet,
}: Props = $props()
let { value = $bindable(), max, min = 0 }: Props = $props()
let number = $state<number>(0)
let duration = $state<Duration>(value == -1 ? 'permanent' : 'day')
@@ -1,24 +1,21 @@
<script lang="ts">
import { run } from 'svelte/legacy'
import { browser } from '$app/environment'
import { tick } from 'svelte'
import type { HTMLTextareaAttributes } from 'svelte/elements'
let textarea: HTMLTextAreaElement | undefined = $state()
async function adjustHeight(value: string) {
async function adjustHeight() {
await tick()
if (textarea) {
textarea.style.height = 'auto' // Reset height to auto to calculate new height
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
}
}
interface Props {
interface Props extends HTMLTextareaAttributes {
label?: string | undefined
value: string
required?: boolean
class?: string
[key: string]: any
}
let {
@@ -29,8 +26,8 @@
...rest
}: Props = $props()
run(() => {
adjustHeight(value)
$effect(() => {
if (value) adjustHeight()
})
</script>
@@ -45,7 +42,7 @@
{/if}
<textarea
bind:this={textarea}
oninput={() => adjustHeight(value)}
oninput={() => adjustHeight()}
bind:value
{required}
{...rest}
+4 -3
View File
@@ -2,21 +2,22 @@
export const parseURL = (href: string) => {
try {
return new URL(href)
} catch (e) {
} catch {
return undefined
}
}
</script>
<script lang="ts">
interface Props {
import type { HTMLAnchorAttributes } from 'svelte/elements'
interface Props extends HTMLAnchorAttributes {
href: string
highlight?: boolean
nowrap?: boolean
children?: import('svelte').Snippet
class?: string
icon?: import('svelte').Snippet
[key: string]: any
}
let {
+2 -42
View File
@@ -1,6 +1,4 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy'
type T = $$Generic
interface Props {
@@ -8,10 +6,7 @@
disabled?: boolean[]
optionNames?: string[]
selected: T
headless?: boolean
class?: string
buttonClazz?: string
children?: import('svelte').Snippet<[any]>
children?: import('svelte').Snippet<[{ selected: T }]>
onselect?: (item: T) => void
}
@@ -20,9 +15,6 @@
disabled = [],
optionNames = [],
selected = $bindable(),
headless = false,
class: clazz = '',
buttonClazz = '',
children,
onselect,
}: Props = $props()
@@ -30,38 +22,6 @@
$effect(() => {
onselect?.(selected)
})
let containerClass = `
flex flex-row rtl:flex-row-reverse items-center w-max max-w-full overflow-auto
${headless ? 'pb-1 gap-1' : ''}
${clazz}
`
const buttonClass = (selected: boolean) => `
first:rounded-l-lg first:border-l dark:first:border-l-transparent
last:rounded-r-lg last:border-r dark:last:border-r-transparent
rounded-l-none
rounded-r-none
px-3 py-1.5 text-sm hover:brightness-110 ${buttonClazz || ''}
${
!selected
? `dark:hover:bg-zinc-800 border-slate-100 border-t border-b border-b-slate-300 dark:border-b-0
dark:border-t dark:border-t-zinc-700`
: ''
}
transition-all transition-filters rounded-full
${
selected
? headless
? ''
: `bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900`
: headless
? ''
: 'bg-white dark:bg-zinc-800'
}
disabled:opacity-60 disabled:pointer-events-none whitespace-nowrap
relative
`
</script>
<div
@@ -76,7 +36,7 @@
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900'
: 'dark:bg-zinc-900/50 bg-white',
]}
onclick={(e) => {
onclick={e => {
e.preventDefault()
selected = option
}}
@@ -1,11 +1,10 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import { getClient } from '$lib/lemmy.svelte.js'
import type { Community, CommunityView, ListingType } from 'lemmy-js-client'
import type { Community, ListingType } from 'lemmy-js-client'
import { MenuButton, Search } from 'mono-svelte'
import type { SearchProps } from 'mono-svelte/search/Search.svelte'
import { createEventDispatcher } from 'svelte'
import { Icon, XCircle, ServerStack } from 'svelte-hero-icons'
import { Icon, ServerStack, XCircle } from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
interface Props {
@@ -14,8 +13,8 @@
instance?: string | undefined
listing_type?: ListingType
showWhenEmpty?: boolean
// eslint-disable-next-line
onselect?: (item: any) => void
[key: string]: any
}
let {
@@ -35,7 +34,7 @@
{#if type == 'community'}
<Search
search={async (q) => {
search={async q => {
const results = await getClient(instance).search({
q: q || ' ',
type_: 'Communities',
@@ -44,9 +43,9 @@
sort: 'TopAll',
})
return results.communities.map((c) => c.community)
return results.communities.map(c => c.community)
}}
extractName={(c) => `${c.title}@${new URL(c.actor_id).hostname}`}
extractName={c => `${c.title}@${new URL(c.actor_id).hostname}`}
bind:query={q}
{...rest}
>
@@ -80,16 +79,16 @@
</Search>
{:else if type == 'instance'}
<Search
search={async (q) => {
search={async q => {
const results = (await instances) || {}
return q
? (results.federated_instances?.linked || []).filter(
(i) => i.software === 'lemmy' && i.domain.includes(q),
i => i.software === 'lemmy' && i.domain.includes(q),
)
: []
}}
extractName={(i) => `${i.domain}`}
extractName={i => `${i.domain}`}
bind:query={q}
{...rest}
>
+8 -17
View File
@@ -2,27 +2,18 @@
import Markdown from '$lib/components/markdown/Markdown.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import StickyCard from '$lib/components/ui/StickyCard.svelte'
import { t } from '$lib/i18n/translations'
import { userLink } from '$lib/lemmy/generic'
import { settings } from '$lib/settings.svelte'
import type { PersonView, SiteView, Tagline } from 'lemmy-js-client'
import { Badge, Button } from 'mono-svelte'
import {
BuildingOffice,
ChartBar,
Icon,
InformationCircle,
Newspaper,
ServerStack,
UserGroup,
} from 'svelte-hero-icons'
import { Badge } from 'mono-svelte'
import { Icon, ServerStack } from 'svelte-hero-icons'
import Link from '../input/Link.svelte'
import Entity from '../ui/Entity.svelte'
import Expandable from '../ui/Expandable.svelte'
import LabelStat from '../ui/LabelStat.svelte'
import ItemList from './generic/ItemList.svelte'
import { userLink } from '$lib/lemmy/generic'
import { t } from '$lib/i18n/translations'
import Entity from '../ui/Entity.svelte'
import { settings } from '$lib/settings.svelte'
import { optimizeImageURL } from './post/helpers'
import Link from '../input/Link.svelte'
import EndPlaceholder from '../ui/EndPlaceholder.svelte'
interface Props {
site: SiteView
@@ -130,7 +121,7 @@
</span>
{/snippet}
<ItemList
items={admins.map((a) => ({
items={admins.map(a => ({
id: a.person.id,
name: a.person.name,
url: userLink(a.person),
+21 -21
View File
@@ -1,4 +1,16 @@
<script lang="ts">
import { page } from '$app/state'
import { profile } from '$lib/auth.svelte.js'
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js'
import { Button, Modal, toast } from 'mono-svelte'
import { onMount } from 'svelte'
import {
Bookmark,
Icon,
@@ -8,25 +20,13 @@
Plus,
Trash,
} from 'svelte-hero-icons'
import type { CommentNodeI } from './comments.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import CommentForm from './CommentForm.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
import { getClient } from '$lib/lemmy.svelte.js'
import { Disclosure, toast } from 'mono-svelte'
import { profile } from '$lib/auth.svelte.js'
import { Button, Modal } from 'mono-svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import { page } from '$app/state'
import { onMount } from 'svelte'
import { t } from '$lib/i18n/translations'
import { fly, slide } from 'svelte/transition'
import { expoInOut, expoOut } from 'svelte/easing'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { expoOut } from 'svelte/easing'
import type { ClassValue } from 'svelte/elements'
import { fly, slide } from 'svelte/transition'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import CommentForm from './CommentForm.svelte'
import type { CommentNodeI } from './comments.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
node: CommentNodeI
@@ -76,7 +76,7 @@
editing = false
} catch (err) {
toast({
content: err as any,
content: errorMessage(err as string),
type: 'error',
})
}
@@ -102,7 +102,7 @@
<span>{$t('form.edit')}</span>
{/snippet}
<form
onsubmit={(e) => {
onsubmit={e => {
e.preventDefault()
save()
}}
@@ -253,7 +253,7 @@
label={$t('comment.reply')}
{postId}
parentId={node.comment_view.comment.id}
oncomment={(e) => {
oncomment={e => {
node.children = [
{
children: [],
@@ -1,32 +1,28 @@
<script lang="ts">
import type { CommentView } from 'lemmy-js-client'
import { profile } from '$lib/auth.svelte.js'
import CommentVote from '$lib/components/lemmy/comment/CommentVote.svelte'
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
import {
amMod,
isAdmin,
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import { t } from '$lib/i18n/translations'
import { deleteItem, save } from '$lib/lemmy/contentview.js'
import { settings } from '$lib/settings.svelte'
import type { CommentView } from 'lemmy-js-client'
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
import {
ArrowUturnLeft,
Bookmark,
BookmarkSlash,
ChatBubbleOvalLeft,
EllipsisHorizontal,
Flag,
Icon,
Language,
PencilSquare,
Square2Stack,
Trash,
} from 'svelte-hero-icons'
import { createEventDispatcher } from 'svelte'
import { isCommentMutable } from '$lib/components/lemmy/post/helpers.js'
import {
amMod,
isAdmin,
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
import { profile } from '$lib/auth.svelte.js'
import { deleteItem, save } from '$lib/lemmy/contentview.js'
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import { settings } from '$lib/settings.svelte'
interface Props {
comment: CommentView
@@ -84,9 +80,11 @@
<MenuDivider>{$t('comment.actions.label')}</MenuDivider>
<MenuButton
onclick={() => {
navigator.share?.({
url: comment.comment.ap_id,
}) ?? navigator.clipboard.writeText(comment.comment.ap_id)
if (navigator.share)
navigator.share?.({
url: comment.comment.ap_id,
})
else navigator.clipboard.writeText(comment.comment.ap_id)
}}
>
<Icon src={Square2Stack} mini size="16" />
@@ -102,11 +100,7 @@
<MenuButton
onclick={async () => {
if (profile.data?.jwt)
comment.saved = await save(
comment,
!comment.saved,
profile.data.jwt,
)
comment.saved = await save(comment, !comment.saved)
}}
>
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
@@ -122,7 +116,6 @@
comment.comment.deleted = await deleteItem(
comment,
!comment.comment.deleted,
profile.data.jwt,
)
}}
>
@@ -1,18 +1,17 @@
<script lang="ts">
import type { CommentResponse } from 'lemmy-js-client'
import { getClient, site } from '$lib/lemmy.svelte.js'
import { createEventDispatcher } from 'svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { profile } from '$lib/auth.svelte.js'
import { Menu, Select, Spinner, toast, Option, MenuButton } from 'mono-svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { placeholders } from '$lib/util.svelte.js'
import { Button } from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import { getClient, site } from '$lib/lemmy.svelte.js'
import { errorMessage } from '$lib/lemmy/error'
import { placeholders } from '$lib/util.svelte.js'
import type { CommentResponse } from 'lemmy-js-client'
import { Button, Menu, MenuButton, toast } from 'mono-svelte'
import { ArrowUp, Icon, Language, XMark } from 'svelte-hero-icons'
import type { ClassValue, HTMLTextareaAttributes } from 'svelte/elements'
interface Props {
interface Props extends Omit<HTMLTextareaAttributes, 'oncancel'> {
postId: number
parentId?: number | undefined
locked?: boolean
@@ -22,10 +21,13 @@
value?: string
actions?: boolean
preview?: boolean
class?: ClassValue
required?: boolean
id?: string
label?: string
oncomment?: (comment: CommentResponse) => void
onconfirm?: (value: string) => void
oncancel?: (cancel: boolean) => void
[key: string]: any
}
let {
@@ -40,7 +42,6 @@
preview: previewAction = true,
oncancel,
oncomment,
onconfirm,
...rest
}: Props = $props()
@@ -65,7 +66,7 @@
} catch (err) {
console.error(err)
toast({
content: errorMessage(err as any),
content: errorMessage(err as string),
type: 'error',
})
}
@@ -93,12 +94,6 @@
: (placeholder ?? placeholders.get('comment'))}
bind:value
disabled={locked || loading || banned}
onconfirm={() => {
if (actions) {
submit()
onconfirm?.(value)
}
}}
previewButton={previewAction}
>
<Menu>
@@ -2,7 +2,7 @@
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
import { settings } from '$lib/settings.svelte.js'
import { settings, type View } from '$lib/settings.svelte.js'
import { t } from '$lib/i18n/translations'
import type { CommentView } from 'lemmy-js-client'
import { Button, Material } from 'mono-svelte'
@@ -10,12 +10,11 @@
interface Props {
comment: CommentView
view?: any
view?: View
community?: boolean
meta?: boolean
class?: string
commentClass?: string
[key: string]: any
}
let {
@@ -1,10 +1,9 @@
<script lang="ts">
import VirtualList from '$lib/components/render/VirtualList.svelte'
import type { Post } from 'lemmy-js-client'
import { onMount } from 'svelte'
import type { CommentNodeI } from './comments.svelte'
import Comments from './Comments.svelte'
import { onMount, tick } from 'svelte'
import VirtualList from '$lib/components/render/VirtualList.svelte'
import { page } from '$app/state'
interface Props {
nodes: CommentNodeI[]
@@ -35,7 +34,7 @@
// IntersectionObserver to watch for shifts
const observer = new IntersectionObserver(
(entries) => {
entries => {
entries.forEach(updateOffset)
},
{ threshold: [0, 1] },
@@ -59,11 +58,11 @@
{initialOffset}
bind:this={list}
>
{#snippet item(item, index)}
{#snippet item(index)}
<div class="-mx-4 sm:-mx-6 px-4 sm:px-6">
<Comments
isParent={true}
bind:nodes={() => [nodes[index]], (v) => (nodes[index] = v[0])}
bind:nodes={() => [nodes[index]], v => (nodes[index] = v[0])}
{post}
/>
</div>
@@ -1,22 +1,13 @@
<script lang="ts">
import {
ArrowDownCircle,
ArrowUp,
ArrowUpCircle,
ChevronDown,
ChevronUp,
Icon,
} from 'svelte-hero-icons'
import { getClient, site } from '$lib/lemmy.svelte'
import { settings } from '$lib/settings.svelte'
import { profile } from '$lib/auth.svelte.js'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { Button, buttonColor, toast } from 'mono-svelte'
import { vote as voteItem } from '$lib/lemmy/contentview'
import { shouldShowVoteColor } from '../post/PostVote.svelte'
import { fly } from 'svelte/transition'
import { backOut } from 'svelte/easing'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte'
import { buttonColor, toast } from 'mono-svelte'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
import { backOut } from 'svelte/easing'
import { fly } from 'svelte/transition'
import { shouldShowVoteColor } from '../post/PostVote.svelte'
interface Props {
vote?: number
@@ -1,20 +1,19 @@
<script lang="ts">
import Comments from './Comments.svelte'
import Comment from './Comment.svelte'
import { buildCommentsTree, type CommentNodeI } from './comments.svelte'
import { page } from '$app/state'
import { onMount, setContext } from 'svelte'
import { Icon, ArrowDownCircle } from 'svelte-hero-icons'
import { getClient } from '$lib/lemmy.svelte.js'
import type { CommentView, Post } from 'lemmy-js-client'
import { fly } from 'svelte/transition'
import { toast } from 'mono-svelte'
import { profile } from '$lib/auth.svelte.js'
import { Button } from 'mono-svelte'
import { afterNavigate, goto } from '$app/navigation'
import { backOut, expoOut } from 'svelte/easing'
import { t } from '$lib/i18n/translations'
import { browser } from '$app/environment'
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js'
import type { Post } from 'lemmy-js-client'
import { Button, toast } from 'mono-svelte'
import { onMount } from 'svelte'
import { ArrowDownCircle, Icon } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
import { fly } from 'svelte/transition'
import Comment from './Comment.svelte'
import Comments from './Comments.svelte'
import { buildCommentsTree, type CommentNodeI } from './comments.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
nodes: CommentNodeI[]
@@ -36,7 +35,6 @@
}
})
let loadingChildren = false
let childrenPage = 0
async function fetchChildren(parent: CommentNodeI) {
@@ -60,7 +58,6 @@
})
if (newComments.comments.length == 0) {
loadingChildren = false
toast({
content: $t('toast.noComments'),
type: 'error',
@@ -96,10 +93,10 @@
}
}
childrenPage++
} catch (error) {
console.error(error)
} catch (err) {
console.error(err)
toast({
content: error as any,
content: errorMessage(err as string),
type: 'error',
})
}
@@ -162,7 +159,6 @@
/>
{/snippet}
{$t('comment.more', {
// @ts-ignore
comments: node.comment_view.counts.child_count,
})}
</Button>
@@ -26,7 +26,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 = () => true,
): CommentNodeI[] {
const map = new Map<number, CommentNodeI>()
@@ -21,8 +21,8 @@
})
return block
} catch (error) {
toast({ content: error as any, type: 'error' })
} catch (err) {
toast({ content: errorMessage(err as string), type: 'error' })
return !block
}
}
@@ -36,8 +36,8 @@
})
removeToast(purgeToast)
toast({ content: t.get('toast.purgedCommunity'), type: 'success' })
} catch (e) {
toast({ content: e as any, type: 'error' })
} catch (err) {
toast({ content: errorMessage(err as string), type: 'error' })
}
}
@@ -59,8 +59,8 @@
content: `Successfully blocked that instance.`,
type: 'success',
})
} catch (error) {
toast({ content: error as any, type: 'error' })
} catch (err) {
toast({ content: errorMessage(err as string), type: 'error' })
}
}
</script>
@@ -73,43 +73,39 @@
} from '$lib/components/lemmy/moderation/moderation.js'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Entity from '$lib/components/ui/Entity.svelte'
import Expandable from '$lib/components/ui/Expandable.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import StickyCard from '$lib/components/ui/StickyCard.svelte'
import {
Menu,
MenuButton,
Modal,
removeToast,
toast,
modal,
action,
} from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import { client, getClient } from '$lib/lemmy.svelte.js'
import { errorMessage } from '$lib/lemmy/error'
import { userLink } from '$lib/lemmy/generic'
import { addSubscription } from '$lib/lemmy/user.js'
import { settings } from '$lib/settings.svelte'
import { fullCommunityName } from '$lib/util.svelte.js'
import type { CommunityModeratorView, CommunityView } from 'lemmy-js-client'
import { Button } from 'mono-svelte'
import {
action,
Button,
Menu,
MenuButton,
modal,
removeToast,
toast,
} from 'mono-svelte'
import {
BuildingOffice2,
Calendar,
ChartBar,
Check,
Cog6Tooth,
EllipsisHorizontal,
Fire,
Icon,
InformationCircle,
Newspaper,
NoSymbol,
Plus,
} from 'svelte-hero-icons'
import Expandable from '$lib/components/ui/Expandable.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import ItemList from '../generic/ItemList.svelte'
import { userLink } from '$lib/lemmy/generic'
import { t } from '$lib/i18n/translations'
import Entity from '$lib/components/ui/Entity.svelte'
import { settings } from '$lib/settings.svelte'
let loading = $state({
blocking: false,
@@ -128,8 +124,8 @@
community_id: community_view.community.id,
follow: !subscribed,
})
} catch (error) {
toast({ content: error as any, type: 'error' })
} catch (err) {
toast({ content: errorMessage(err as string), type: 'error' })
}
community_view.subscribed = subscribed ? 'NotSubscribed' : 'Subscribed'
@@ -219,7 +215,7 @@
</span>
{/snippet}
<ItemList
items={moderators.map((m) => ({
items={moderators.map(m => ({
id: m.moderator.id,
name: m.moderator.name,
url: userLink(m.moderator),
@@ -4,22 +4,27 @@
import { goto } from '$app/navigation'
import { profile } from '$lib/auth.svelte.js'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { Badge, ImageInput, MenuButton, Switch, toast } from 'mono-svelte'
import { client, getClient, site } from '$lib/lemmy.svelte.js'
import { addSubscription } from '$lib/lemmy/user.js'
import { Button, Checkbox, TextInput } from 'mono-svelte'
import { uploadImage } from '$lib/util.svelte.js'
import { t } from '$lib/i18n/translations'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import ImagePreviewInput from '$lib/components/input/ImagePreviewInput.svelte'
import Label from 'mono-svelte/forms/Label.svelte'
import { DocumentPlus, GlobeAlt, Icon, MapPin, Plus } from 'svelte-hero-icons'
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
import Select from 'mono-svelte/forms/select/Select.svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import { t } from '$lib/i18n/translations'
import { getClient, site } from '$lib/lemmy.svelte.js'
import { addSubscription } from '$lib/lemmy/user.js'
import {
Badge,
Button,
MenuButton,
Switch,
TextInput,
toast,
} from 'mono-svelte'
import Label from 'mono-svelte/forms/Label.svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import Select from 'mono-svelte/forms/select/Select.svelte'
import Material from 'mono-svelte/materials/Material.svelte'
import Menu from 'mono-svelte/popover/Menu.svelte'
import { DocumentPlus, GlobeAlt, Icon, MapPin, Plus } from 'svelte-hero-icons'
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
/**
@@ -96,7 +101,7 @@
if (profile.data.user) {
const c = profile.data.user.moderates
.map((m) => m.community.id)
.map(m => m.community.id)
.indexOf(res.community_view.community.id)
if (c != -1) {
profile.data.user.moderates[c] = {
@@ -127,7 +132,7 @@
)
} catch (err) {
toast({
content: err as any,
content: errorMessage(err as string),
type: 'error',
})
}
@@ -184,7 +189,7 @@
<ImageUploadModal
bind:open={uploading.icon}
multiple={false}
onupload={(uploaded) => {
onupload={uploaded => {
uploading.icon = false
formData.icon = uploaded[0]
}}
@@ -212,7 +217,7 @@
<ImageUploadModal
bind:open={uploading.banner}
multiple={false}
onupload={(uploaded) => {
onupload={uploaded => {
uploading.banner = false
formData.banner = uploaded[0]
}}
@@ -249,7 +254,7 @@
</Badge>
</button>
{/snippet}
{#each site.data.all_languages.filter((l) => !formData.languages?.includes(l.id)) as language, index}
{#each site.data.all_languages.filter(l => !formData.languages?.includes(l.id)) as language (language.id)}
<MenuButton
class="min-h-[16px] py-0"
onclick={() => {
@@ -263,9 +268,9 @@
</MenuButton>
{/each}
</Menu>
{#each formData.languages ?? [] as languageId, index}
{#each formData.languages ?? [] as languageId, index (languageId)}
{@const language = site.data.all_languages.find(
(l) => l.id == languageId,
l => l.id == languageId,
)}
<button
type="button"
@@ -1,7 +1,12 @@
<script lang="ts">
import { profile } from '$lib/auth.svelte'
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
import Expandable from '$lib/components/ui/Expandable.svelte'
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
import { publishedToDate } from '$lib/components/util/date'
import { t } from '$lib/i18n/translations'
import { userLink } from '$lib/lemmy/generic'
import { settings } from '$lib/settings.svelte'
import { fullCommunityName } from '$lib/util.svelte'
import type {
Community,
@@ -9,28 +14,22 @@
CommunityModeratorView,
SubscribedType,
} from 'lemmy-js-client'
import { Button, toast, Menu, MenuButton, modal, action } from 'mono-svelte'
import { action, Button, Menu, MenuButton, modal, toast } from 'mono-svelte'
import {
BuildingOffice2,
Check,
Cog6Tooth,
Icon,
EllipsisHorizontal,
Plus,
Newspaper,
BuildingOffice2,
Fire,
Icon,
Newspaper,
NoSymbol,
Plus,
} from 'svelte-hero-icons'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import Expandable from '$lib/components/ui/Expandable.svelte'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import ItemList from '../generic/ItemList.svelte'
import { userLink } from '$lib/lemmy/generic'
import { formatRelativeDate } from '$lib/components/util/RelativeDate.svelte'
import { publishedToDate } from '$lib/components/util/date'
import { isAdmin } from '../moderation/moderation'
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
import { settings } from '$lib/settings.svelte'
interface Props {
community: Community
@@ -102,7 +101,7 @@
<hr class="flex-1 border-slate-200 dark:border-zinc-800 mx-3" />
{/snippet}
<ItemList
items={moderators.map((m) => ({
items={moderators.map(m => ({
id: m.moderator.id,
name: m.moderator.name,
url: userLink(m.moderator),
@@ -119,8 +118,7 @@
community: community,
banned_from_community: false,
blocked: false,
// @ts-ignore
counts: counts ?? {},
counts: counts!,
subscribed: subscribed,
}}
>
@@ -153,7 +151,7 @@
{/if}
{#if profile.data?.user && profile.data.user.moderates
.map((c) => c.community.id)
.map(c => c.community.id)
.includes(community.id)}
<Button
size="square-lg"
@@ -1,29 +1,25 @@
<script lang="ts">
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import { profile } from '$lib/auth.svelte.js'
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations'
import { addSubscription } from '$lib/lemmy/user.js'
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
import type { CommunityView } from 'lemmy-js-client'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import { Button, Modal } from 'mono-svelte'
import {
ChatBubbleOvalLeftEllipsis,
Check,
ExclamationTriangle,
Icon,
InformationCircle,
MapPin,
NoSymbol,
PencilSquare,
Plus,
Trash,
UserGroup,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { Button, Modal } from 'mono-svelte'
import { fullCommunityName, isSubscribed } from '$lib/util.svelte.js'
import { profile } from '$lib/auth.svelte.js'
import { addSubscription } from '$lib/lemmy/user.js'
import Avatar from '$lib/components/ui/Avatar.svelte'
import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import { t } from '$lib/i18n/translations'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
let showInfo = $state(false)
interface Props {
@@ -13,10 +13,11 @@
avatarSize?: number
showInstance?: boolean
displayName?: boolean
badges?: any
badges?: {
nsfw: boolean
}
class?: string
instanceClass?: string
[key: string]: any
}
let {
@@ -13,19 +13,18 @@
import { amModOfAny } from '../moderation/moderation'
import { t } from '$lib/i18n/translations'
import Option from 'mono-svelte/forms/select/Option.svelte'
import type { SelectProps } from 'mono-svelte/forms/select/Select.svelte'
interface Props {
interface Props extends SelectProps<string> {
selected: string
navigate?: boolean
changeDefault?: boolean
showLabel?: boolean
[key: string]: any
}
let {
selected = $bindable(),
navigate = true,
changeDefault = false,
showLabel = true,
...rest
}: Props = $props()
@@ -3,6 +3,8 @@
import { t } from '$lib/i18n/translations'
import { searchParam } from '$lib/util.svelte.js'
import { Select } from 'mono-svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import type { SelectProps } from 'mono-svelte/forms/select/Select.svelte'
import {
ArrowTrendingDown,
ArrowTrendingUp,
@@ -21,21 +23,18 @@
Trophy,
} from 'svelte-hero-icons'
import { backOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition'
import Option from 'mono-svelte/forms/select/Option.svelte'
import { fly } from 'svelte/transition'
interface Props {
interface Props extends SelectProps<string> {
selected: string
navigate?: boolean
changeDefault?: boolean
class?: string
[key: string]: any
}
let {
selected = $bindable(),
navigate = true,
changeDefault = false,
class: clazz = '',
...rest
}: Props = $props()
@@ -1,22 +1,12 @@
<script lang="ts">
import { settings } from '$lib/settings.svelte.js'
import { t } from '$lib/i18n/translations'
import { settings } from '$lib/settings.svelte.js'
import { Select } from 'mono-svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import {
Bars3,
Clock,
Icon,
ListBullet,
QueueList,
RectangleGroup,
Square2Stack,
ViewColumns,
} from 'svelte-hero-icons'
import { Bars3, Icon, RectangleGroup, ViewColumns } from 'svelte-hero-icons'
interface Props {
showLabel?: boolean
[key: string]: any
}
let { showLabel = true, ...rest }: Props = $props()
@@ -1,6 +1,5 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import { Button } from 'mono-svelte'
import { flip } from 'svelte/animate'
import { expoOut } from 'svelte/easing'
@@ -4,7 +4,7 @@
import { errorMessage } from '$lib/lemmy/error'
import { t } from '$lib/i18n/translations'
import { uploadImage } from '$lib/util.svelte.js'
import { ImageInput, Spinner, toast } from 'mono-svelte'
import { toast } from 'mono-svelte'
import { Button, Modal } from 'mono-svelte'
import { DocumentPlus, Icon } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
@@ -39,19 +39,19 @@
try {
const uploaded = (
await Promise.all(
Array.from(image).map((i) =>
Array.from(image).map(i =>
uploadImage(i, profile.data.instance, profile.data.jwt!)
.then((uploaded) => {
.then(uploaded => {
progress += 1 / (image?.length ?? 0)
return uploaded
})
.catch((err) => {
.catch(err => {
toast({ content: errorMessage(err), type: 'error' })
return 'Failed to upload'
}),
),
)
).filter((i) => i != undefined)
).filter(i => i != undefined)
if (!uploaded) throw new Error('Image upload returned undefined')
@@ -80,7 +80,7 @@
{/if}
<form
class="flex flex-col gap-4"
onsubmit={(e) => {
onsubmit={e => {
e.preventDefault()
upload()
}}
@@ -96,7 +96,6 @@
{multiple ? 'grid-cols-3 grid-rows-2' : 'grid-cols-1 grid-rows-1'}"
>
{#each previewURLs as file}
<!-- svelte-ignore a11y_missing_attribute -->
<img
src={file}
onload={() => URL.revokeObjectURL(file)}
@@ -9,6 +9,7 @@
import type { Person } from 'lemmy-js-client'
import { Button, Modal, toast } from 'mono-svelte'
import { Icon, PaperAirplane } from 'svelte-hero-icons'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
open?: boolean
@@ -40,7 +41,7 @@
open = false
} catch (err) {
toast({
content: err as any,
content: errorMessage(err as string),
type: 'error',
})
}
@@ -1,17 +1,18 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy'
import { preventDefault } from 'svelte/legacy'
import Avatar from '$lib/components/ui/Avatar.svelte'
import type { Community, Person, PersonView } from 'lemmy-js-client'
import type { Community, Person } from 'lemmy-js-client'
import { getClient } from '$lib/lemmy.svelte.js'
import { toast } from 'mono-svelte'
import { profile } from '$lib/auth.svelte.js'
import { Button, Checkbox, Modal, TextInput } from 'mono-svelte'
import { Button, Checkbox, Modal } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { t } from '$lib/i18n/translations'
import CommunityLink from '../community/CommunityLink.svelte'
import Duration from '$lib/components/form/Duration.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
open?: boolean
@@ -84,7 +85,7 @@
item.banned = !banned
} catch (err) {
toast({
content: err as any,
content: errorMessage(err),
type: 'error',
})
}
@@ -16,7 +16,6 @@
interface Props {
item: PostView | CommentView
[key: string]: any
}
let { item = $bindable(), ...rest }: Props = $props()
@@ -1,9 +1,11 @@
<script lang="ts">
import { profile } from '$lib/auth.svelte.js'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte'
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
import type { CommentView, PostView } from 'lemmy-js-client'
import { amMod, ban, isAdmin, remove } from './moderation'
import { Button, Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
import {
ArrowsUpDown,
Fire,
Icon,
LockClosed,
@@ -12,16 +14,12 @@
ShieldExclamation,
Trash,
} from 'svelte-hero-icons'
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
import { Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
import { profile } from '$lib/auth.svelte.js'
import { Button } from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import { amMod, ban, isAdmin, remove } from './moderation'
import ShieldIcon from './ShieldIcon.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
item: PostView | CommentView
[key: string]: any
}
let { item = $bindable(), ...rest }: Props = $props()
@@ -44,7 +42,7 @@
item.post.locked = lock
} catch (err) {
toast({
content: err as any,
content: errorMessage(err),
type: 'error',
})
}
@@ -67,7 +65,7 @@
item.post.featured_community = pinned
} catch (err) {
toast({
content: err as any,
content: errorMessage(err),
type: 'error',
})
}
@@ -1,23 +1,23 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy'
import { preventDefault, run } from 'svelte/legacy'
import { profile } from '$lib/auth.svelte.js'
import MultiSelect from '$lib/components/input/Switch.svelte'
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
import Post from '$lib/components/lemmy/post/Post.svelte'
import { Select, Switch, toast } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js'
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
import type { CommentView, PostView } from 'lemmy-js-client'
import { profile } from '$lib/auth.svelte.js'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { Fire, Icon, Trash } from 'svelte-hero-icons'
import MultiSelect from '$lib/components/input/Switch.svelte'
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
import { settings } from '$lib/settings.svelte.js'
import { fullCommunityName } from '$lib/util.svelte.js'
import { amMod, isAdmin } from './moderation'
import { Button, Checkbox, Modal } from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import type { CommentView, PostView } from 'lemmy-js-client'
import { Button, Modal, Select, Switch, toast } from 'mono-svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import { Fire, Icon, Trash } from 'svelte-hero-icons'
import { amMod, isAdmin } from './moderation'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
open: boolean
@@ -153,7 +153,7 @@
open = false
} catch (err) {
toast({
content: err as any,
content: errorMessage(err),
type: 'error',
})
}
@@ -1,22 +1,20 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy'
import { preventDefault, run } from 'svelte/legacy'
import { profile } from '$lib/auth.svelte.js'
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import Post from '$lib/components/lemmy/post/Post.svelte'
import { toast } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { t } from '$lib/i18n/translations'
import { getClient } from '$lib/lemmy.svelte.js'
import type {
CommentView,
PostView,
PrivateMessageView,
} from 'lemmy-js-client'
import { profile } from '$lib/auth.svelte.js'
import { Button, Modal } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { onMount } from 'svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { t } from '$lib/i18n/translations'
import { Button, Modal, toast } from 'mono-svelte'
import PrivateMessage from '../inbox/PrivateMessage.svelte'
import { errorMessage } from '$lib/lemmy/error'
interface Props {
open: boolean
@@ -67,7 +65,7 @@
type: 'success',
})
} catch (err) {
toast({ content: err as any, type: 'error' })
toast({ content: errorMessage(err as string), type: 'error' })
}
loading = false
@@ -9,7 +9,7 @@ import type {
PostView,
PrivateMessageView,
} from 'lemmy-js-client'
import { get, writable } from 'svelte/store'
import { writable } from 'svelte/store'
interface Modals {
reporting: {
@@ -29,7 +29,7 @@ interface Modals {
}
}
export let modals = writable<Modals>({
export const modals = writable<Modals>({
reporting: {
open: false,
item: undefined,
@@ -48,7 +48,7 @@ export let modals = writable<Modals>({
})
export function report(item: PostView | CommentView | PrivateMessageView) {
modals.update((m) => ({
modals.update(m => ({
...m,
reporting: {
open: true,
@@ -58,7 +58,7 @@ export function report(item: PostView | CommentView | PrivateMessageView) {
}
export function remove(item: SubmissionView, purge: boolean = false) {
modals.update((m) => ({
modals.update(m => ({
...m,
removing: {
open: true,
@@ -69,7 +69,7 @@ export function remove(item: SubmissionView, purge: boolean = false) {
}
export function ban(banned: boolean, item: Person, community?: Community) {
modals.update((m) => ({
modals.update(m => ({
...m,
banning: {
open: true,
@@ -88,16 +88,13 @@ export async function feature(featured: boolean, item: Comment, jwt: string) {
}
export const amMod = (me: MyUserInfo, community: Community) =>
me.moderates.map((c) => c.community.id).includes(community.id) ||
me.moderates.map(c => c.community.id).includes(community.id) ||
(community.local && isAdmin(me))
export const amModOfAny = (me?: MyUserInfo) =>
me && (me.moderates.length > 0 || isAdmin(me))
export const isAdmin = (me: MyUserInfo) =>
// backwards compatibility hack
// @ts-ignore
me.local_user_view.local_user.admin ?? me.local_user_view.person?.admin
export const isAdmin = (me: MyUserInfo) => me.local_user_view.local_user.admin
export const removalTemplate = (
input: string,
+17 -24
View File
@@ -1,29 +1,27 @@
<script lang="ts">
import type { PostView } from 'lemmy-js-client'
import { goto } from '$app/navigation'
import { profile } from '$lib/auth.svelte'
import { mediaType, postLink } from '$lib/components/lemmy/post/helpers.js'
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
import PostActions from '$lib/components/lemmy/post/PostActions.svelte'
import { settings, type View } from '$lib/settings.svelte.js'
import PostMeta, {
parseTags,
type Tag,
} from '$lib/components/lemmy/post/PostMeta.svelte'
import { Badge } from 'mono-svelte'
import { mediaType, postLink } from '$lib/components/lemmy/post/helpers.js'
import { publishedToDate } from '$lib/components/util/date.js'
import { ArrowUp, ChatBubbleOvalLeft, Icon } from 'svelte-hero-icons'
import PostMedia from '$lib/components/lemmy/post/media/PostMedia.svelte'
import PostMediaCompact from '$lib/components/lemmy/post/media/PostMediaCompact.svelte'
import PostBody from './PostBody.svelte'
import { profile } from '$lib/auth.svelte'
import { goto } from '$app/navigation'
import { settings, type View } from '$lib/settings.svelte.js'
import type { PostView } from 'lemmy-js-client'
import type { ClassValue } from 'svelte/elements'
import PostBody from './PostBody.svelte'
function getTagRule(tags: Tag[]): 'blur-sm' | 'hide' | undefined {
const tagContent = tags.map((t) => t.content.toLowerCase())
const tagContent = tags.map(t => t.content.toLowerCase())
let rule: 'blur-sm' | 'hide' | undefined
if (settings.nsfwBlur && (post.post.nsfw || post.community.nsfw))
rule = 'blur-sm'
tagContent.forEach((tag) => {
tagContent.forEach(tag => {
if (settings.tagRules?.[tag]) rule = settings.tagRules?.[tag] ?? rule
if (rule == 'hide') return rule
})
@@ -31,8 +29,8 @@
return rule
}
function onClick(e: any) {
const event = e as MouseEvent
function onClick(e: Event) {
const event = e as Event
const parent = document.getElementById(post.post.id.toString())
if (event.target == parent) {
@@ -68,7 +66,7 @@
})
let tags = $derived(parseTags(post.post.name))
let type = $derived(mediaType(post.post.url, view))
let type = $derived(mediaType(post.post.url))
let rule = $derived(getTagRule(tags.tags))
let hideTitle = $derived(
settings.posts.deduplicateEmbed &&
@@ -100,7 +98,6 @@
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 -->
<div
class={[
@@ -111,11 +108,10 @@
clazz,
]}
id={post.post.id.toString()}
onclick={(e) => {
onclick={e => {
onClick(e)
}}
onkeydown={(e) => {
// @ts-ignore
onkeydown={e => {
if (e.key == 'Enter') onClick(e)
}}
tabindex="0"
@@ -128,7 +124,7 @@
published={publishedToDate(post.post.published)}
{badges}
subscribed={profile.data?.user?.follows
.map((c) => c.community.id)
.map(c => c.community.id)
.includes(post.community.id)
? 'Subscribed'
: 'NotSubscribed'}
@@ -156,9 +152,7 @@
<PostMediaCompact
post={post.post}
{type}
class="{settings.leftAlign
? 'mr-3'
: 'ml-3'} shrink no-list-margin"
class="{settings.leftAlign ? 'mr-3' : 'ml-3'} shrink no-list-margin"
style="grid-area: media;"
blur={rule == 'blur-sm' ? true : undefined}
{view}
@@ -169,7 +163,6 @@
<PostBody
element="section"
body={post.post.body}
{view}
style="grid-area: body"
class="relative"
/>
+51 -126
View File
@@ -1,43 +1,25 @@
<script lang="ts">
import type { PostView } from 'lemmy-js-client'
import PostVote from './PostVote.svelte'
import { site } from '$lib/lemmy.svelte.js'
import {
ArrowsUpDown,
ArrowTopRightOnSquare,
Bookmark,
BookmarkSlash,
BugAnt,
ChatBubbleOvalLeft,
ChatBubbleOvalLeftEllipsis,
Clock,
EllipsisHorizontal,
Eye,
EyeSlash,
Flag,
GlobeAmericas,
Icon,
MapPin,
Newspaper,
Pencil,
PencilSquare,
Share,
Trash,
UserCircle,
XMark,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { goto } from '$app/navigation'
import { profile } from '$lib/auth.svelte.js'
import {
amMod,
isAdmin,
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import { profile } from '$lib/auth.svelte.js'
import TextProps from '$lib/components/ui/text/TextProps.svelte'
import { publishedToDate } from '$lib/components/util/date'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations'
import { instance } from '$lib/instance.svelte'
import { site } from '$lib/lemmy.svelte.js'
import { deleteItem, markAsRead, save } from '$lib/lemmy/contentview.js'
import { communityLink, userLink } from '$lib/lemmy/generic'
import { setSessionStorage } from '$lib/session.js'
import { goto } from '$app/navigation'
import { settings, type View } from '$lib/settings.svelte.js'
import { instanceToURL } from '$lib/util.svelte'
import { feature } from '$lib/version'
import type { PostView } from 'lemmy-js-client'
import {
Button,
Menu,
@@ -47,17 +29,29 @@
Spinner,
toast,
} from 'mono-svelte'
import { t } from '$lib/i18n/translations'
import {
ArrowTopRightOnSquare,
Bookmark,
BookmarkSlash,
BugAnt,
ChatBubbleOvalLeft,
ChatBubbleOvalLeftEllipsis,
EllipsisHorizontal,
Eye,
EyeSlash,
Flag,
GlobeAmericas,
Icon,
MapPin,
Newspaper,
PencilSquare,
Share,
Trash,
UserCircle,
XMark,
} from 'svelte-hero-icons'
import { hidePost, postLink } from './helpers'
import { feature } from '$lib/version'
import { instanceId, instanceToURL } from '$lib/util.svelte'
import { publishedToDate } from '$lib/components/util/date'
import TextProps from '$lib/components/ui/text/TextProps.svelte'
import { communityLink, userLink } from '$lib/lemmy/generic'
import RelativeDate, {
formatRelativeDate,
} from '$lib/components/util/RelativeDate.svelte'
import { instance } from '$lib/instance.svelte'
import PostVote from './PostVote.svelte'
let editing = $state(false)
let saving = $state(false)
@@ -98,7 +92,7 @@
<PostForm
edit
editingPost={post.post}
onsubmit={(e) => {
onsubmit={e => {
editing = false
post = e
onedit?.(e)
@@ -106,7 +100,6 @@
>
{#snippet formtitle()}
<!-- Have the title not exist at all -->
{''}
{/snippet}
</PostForm>
{/await}
@@ -136,7 +129,6 @@
rounding="pill"
target={settings.openLinksInNewTab ? '_blank' : ''}
title={$t('post.actions.comments')}
animations={{ scale: true, large: false }}
>
{@const newComment =
publishedToDate(post.counts.newest_comment_time).getTime() >
@@ -148,7 +140,6 @@
<FormattedNumber number={post.counts.comments} />
</Button>
<div class="flex-1"></div>
{#if settings.debugInfo}
{#if debug}
{#await import('$lib/components/util/debug/DebugObject.svelte') then { default: DebugObject }}
@@ -185,7 +176,7 @@
onclick={async () => {
if (!profile.data?.jwt) return
saving = true
post.saved = await save(post, !post.saved, profile.data?.jwt)
post.saved = await save(post, !post.saved)
saving = false
}}
size="custom"
@@ -195,7 +186,6 @@
loading={saving}
disabled={saving}
title={post.saved ? $t('post.actions.unsave') : $t('post.actions.save')}
animations={{ scale: true, large: true }}
>
{#snippet prefix()}
<Icon src={post.saved ? BookmarkSlash : Bookmark} size="16" mini />
@@ -203,13 +193,7 @@
</Button>
{/if}
<Menu
placement="bottom-end"
containerClass="overflow-auto max-h-[400px]"
class="h-8"
targetClass="h-full"
title={$t('post.actions.more.label')}
>
<Menu placement="bottom-end" class="h-8">
{#snippet target()}
<Button
title={$t('post.actions.more.label')}
@@ -224,59 +208,6 @@
{/snippet}
</Button>
{/snippet}
<MenuDivider>{$t('cards.site.stats')}</MenuDivider>
<div class="flex flex-row gap-1 items-center">
<MenuButton class="flex-1">
{#snippet prefix()}
<Icon src={Clock} size="16" micro />
{/snippet}
<span>
{publishedToDate(post.post.published).toLocaleDateString(undefined, {
dateStyle: 'short',
})}
</span>
</MenuButton>
{#if post.post.updated}
{@const editedTime = formatRelativeDate(
publishedToDate(post.post.updated),
{
style: 'long',
},
)}
<MenuButton class="flex-1" aria-label={editedTime}>
{#snippet prefix()}
<Icon src={Pencil} size="16" micro />
{/snippet}
<RelativeDate date={publishedToDate(post.post.updated)} />
</MenuButton>
{/if}
</div>
{#if post.counts.score}
{@const ratio =
post.counts.upvotes / (post.counts.upvotes + post.counts.downvotes)}
<MenuButton
aria-label={$t('aria.vote.score', { default: post.counts.score })}
>
{#snippet prefix()}
<Icon src={ArrowsUpDown} size="16" micro />
{/snippet}
{$t('post.actions.vote.score')}
•
<FormattedNumber
number={post.counts.score}
options={{ notation: 'standard' }}
class="font-medium"
/>
•
<FormattedNumber
number={ratio}
options={{ style: 'percent' }}
class="font-medium {ratio > 0.7
? 'text-blue-700 dark:text-blue-300'
: 'text-red-500'}"
/>
</MenuButton>
{/if}
<MenuDivider>{$t('post.actions.more.creator')}</MenuDivider>
<MenuButton link href={userLink(post.creator)}>
{#snippet prefix()}
@@ -309,11 +240,7 @@
<MenuButton
onclick={async () => {
if (profile.data?.jwt)
post.read = await markAsRead(
post.post,
!post.read,
profile.data.jwt,
)
post.read = await markAsRead(post.post, !post.read)
}}
>
{#snippet prefix()}
@@ -326,11 +253,13 @@
{/if}
<MenuButton
onclick={() => {
navigator.share?.({
url: localShare
? `${instanceToURL(instance.data)}/post/${post.post.id}`
: post.post.ap_id,
}) ??
if (navigator.share)
navigator.share?.({
url: localShare
? `${instanceToURL(instance.data)}/post/${post.post.id}`
: post.post.ap_id,
})
else
navigator.clipboard.writeText(
localShare
? `${instanceToURL(instance.data)}/post/${post.post.id}`
@@ -346,11 +275,11 @@
{$t('post.actions.more.share')}
<div class="flex-1"></div>
{#if !post.post.local}
<div class="flex">
<div class="flex gap-1">
<Button
color={!localShare ? 'primary' : 'secondary'}
size="square-md"
roundingSide="left"
size="square-sm"
rounding="pill"
onclick={() => (localShare = false)}
title={$t('filter.location.global')}
>
@@ -358,8 +287,8 @@
</Button>
<Button
color={localShare ? 'primary' : 'secondary'}
size="square-md"
roundingSide="right"
size="square-sm"
rounding="pill"
onclick={() => (localShare = true)}
title={$t('filter.location.local')}
>
@@ -401,11 +330,7 @@
<MenuButton
onclick={async () => {
if (profile.data?.jwt)
post.post.deleted = await deleteItem(
post,
!post.post.deleted,
profile.data.jwt,
)
post.post.deleted = await deleteItem(post, !post.post.deleted)
}}
color="danger-subtle"
>
@@ -1,6 +1,5 @@
<script lang="ts">
import Markdown from '$lib/components/markdown/Markdown.svelte'
import type { View } from '$lib/settings.svelte'
import { Button } from 'mono-svelte'
import { ChevronDown, Icon } from 'svelte-hero-icons'
@@ -16,7 +15,6 @@
interface Props {
body: string
view?: View
clickThrough?: boolean
element?: string
style?: string
@@ -25,7 +23,6 @@
let {
body,
view = 'cozy',
clickThrough = false,
element: htmlElement = 'div',
style = '',
+23 -14
View File
@@ -20,11 +20,11 @@
const newTitle = title
.toString()
.replace(/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g, (match, content) => {
.replace(/^(\[.[^\]]+\])|(\[.[^\]]+\])$/g, match => {
const contents = match.split(',').map((part: string) => part.trim())
contents
.map((i) => i.replaceAll(/(\[|\])/g, ''))
.map(i => i.replaceAll(/(\[|\])/g, ''))
.forEach((content: string) => {
extracted.push(
textToTag.get(content) ?? {
@@ -44,32 +44,32 @@
<script lang="ts">
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import { Badge, Popover } from 'mono-svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import { publishedToDate } from '$lib/components/util/date'
import RelativeDate, {
formatRelativeDate,
} from '$lib/components/util/RelativeDate.svelte'
import { t } from '$lib/i18n/translations'
import { instance } from '$lib/instance.svelte'
import { settings, type View } from '$lib/settings.svelte'
import type { Community, Person, SubscribedType } from 'lemmy-js-client'
import { Badge, Popover } from 'mono-svelte'
import {
Bookmark,
ExclamationTriangle,
Icon,
LockClosed,
Megaphone,
PaperAirplane,
Pencil,
Tag,
Trash,
PaperAirplane,
type IconSource,
} from 'svelte-hero-icons'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
import { settings, type View } from '$lib/settings.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { t } from '$lib/i18n/translations'
import { Pencil, type IconSource } from 'svelte-hero-icons'
import CommunityHeader from '../community/CommunityHeader.svelte'
import { publishedToDate } from '$lib/components/util/date'
import { profile } from '$lib/auth.svelte'
import { instance } from '$lib/instance.svelte'
import ShieldIcon from '../moderation/ShieldIcon.svelte'
interface Props {
community?: Community | undefined
@@ -83,7 +83,16 @@
edited?: string | undefined
view?: View
// Badges
badges?: any
badges?: {
nsfw: boolean
saved: boolean
featured: boolean
deleted: boolean
removed: boolean
locked: boolean
moderator: boolean
admin: boolean
}
tags?: Tag[]
style?: string
titleClass?: string
+11 -15
View File
@@ -1,6 +1,5 @@
<script lang="ts" module>
import { settings } from '$lib/settings.svelte.js'
export const voteColor = (vote: number, border: boolean = false) =>
export const voteColor = (vote: number) =>
vote == 1
? `bg-linear-to-br from-blue-500 to-indigo-500 dark:from-blue-400 dark:to-indigo-500 text-slate-50 dark:text-zinc-900`
: vote == -1
@@ -17,17 +16,17 @@
</script>
<script lang="ts">
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import type { Post } from 'lemmy-js-client'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
import { profile } from '$lib/auth.svelte.js'
import { vote as voteItem } from '$lib/lemmy/contentview.js'
import { Button, Popover, buttonColor, toast } from 'mono-svelte'
import { site } from '$lib/lemmy.svelte.js'
import { fade, fly } from 'svelte/transition'
import { backOut } from 'svelte/easing'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations'
import { site } from '$lib/lemmy.svelte.js'
import { vote as voteItem } from '$lib/lemmy/contentview.js'
import { errorMessage } from '$lib/lemmy/error'
import type { Post } from 'lemmy-js-client'
import { buttonColor, toast } from 'mono-svelte'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
import { backOut } from 'svelte/easing'
import { fly } from 'svelte/transition'
interface Props {
post: Post
@@ -36,7 +35,7 @@
upvotes?: number
downvotes?: number
showCounts?: boolean
children?: import('svelte').Snippet<[any]>
children?: import('svelte').Snippet<[{ vote: number; score: number }]>
}
let {
@@ -51,17 +50,14 @@
let loading = $state(false)
let oldScore = score
const castVote = async (newVote: number) => {
if (!profile.data?.jwt) {
toast({ content: $t('toast.loginVoteGate'), type: 'warning' })
return
}
loading = true
oldScore = score
vote = newVote
const res = await voteItem(post, newVote, profile.data.jwt).catch((e) => {
const res = await voteItem(post, newVote).catch(e => {
toast({ content: errorMessage(e), type: 'error' })
return { upvotes: 0, downvotes: 0, score: 0 }
})
@@ -3,24 +3,17 @@
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { settings } from '$lib/settings.svelte.js'
import type { PostView } from 'lemmy-js-client'
import { Badge, Button } from 'mono-svelte'
import { ArchiveBox, Icon, Minus, Plus } from 'svelte-hero-icons'
import { Button } from 'mono-svelte'
import type { Snippet } from 'svelte'
import { ArchiveBox, Icon, Plus } from 'svelte-hero-icons'
interface Props {
posts: PostView[]
community?: boolean
feedData: any
children?: import('svelte').Snippet
[key: string]: any
children?: Snippet
}
let {
posts = $bindable(),
community = false,
feedData,
children,
...rest
}: Props = $props()
let { posts = $bindable(), community = false, children }: Props = $props()
</script>
<ul
@@ -1,8 +1,10 @@
<script lang="ts">
import { browser } from '$app/environment'
import Post from '$lib/components/lemmy/post/Post.svelte'
import VirtualList from '$lib/components/render/VirtualList.svelte'
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { t } from '$lib/i18n/translations'
import { client } from '$lib/lemmy.svelte'
import {
postFeeds,
@@ -10,10 +12,9 @@
type PostFeedID,
} from '$lib/lemmy/postfeed.svelte'
import { settings } from '$lib/settings.svelte.js'
import { t } from '$lib/i18n/translations'
import type { PostView } from 'lemmy-js-client'
import { Button } from 'mono-svelte'
import { onMount, tick, untrack } from 'svelte'
import { onMount, untrack } from 'svelte'
import {
ArchiveBox,
ChevronDoubleUp,
@@ -22,7 +23,6 @@
Plus,
} from 'svelte-hero-icons'
import InfiniteScroll from 'svelte-infinite-scroll'
import VirtualList from '$lib/components/render/VirtualList.svelte'
interface Props {
posts: PostView[]
@@ -45,7 +45,7 @@
scrollToIndex: (index: number, window?: boolean) => void
}>()
let error: any = $state(undefined)
let error = $state()
let loading = $state(false)
let hasMore = $state(true)
@@ -69,7 +69,7 @@
sort: feedData.sort,
type_: feedData.type_,
})
.catch((e) => {
.catch(e => {
throw new Error(e)
})
@@ -90,7 +90,7 @@
}
const callback: IntersectionObserverCallback = (entries, observer) => {
entries.forEach((entry) => {
entries.forEach(entry => {
if (!entry.isIntersecting) return
const element = entry.target as HTMLElement
@@ -130,7 +130,7 @@
const feed = document.getElementById('feed')
if (!feed) return
new MutationObserver((mutations) => {
new MutationObserver(mutations => {
mutations.forEach(({ addedNodes, removedNodes }) => {
addedNodes.forEach(observePost)
removedNodes.forEach(unobservePost)
@@ -176,7 +176,7 @@
bind:restore={postFeeds.value[feedId].clientData}
bind:this={listComp}
>
{#snippet item(_, row, __)}
{#snippet item(row)}
<li
data-index={row}
style={row < 7 ? `--anim-delay: ${row * 100}ms` : ''}
@@ -238,7 +238,6 @@
<div style="border-top-width: 0">
<EndPlaceholder>
{$t('routes.frontpage.endFeed', {
// @ts-ignore
community_name: feedData.community_name ?? 'undefined',
})}
{#snippet action()}
@@ -1,20 +1,11 @@
import { settings } from '$lib/settings.svelte'
import type { PostView } from 'lemmy-js-client'
import { get } from 'svelte/store'
export type PostViewWithCrossposts = PostView & {
withCrossposts: true
crossposts: PostView[]
}
export type PostViewWithoutCrossposts = PostView & { withCrossposts?: false }
const addCrosspostProperty = (
post: PostView,
crossposts: PostView[],
): PostViewWithCrossposts => ({
...post,
crossposts: crossposts,
withCrossposts: true,
})
export const combineCrossposts = (
posts: PostView[],
@@ -26,7 +17,7 @@ export const combineCrossposts = (
const results: (PostViewWithCrossposts | PostViewWithoutCrossposts)[] = []
const seenUrls = new Set<string>()
posts?.forEach((post) => {
posts?.forEach(post => {
if (
!post ||
(settings.hidePosts.deleted && post.post.deleted) ||
@@ -38,7 +29,7 @@ export const combineCrossposts = (
return
}
let existing = urlMap.get(post.post.url)
const existing = urlMap.get(post.post.url)
if (existing) {
existing.withCrossposts = true
if (existing.withCrossposts) {
@@ -1,40 +1,44 @@
<script lang="ts">
import { run, preventDefault } from 'svelte/legacy'
import { preventDefault, run } from 'svelte/legacy'
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
import { client, site } from '$lib/lemmy.svelte.js'
import type { Community, Post, PostView } from 'lemmy-js-client'
import { Select, Spinner, Switch, toast } from 'mono-svelte'
import {
Icon,
Photo,
ArrowPath,
Sparkles,
ChatBubbleBottomCenterText,
Plus,
Language,
Link,
XMark,
} from 'svelte-hero-icons'
import { profile } from '$lib/auth.svelte.js'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { placeholders, uploadImage } from '$lib/util.svelte.js'
import { Checkbox, TextInput } from 'mono-svelte'
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
import { Button } from 'mono-svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import { t } from '$lib/i18n/translations'
import { slide } from 'svelte/transition'
import { feature } from '$lib/version'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import ErrorContainer, {
clearErrorScope,
pushError,
} from '$lib/components/error/ErrorContainer.svelte'
import { errorMessage } from '$lib/lemmy/error'
import FreeTextInput from '$lib/components/input/FreeTextInput.svelte'
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { t } from '$lib/i18n/translations'
import { client, site } from '$lib/lemmy.svelte.js'
import { errorMessage } from '$lib/lemmy/error'
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
import { placeholders } from '$lib/util.svelte.js'
import type { Community, Post, PostView } from 'lemmy-js-client'
import {
Button,
Select,
Spinner,
Switch,
TextInput,
toast,
} from 'mono-svelte'
import Option from 'mono-svelte/forms/select/Option.svelte'
import { onDestroy, onMount } from 'svelte'
import {
ArrowPath,
ChatBubbleBottomCenterText,
Icon,
Language,
Link,
Photo,
Plus,
Sparkles,
XMark,
} from 'svelte-hero-icons'
import { slide } from 'svelte/transition'
interface Props {
edit?: boolean
@@ -82,7 +86,6 @@
let data = $state(passedData)
// weird select menu language handling
// @ts-ignore
$effect(() => {
if (data.language_id === '') data.language_id = undefined
})
@@ -100,7 +103,6 @@
data.nsfw = editingPost.nsfw
data.alt_text = editingPost.alt_text
data.thumbnail = editingPost.thumbnail_url
// @ts-ignore
data.language_id = editingPost.language_id.toString()
}
@@ -115,12 +117,12 @@
limit: 40,
})
communities = list.communities.map((c) => c.community)
communities = list.communities.map(c => c.community)
}
})
onDestroy(() => {
// @ts-ignore
// @ts-expect-error TODO get rid of sessionStorage stuff
if (saveDraft) setSessionStorage('postDraft', data)
})
@@ -137,7 +139,7 @@
if (data.url && data.url != '') {
try {
new URL(data.url)
} catch (err) {
} catch {
pushError({
message: $t('toast.invalidURL'),
scope: 'post-form',
@@ -190,7 +192,7 @@
onsubmit?.(post.post_view)
}
} catch (err) {
pushError({ message: errorMessage(err as any), scope: 'post-form' })
pushError({ message: errorMessage(err as string), scope: 'post-form' })
data.loading = false
}
}
@@ -212,7 +214,7 @@
if (res.metadata.description)
data.body = res.metadata.description
.split('\n')
.map((l) => `> ${l}`)
.map(l => `> ${l}`)
.join('\n')
toast({
@@ -221,7 +223,7 @@
action: () => (data = oldData),
duration: 15 * 1000,
})
} catch (e) {
} catch {
pushError({
message: $t('toast.failGenerateTitle'),
scope: 'post-form',
@@ -234,7 +236,7 @@
if (!url) return false
try {
new URL(url)
} catch (e) {
} catch {
return false
}
return true
@@ -258,7 +260,7 @@
<UploadModal
bind:open={uploadingImage}
multiple={false}
onupload={(e) => {
onupload={e => {
if (e) data.url = e[0]
uploadingImage = false
}}
@@ -282,7 +284,7 @@
listing_type="All"
label={$t('form.post.community')}
required
onselect={(e) => {
onselect={e => {
const c = e
if (!c) {
data.community = null
@@ -399,7 +401,9 @@
const url = new URL(await navigator.clipboard.readText())
data.url = url.toString()
} catch (e) {}
} catch {
/* empty */
}
}}
size="sm"
rounding="pill"
@@ -472,9 +476,9 @@
toast({ content: $t('toast.restoredFromDraft') })
const draft = getSessionStorage('postDraft')
if (draft && !edit) {
// @ts-ignore
// @ts-expect-error TODO get rid of session storage
draft.loading = false
// @ts-ignore
// @ts-expect-error TODO get rid of session storage
data = draft
}
}}
+6 -6
View File
@@ -1,11 +1,8 @@
import { profile } from '$lib/auth.svelte'
import { instance } from '$lib/instance.svelte'
import { client } from '$lib/lemmy.svelte.js'
import type { View } from '$lib/settings.svelte'
import { isImage, isVideo } from '$lib/ui/image'
import { canParseUrl, findClosestNumber } from '$lib/util.svelte'
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
import { get } from 'svelte/store'
import type { CommentView, PersonView, Post } from 'lemmy-js-client'
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
me.person.id == comment.creator.id
@@ -15,6 +12,9 @@ export const bestImageURL = (
compact: boolean = true,
width: number = 1024,
) => {
if (compact) {
/* empty */
}
if (post.url) return optimizeImageURL(post.url, width)
else if (post.thumbnail_url)
return optimizeImageURL(post.thumbnail_url, width)
@@ -67,7 +67,7 @@ export const postLink = (post: Post) =>
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
export type IframeType = 'youtube' | 'video' | 'none'
export const mediaType = (url?: string, view: View = 'cozy'): MediaType => {
export const mediaType = (url?: string): MediaType => {
if (url) {
if (isImage(url)) return 'image'
if (isVideo(url)) return 'iframe'
@@ -89,7 +89,7 @@ export async function hidePost(
hide: boolean,
jwt: string,
): Promise<boolean> {
const res = await client({ auth: jwt }).hidePost({
await client({ auth: jwt }).hidePost({
hide: hide,
post_ids: [id],
})
@@ -1,31 +1,22 @@
<script lang="ts">
import Link, { parseURL } from '$lib/components/input/Link.svelte'
import { Button, Material } from 'mono-svelte'
import {
CheckBadge,
ChevronDown,
Icon,
Link as LinkIcon,
} from 'svelte-hero-icons'
import { optimizeImageURL } from '../helpers'
import { t } from '$lib/i18n/translations'
import { parseURL } from '$lib/components/input/Link.svelte'
import type { View } from '$lib/settings.svelte'
import { Button, Material } from 'mono-svelte'
import { optimizeImageURL } from '../helpers'
interface Props {
url: string
thumbnail_url?: string | undefined
thumbnail_url?: string
nsfw?: boolean
embed_title?: string | undefined
embed_description?: string | undefined
embed_title?: string
view?: View
}
let {
url,
thumbnail_url = undefined,
thumbnail_url,
nsfw = false,
embed_title = undefined,
embed_description = undefined,
embed_title,
view = 'cozy',
}: Props = $props()
@@ -27,15 +27,14 @@
</script>
<script lang="ts">
import { settings } from '$lib/settings.svelte'
import {
Icon,
PuzzlePiece,
VideoCamera,
type IconSource,
} from 'svelte-hero-icons'
import { optimizeImageURL, type IframeType, type MediaType } from '../helpers'
import { settings } from '$lib/settings.svelte'
import { get } from 'svelte/store'
import { optimizeImageURL, type IframeType } from '../helpers'
const urlToEmbed = (inputUrl: string) => {
if (type == 'video') {
@@ -89,7 +88,7 @@
type?: IframeType
thumbnail?: string | undefined
url: string
opened?: any
opened?: boolean
autoplay?: boolean
class?: string
}
@@ -1,12 +1,10 @@
<script lang="ts">
import { stopPropagation } from 'svelte/legacy'
import { settings, type View } from '$lib/settings.svelte'
import type { Post } from 'lemmy-js-client'
import { bestImageURL, postLink } from '../helpers'
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import { settings } from '$lib/settings.svelte'
import type { Post } from 'lemmy-js-client'
import { Button, modal } from 'mono-svelte'
import { onMount } from 'svelte'
import { bestImageURL, postLink } from '../helpers'
interface Props {
post: Post
@@ -54,7 +52,6 @@
srcset={bestImageURL(post, false, 1536)}
media="(max-width: 1024px)"
/>
<!-- svelte-ignore a11y_missing_attribute -->
<img
src={bestImageURL(post, false, -1)}
loading="lazy"
@@ -74,11 +71,11 @@
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"
onclick={(e) => e.stopPropagation()}
onclick={e => e.stopPropagation()}
>
{#if post.alt_text}
<Button
onclick={(e) => {
onclick={e => {
e.stopPropagation()
modal({
title: 'Alt',
@@ -1,21 +1,12 @@
<script lang="ts">
import Empty from '$lib/components/helper/Empty.svelte'
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
import {
bestImageURL,
postLink,
type MediaType,
iframeType,
type MediaType,
} from '$lib/components/lemmy/post/helpers.js'
import ExpandableImage, {
showImage,
} from '$lib/components/ui/ExpandableImage.svelte'
import PostLink from '$lib/components/lemmy/post/link/PostLink.svelte'
import { settings, type View } from '$lib/settings.svelte.js'
import type { Post } from 'lemmy-js-client'
import PostIframe from './PostIframe.svelte'
import { Button, Material, modal } from 'mono-svelte'
import { onMount } from 'svelte'
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
import PostImage from './PostImage.svelte'
interface Props {
@@ -7,17 +7,16 @@
} from '$lib/components/lemmy/post/helpers.js'
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import { settings, type View } from '$lib/settings.svelte.js'
import { t } from '$lib/i18n/translations'
import { isImage } from '$lib/ui/image'
import type { Post } from 'lemmy-js-client'
import { Material, modal, Popover } from 'mono-svelte'
import { modal } from 'mono-svelte'
import Button from 'mono-svelte/button/Button.svelte'
import {
DocumentText,
ExclamationTriangle,
Icon,
Link,
VideoCamera,
ExclamationTriangle,
} from 'svelte-hero-icons'
const thumbnailSize = (view: View) =>
@@ -68,6 +67,7 @@
}}
role="button"
tabindex="0"
class="cursor-pointer"
>
{#if post.thumbnail_url || isImage(post.url)}
<div class="relative overflow-hidden rounded-xl">
@@ -75,16 +75,20 @@
<img
src={optimizeImageURL(post.thumbnail_url || post.url || '', 256)}
loading="lazy"
class="object-cover relative overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl
transition-colors {size}"
class={[
'object-cover relative overflow-hidden bg-slate-100 dark:bg-zinc-800 rounded-xl transition-colors',
size,
]}
alt={post.alt_text ?? ' '}
class:blur-xl={blur}
/>
{#if type != 'image'}
<div
class="absolute w-8 h-8 m-1 bottom-0 left-0 rounded-xl text-slate-800 dark:text-zinc-200
bg-slate-25 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-700
grid place-items-center"
class={[
'absolute w-8 h-8 m-1 bottom-0 left-0 rounded-xl text-slate-800 dark:text-zinc-200',
'bg-slate-25 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-700',
'grid place-items-center',
]}
>
<Icon
src={type == 'iframe' ? VideoCamera : Link}
@@ -109,10 +113,13 @@
{/if}
{:else}
<div
class="object-cover overflow-hidden bg-slate-50 dark:bg-zinc-900 rounded-xl
border border-slate-200 dark:border-zinc-800 group-hover/media:border-slate-400
dark:group-hover/media:border-zinc-600 transition-colors text-slate-400 dark:text-zinc-600 grid
place-items-center {size}"
class={[
'object-cover overflow-hidden bg-slate-50 dark:bg-zinc-900 rounded-xl',
'border border-slate-200 dark:border-zinc-800 group-hover/media:border-slate-400',
'dark:group-hover/media:border-zinc-600 transition-colors text-slate-400 dark:text-zinc-600 grid',
'place-items-center',
size,
]}
>
<Icon
src={type == 'embed'
@@ -1,7 +1,7 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import { getClient } from '$lib/lemmy.svelte.js'
import type { Community, ListingType, Person } from 'lemmy-js-client'
import type { ListingType, Person } from 'lemmy-js-client'
import { MenuButton, Search } from 'mono-svelte'
import { createEventDispatcher } from 'svelte'
import { Icon, XCircle } from 'svelte-hero-icons'
@@ -12,8 +12,7 @@
instance?: string | undefined
listing_type?: ListingType
showWhenEmpty?: boolean
onselect?: (e: any) => void
[key: string]: any
onselect?: (e: Person) => void
}
let {
@@ -28,7 +27,7 @@
</script>
<Search
search={async (q) => {
search={async q => {
const results = await getClient(instance).search({
q: q || ' ',
type_: 'Users',
@@ -37,9 +36,9 @@
sort: 'TopAll',
})
return results.users.map((c) => c.person)
return results.users.map(c => c.person)
}}
extractName={(c) => `${c.name}@${new URL(c.actor_id).hostname}`}
extractName={c => `${c.name}@${new URL(c.actor_id).hostname}`}
bind:query={q}
{...rest}
>
@@ -1,15 +1,8 @@
<script lang="ts">
import type { PersonView } from 'lemmy-js-client'
import {
ChatBubbleOvalLeftEllipsis,
Icon,
PencilSquare,
} from 'svelte-hero-icons'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import { userLink } from '$lib/lemmy/generic'
import Avatar from '$lib/components/ui/Avatar.svelte'
import type { PersonView } from 'lemmy-js-client'
interface Props {
user: PersonView
@@ -10,7 +10,7 @@
} else {
return {}
}
} catch (e) {
} catch {
return {}
}
}
@@ -61,7 +61,7 @@
badges?: boolean
inComment?: boolean
showInstance?: boolean
displayName?: any
displayName?: boolean
instanceClass?: string
class?: string
children?: import('svelte').Snippet
@@ -1,31 +0,0 @@
<script lang="ts">
import { preventDefault } from 'svelte/legacy'
import { goto } from '$app/navigation'
import { t } from '$lib/i18n/translations'
import { TextInput } from 'mono-svelte'
let query: string = $state('')
let loading = $state(false)
function search() {
loading = true
goto(`/search?q=${query}`).then(() => (loading = false))
}
interface Props {
class?: string
children?: import('svelte').Snippet<[any]>
}
let { class: clazz = '', children }: Props = $props()
</script>
<form onsubmit={preventDefault(search)} class="w-full h-full {clazz}">
<TextInput
bind:value={query}
class="w-full h-full {clazz}"
placeholder={$t('nav.search')}
autofocus
/>
</form>
{@render children?.({ search, loading })}
+8 -5
View File
@@ -21,19 +21,22 @@
MdSuperscript,
MdText,
} from './renderers/index'
import { linkify, subSupscriptExtension } from './renderers/plugins'
import containerExtension from './renderers/spoiler/spoiler'
import { linkify, subSupscriptExtension } from './renderers/plugins.js'
import containerExtension from './renderers/spoiler/spoiler.js'
export const options: any = {
export const options = {
mangle: false,
headerIds: false,
pedantic: false,
inline: false,
}
marked.setOptions(options)
marked.use(linkify, {
extensions: [
// @ts-expect-error hell with marked
// eslint-disable-next-line
containerExtension((params: any) => {
if (params.type == 'spoiler') {
return {
@@ -45,6 +48,8 @@
}
return null
}),
// @ts-expect-error hell with marked
// eslint-disable-next-line
subSupscriptExtension((params: any) => {
if (params.type == 'subscript') {
return {
@@ -74,7 +79,6 @@
html: MdHtml,
code: MdCode,
list: MdList,
// @ts-ignore
spoiler: MdSpoiler,
table: MdTable,
tablebody: MdTableBody,
@@ -96,7 +100,6 @@
html: MdText,
code: MdText,
list: MdText,
// @ts-ignore
spoiler: MdText,
table: MdText,
tablebody: MdText,
@@ -1,18 +1,13 @@
<script lang="ts">
import { run } from 'svelte/legacy'
import { profile } from '$lib/auth.svelte.js'
import MultiSelect from '$lib/components/input/Switch.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import { t } from '$lib/i18n/translations'
import { uploadImage } from '$lib/util.svelte.js'
import { ImageInput, toast } from 'mono-svelte'
import { Button, Label, Modal, TextArea } from 'mono-svelte'
import { createEventDispatcher, tick } from 'svelte'
import { Button, Label, TextArea } from 'mono-svelte'
import type { TextAreaProps } from 'mono-svelte/forms/TextArea.svelte'
import { tick } from 'svelte'
import {
Bold,
CodeBracket,
DocumentPlus,
ExclamationTriangle,
H1,
Icon,
@@ -23,8 +18,7 @@
Strikethrough,
} from 'svelte-hero-icons'
import ImageUploadModal from '../lemmy/modal/ImageUploadModal.svelte'
import type { HTMLTextareaAttributes } from 'svelte/elements'
import type { TextAreaProps } from 'mono-svelte/forms/TextArea.svelte'
import type { ClassValue } from 'svelte/elements'
let textArea: HTMLTextAreaElement | undefined = $state()
@@ -60,7 +54,7 @@
}
let uploadingImage = $state(false)
let image = $state<any>(null)
let image = $state<FileList | null | undefined>(null)
const shortcuts = {
KeyB: () => wrapSelection('**', '**'),
@@ -68,11 +62,6 @@
KeyS: () => wrapSelection('~~', '~~'),
KeyH: () => wrapSelection('\n# ', ''),
KeyK: () => wrapSelection('[](', ')'),
Enter: (e: any) => {
onconfirm?.(value)
const newEvent = new Event('submit', { cancelable: true })
e?.target?.form?.dispatchEvent(newEvent)
},
}
async function adjustHeight() {
@@ -93,10 +82,9 @@
rows?: number
beforePreview?: (input: string) => string
previewing?: boolean
class?: string
class?: ClassValue
customLabel?: import('svelte').Snippet
children?: import('svelte').Snippet
onconfirm?: (value: string) => void
}
let {
@@ -107,12 +95,11 @@
tools = true,
disabled = false,
rows = 2,
beforePreview = (input) => input,
beforePreview = input => input,
previewing = $bindable(false),
class: clazz = '',
customLabel,
children,
onconfirm,
...rest
}: Props = $props()
@@ -125,8 +112,8 @@
<ImageUploadModal
bind:open={uploadingImage}
bind:image
onupload={(e) => {
e.forEach((i) => {
onupload={e => {
e.forEach(i => {
wrapSelection(`![](${i})\n\n`, '')
})
}}
@@ -265,10 +252,10 @@ overflow-hidden transition-colors {clazz}"
class="bg-inherit z-0 border-0 rounded-none ring-0! focus:ring-transparent! transition-none! resize-none"
bind:value
bind:element={textArea}
onkeydown={(e) => {
onkeydown={e => {
if (disabled) return
if (e.ctrlKey || e.metaKey) {
// @ts-ignore
// @ts-expect-error yes it can
let shortcut = shortcuts[e.code]
if (shortcut) {
e.preventDefault()
@@ -277,11 +264,11 @@ overflow-hidden transition-colors {clazz}"
}
}}
oninput={adjustHeight}
onpaste={(e) => {
onpaste={e => {
if (!e.clipboardData?.files) return
const files = Array.from(e.clipboardData.files)
if (files[0]?.type.startsWith('image/')) {
image = e.clipboardData.files[0]
image = e.clipboardData.files[0] as unknown as FileList | null
uploadingImage = true
}
}}
@@ -1,14 +1,14 @@
<script lang="ts">
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import {
iframeType,
mediaType,
optimizeImageURL,
} from '$lib/components/lemmy/post/helpers'
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
import { getContext } from 'svelte'
import { ArrowDown, ArrowDownTray, Icon } from 'svelte-hero-icons'
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
import { t } from '$lib/i18n/translations'
import { getContext } from 'svelte'
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
let loaded: boolean = $state(
(getContext('options') as { autoloadImages: boolean })?.autoloadImages ??
@@ -42,7 +42,7 @@
{:else}
<button
class="inline"
onclick={() => showImage(optimizeImageURL(href, -1), text)}
onclick={() => showImage(optimizeImageURL(href, -1))}
>
<img
src={optimizeImageURL(href, 1024)}
@@ -1,9 +1,9 @@
<script lang="ts">
import { photonify } from './plugins'
import { photonify } from './plugins.js'
interface Props {
href?: string
title?: any
title?: string
children?: import('svelte').Snippet
}
@@ -12,7 +12,7 @@
export const parseURL = (href: string) => {
try {
return new URL(href)
} catch (e) {
} catch {
return undefined
}
}
@@ -1,5 +1,5 @@
<script>
let { tokens, children } = $props()
let { children } = $props()
</script>
<li>
@@ -1,9 +1,6 @@
<script lang="ts">
import { marked } from 'marked'
import SvelteMarkdown from 'svelte-markdown'
import { options, renderers } from '../Markdown.svelte'
import { Disclosure } from 'mono-svelte'
import { Icon } from 'svelte-hero-icons'
import Expandable from '$lib/components/ui/Expandable.svelte'
interface Props {
@@ -4,10 +4,11 @@ import markedLinkifyIt from 'marked-linkify-it'
export const spoilerPlugin = {
name: 'spoiler',
level: 'block',
start(src: string) {
start(src) {
return src.match(/^:::/)?.index
},
tokenizer(src: string, tokens: any) {
// eslint-disable-next-line
tokenizer(src, tokens) {
const rule = /^::: spoiler (.+)\n([\s\S]*?)\n:::/
const match = rule.exec(src)
if (match) {
@@ -19,7 +20,7 @@ export const spoilerPlugin = {
}
}
},
renderer(token: any) {
renderer(token) {
return `
<details>
<summary>${marked.parseInline(token.title)}</summary>
@@ -32,12 +33,12 @@ export const spoilerPlugin = {
export const linkify = markedLinkifyIt(
{
'!': {
validate: function (text: any, pos: any, self: any) {
validate: function (text, pos, self) {
var tail = text.slice(pos)
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)) {
@@ -46,11 +47,11 @@ export const linkify = markedLinkifyIt(
if (pos >= 2 && tail[pos - 2] === '!') {
return false
}
return tail.match(self.re.community)![0].length
return tail.match(self.re.community)[0].length
}
return 0
},
normalize: function (match: any) {
normalize: function (match) {
let prefix = match.url
prefix = prefix.startsWith('c/') ? prefix.slice(2) : prefix.slice(1)
@@ -58,12 +59,12 @@ export const linkify = markedLinkifyIt(
},
},
'@': {
validate: function (text: any, pos: any, self: any) {
validate: function (text, pos, self) {
var tail = text.slice(pos)
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)) {
@@ -72,11 +73,11 @@ export const linkify = markedLinkifyIt(
if (pos >= 2 && tail[pos - 2] === '!') {
return false
}
return tail.match(self.re.user)![0].length
return tail.match(self.re.user)[0].length
}
return 0
},
normalize: function (match: any) {
normalize: function (match) {
let prefix = match.url
prefix = prefix.startsWith('u/') ? prefix.slice(2) : prefix.slice(1)
@@ -94,13 +95,13 @@ const regexes = {
comment: /^https:\/\/([a-zA-Z0-9.-]+)\/comment\/(\d+)$/i,
user: /^https:\/\/([a-zA-Z0-9.-]+)(\/u\/)([a-zA-Z0-9.-_]+)$/i,
community: /^https:\/\/([a-zA-Z0-9.-]+)(\/c\/)([a-zA-Z0-9.-_]+)$/i,
implicitUser: /^mailto:([a-z0-9_\.-]+)@(([\da-z\.-]+)\.([a-z]{2,63}))/i,
implicitUser: /^mailto:([a-z0-9_.-]+)@(([\da-z.-]+)\.([a-z]{2,63}))/i,
}
/**
* Convert links to photon links
*/
export const photonify = (link: string) => {
export const photonify = link => {
if (regexes.community.test(link)) {
const match = link.match(regexes.community)
if (!match) return
@@ -136,16 +137,17 @@ export const photonify = (link: string) => {
}
}
export function subSupscriptExtension(tokensExtractor: any): any {
export function subSupscriptExtension(tokensExtractor) {
return {
name: 'subscriptSuperscript',
level: 'inline',
start(src: string) {
start(src) {
return src.match(/[~^]/)?.index
},
tokenizer(src: string, tokens: any[]): any {
// eslint-disable-next-line
tokenizer(src, tokens) {
const subscriptRule = /^~([^~\s](?:[^~]*[^~\s])?)~/
const superscriptRule = /^\^([^\^\s](?:[^\^]*[^\^\s])?)\^/
const superscriptRule = /^\^([^^\s](?:[^^]*[^^\s])?)\^/
let match
@@ -1,32 +1,3 @@
import { Lexer } from 'marked'
export type ContainerOptions = Record<string, boolean | string>
export type TokenExtractionParameters = {
/**
* The type of container
*/
type: string
/**
* The content inside the container
*/
content: string
/**
* The raw full container block
*/
raw: string
/**
* The options of the container
*/
options: ContainerOptions
/**
* The lexer that can be used to render nested tokens if needed
*/
lexer: Lexer
}
export type TokenExtractor = (params: any) => any
/**
* Container extension is a marked extension that parses a block of text surrounded by :::
*
@@ -48,14 +19,14 @@ export type TokenExtractor = (params: any) => any
* **content**: `Something inside the container`
* **options**: { 'option': 'option-1', 'option-2': 'option-2', 'boolean-option': true }
*/
export default function (tokensExtractor: any): any {
export default function (tokensExtractor) {
return {
name: 'container',
level: 'block',
start(src: any) {
start(src) {
return src.match(/^:::[^:\n]/)?.index
},
tokenizer(src: any): any {
tokenizer(src) {
const rule =
/^:::[\s]?(?<type>[a-z0-9-]+)(?<options>.*)?\n(?<content>(?:.|\n)*)\n:::(?:\n|$)/i
@@ -83,7 +54,7 @@ export default function (tokensExtractor: any): any {
}
}
function findRawContainer(src: any): any {
function findRawContainer(src) {
if (!src.startsWith(':::')) return undefined
const lines = src.split('\n')
let open = 1
@@ -107,8 +78,8 @@ function findRawContainer(src: any): any {
return lines.slice(0, lineNumber + 1).join('\n')
}
function parseOptions(options: string): ContainerOptions {
const output: any = {}
function parseOptions(options) {
const output = {}
let remaining = options
while (true) {
+5 -6
View File
@@ -1,15 +1,14 @@
<script lang="ts" generics="T">
import { browser } from '$app/environment'
import { debounce } from 'mono-svelte/util/time'
import { onDestroy, tick, untrack, type Snippet } from 'svelte'
import { onDestroy, untrack, type Snippet } from 'svelte'
import type { HTMLAttributes } from 'svelte/elements'
import { innerHeight, scrollY } from 'svelte/reactivity/window'
import { innerHeight } from 'svelte/reactivity/window'
interface Props extends HTMLAttributes<HTMLDivElement> {
items: T[]
estimatedHeight?: number
overscan?: number
item: Snippet<[T, number, Function]>
item: Snippet<[number]>
restore?: {
itemHeights: (number | null)[]
}
@@ -117,7 +116,7 @@
}
function resizeObserver(node: HTMLElement) {
const observer = new ResizeObserver((entries) => {
const observer = new ResizeObserver(entries => {
for (const entry of entries) {
const indexAttr = node.getAttribute('data-index')
if (indexAttr === null) continue
@@ -174,7 +173,7 @@
class="post-container fix-divide"
use:resizeObserver
>
{@render itemSnippet(items[item.index], item.index, () => {})}
{@render itemSnippet(item.index)}
</div>
{/each}
</div>
+2 -3
View File
@@ -23,7 +23,7 @@
}
return urlObj.toString()
} catch (e) {
} catch {
return undefined
}
}
@@ -37,7 +37,6 @@
res?: number | undefined
style?: string
class?: ClassValue
[key: string]: any
}
let {
@@ -53,7 +52,7 @@
}: Props = $props()
let optimizedURLs = $derived(
[2, 3, 6, -1].map((n) => optimizeUrl(url, (res || width) * n)),
[2, 3, 6, -1].map(n => optimizeUrl(url, (res || width) * n)),
)
</script>
+3 -10
View File
@@ -1,15 +1,9 @@
<script lang="ts">
import { Material } from 'mono-svelte'
import Avatar from './Avatar.svelte'
import PostBody from '../lemmy/post/PostBody.svelte'
import LabelStat from './LabelStat.svelte'
import { optimizeImageURL } from '../lemmy/post/helpers'
import FormattedNumber from '../util/FormattedNumber.svelte'
import Expandable from './Expandable.svelte'
import { Icon, InformationCircle } from 'svelte-hero-icons'
import { t } from '$lib/i18n/translations'
import Markdown from '../markdown/Markdown.svelte'
import EndPlaceholder from './EndPlaceholder.svelte'
import FormattedNumber from '../util/FormattedNumber.svelte'
import Avatar from './Avatar.svelte'
import Expandable from './Expandable.svelte'
interface Props {
avatar?: string | undefined
@@ -27,7 +21,6 @@
nameDetail?: import('svelte').Snippet
actions?: import('svelte').Snippet
children?: import('svelte').Snippet
[key: string]: any
}
let {
+3 -6
View File
@@ -1,7 +1,7 @@
<script lang="ts" module>
import { pushState } from '$app/navigation'
export function showImage(url: string, alt: string = '') {
export function showImage(url: string) {
pushState('', {
openImage: url,
})
@@ -30,16 +30,13 @@
</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 -->
<div
class="fixed top-0 left-0 w-screen h-svh overflow-auto bg-white/50 dark:bg-black/50
flex flex-col z-100 backdrop-blur-xs"
transition:fade={{ duration: 150 }}
onclick={() => history.back()}
onkeydown={(e) => {
onkeydown={e => {
if (e.key == 'Escape') history.back()
}}
use:focusTrap
@@ -60,7 +57,7 @@
rounding="full"
padding="none"
color="uniform"
onclick={(e) => e.stopPropagation()}
onclick={e => e.stopPropagation()}
>
<Button
onclick={() => {
-2
View File
@@ -1,6 +1,4 @@
<script lang="ts">
import { settings } from '$lib/settings.svelte'
interface Props {
width?: number
}
-4
View File
@@ -12,8 +12,6 @@
cursor?: { next?: string; back?: string } | undefined
hasMore?: boolean
children?: import('svelte').Snippet
onchange?: (page: number) => void
onchangecursor?: (cursor: string) => void
href?: (current: number | string) => string
back?: boolean
}
@@ -23,8 +21,6 @@
cursor = undefined,
hasMore = true,
children,
onchange,
onchangecursor,
href,
back = true,
}: Props = $props()
-2
View File
@@ -5,7 +5,6 @@
icon?: IconSource | undefined
title: string
description?: string | undefined
center?: boolean
class?: string
children?: import('svelte').Snippet
}
@@ -14,7 +13,6 @@
icon = undefined,
title,
description = undefined,
center = false,
class: clazz = '',
children,
}: Props = $props()
+3 -2
View File
@@ -1,9 +1,10 @@
<script lang="ts">
interface Props {
import type { HTMLAttributes } from 'svelte/elements'
interface Props extends HTMLAttributes<HTMLSpanElement> {
small?: boolean
class?: string
children?: import('svelte').Snippet
[key: string]: any
}
let { small = false, class: clazz = '', children, ...rest }: Props = $props()
+8 -9
View File
@@ -1,22 +1,20 @@
<script lang="ts">
import { settings } from '$lib/settings.svelte.js'
import { theme } from '$lib/ui/colors.svelte'
import type { Snippet } from 'svelte'
import type { ClassValue, UIEventHandler } from 'svelte/elements'
import { scrollY } from 'svelte/reactivity/window'
interface Props {
route?: { id: string | null } | undefined
class?: ClassValue
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
children?: Snippet
navbar?: Snippet<[{ class: string; style: string }]>
sidebar?: Snippet<[{ class: string; style: string }]>
main?: Snippet<[{ class: string; style: string }]>
suffix?: Snippet<[{ class: string; style: string }]>
}
let {
route = undefined,
class: clazz = '',
children,
navbar,
@@ -27,7 +25,7 @@
}: Props = $props()
let previousTop = 0
const onscroll: UIEventHandler<Window> = (e) => {
const onscroll: UIEventHandler<Window> = () => {
if (!settings.dock.autoHide) {
dockVisible = true
return
@@ -56,6 +54,7 @@
class: `bg-slate-50/50 dark:bg-zinc-950/90 border-slate-100 dark:border-zinc-900
pointer-events-auto backdrop-blur-xl border lg:border-t-0 lg:border-x-0
rounded-full lg:rounded-none`,
style: '',
})}
</div>
<div
@@ -1,7 +1,6 @@
<script lang="ts">
import { invalidate, invalidateAll } from '$app/navigation'
import { invalidateAll } from '$app/navigation'
import { page } from '$app/state'
import { fly } from 'svelte/transition'
interface Props {
routes: {
@@ -18,7 +17,7 @@
let {
routes,
currentRoute = undefined,
buildUrl = (route, href) => href,
buildUrl = (_, href) => href,
defaultRoute = undefined,
class: clazz = '',
children,
@@ -49,7 +48,7 @@
''}
"
>
{#each routes as route}
{#each routes as route (route.href)}
<a
onclick={() => invalidateAll()}
href={buildUrl(currentRoute, route.href)}
@@ -3,6 +3,7 @@
import { Button, buttonColor } from 'mono-svelte'
import { Icon, type IconSource } from 'svelte-hero-icons'
import type { ButtonProps } from 'mono-svelte/button/Button.svelte'
import type { Snippet } from 'svelte'
interface Props extends ButtonProps {
label: string
@@ -11,9 +12,8 @@
adaptive?: boolean
isSelectedFilter?: (path: string) => boolean
class?: string
customIcon?: import('svelte').Snippet<[any]>
children?: import('svelte').Snippet
[key: string]: any
customIcon?: Snippet<[{ size: number; isSelected?: boolean }]>
children?: Snippet
}
let {
@@ -21,7 +21,7 @@
icon,
href,
adaptive = true,
isSelectedFilter = (path) => href != undefined && path == href,
isSelectedFilter = path => href != undefined && path == href,
class: clazz = '',
customIcon,
children,
+9 -9
View File
@@ -6,8 +6,10 @@
isAdmin,
} from '$lib/components/lemmy/moderation/moderation.js'
import Avatar from '$lib/components/ui/Avatar.svelte'
import { t } from '$lib/i18n/translations'
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
import { site } from '$lib/lemmy.svelte.js'
import { Button, Menu, MenuButton, MenuDivider, Spinner } from 'mono-svelte'
import { Menu, MenuButton, MenuDivider, Spinner } from 'mono-svelte'
import {
GlobeAlt,
Icon,
@@ -17,13 +19,11 @@
Plus,
ServerStack,
} from 'svelte-hero-icons'
import Profile from './Profile.svelte'
import NavButton from './NavButton.svelte'
import Logo from '../Logo.svelte'
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
import { t } from '$lib/i18n/translations'
import CommandsWrapper from './commands/CommandsWrapper.svelte'
import type { ClassValue } from 'svelte/elements'
import Logo from '../Logo.svelte'
import NavButton from './NavButton.svelte'
import Profile from './Profile.svelte'
import CommandsWrapper from './commands/CommandsWrapper.svelte'
let promptOpen: boolean = $state(false)
interface Props {
@@ -43,7 +43,7 @@
{style}
>
<NavButton
oncontextmenu={(e) => {
oncontextmenu={e => {
e.preventDefault()
promptOpen = true
return true
@@ -81,7 +81,7 @@
label={$t('nav.admin')}
icon={ServerStack}
class="relative"
isSelectedFilter={(path) => path.startsWith('/admin')}
isSelectedFilter={path => path.startsWith('/admin')}
>
{#if ($notifications.applications ?? 0) > 0}
<div
+15 -16
View File
@@ -3,6 +3,11 @@
import { notifications, profile } from '$lib/auth.svelte'
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
import { t } from '$lib/i18n/translations'
import { site } from '$lib/lemmy.svelte'
import { settings } from '$lib/settings.svelte'
import { theme } from '$lib/ui/colors.svelte'
import {
Badge,
Button,
@@ -10,12 +15,12 @@
MenuButton,
MenuDivider,
Modal,
Option,
Select,
Spinner,
toast,
Option,
} from 'mono-svelte'
import Avatar from '../Avatar.svelte'
import type { Placement } from 'svelte-floating-ui/core'
import {
Bars3,
Bookmark,
@@ -23,10 +28,8 @@
CodeBracketSquare,
Cog6Tooth,
ComputerDesktop,
Heart,
Icon,
Inbox,
InformationCircle,
Moon,
ServerStack,
Sun,
@@ -34,17 +37,13 @@
UserCircle,
UserGroup,
} from 'svelte-hero-icons'
import { theme } from '$lib/ui/colors.svelte'
import { settings } from '$lib/settings.svelte'
import { site } from '$lib/lemmy.svelte'
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
import { t } from '$lib/i18n/translations'
import Avatar from '../Avatar.svelte'
let showInstance = $state(false)
interface Props {
buttonClass?: string
[key: string]: any
placement?: Placement
}
let { buttonClass = '', ...rest }: Props = $props()
@@ -97,13 +96,13 @@
{/snippet}
<MenuDivider>{$t('nav.menu.label')}</MenuDivider>
{#if profile.data?.jwt}
<MenuButton link href="/profile">
<MenuButton href="/profile">
{#snippet prefix()}
<Icon src={UserCircle} micro width={16} />
{/snippet}
{$t('profile.profile')}
</MenuButton>
<MenuButton link href="/inbox">
<MenuButton href="/inbox">
{#snippet prefix()}
<Icon src={Inbox} micro width={16} />
{/snippet}
@@ -114,21 +113,21 @@
</Badge>
{/if}
</MenuButton>
<MenuButton link href="/saved">
<MenuButton href="/saved">
{#snippet prefix()}
<Icon src={Bookmark} micro width={16} />
{/snippet}
{$t('profile.saved')}
</MenuButton>
{/if}
<MenuButton link href="/accounts">
<MenuButton href="/accounts">
{#snippet prefix()}
<Icon src={UserGroup} micro width={16} />
{/snippet}
{$t('account.accounts')}
</MenuButton>
<MenuDivider>{$t('nav.menu.app')}</MenuDivider>
<MenuButton link href="/settings">
<MenuButton href="/settings">
{#snippet prefix()}
<Icon src={Cog6Tooth} micro width={16} />
{/snippet}
@@ -176,7 +175,7 @@
{$t('nav.menu.theme')}
</MenuButton>
{#if settings.debugInfo}
<MenuButton link href="/util">
<MenuButton href="/util">
{#snippet prefix()}
<Icon src={BugAnt} mini width={16} />
{/snippet}
@@ -1,21 +1,16 @@
<script lang="ts">
import { Button, Material } from 'mono-svelte'
import {
ArrowUturnDown,
Icon,
QuestionMarkCircle,
type IconSource,
} from 'svelte-hero-icons'
import { Button } from 'mono-svelte'
import { ArrowUturnDown, Icon, QuestionMarkCircle } from 'svelte-hero-icons'
import type { HTMLButtonAttributes } from 'svelte/elements'
import Avatar from '../../Avatar.svelte'
import type { Action } from './actions.svelte'
import type { HTMLButtonAttributes } from 'svelte/elements'
import type { Snippet } from 'svelte'
interface Props {
action: Action
class?: string
children?: import('svelte').Snippet
children?: Snippet
onclick?: HTMLButtonAttributes['onclick']
[key: string]: any
}
let { action, class: clazz = '', children, ...rest }: Props = $props()
@@ -1,18 +1,16 @@
<script lang="ts">
import { run } from 'svelte/legacy'
import { browser } from '$app/environment'
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { profile, profileData } from '$lib/auth.svelte'
import { t } from '$lib/i18n/translations'
import { resumables } from '$lib/lemmy/item'
import { theme } from '$lib/ui/colors.svelte'
import { TextInput } from 'mono-svelte'
import { createEventDispatcher, onMount } from 'svelte'
import { Home, Icon, MagnifyingGlass } from 'svelte-hero-icons'
import { t } from '$lib/i18n/translations'
import CommandItem from './CommandItem.svelte'
import { browser } from '$app/environment'
import { afterNavigate, goto } from '$app/navigation'
import { profile, profileData } from '$lib/auth.svelte'
import { getGroups, type Action, type Group } from './actions.svelte'
import { theme } from '$lib/ui/colors.svelte'
import { page } from '$app/state'
import CommandItem from './CommandItem.svelte'
interface Props {
open?: boolean
@@ -73,6 +71,7 @@
const debounce = (fn: Function, ms = 300) => {
let timeoutId: ReturnType<typeof setTimeout>
// eslint-disable-next-line
return function (this: any, ...args: any[]) {
clearTimeout(timeoutId)
timeoutId = setTimeout(() => fn.apply(this, args), ms)
@@ -82,16 +81,16 @@
function searchGroup(term: string) {
if (term.length < 1) {
if (breadcrumbs.length <= 0) {
filteredGroups = groups.map((group) => ({
filteredGroups = groups.map(group => ({
...group,
actions: flattenActions(group.actions, false),
}))
}
} else {
filteredGroups = groups
.map((group) => {
.map(group => {
const scoredActions = flattenActions(group.actions)
.map((action) => ({
.map(action => ({
...action,
score: Math.max(
fuzzySearch(action.name, term),
@@ -99,7 +98,7 @@
action.detail ? fuzzySearch(action.detail, term) : -1,
),
}))
.filter((action) => action.score > 0)
.filter(action => action.score > 0)
.sort((a, b) => b.score - a.score)
return {
@@ -107,11 +106,11 @@
actions: scoredActions,
score: Math.max(
fuzzySearch(group.name, term),
...scoredActions.map((a) => a.score),
...scoredActions.map(a => a.score),
),
}
})
.filter((group) => group.actions.length > 0)
.filter(group => group.actions.length > 0)
.sort((a, b) => b.score - a.score)
}
}
@@ -143,7 +142,7 @@
actions: Action[],
subaction: boolean = true,
): Action[] {
return actions.flatMap((action) => [
return actions.flatMap(action => [
action,
...(action.subActions && subaction
? flattenActions(action.subActions)
@@ -164,10 +163,10 @@
function handleKeydown(event: KeyboardEvent) {
if (event.ctrlKey) {
const actions = groups
.flatMap((g) => g.actions)
.filter((a) => a.shortcut != undefined)
.flatMap(g => g.actions)
.filter(a => a.shortcut != undefined)
actions.forEach((a) => {
actions.forEach(a => {
if (event.key === a.shortcut) {
event.preventDefault()
if (a.href) goto(a.href)
@@ -247,7 +246,7 @@
})
let flattenedActions = $derived(
filteredGroups.flatMap((group) => group.actions),
filteredGroups.flatMap(group => group.actions),
)
</script>
@@ -269,7 +268,7 @@
>
<Icon src={Home} size="16" mini />
</button>
{#each breadcrumbs as crumb, index}
{#each breadcrumbs as crumb (crumb.href)}
<span class="text-base text-slate-400 dark:text-zinc-600">/</span>
<span class="text-[13px] font-medium">
{crumb.name}
@@ -278,11 +277,11 @@
</div>
{/if}
<div class="space-y-1" bind:this={container}>
{#each filteredGroups as group, groupIndex}
{#each filteredGroups as group, groupIndex (group.name)}
<div class="space-y-1">
<span class="text-sm font-medium">{group.name}</span>
<ul class="flex flex-col gap-1">
{#each group.actions as action, actionIndex}
{#each group.actions as action, actionIndex (action.href)}
{@const globalIndex =
filteredGroups
.slice(0, groupIndex)
@@ -290,7 +289,7 @@
<li>
<CommandItem
{action}
onclick={(e) => {
onclick={e => {
if (action.href) {
togglePalette()
return
@@ -1,8 +1,6 @@
<script lang="ts">
import { t } from '$lib/i18n/translations'
import { Modal, Spinner } from 'mono-svelte'
import Commands from './Commands.svelte'
import { CommandLine, Icon } from 'svelte-hero-icons'
interface Props {
open?: boolean
@@ -5,47 +5,46 @@ import {
amModOfAny,
isAdmin,
} from '$lib/components/lemmy/moderation/moderation'
import { resumables, type ResumableItem } from '$lib/lemmy/item'
import { settings } from '$lib/settings.svelte'
import { t } from '$lib/i18n/translations'
import { type ResumableItem } from '$lib/lemmy/item'
import { settings } from '$lib/settings.svelte'
import { theme, type ThemeData } from '$lib/ui/colors.svelte'
import { fullCommunityName } from '$lib/util.svelte'
import {
ArrowRightOnRectangle,
ArrowTrendingDown,
ArrowTrendingUp,
Bookmark,
ChartBar,
ChatBubbleLeftRight,
ChatBubbleOvalLeftEllipsis,
Clock,
Cog6Tooth,
ComputerDesktop,
Fire,
GlobeAlt,
GlobeAmericas,
Home,
Identification,
Inbox,
MapPin,
Moon,
Newspaper,
PaintBrush,
PencilSquare,
Plus,
Scale,
ServerStack,
ShieldCheck,
Star,
Sun,
Swatch,
Trophy,
UserCircle,
UserGroup,
ViewColumns,
type IconSource,
PaintBrush,
ComputerDesktop,
Sun,
Moon,
MapPin,
GlobeAmericas,
ChartBar,
Trophy,
ArrowTrendingUp,
Fire,
Scale,
Star,
Clock,
ArrowTrendingDown,
ChatBubbleOvalLeftEllipsis,
ChatBubbleLeftRight,
Swatch,
Plus,
} from 'svelte-hero-icons'
import { get } from 'svelte/store'
export interface Group {
name: string
@@ -55,7 +54,7 @@ export interface Group {
export interface Action {
name: string
desc?: string
handle?: () => any
handle?: () => void
href?: string
shortcut?: string
icon: string | IconSource
@@ -73,7 +72,7 @@ export function getGroups(
return [
{
name: t.get('nav.commands.recents'),
actions: resumables.map((r) => ({
actions: resumables.map(r => ({
name: r.name,
icon: r.avatar ?? PencilSquare,
href: r.url,
@@ -306,7 +305,7 @@ export function getGroups(
},
{
name: t.get('account.accounts'),
actions: profiles.map((p) => ({
actions: profiles.map(p => ({
name: p.username ?? t.get('account.guest'),
icon: p.avatar ?? UserCircle,
detail: p.instance,
@@ -379,7 +378,7 @@ export function getGroups(
{
name: t.get('nav.commands.setTheme'),
icon: Swatch,
subActions: td.themes.map((th) => ({
subActions: td.themes.map(th => ({
name: t.get('nav.commands.setThemeTo', { default: th.name }),
icon: Swatch,
handle: () => (theme.data.currentTheme = th.id),
@@ -405,7 +404,7 @@ export function getGroups(
{
name: t.get('profile.subscribed'),
actions:
profile.user?.follows.map((f) => ({
profile.user?.follows.map(f => ({
icon: f.community.icon,
name: f.community.title,
href: `/c/${fullCommunityName(
-2
View File
@@ -1,6 +1,5 @@
import { t } from '$lib/i18n/translations'
import {
UserCircle,
type IconSource,
Home,
ChartBar,
@@ -17,7 +16,6 @@ import {
ArrowTrendingUp,
Star,
} from 'svelte-hero-icons'
import { get } from 'svelte/store'
export interface Link {
url: string
@@ -5,7 +5,6 @@
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
import ProfileAvatar from '$lib/lemmy/ProfileAvatar.svelte'
import { Button } from 'mono-svelte'
import { Icon, QuestionMarkCircle } from 'svelte-hero-icons'
let switching: boolean = $state(false)
+10 -14
View File
@@ -1,4 +1,12 @@
<script lang="ts">
import { notifications, profile, profileData } from '$lib/auth.svelte.js'
import Expandable from '$lib/components/ui/Expandable.svelte'
import CommunityList from '$lib/components/ui/sidebar/CommunityList.svelte'
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import { t } from '$lib/i18n/translations'
import { settings } from '$lib/settings.svelte.js'
import { Badge } from 'mono-svelte'
import {
ArrowLeftOnRectangle,
Bookmark,
@@ -8,17 +16,7 @@
UserCircle,
UserGroup,
} from 'svelte-hero-icons'
import { notifications, profile, profileData } from '$lib/auth.svelte.js'
import { settings } from '$lib/settings.svelte.js'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
import CommunityList from '$lib/components/ui/sidebar/CommunityList.svelte'
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
import { flip } from 'svelte/animate'
import { expoOut } from 'svelte/easing'
import { Badge } from 'mono-svelte'
import Expandable from '$lib/components/ui/Expandable.svelte'
import EndPlaceholder from '../EndPlaceholder.svelte'
import { t } from '$lib/i18n/translations'
interface Props {
style?: string
@@ -162,7 +160,7 @@
</span>
{/snippet}
<CommunityList
items={profile.data.user.moderates.map((i) => i.community)}
items={profile.data.user.moderates.map(i => i.community)}
/>
</Expandable>
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
@@ -184,9 +182,7 @@
</EndPlaceholder>
</span>
{/snippet}
<CommunityList
items={profile.data.user.follows.map((i) => i.community)}
/>
<CommunityList items={profile.data.user.follows.map(i => i.community)} />
</Expandable>
{/if}
</nav>
@@ -1,17 +1,17 @@
<script lang="ts">
import { page } from '$app/state'
import { Button } from 'mono-svelte'
import type { ButtonProps } from 'mono-svelte/button/Button.svelte'
import { Icon, type IconSource } from 'svelte-hero-icons'
interface Props {
interface Props extends ButtonProps {
href?: string | undefined
icon?: IconSource | undefined
selected?: boolean
class?: string
customIcon?: import('svelte').Snippet<[any]>
customIcon?: import('svelte').Snippet<[{ selected: boolean }]>
children?: import('svelte').Snippet
label?: import('svelte').Snippet
[key: string]: any
}
let {
+3 -3
View File
@@ -28,11 +28,11 @@
const rtf = new Intl.RelativeTimeFormat(language, options)
return rtf.format(-value, thresholds[i].unit as any)
return rtf.format(-value, thresholds[i].unit as 'second')
}
}
return 'Now'
} catch (err) {
} catch {
return 'Invalid Date'
}
}
@@ -44,7 +44,7 @@
const toLocaleDateString = (date: Date): string => {
try {
return date.toLocaleString()
} catch (err) {
} catch {
return 'Invalid Date'
}
}
@@ -3,6 +3,7 @@
import { Modal } from 'mono-svelte'
interface Props {
// eslint-disable-next-line
object: any
open?: boolean
title?: import('svelte').Snippet
@@ -1,6 +1,7 @@
<script lang="ts">
import DebugTree from './DebugTree.svelte'
interface Props {
// eslint-disable-next-line
object: any
isParent?: boolean
}
+6 -2
View File
@@ -1,4 +1,4 @@
import i18n, { type Config } from 'sveltekit-i18n'
import i18n, { type Config, type Parser } from 'sveltekit-i18n'
const config: Config = {
loaders: [
@@ -116,4 +116,8 @@ export const aliases = new Map([
['he-IL', 'he'],
])
export let { t, locale, locales, loading, loadTranslations } = new i18n(config)
export const { t, locale, locales, loading, loadTranslations } = new i18n<
Parser.Params<any, object>, // eslint-disable-line
object,
object
>(config)
+1 -4
View File
@@ -1,8 +1,5 @@
// maybe fix circular dependency, hopefully.
import { browser } from '$app/environment'
import { env } from '$env/dynamic/public'
import { writable } from 'svelte/store'
import { profile } from './auth.svelte'
class InstanceData {
@@ -13,7 +10,7 @@ class InstanceData {
}
}
export let instance = new InstanceData()
export const instance = new InstanceData()
export const LINKED_INSTANCE_URL =
(env.PUBLIC_LOCK_TO_INSTANCE ?? 'true').toLowerCase() == 'true'
+7 -9
View File
@@ -1,10 +1,8 @@
import { type GetSiteResponse, LemmyHttp } from 'lemmy-js-client'
import { get, writable } from 'svelte/store'
import { error } from '@sveltejs/kit'
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.svelte.js'
import { instanceToURL } from '$lib/util.svelte'
import { profile } from '$lib/auth.svelte'
import { toast } from 'mono-svelte'
import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js'
import { instanceToURL } from '$lib/util.svelte'
import { error } from '@sveltejs/kit'
import { LemmyHttp, type GetSiteResponse } from 'lemmy-js-client'
class SiteData {
#data = $state<GetSiteResponse>()
@@ -63,13 +61,13 @@ export function client({
} = {}) {
if (!instanceURL) instanceURL = profile.data.instance || DEFAULT_INSTANCE_URL
let jwt = auth ? auth : profile.data?.jwt
const jwt = auth ? auth : profile.data?.jwt
const headers = jwt ? { authorization: `Bearer ${jwt}` } : {}
return new LemmyHttp(instanceToURL(instanceURL), {
fetchFunction: (input, init) => customFetch(func, input, init, jwt),
//@ts-ignore
// @ts-expect-error headers thing
headers: headers,
})
}
@@ -92,7 +90,7 @@ export async function validateInstance(instance: string): Promise<boolean> {
await getClient(instance).getSite()
return true
} catch (err) {
} catch {
return false
}
}
+1 -7
View File
@@ -1,5 +1,5 @@
import { getClient } from '$lib/lemmy.svelte.js'
import { isComment, isCommentView, isPostView } from '$lib/lemmy/item.js'
import { isComment, isCommentView } from '$lib/lemmy/item.js'
import type {
CommentView,
Person,
@@ -63,7 +63,6 @@ export const contentItem = (item: Submission): ContentView => {
export async function save(
item: ContentView | SubmissionView,
save: boolean,
jwt: string,
): Promise<boolean> {
if (isSubmissionView(item)) item = contentView(item)
@@ -88,7 +87,6 @@ export async function save(
export async function deleteItem(
item: ContentView | SubmissionView,
deleted: boolean,
jwt: string,
): Promise<boolean> {
if (isSubmissionView(item)) item = contentView(item)
@@ -113,7 +111,6 @@ export async function deleteItem(
export async function vote(
item: ContentView | Submission,
vote: number,
jwt: string,
): Promise<{ upvotes: number; downvotes: number; score: number }> {
if (isSubmission(item)) item = contentItem(item)
@@ -138,14 +135,11 @@ export async function vote(
export async function markAsRead(
item: ContentView | Submission,
read: boolean,
jwt: string,
): Promise<boolean> {
if (isSubmission(item)) item = contentItem(item)
if (item.type == 'post') {
getClient().markPostAsRead({
// @ts-ignore
post_id: item.id,
post_ids: [item.id],
read: read,
})
+3 -1
View File
@@ -1,5 +1,6 @@
import { t } from '$lib/i18n/translations'
// eslint-disable-next-line
export function errorMessage(error: any, instance?: string): string {
try {
if (error?.body?.message) {
@@ -12,7 +13,8 @@ export function errorMessage(error: any, instance?: string): string {
if (!error) throw error
return t.get(`error.${error}`)
} catch (e) {
} catch {
// eslint-disable-next-line
return error as any
}
}
-1
View File
@@ -1,5 +1,4 @@
import type {
Comment,
CommentReplyView,
CommentView,
Person,
+11 -11
View File
@@ -1,18 +1,18 @@
import { profile, profileData } from '$lib/auth.svelte'
import { profile } from '$lib/auth.svelte'
import type {
Comment,
CommentReportView,
CommentView,
Community,
CommunityView,
Comment,
PersonView,
Post,
PostReportView,
PostView,
Post,
PrivateMessageReportView,
PrivateMessageView,
Community,
} from 'lemmy-js-client'
import { get, writable } from 'svelte/store'
import { writable } from 'svelte/store'
export type Result =
| PostView
@@ -90,8 +90,8 @@ function resumableStore(limit: number = 10) {
set,
update,
add: (item: ResumableItem) => {
update((resumables) => {
if (resumables.find((i) => JSON.stringify(i) == JSON.stringify(item)))
update(resumables => {
if (resumables.find(i => JSON.stringify(i) == JSON.stringify(item)))
return resumables
resumables.unshift(item)
if (resumables.length > limit) resumables.pop()
@@ -101,13 +101,13 @@ function resumableStore(limit: number = 10) {
}
}
export let resumables = resumableStore()
export const resumables = resumableStore()
export function addFavorite(item: Community, add: boolean = true) {
let favs = profile.data.favorites ?? []
if (favs.map((fav) => fav.id).includes(item.id)) if (add) return
const favs = profile.data.favorites ?? []
if (favs.map(fav => fav.id).includes(item.id)) if (add) return
if (!add) {
favs.splice(favs.map((c) => c.id).indexOf(item.id), 1)
favs.splice(favs.map(c => c.id).indexOf(item.id), 1)
} else {
favs.unshift(item)
}
+1 -1
View File
@@ -104,4 +104,4 @@ export interface PostFeed {
}
}
export let postFeeds = new PostFeedState()
export const postFeeds = new PostFeedState()
-1
View File
@@ -7,7 +7,6 @@ import type {
PostView,
PrivateMessage,
PrivateMessageReportView,
PrivateMessageView,
} from 'lemmy-js-client'
interface CommentReport {
+10 -10
View File
@@ -1,34 +1,34 @@
import { profile, profileData, type Profile } from '$lib/auth.svelte'
import { profile, type Profile } from '$lib/auth.svelte'
import { getClient } from '$lib/lemmy.svelte.js'
import { trycatch } from '$lib/util.svelte'
import type { Community, MyUserInfo, PersonView } from 'lemmy-js-client'
import { get } from 'svelte/store'
import type { Community, MyUserInfo } from 'lemmy-js-client'
// TODO obliterate this file
export const blockUser = async (block: boolean, id: number) => {
const auth = profile.data?.jwt
if (!auth) throw new Error('Unauthorized')
const response = await getClient().blockPerson({
await getClient().blockPerson({
block: block,
person_id: id,
})
}
export const isBlocked = (me: MyUserInfo, user: number) =>
me.person_blocks.map((b) => b.target.id).includes(user)
me.person_blocks.map(b => b.target.id).includes(user)
export const addSubscription = (
community: Community,
subscribe: boolean = true,
) => {
const index = profile.data.user?.follows
.map((f) => f.community.id)
.map(f => f.community.id)
.indexOf(community.id)
if (subscribe && index == -1) {
profile.data.user?.follows.push({
// @ts-ignore
follower: profile.data.user.follows[0]?.follower,
community: community,
})
@@ -37,7 +37,7 @@ export const addSubscription = (
}
}
export const addAdmin = async (handle: string, added: boolean, jwt: string) =>
export const addAdmin = async (handle: string, added: boolean) =>
trycatch(async () => {
const user = await getClient().resolveObject({
q: handle,
@@ -46,10 +46,10 @@ export const addAdmin = async (handle: string, added: boolean, jwt: string) =>
if (!user.person) throw new Error('No user found')
return await getClient().addAdmin({
added: true,
added: added,
person_id: user.person.person.id,
})
})
export const hasFavorite = (profile: Profile, id: number): boolean =>
profile.favorites?.map((i) => i.id).includes(id) ?? false
profile.favorites?.map(i => i.id).includes(id) ?? false
+7 -8
View File
@@ -108,7 +108,8 @@
},
}
interface Props extends Omit<HTMLButtonAttributes, 'prefix'> {
interface Props
extends Omit<HTMLButtonAttributes | HTMLAnchorAttributes, 'prefix'> {
loading?: boolean
submit?: boolean
color?: ButtonColor
@@ -118,7 +119,6 @@
alignment?: ButtonAlignment
shadow?: ButtonShadow
column?: boolean
animations?: any
loaderWidth?: number | undefined
href?: string | undefined
class?: ClassValue
@@ -126,14 +126,17 @@
children?: Snippet
suffix?: Snippet
onclick?: HTMLButtonAttributes['onclick']
[key: string]: any
}
export type { Props as ButtonProps }
</script>
<script lang="ts">
import type { ClassValue, HTMLButtonAttributes } from 'svelte/elements'
import type {
ClassValue,
HTMLAnchorAttributes,
HTMLButtonAttributes,
} from 'svelte/elements'
import Spinner from '../loader/Spinner.svelte'
import type { Snippet } from 'svelte'
@@ -148,10 +151,6 @@
alignment = 'center',
shadow = 'none',
column = false,
animations = {
scale: false,
large: false,
},
disabled,
loaderWidth = undefined,
href = undefined,
+1 -2
View File
@@ -6,7 +6,7 @@
let copied = $state(false)
let pre: HTMLPreElement = $state()
let pre = $state<HTMLPreElement>()
const copy = () => {
if (children) {
@@ -22,7 +22,6 @@
htmlSrc?: string | undefined
children?: import('svelte').Snippet
class?: string
[key: string]: any
}
let {
+5 -5
View File
@@ -1,15 +1,15 @@
<script lang="ts">
import { backOut, expoOut } from 'svelte/easing'
import type { Snippet } from 'svelte'
import { expoOut } from 'svelte/easing'
import type { ClassValue } from 'svelte/elements'
import { slide } from 'svelte/transition'
interface Props {
open?: boolean
class?: ClassValue
summary?: import('svelte').Snippet<[any]>
extended?: import('svelte').Snippet
children?: import('svelte').Snippet<[any]>
[key: string]: any
summary?: Snippet<[{ open: boolean }]>
extended?: Snippet
children?: Snippet<[{ open: boolean }]>
}
let {
+2 -4
View File
@@ -2,7 +2,6 @@
import Button from '../button/Button.svelte'
import { generateID } from '../forms/helper.js'
import { Label } from '../index.js'
import { Icon, PaperClip } from 'svelte-hero-icons'
interface Props {
accept?: string
@@ -51,12 +50,11 @@
<div
class="flex flex-row items-center -space-x-1 hover:space-x-1 z-20 h-8"
>
{#each previewURLs as file}
<!-- svelte-ignore a11y_missing_attribute -->
{#each previewURLs as file (file)}
<img
src={file}
onload={() => URL.revokeObjectURL(file)}
alt={file}
alt=""
class="w-8 h-8 object-cover rounded-full hover:w-16
hover:h-16 transition-all border border-slate-200 ring-1
ring-slate-50 dark:ring-zinc-950 bg-white dark:bg-zinc-950"
+4 -6
View File
@@ -1,9 +1,7 @@
<script lang="ts">
import { preventDefault } from 'svelte/legacy'
import { DocumentPlus, Icon } from 'svelte-hero-icons'
import Label from '../forms/Label.svelte'
import { generateID } from '../forms/helper.js'
import { DocumentPlus, Icon } from 'svelte-hero-icons'
import TextInput from './TextInput.svelte'
interface Props {
@@ -43,11 +41,11 @@
: ''}
{url != undefined ? 'rounded-b-none' : ''}
"
ondrop={(event) => {
ondrop={event => {
event.preventDefault()
files = event.dataTransfer?.files ?? null
}}
ondragover={(event) => {
ondragover={event => {
event.preventDefault()
if (event.dataTransfer) {
@@ -55,7 +53,7 @@
dragover = true
}
}}
ondragleave={(e) => {
ondragleave={e => {
e.preventDefault()
dragover = false
}}
+3 -2
View File
@@ -1,5 +1,7 @@
<script lang="ts">
interface Props {
import type { HTMLAttributes } from 'svelte/elements'
interface Props extends HTMLAttributes<HTMLSpanElement> {
for?: string | undefined
/**
* The `text` prop will take precedence over the slot.
@@ -7,7 +9,6 @@
text?: string | undefined
class?: string
children?: import('svelte').Snippet
[key: string]: any
}
let {
Loaded 100 of 225 files, more files were not shown because too many files have changed in this diff. Show more