migrate: switch to svelte 5 events system for inputs
This commit is contained in:
1 parent
6f442eceab
commit
43a857ed66
11 files changed
+99
-98
No files matched your search
@@ -112,7 +112,7 @@
|
||||
value={newComment}
|
||||
actions={false}
|
||||
preview={true}
|
||||
on:confirm={save}
|
||||
onconfirm={save}
|
||||
/>
|
||||
<Button
|
||||
submit
|
||||
@@ -252,18 +252,18 @@
|
||||
label={$t('comment.reply')}
|
||||
{postId}
|
||||
parentId={node.comment_view.comment.id}
|
||||
on:comment={(e) => {
|
||||
oncomment={(e) => {
|
||||
node.children = [
|
||||
{
|
||||
children: [],
|
||||
comment_view: e.detail.comment_view,
|
||||
comment_view: e.comment_view,
|
||||
depth: node.depth + 1,
|
||||
},
|
||||
...node.children,
|
||||
]
|
||||
replying = false
|
||||
}}
|
||||
on:cancel={() => (replying = false)}
|
||||
oncancel={() => (replying = false)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,12 +12,6 @@
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Icon, XMark } from 'svelte-hero-icons'
|
||||
|
||||
const dispatch = createEventDispatcher<{
|
||||
comment: CommentResponse
|
||||
confirm: string
|
||||
cancel: boolean
|
||||
}>()
|
||||
|
||||
interface Props {
|
||||
postId: number
|
||||
parentId?: number | undefined
|
||||
@@ -28,6 +22,9 @@
|
||||
value?: string
|
||||
actions?: boolean
|
||||
preview?: boolean
|
||||
oncomment?: (comment: CommentResponse) => void
|
||||
onconfirm?: (value: string) => void
|
||||
oncancel?: (cancel: boolean) => void
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
@@ -41,6 +38,9 @@
|
||||
value = $bindable(''),
|
||||
actions = true,
|
||||
preview: previewAction = true,
|
||||
oncancel,
|
||||
oncomment,
|
||||
onconfirm,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
post_id: postId,
|
||||
parent_id: parentId,
|
||||
})
|
||||
dispatch('comment', response)
|
||||
oncomment?.(response)
|
||||
|
||||
value = ''
|
||||
} catch (err) {
|
||||
@@ -92,13 +92,12 @@
|
||||
: (placeholder ?? placeholders.get('comment'))}
|
||||
bind:value
|
||||
disabled={locked || loading || banned}
|
||||
on:confirm={() => {
|
||||
onconfirm={() => {
|
||||
if (actions) {
|
||||
submit()
|
||||
dispatch('confirm', value)
|
||||
onconfirm?.(value)
|
||||
}
|
||||
}}
|
||||
on:focus
|
||||
previewButton={previewAction}
|
||||
>
|
||||
<div class="flex-1"></div>
|
||||
@@ -106,19 +105,26 @@
|
||||
<Button
|
||||
size="custom"
|
||||
title={$t('common.cancel')}
|
||||
onclick={() => dispatch('cancel', true)}
|
||||
onclick={() => oncancel?.(true)}
|
||||
color="tertiary"
|
||||
class="w-8 h-8"
|
||||
rounding="xl"
|
||||
rounding="pill"
|
||||
>
|
||||
<Icon src={XMark} size="16" micro />
|
||||
<Icon
|
||||
src={XMark}
|
||||
size="20"
|
||||
micro
|
||||
class="text-slate-600 dark:text-zinc-400"
|
||||
/>
|
||||
</Button>
|
||||
<Button
|
||||
onclick={submit}
|
||||
color="primary"
|
||||
rounding="pill"
|
||||
size="sm"
|
||||
class="py-2 px-4"
|
||||
{loading}
|
||||
disabled={locked || loading || banned}
|
||||
size="lg"
|
||||
>
|
||||
{$t('form.submit')}
|
||||
</Button>
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
required
|
||||
label={$t('form.name')}
|
||||
bind:value={formData.name}
|
||||
on:input={() => {
|
||||
oninput={() => {
|
||||
formData.name = formData.name.toLowerCase().replaceAll(' ', '_')
|
||||
}}
|
||||
disabled={edit != undefined}
|
||||
|
||||
@@ -32,9 +32,7 @@
|
||||
</script>
|
||||
|
||||
<ul
|
||||
class="flex flex-col list-none {settings.view == 'card'
|
||||
? 'gap-3 md:gap-4'
|
||||
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
|
||||
class="flex flex-col list-none divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
>
|
||||
{#if posts?.length == 0}
|
||||
<div class="h-full grid place-items-center">
|
||||
@@ -63,7 +61,7 @@
|
||||
: settings.view}
|
||||
{post}
|
||||
class="transition-all duration-250"
|
||||
on:hide={() => {
|
||||
onhide={() => {
|
||||
posts = posts.toSpliced(index, 1)
|
||||
}}
|
||||
>
|
||||
@@ -100,10 +98,7 @@
|
||||
easing: expoOut,
|
||||
}}
|
||||
>
|
||||
<span
|
||||
class="text-sm flex flex-row gap-2 items-center"
|
||||
class:my-4={settings.view == 'card'}
|
||||
>
|
||||
<span class="text-sm flex flex-row gap-2 items-center">
|
||||
Crossposts <hr class="w-full dark:border-zinc-800" />
|
||||
{post.crossposts.length}
|
||||
</span>
|
||||
|
||||
@@ -198,9 +198,7 @@
|
||||
<!-- <svelte:window on:keydown={handleKeydown} /> -->
|
||||
|
||||
<ul
|
||||
class="flex flex-col list-none {settings.view == 'card'
|
||||
? 'gap-3 md:gap-4'
|
||||
: 'divide-y'} divide-slate-200 dark:divide-zinc-800"
|
||||
class="flex flex-col list-none divide-y divide-slate-200 dark:divide-zinc-800"
|
||||
>
|
||||
{#if posts?.length == 0}
|
||||
<div class="h-full grid place-items-center">
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
Strikethrough,
|
||||
} from 'svelte-hero-icons'
|
||||
import ImageUploadModal from '../lemmy/modal/ImageUploadModal.svelte'
|
||||
|
||||
const dispatcher = createEventDispatcher<{ confirm: string }>()
|
||||
import type { HTMLTextareaAttributes } from 'svelte/elements'
|
||||
import type { TextAreaProps } from 'mono-svelte/forms/TextArea.svelte'
|
||||
|
||||
let textArea: HTMLTextAreaElement | undefined = $state()
|
||||
|
||||
@@ -69,9 +69,9 @@
|
||||
KeyH: () => wrapSelection('\n# ', ''),
|
||||
KeyK: () => wrapSelection('[](', ')'),
|
||||
Enter: (e: any) => {
|
||||
dispatcher('confirm', value)
|
||||
onconfirm?.(value)
|
||||
const newEvent = new Event('submit', { cancelable: true })
|
||||
e.target.form.dispatchEvent(newEvent)
|
||||
e?.target?.form?.dispatchEvent(newEvent)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
interface Props {
|
||||
interface Props extends TextAreaProps {
|
||||
images?: boolean
|
||||
value?: string
|
||||
label?: string | undefined
|
||||
@@ -96,7 +96,7 @@
|
||||
class?: string
|
||||
customLabel?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
onconfirm?: (value: string) => void
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -112,10 +112,11 @@
|
||||
class: clazz = '',
|
||||
customLabel,
|
||||
children,
|
||||
onconfirm,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
run(() => {
|
||||
$effect(() => {
|
||||
if (!previewing && value) adjustHeight()
|
||||
})
|
||||
</script>
|
||||
@@ -264,7 +265,7 @@ 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}
|
||||
on:keydown={(e) => {
|
||||
onkeydown={(e) => {
|
||||
if (disabled) return
|
||||
if (e.ctrlKey || e.metaKey) {
|
||||
// @ts-ignore
|
||||
@@ -275,9 +276,8 @@ overflow-hidden transition-colors {clazz}"
|
||||
}
|
||||
}
|
||||
}}
|
||||
on:input={adjustHeight}
|
||||
on:focus
|
||||
on:paste={(e) => {
|
||||
oninput={adjustHeight}
|
||||
onpaste={(e) => {
|
||||
if (!e.clipboardData?.files) return
|
||||
const files = Array.from(e.clipboardData.files)
|
||||
if (files[0]?.type.startsWith('image/')) {
|
||||
|
||||
Reference in new issue
Block a user