feat: add preview option
This commit is contained in:
1 parent
aac2b5fde0
commit
fe8db93eba
4 files changed
+123
-98
No files matched your search
@@ -32,6 +32,7 @@
|
||||
disabled:opacity-60 disabled:pointer-events-none whitespace-nowrap"
|
||||
on:click={() => (selected = option)}
|
||||
disabled={disabled[index] ?? false}
|
||||
type="button"
|
||||
>
|
||||
{optionNames[index] || option}
|
||||
</button>
|
||||
|
||||
@@ -192,6 +192,7 @@
|
||||
label="Body"
|
||||
bind:value={data.body}
|
||||
placeholder={placeholder2}
|
||||
previewButton
|
||||
/>
|
||||
<div>
|
||||
<span class="block my-1 font-bold text-sm">Image</span>
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import FileInput from '$lib/components/input/FileInput.svelte'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||
import { toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { uploadImage } from '$lib/lemmy.js'
|
||||
@@ -18,6 +20,7 @@
|
||||
export let images: boolean = true
|
||||
export let value: string = ''
|
||||
export let label: string | undefined = undefined
|
||||
export let previewButton: boolean = false
|
||||
|
||||
let textArea: HTMLTextAreaElement
|
||||
|
||||
@@ -77,6 +80,8 @@
|
||||
|
||||
loading = false
|
||||
}
|
||||
|
||||
let previewing = false
|
||||
</script>
|
||||
|
||||
{#if uploadingImage && images}
|
||||
@@ -99,107 +104,125 @@
|
||||
class="flex flex-col border border-slate-200 dark:border-zinc-800 rounded-md
|
||||
overflow-hidden"
|
||||
>
|
||||
<!--Toolbar-->
|
||||
<div class="[&>*]:flex-shrink-0 flex flex-row overflow-auto p-1.5 gap-1.5">
|
||||
<Button
|
||||
on:click={() => wrapSelection('**', '**')}
|
||||
title="Bold"
|
||||
size="square-md"
|
||||
{#if previewing}
|
||||
<div class="px-3 py-2.5 h-32 overflow-auto text-sm">
|
||||
<Markdown source={value} />
|
||||
</div>
|
||||
{:else}
|
||||
<!--Toolbar-->
|
||||
<div
|
||||
class="[&>*]:flex-shrink-0 flex flex-row overflow-auto p-1.5 gap-1.5"
|
||||
>
|
||||
<span class="font-bold">B</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('*', '*')}
|
||||
title="Italic"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="italic font-bold">I</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('[label](url)', '')}
|
||||
title="Link"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Link} mini size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('\n# ', '')}
|
||||
title="Header"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="italic font-bold font-serif">H</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('~~', '~~')}
|
||||
title="Strikethrough"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="line-through font-bold">S</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('\n> ', '')}
|
||||
title="Quote"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="font-bold font-serif">"</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('\n- ', '')}
|
||||
title="List"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={ListBullet} mini size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('`', '`')}
|
||||
title="Code"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={CodeBracket} mini size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('::: spoiler <spoiler title>\n', '\n:::')}
|
||||
title="Spoiler"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={ExclamationTriangle} mini size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('~', '~')}
|
||||
title="Subscript"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="font-bold">
|
||||
X
|
||||
<sub>1</sub>
|
||||
</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('^', '^')}
|
||||
title="Superscript"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="font-bold">
|
||||
X
|
||||
<sup>1</sup>
|
||||
</span>
|
||||
</Button>
|
||||
{#if images}
|
||||
<Button
|
||||
on:click={() => (uploadingImage = !uploadingImage)}
|
||||
title="Image"
|
||||
on:click={() => wrapSelection('**', '**')}
|
||||
title="Bold"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Photo} size="16" mini />
|
||||
<span class="font-bold">B</span>
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
<!--Actual text area-->
|
||||
<TextArea
|
||||
class="bg-inherit border-0 rounded-none"
|
||||
bind:value
|
||||
bind:item={textArea}
|
||||
{...$$restProps}
|
||||
/>
|
||||
<Button
|
||||
on:click={() => wrapSelection('*', '*')}
|
||||
title="Italic"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="italic font-bold">I</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('[label](url)', '')}
|
||||
title="Link"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Link} mini size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('\n# ', '')}
|
||||
title="Header"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="italic font-bold font-serif">H</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('~~', '~~')}
|
||||
title="Strikethrough"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="line-through font-bold">S</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('\n> ', '')}
|
||||
title="Quote"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="font-bold font-serif">"</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('\n- ', '')}
|
||||
title="List"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={ListBullet} mini size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('`', '`')}
|
||||
title="Code"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={CodeBracket} mini size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() =>
|
||||
wrapSelection('::: spoiler <spoiler title>\n', '\n:::')}
|
||||
title="Spoiler"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={ExclamationTriangle} mini size="16" />
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('~', '~')}
|
||||
title="Subscript"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="font-bold">
|
||||
X
|
||||
<sub>1</sub>
|
||||
</span>
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => wrapSelection('^', '^')}
|
||||
title="Superscript"
|
||||
size="square-md"
|
||||
>
|
||||
<span class="font-bold">
|
||||
X
|
||||
<sup>1</sup>
|
||||
</span>
|
||||
</Button>
|
||||
{#if images}
|
||||
<Button
|
||||
on:click={() => (uploadingImage = !uploadingImage)}
|
||||
title="Image"
|
||||
size="square-md"
|
||||
>
|
||||
<Icon src={Photo} size="16" mini />
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
<!--Actual text area-->
|
||||
<TextArea
|
||||
class="bg-inherit border-0 rounded-none"
|
||||
bind:value
|
||||
bind:item={textArea}
|
||||
{...$$restProps}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
{#if previewButton}
|
||||
<div class="mt-2">
|
||||
<MultiSelect
|
||||
bind:selected={previewing}
|
||||
options={[false, true]}
|
||||
optionNames={['Edit', 'Preview']}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
Reference in new issue
Block a user