feat: sending messages

This commit is contained in:
Shibo Lyu 2024-09-03 03:45:25 +08:00
parent 09b7d24b95
commit 72b962fb77
8 changed files with 106 additions and 32 deletions

View file

@ -5,6 +5,7 @@
import { tw } from '$lib/tw';
export let delta: Delta | null = null;
export let plainText: string | undefined = undefined;
export let placeholder: string = '';
let className = '';
@ -23,7 +24,7 @@
<p>{placeholder}</p>
</div>
{:then Input}
<svelte:component this={Input} bind:delta {placeholder}>
<svelte:component this={Input} bind:delta bind:plainText {placeholder} on:keydown>
<slot />
</svelte:component>
{/await}

View file

@ -2,6 +2,7 @@
import { Delta, Editor, asRoot, h } from 'typewriter-editor';
export let delta: Delta = new Delta();
export let plainText: string | undefined = undefined;
export let placeholder: string = '';
const editor = new Editor();
@ -23,12 +24,13 @@
render: (attributes, children) => h('s', null, children)
});
delta = editor.getDelta();
editor.on('change', () => {
delta = editor.getDelta();
if (typeof plainText === 'string') plainText = editor.getText();
});
$: editor.setDelta(delta);
$: editor.setDelta(delta ?? new Delta());
$: if (typeof plainText === 'string' && plainText !== editor.getText()) editor.setText(plainText);
</script>
<div
@ -38,6 +40,9 @@
? 'true'
: undefined}
data-weblah-placeholder={placeholder}
on:keydown
role="textbox"
tabindex="0"
>
<slot />
</div>