mirror of
https://github.com/Blah-IM/Weblah.git
synced 2025-07-06 22:15:34 +00:00
feat: basic rich text input & format
This commit is contained in:
parent
e386fe2583
commit
ca380e9ce6
8 changed files with 219 additions and 24 deletions
19
src/lib/components/RichTextInput.svelte
Normal file
19
src/lib/components/RichTextInput.svelte
Normal file
|
@ -0,0 +1,19 @@
|
|||
<script lang="ts">
|
||||
import { browser } from '$app/environment';
|
||||
import type { Delta } from 'typewriter-editor';
|
||||
|
||||
export let delta: Delta;
|
||||
|
||||
let className = '';
|
||||
export { className as class };
|
||||
|
||||
const loadClientComponent = async () => {
|
||||
if (!browser) return;
|
||||
const { default: ClientInput } = await import('./RichTextInput/ClientInput.svelte');
|
||||
return ClientInput;
|
||||
};
|
||||
</script>
|
||||
|
||||
{#await loadClientComponent() then Input}
|
||||
<svelte:component this={Input} bind:delta class={className}><slot /></svelte:component>
|
||||
{/await}
|
24
src/lib/components/RichTextInput/ClientInput.svelte
Normal file
24
src/lib/components/RichTextInput/ClientInput.svelte
Normal file
|
@ -0,0 +1,24 @@
|
|||
<script lang="ts">
|
||||
import InputFrame from '$lib/components/InputFrame.svelte';
|
||||
import { tw } from '$lib/tw';
|
||||
import { Delta, Editor, asRoot } from 'typewriter-editor';
|
||||
|
||||
let className = '';
|
||||
export { className as class };
|
||||
|
||||
export let delta: Delta;
|
||||
|
||||
const editor = new Editor();
|
||||
delta = editor.getDelta();
|
||||
editor.on('change', () => {
|
||||
delta = editor.getDelta();
|
||||
});
|
||||
|
||||
$: editor.setDelta(delta);
|
||||
</script>
|
||||
|
||||
<InputFrame class={tw('overflow-y-auto', className)}>
|
||||
<div class="rich-text w-full outline-none" use:asRoot={editor}>
|
||||
<slot />
|
||||
</div>
|
||||
</InputFrame>
|
Loading…
Add table
Add a link
Reference in a new issue