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