diff --git a/bun.lockb b/bun.lockb index 232920a2..6480ec87 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index ed884f52..cb3d499c 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@sveltejs/vite-plugin-svelte": "^4.0.0", "@tailwindcss/container-queries": "^0.1.1", "@tailwindcss/postcss": "^4.1.8", + "@types/nprogress": "^0.2.0", "@types/ua-parser-js": "^0.7.39", "eslint": "^9.28.0", "eslint-plugin-svelte": "^3.9.1", @@ -22,6 +23,7 @@ "linkify-it": "^5.0.0", "marked": "7.0.5", "marked-linkify-it": "^3.1.10", + "nprogress": "^0.2.0", "postcss": "^8.4.30", "prettier": "^3.3.3", "prettier-plugin-svelte": "^3.2.7", diff --git a/src/lib/components/lemmy/comment/comments.svelte.ts b/src/lib/components/lemmy/comment/comments.svelte.ts index 1234938e..9a8b4aed 100644 --- a/src/lib/components/lemmy/comment/comments.svelte.ts +++ b/src/lib/components/lemmy/comment/comments.svelte.ts @@ -1,5 +1,4 @@ import type { Comment, CommentView } from 'lemmy-js-client' -import { SvelteMap } from 'svelte/reactivity' export interface CommentNodeI { comment_view: CommentView @@ -29,7 +28,7 @@ export function buildCommentsTree( baseDepth: number = 0, filter: (c: CommentView) => boolean = () => true, ): CommentNodeI[] { - const map = new SvelteMap() + const map = new Map() let min_depth = Number.MAX_VALUE for (const comment_view of comments) { diff --git a/src/lib/components/lemmy/moderation/ModerationMenu.svelte b/src/lib/components/lemmy/moderation/ModerationMenu.svelte index ea56015a..ee02024e 100644 --- a/src/lib/components/lemmy/moderation/ModerationMenu.svelte +++ b/src/lib/components/lemmy/moderation/ModerationMenu.svelte @@ -2,11 +2,9 @@ import { profile } from '$lib/auth.svelte.js' import { t } from '$lib/i18n/translations' import { getClient } from '$lib/lemmy.svelte' - import { errorMessage } from '$lib/lemmy/error' import { isCommentView, isPostView } from '$lib/lemmy/item.js' import type { CommentView, PostView } from 'lemmy-js-client' - import { Menu, MenuButton, MenuDivider, toast } from 'mono-svelte' - import type { Snippet } from 'svelte' + import { Button, Menu, MenuButton, MenuDivider, toast } from 'mono-svelte' import { ArrowsUpDown, Fire, @@ -19,19 +17,23 @@ Trash, } from 'svelte-hero-icons' import { amMod, ban, isAdmin, remove, viewVotes } from './moderation' + import ShieldIcon from './ShieldIcon.svelte' + import { errorMessage } from '$lib/lemmy/error' interface Props { item: PostView | CommentView - target: Snippet<[boolean]> } - let { item = $bindable(), target: passedTarget }: Props = $props() + let { item = $bindable(), ...rest }: Props = $props() - let acting = $state(false) + let locking = $state(false) + let pinning = $state(false) + + let acting = $derived(locking || pinning) async function lock(lock: boolean) { if (!profile.current?.jwt || !isPostView(item)) return - acting = true + locking = true try { await getClient().lockPost({ @@ -47,13 +49,13 @@ }) } - acting = false + locking = false } async function pin(pinned: boolean, toInstance: boolean = false) { if (!profile.current?.jwt || !isPostView(item)) return - acting = true + pinning = true try { await getClient().featurePost({ @@ -70,13 +72,21 @@ }) } - acting = false + pinning = false } {#snippet target()} - {@render passedTarget(acting)} + {/snippet} {#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))} @@ -89,7 +99,8 @@ lock(!item.post.locked)} - loading={acting} + loading={locking} + disabled={locking} > {#snippet prefix()} @@ -101,7 +112,8 @@ color="success-subtle" onclick={() => pin(isPostView(item) ? !item.post.featured_community : false)} - loading={acting} + loading={pinning} + disabled={pinning} >
+ import { goto } from '$app/navigation' import { profile } from '$lib/auth.svelte' - import { mediaType } from '$lib/components/lemmy/post/helpers.js' + 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' @@ -27,6 +28,15 @@ return rule } + function onClick(e: Event) { + const event = e as Event + const parent = document.getElementById(post.post.id.toString()) + + if (event.target == parent) { + goto(postLink(post.post)) + } + } + interface Props { post: PostView actions?: boolean @@ -76,6 +86,8 @@ This is the sole component for displaying posts. It adapts to all kinds of form factors for different contexts, such as feeds, full post view, and crosspost list. --> + +
{ + onClick(e) + }} + onkeydown={e => { + if (e.key == 'Enter') onClick(e) + }} + tabindex="0" {style} > {/if} {#if profile.current?.user && (amMod(profile.current.user, post.community) || isAdmin(profile.current.user))} - {#await import('$lib/components/lemmy/moderation/ModerationMenu.svelte') then { default: ModerationMenu }} - - {#snippet target(acting)} - - {/snippet} - - {/await} + {/if} {#if profile.current?.jwt} diff --git a/src/lib/components/lemmy/post/PostItem.svelte b/src/lib/components/lemmy/post/PostItem.svelte index 91613a6a..d8e5bc18 100644 --- a/src/lib/components/lemmy/post/PostItem.svelte +++ b/src/lib/components/lemmy/post/PostItem.svelte @@ -6,7 +6,7 @@ post: PostView } - let { post }: Props = $props() + let { post } = $props() diff --git a/src/lib/components/lemmy/post/PostMeta.svelte b/src/lib/components/lemmy/post/PostMeta.svelte index 11290170..5e83fde4 100644 --- a/src/lib/components/lemmy/post/PostMeta.svelte +++ b/src/lib/components/lemmy/post/PostMeta.svelte @@ -1,14 +1,4 @@ - -
0 && 'use-transition', - ]} - style="width: {progress}%;" - id="progress-bar" ->
- - diff --git a/src/lib/components/ui/layout/Shell.svelte b/src/lib/components/ui/layout/Shell.svelte index 9b588b9e..42fbd284 100644 --- a/src/lib/components/ui/layout/Shell.svelte +++ b/src/lib/components/ui/layout/Shell.svelte @@ -97,7 +97,7 @@ } } - @media (min-width: 80rem) { + @media (min-width: 1280px) { .content { grid-template-columns: 20% 60% 20%; justify-items: end center start; diff --git a/src/lib/components/ui/navbar/commands/actions.svelte.ts b/src/lib/components/ui/navbar/commands/actions.svelte.ts index 31b3243a..57f7321d 100644 --- a/src/lib/components/ui/navbar/commands/actions.svelte.ts +++ b/src/lib/components/ui/navbar/commands/actions.svelte.ts @@ -45,7 +45,6 @@ import { ViewColumns, type IconSource, } from 'svelte-hero-icons' -import { SvelteURL } from 'svelte/reactivity' export interface Group { name: string @@ -412,7 +411,7 @@ export function getGroups( f.community.name, f.community.actor_id, )}`, - detail: new SvelteURL(f.community.actor_id).hostname, + detail: new URL(f.community.actor_id).hostname, })) ?? [], }, ] diff --git a/src/lib/components/ui/sidebar/ProfileButton.svelte b/src/lib/components/ui/sidebar/ProfileButton.svelte index 15566bf8..f11c52d8 100644 --- a/src/lib/components/ui/sidebar/ProfileButton.svelte +++ b/src/lib/components/ui/sidebar/ProfileButton.svelte @@ -18,7 +18,9 @@ { @@ -45,10 +47,9 @@ /> {/snippet} {prof.username ?? prof.user?.local_user_view.person.name} {#if !guest && !LINKED_INSTANCE_URL} diff --git a/src/lib/components/ui/sidebar/Sidebar.svelte b/src/lib/components/ui/sidebar/Sidebar.svelte index 2188002b..6403e942 100644 --- a/src/lib/components/ui/sidebar/Sidebar.svelte +++ b/src/lib/components/ui/sidebar/Sidebar.svelte @@ -34,25 +34,29 @@ {#if profile.current?.jwt} {#snippet label()} - {$t('profile.profile')} + + {$t('profile.profile')} + {/snippet} {#snippet label()} - {$t('profile.inbox')} - {#if $notifications.inbox} - - {$notifications.inbox > 99 ? '∞' : $notifications.inbox} - - {/if} + + {$t('profile.inbox')} + {#if $notifications.inbox} + + {$notifications.inbox > 99 ? '∞' : $notifications.inbox} + + {/if} + {/snippet} {#snippet label()} - {$t('profile.saved')} + {$t('profile.saved')} {/snippet} {:else} @@ -62,7 +66,7 @@ icon={ArrowLeftOnRectangle} > {#snippet label()} - {$t('account.login')} + {$t('account.login')} {/snippet} {#snippet label()} - {$t('account.signup')} + {$t('account.signup')} {/snippet} {#snippet label()} - {$t('nav.menu.settings')} + {$t('nav.menu.settings')} {/snippet} {/if} @@ -105,7 +109,9 @@ {/snippet}
{#each [...profile.meta.profiles] as prof, index} - +
+ +
{/each}
diff --git a/src/lib/mono/badge/Badge.svelte b/src/lib/mono/badge/Badge.svelte index f69c5bdf..d66d2afe 100644 --- a/src/lib/mono/badge/Badge.svelte +++ b/src/lib/mono/badge/Badge.svelte @@ -1,5 +1,11 @@ + +
+
+		{value}
+	
+ {#if copy} + + {/if} +
diff --git a/src/lib/mono/forms/Radio.svelte b/src/lib/mono/forms/Radio.svelte new file mode 100644 index 00000000..c3248295 --- /dev/null +++ b/src/lib/mono/forms/Radio.svelte @@ -0,0 +1,58 @@ + + +
+ + +
diff --git a/src/lib/mono/forms/RadioGroup.svelte b/src/lib/mono/forms/RadioGroup.svelte new file mode 100644 index 00000000..6444b0f0 --- /dev/null +++ b/src/lib/mono/forms/RadioGroup.svelte @@ -0,0 +1,25 @@ + + +
+
+ {@render children?.({ group })} +
+
diff --git a/src/lib/mono/index.ts b/src/lib/mono/index.ts index 5bd35ec5..a2987180 100644 --- a/src/lib/mono/index.ts +++ b/src/lib/mono/index.ts @@ -3,6 +3,7 @@ export { default as Button } from './button/Button.svelte' export { buttonColor, buttonSize, buttonShadow } from './button/Button.svelte' export { default as Codeblock } from './code/Codeblock.svelte' +export { default as Snippet } from './code/Snippet.svelte' export { default as Spinner } from './loader/Spinner.svelte' export { default as Material } from './materials/Material.svelte' @@ -17,6 +18,9 @@ export { default as ImageInput } from './forms/ImageInput.svelte' export { default as Checkbox } from './forms/Checkbox.svelte' export { default as Switch } from './forms/Switch.svelte' +export { default as Radio } from './forms/Radio.svelte' +export { default as RadioGroup } from './forms/RadioGroup.svelte' + export { default as Popover } from './popover/Popover.svelte' export { default as Menu } from './popover/Menu.svelte' export { default as MenuDivider } from './popover/MenuDivider.svelte' diff --git a/src/lib/mono/popover/Popover.svelte b/src/lib/mono/popover/Popover.svelte index 6aecd57f..107ebf61 100644 --- a/src/lib/mono/popover/Popover.svelte +++ b/src/lib/mono/popover/Popover.svelte @@ -1,3 +1,16 @@ + + { if (open && e.key == 'Escape') { open = false + // @ts-expect-error svelte hell + el?.firstChild.focus() } }} /> diff --git a/src/lib/util.svelte.ts b/src/lib/util.svelte.ts index d49e6eb2..14077ac0 100644 --- a/src/lib/util.svelte.ts +++ b/src/lib/util.svelte.ts @@ -7,7 +7,6 @@ import { toast } from 'mono-svelte' import { t } from './i18n/translations' import { site } from './lemmy.svelte' import { errorMessage } from './lemmy/error' -import { SvelteURL } from 'svelte/reactivity' // Despite the name, this will round up // Example: findClosestNumber([8, 16, 32, 64, 128], 76) will return 128 @@ -30,7 +29,7 @@ export const searchParam = ( } export const fullCommunityName = (name: string, actorId: string) => - `${name}@${new SvelteURL(actorId).hostname}` + `${name}@${new URL(actorId).hostname}` export const placeholders = { url: ['https://example.com'], @@ -134,6 +133,30 @@ export async function uploadImage( if (res.url) return res.url else throw new Error(`Failed to upload image. ${res.msg}`) + } else { + const response = await fetch( + `${ + window.location.origin + }/cors/${instance}/pictrs/image?${new URLSearchParams({ + auth: jwt, + })}`, + { + method: 'POST', + body: formData, + }, + ) + + const json = await response.json() + + if (json.msg == 'ok') { + return `https://${instance}/pictrs/image/${json.files?.[0]?.file}` + } + throw new Error( + `${ + (await response.text().catch(() => undefined)) ?? + 'Failed to upload image' + }: ${response.status}: ${response.statusText}`, + ) } } @@ -144,7 +167,7 @@ export const instanceToURL = (input: string) => export function canParseUrl(url: string): boolean { try { - new SvelteURL(url) + new URL(url) return true } catch { return false @@ -152,7 +175,7 @@ export function canParseUrl(url: string): boolean { } export function instanceId(actorId: string) { - return new SvelteURL(actorId).hostname + return new URL(actorId).hostname } export function escapeHtml(input: string): string { diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 80895789..5fa8148d 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,6 +2,7 @@ import { browser } from '$app/environment' import { navigating, page } from '$app/state' import Moderation from '$lib/components/lemmy/moderation/Moderation.svelte' + import SiteCard from '$lib/components/lemmy/SiteCard.svelte' import ExpandableImage from '$lib/components/ui/ExpandableImage.svelte' import Shell from '$lib/components/ui/layout/Shell.svelte' import Navbar from '$lib/components/ui/navbar/Navbar.svelte' @@ -13,17 +14,25 @@ import { inDarkColorScheme, rgbToHex, theme } from '$lib/ui/colors.svelte.js' import { getDefaultColors } from '$lib/ui/presets' import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte' + import nProgress from 'nprogress' + import 'nprogress/nprogress.css' import { onMount } from 'svelte' import { Forward, Icon } from 'svelte-hero-icons' import '../style/app.css' - import NavigationProgress from '$lib/components/ui/layout/NavigationProgress.svelte' interface Props { children?: import('svelte').Snippet } let { children }: Props = $props() - let progressBar = $state<{ start: () => void; stop: () => void }>() + nProgress.configure({ + minimum: 0.4, + trickleSpeed: 200, + easing: 'ease-out', + speed: 300, + showSpinner: false, + }) + onMount(() => { if (browser) { if (window.location.hash == 'main') { @@ -63,12 +72,12 @@ document.documentElement.dir = ($locale == 'he' || $locale == 'ar') && settings.useRtl ? 'rtl' : 'ltr' }) - - $effect(() => { - if (navigating.to) progressBar?.start() - else progressBar?.stop() - }) } + + $effect(() => { + if (navigating.to) nProgress.start() + else nProgress.done() + }) @@ -96,7 +105,6 @@ - - @@ -133,14 +139,12 @@ {@const SvelteComponent = page.data.slots.sidebar.component} {:else if site.data} - {#await import('$lib/components/lemmy/SiteCard.svelte') then { default: SiteCard }} - - {/await} + {:else}
diff --git a/src/routes/inbox/+page.svelte b/src/routes/inbox/+page.svelte index f3cd08b6..c7c8d7d6 100644 --- a/src/routes/inbox/+page.svelte +++ b/src/routes/inbox/+page.svelte @@ -12,7 +12,6 @@ import { Button } from 'mono-svelte' import { ArrowPath, Check, Icon, Inbox } from 'svelte-hero-icons' import InboxItem from './InboxItem.svelte' - import { SvelteURLSearchParams } from 'svelte/reactivity' let { data } = $props() @@ -43,11 +42,11 @@ currentSearchParams: URLSearchParams, newParamString: string, ) { - // Create a new SvelteURLSearchParams object from the current search params - const updatedParams = new SvelteURLSearchParams(currentSearchParams) + // Create a new URLSearchParams object from the current search params + const updatedParams = new URLSearchParams(currentSearchParams) // Parse the new parameter string - const newParam = new SvelteURLSearchParams(newParamString) + const newParam = new URLSearchParams(newParamString) // Get the key and value of the new parameter const [key, value]: [string, string] = newParam.entries().next().value! diff --git a/src/routes/inbox/messages/+page.svelte b/src/routes/inbox/messages/+page.svelte index 4dab47b8..2deaecd2 100644 --- a/src/routes/inbox/messages/+page.svelte +++ b/src/routes/inbox/messages/+page.svelte @@ -16,7 +16,6 @@ import { Button, Modal } from 'mono-svelte' import { ChatBubbleOvalLeftEllipsis, Icon, Inbox } from 'svelte-hero-icons' import { expoOut } from 'svelte/easing' - import { SvelteSet } from 'svelte/reactivity' import { fly } from 'svelte/transition' interface ConversationPreview { @@ -35,7 +34,7 @@ } function filterDuplicates(array: T[], predicate: (item: T) => K): T[] { - const seen = new SvelteSet() + const seen = new Set() return array.filter(element => { const value = predicate(element) if (seen.has(value)) { diff --git a/src/routes/you_died/+page.svelte b/src/routes/you_died/+page.svelte new file mode 100644 index 00000000..07f309a6 --- /dev/null +++ b/src/routes/you_died/+page.svelte @@ -0,0 +1,48 @@ + + + + +
+
+

{profile.current.username ?? 'You'} was slain by Command Palette

+
+ Minecraft 'you died' +
+
+ + diff --git a/static/other/mc.mp3 b/static/other/mc.mp3 new file mode 100644 index 00000000..402a18b6 Binary files /dev/null and b/static/other/mc.mp3 differ diff --git a/static/other/mc.png b/static/other/mc.png new file mode 100644 index 00000000..73383cdf Binary files /dev/null and b/static/other/mc.png differ