mirror of
				https://github.com/Blah-IM/Weblah.git
				synced 2025-11-03 19:31:38 +00:00 
			
		
		
		
	feat: sending messages
This commit is contained in:
		
							parent
							
								
									09b7d24b95
								
							
						
					
					
						commit
						72b962fb77
					
				
					 8 changed files with 106 additions and 32 deletions
				
			
		| 
						 | 
				
			
			@ -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}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue