migrate: switch to svelte 5 events system for everything
This commit is contained in:
1 parent
43a857ed66
commit
53cb0e4f20
27 files changed
+248
-303
No files matched your search
@@ -1,8 +1,9 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { Community, ListingType } from 'lemmy-js-client'
|
||||
import type { Community, CommunityView, 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 { fly } from 'svelte/transition'
|
||||
@@ -13,6 +14,7 @@
|
||||
instance?: string | undefined
|
||||
listing_type?: ListingType
|
||||
showWhenEmpty?: boolean
|
||||
onselect?: (item: any) => void
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
@@ -45,9 +47,7 @@
|
||||
return results.communities.map((c) => c.community)
|
||||
}}
|
||||
extractName={(c) => `${c.title}@${new URL(c.actor_id).hostname}`}
|
||||
on:select
|
||||
bind:query={q}
|
||||
{showWhenEmpty}
|
||||
{...rest}
|
||||
>
|
||||
{#snippet noresults()}
|
||||
@@ -90,9 +90,7 @@
|
||||
: []
|
||||
}}
|
||||
extractName={(i) => `${i.domain}`}
|
||||
on:select
|
||||
bind:query={q}
|
||||
{showWhenEmpty}
|
||||
{...rest}
|
||||
>
|
||||
{#snippet noresults()}
|
||||
|
||||
@@ -175,9 +175,9 @@
|
||||
<ImageUploadModal
|
||||
bind:open={uploading.icon}
|
||||
multiple={false}
|
||||
on:upload={(uploaded) => {
|
||||
onupload={(uploaded) => {
|
||||
uploading.icon = false
|
||||
formData.icon = uploaded.detail[0]
|
||||
formData.icon = uploaded[0]
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
@@ -203,9 +203,9 @@
|
||||
<ImageUploadModal
|
||||
bind:open={uploading.banner}
|
||||
multiple={false}
|
||||
on:upload={(uploaded) => {
|
||||
onupload={(uploaded) => {
|
||||
uploading.banner = false
|
||||
formData.banner = uploaded.detail[0]
|
||||
formData.banner = uploaded[0]
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import ProgressBar from '$lib/components/ui/ProgressBar.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
@@ -8,7 +6,6 @@
|
||||
import { uploadImage } from '$lib/util.svelte.js'
|
||||
import { ImageInput, Spinner, toast } from 'mono-svelte'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { slide } from 'svelte/transition'
|
||||
@@ -18,6 +15,7 @@
|
||||
image?: FileList | null
|
||||
preview?: boolean
|
||||
multiple?: boolean
|
||||
onupload?: (urls: string[]) => void
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -25,6 +23,7 @@
|
||||
image = $bindable(null),
|
||||
preview = true,
|
||||
multiple = true,
|
||||
onupload,
|
||||
}: Props = $props()
|
||||
let progress = $state(1)
|
||||
|
||||
@@ -32,8 +31,6 @@
|
||||
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined,
|
||||
)
|
||||
|
||||
const dispatcher = createEventDispatcher<{ upload: string[] }>()
|
||||
|
||||
async function upload() {
|
||||
if (!$profile?.jwt || image == null) return
|
||||
|
||||
@@ -58,7 +55,7 @@
|
||||
|
||||
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||
|
||||
dispatcher('upload', uploaded)
|
||||
onupload?.(uploaded)
|
||||
progress = 1
|
||||
open = false
|
||||
} catch (err) {
|
||||
@@ -81,7 +78,13 @@
|
||||
<ProgressBar {progress} />
|
||||
</div>
|
||||
{/if}
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(upload)}>
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
upload()
|
||||
}}
|
||||
>
|
||||
<label
|
||||
for="image-input"
|
||||
class="p-4 border-2 border-dashed rounded-xl cursor-pointer transition-colors
|
||||
|
||||
@@ -176,11 +176,6 @@
|
||||
}
|
||||
})
|
||||
|
||||
// onMount(async () => {
|
||||
// await tick()
|
||||
// $virtualizer.measure()
|
||||
// })
|
||||
|
||||
let items = $derived($virtualizer.getVirtualItems())
|
||||
$effect(() => {
|
||||
if (virtualItemEls.length)
|
||||
@@ -195,8 +190,6 @@
|
||||
})
|
||||
</script>
|
||||
|
||||
<!-- <svelte:window on:keydown={handleKeydown} /> -->
|
||||
|
||||
<ul
|
||||
class="flex flex-col list-none divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
>
|
||||
|
||||
@@ -258,8 +258,8 @@
|
||||
<UploadModal
|
||||
bind:open={uploadingImage}
|
||||
multiple={false}
|
||||
on:upload={(e) => {
|
||||
if (e.detail) data.url = e.detail[0]
|
||||
onupload={(e) => {
|
||||
if (e) data.url = e[0]
|
||||
uploadingImage = false
|
||||
}}
|
||||
/>
|
||||
@@ -282,8 +282,8 @@
|
||||
listing_type="All"
|
||||
label={$t('form.post.community')}
|
||||
required
|
||||
on:select={(e) => {
|
||||
const c = e.detail
|
||||
onselect={(e) => {
|
||||
const c = e
|
||||
if (!c) {
|
||||
data.community = null
|
||||
return
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
instance?: string | undefined
|
||||
listing_type?: ListingType
|
||||
showWhenEmpty?: boolean
|
||||
onselect?: (e: any) => void
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
@@ -39,9 +40,7 @@
|
||||
return results.users.map((c) => c.person)
|
||||
}}
|
||||
extractName={(c) => `${c.name}@${new URL(c.actor_id).hostname}`}
|
||||
on:select
|
||||
bind:query={q}
|
||||
{showWhenEmpty}
|
||||
{...rest}
|
||||
>
|
||||
{#snippet noresults()}
|
||||
|
||||
@@ -125,8 +125,8 @@
|
||||
<ImageUploadModal
|
||||
bind:open={uploadingImage}
|
||||
bind:image
|
||||
on:upload={(e) => {
|
||||
e.detail.forEach((i) => {
|
||||
onupload={(e) => {
|
||||
e.forEach((i) => {
|
||||
wrapSelection(`\n\n`, '')
|
||||
})
|
||||
}}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
const dispatcher = createEventDispatcher<{ action: any }>()
|
||||
|
||||
function action(detail: any) {
|
||||
dispatcher('action', detail)
|
||||
}
|
||||
interface Props {
|
||||
class?: string
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
}
|
||||
|
||||
let { class: clazz = '', children }: Props = $props()
|
||||
</script>
|
||||
|
||||
<ul
|
||||
class="divide-y divide-slate-200 dark:divide-zinc-900 flex flex-col {clazz}"
|
||||
>
|
||||
{@render children?.({ action })}
|
||||
</ul>
|
||||
@@ -1,13 +0,0 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<div class="p-2 flex flex-row">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -12,20 +12,7 @@
|
||||
sm: 'shadow-sm',
|
||||
none: 'shadow-none',
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type {
|
||||
HTMLInputAttributes,
|
||||
HTMLInputTypeAttribute,
|
||||
} from 'svelte/elements'
|
||||
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
const borderClass = `
|
||||
border border-slate-200 border-b-slate-300 dark:border-zinc-900 dark:border-t-zinc-800
|
||||
`
|
||||
interface Props extends Omit<HTMLInputAttributes, 'size' | 'prefix'> {
|
||||
label?: string | undefined
|
||||
value?: string
|
||||
@@ -44,6 +31,22 @@
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
export type { Props as TextInputProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type {
|
||||
HTMLInputAttributes,
|
||||
HTMLInputTypeAttribute,
|
||||
} from 'svelte/elements'
|
||||
|
||||
import Label from '../forms/Label.svelte'
|
||||
import { generateID } from '../forms/helper.js'
|
||||
|
||||
const borderClass = `
|
||||
border border-slate-200 border-b-slate-300 dark:border-zinc-900 dark:border-t-zinc-800
|
||||
`
|
||||
|
||||
let {
|
||||
label = undefined,
|
||||
value = $bindable(''),
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
customTitle?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
actions?: import('svelte').Snippet<[any]>
|
||||
ondismissed?: () => void
|
||||
onaction?: () => void
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -25,11 +27,11 @@
|
||||
customTitle,
|
||||
children,
|
||||
actions,
|
||||
ondismissed,
|
||||
onaction,
|
||||
}: Props = $props()
|
||||
|
||||
let el: any = $state()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ action: any; dismissed: any }>()
|
||||
</script>
|
||||
|
||||
<Portal>
|
||||
@@ -46,7 +48,7 @@ bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
if (!el.contains(e.target)) {
|
||||
open = false
|
||||
|
||||
dispatcher('dismissed')
|
||||
ondismissed?.()
|
||||
}
|
||||
}}
|
||||
>
|
||||
@@ -94,9 +96,9 @@ bg-white/50 dark:bg-black/50 box-border p-4"
|
||||
<Button
|
||||
class="w-full"
|
||||
onclick={(e) => {
|
||||
dispatcher('action', e)
|
||||
onaction?.()
|
||||
open = false
|
||||
dispatcher('dismissed')
|
||||
ondismissed?.()
|
||||
}}
|
||||
color="primary"
|
||||
size="lg"
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<Modal
|
||||
title={$shownModal.title}
|
||||
dismissable={$shownModal.dismissable}
|
||||
on:dismissed={() => shownModal.set(undefined)}
|
||||
ondismissed={() => shownModal.set(undefined)}
|
||||
bind:open
|
||||
>
|
||||
<p>{$shownModal.body}</p>
|
||||
|
||||
@@ -1,24 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { Menu, TextInput, Spinner, MenuButton } from '../index.js'
|
||||
import { debounce } from '../util/time.js'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
|
||||
|
||||
type T = $$Generic
|
||||
let items: T[] = $state([])
|
||||
|
||||
/**
|
||||
* This is here so that the menu doesn't open as soon as it's mounted.
|
||||
*/
|
||||
let openMenu = $state(false)
|
||||
let searching = $state(false)
|
||||
|
||||
const dispatcher = createEventDispatcher<{
|
||||
input: Event
|
||||
select: T | undefined
|
||||
}>()
|
||||
|
||||
interface Props {
|
||||
<script lang="ts" module>
|
||||
interface Props<T> extends Omit<TextInputProps, 'onselect' | 'children'> {
|
||||
query?: string
|
||||
selected?: T | undefined
|
||||
search: (query: string) => Promise<T[]>
|
||||
@@ -27,9 +8,28 @@
|
||||
input?: import('svelte').Snippet
|
||||
noresults?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet<[any]>
|
||||
[key: string]: any
|
||||
onselect?: (value: T | undefined) => void
|
||||
oninput?: TextInputProps['oninput']
|
||||
}
|
||||
|
||||
export type { Props as SearchProps }
|
||||
</script>
|
||||
|
||||
<script lang="ts" generics="T">
|
||||
import type { TextInputProps } from 'mono-svelte/forms/TextInput.svelte'
|
||||
import { Menu, TextInput, Spinner, MenuButton } from '../index.js'
|
||||
import { debounce } from '../util/time.js'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
|
||||
|
||||
let items: T[] = $state([])
|
||||
|
||||
/**
|
||||
* This is here so that the menu doesn't open as soon as it's mounted.
|
||||
*/
|
||||
let openMenu = $state(false)
|
||||
let searching = $state(false)
|
||||
|
||||
let {
|
||||
query = $bindable(''),
|
||||
selected = $bindable(undefined),
|
||||
@@ -38,13 +38,15 @@
|
||||
select = (item: T) => {
|
||||
selected = item
|
||||
query = extractName(item)
|
||||
dispatcher('select', item)
|
||||
onselect?.(item)
|
||||
},
|
||||
input,
|
||||
noresults,
|
||||
children,
|
||||
onselect,
|
||||
oninput,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
}: Props<T> = $props()
|
||||
|
||||
const debounceFunc = debounce(async () => {
|
||||
searching = true
|
||||
@@ -63,13 +65,13 @@
|
||||
oninput={(e) => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
dispatcher('input', e)
|
||||
oninput?.(e)
|
||||
debounceFunc()
|
||||
}}
|
||||
onfocus={(e) => {
|
||||
searching = true
|
||||
openMenu = true
|
||||
dispatcher('input', e)
|
||||
oninput?.(e)
|
||||
debounceFunc()
|
||||
}}
|
||||
{...rest}
|
||||
@@ -96,7 +98,6 @@
|
||||
{#if children}{@render children({
|
||||
extractName,
|
||||
item,
|
||||
dispatcher,
|
||||
select,
|
||||
})}{:else}
|
||||
<MenuButton onclick={() => select(item)}>
|
||||
|
||||
Reference in new issue
Block a user