2023-09-24 07:08:37 +00:00
|
|
|
<script lang="ts">
|
2025-11-01 15:49:29 +01:00
|
|
|
// import { preventDefault } from '$lib/utils/functions/svelte';
|
|
|
|
|
// import { writable } from 'svelte/store';
|
|
|
|
|
// // import { useCompletion } from 'ai/svelte';
|
|
|
|
|
// import WandSparklesIcon from '@lucide/svelte/icons/wand-sparkles';
|
|
|
|
|
// import { IconButton } from '$lib/components/IconButton';
|
2026-03-09 11:18:22 +01:00
|
|
|
// import { HTMLRender } from '$features/ui';
|
2025-11-01 15:49:29 +01:00
|
|
|
// import { t } from '$lib/utils/functions/translations';
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// interface Props {
|
|
|
|
|
// className?: string;
|
|
|
|
|
// handleInsert?: any;
|
|
|
|
|
// defaultPrompt?: string;
|
|
|
|
|
// alignPopover?: PopoverProps['align'];
|
|
|
|
|
// isHTML?: boolean;
|
|
|
|
|
// }
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// let {
|
|
|
|
|
// className = '',
|
|
|
|
|
// handleInsert = (_v: string) => {},
|
|
|
|
|
// defaultPrompt = '',
|
|
|
|
|
// alignPopover = 'left',
|
|
|
|
|
// isHTML = false
|
|
|
|
|
// }: Props = $props();
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// let openPopover = $state(false);
|
|
|
|
|
// let plainText = $state('');
|
|
|
|
|
// let textRef: HTMLParagraphElement | undefined = $state();
|
|
|
|
|
// let prompt: string = $state(defaultPrompt);
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// let isSubmitted = $state(false);
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// let isLoading = writable(false);
|
|
|
|
|
// // const { input, handleSubmit, completion, isLoading } = useCompletion({
|
|
|
|
|
// // api: '/api/completion/customprompt'
|
|
|
|
|
// // });
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// function restart() {
|
|
|
|
|
// isSubmitted = false;
|
|
|
|
|
// plainText = '';
|
|
|
|
|
// }
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// function onCompletion(completion: string) {
|
|
|
|
|
// plainText = completion;
|
|
|
|
|
// if (textRef) {
|
|
|
|
|
// textRef.scrollTop = textRef.scrollHeight;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// // function callAI(prompt: string, rephrase: boolean) {
|
|
|
|
|
// // isSubmitted = true;
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// // $input = rephrase ? `${$t('ai.can_you')}: ${plainText}` : prompt;
|
2023-09-24 07:08:37 +00:00
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
// // setTimeout(() => {
|
|
|
|
|
// // handleSubmit({ preventDefault: () => {} });
|
|
|
|
|
// // }, 500);
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
|
|
// $effect(() => {
|
|
|
|
|
// onCompletion($completion);
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// $effect(() => {
|
|
|
|
|
// prompt = defaultPrompt;
|
|
|
|
|
// });
|
2023-09-24 07:08:37 +00:00
|
|
|
</script>
|
|
|
|
|
|
2025-11-01 15:49:29 +01:00
|
|
|
<div></div>
|
|
|
|
|
<!--
|
2023-09-24 07:08:37 +00:00
|
|
|
<div class="{className} relative z-[100]">
|
|
|
|
|
<IconButton
|
|
|
|
|
contained={true}
|
2025-12-22 02:36:48 +01:00
|
|
|
color="ui:text-primary dark:bg-neutral-500 dark:text-white"
|
2023-09-24 07:08:37 +00:00
|
|
|
size="large"
|
|
|
|
|
onClick={() => (openPopover = !openPopover)}
|
|
|
|
|
>
|
2025-11-01 15:49:29 +01:00
|
|
|
<MagicWandFilled />
|
2023-09-24 07:08:37 +00:00
|
|
|
<Popover caret align={alignPopover} bind:open={openPopover}>
|
2025-11-01 15:49:29 +01:00
|
|
|
<div class="h-[220px] w-[300px] p-2 text-start">
|
2023-09-24 07:08:37 +00:00
|
|
|
{#if isSubmitted}
|
|
|
|
|
<div class="h-[200px]">
|
|
|
|
|
<div
|
|
|
|
|
bind:this={textRef}
|
2025-11-01 15:49:29 +01:00
|
|
|
class="my-1 h-[82%] w-full overflow-y-auto bg-white p-2 text-start text-sm dark:bg-neutral-700"
|
2023-09-24 07:08:37 +00:00
|
|
|
>
|
|
|
|
|
{#if isHTML}
|
2026-03-09 11:18:22 +01:00
|
|
|
<HTMLRender>{plainText}</HTMLRender>
|
2023-09-24 07:08:37 +00:00
|
|
|
{:else}
|
|
|
|
|
<p class="font-normal">
|
|
|
|
|
{plainText}
|
|
|
|
|
</p>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2025-11-01 15:49:29 +01:00
|
|
|
<div class="ml-2 flex gap-5">
|
2023-09-24 07:08:37 +00:00
|
|
|
<button
|
2025-11-01 15:49:29 +01:00
|
|
|
class="cursor-pointer rounded-md border-[1px] px-4 py-2 text-xs font-medium"
|
|
|
|
|
onclick={() => {
|
2023-09-24 07:08:37 +00:00
|
|
|
handleInsert(plainText);
|
|
|
|
|
openPopover = false;
|
|
|
|
|
}}
|
|
|
|
|
type="button"
|
|
|
|
|
disabled={$isLoading}
|
|
|
|
|
>
|
|
|
|
|
{#if $isLoading}
|
|
|
|
|
<Loading withOverlay={false} small />
|
|
|
|
|
{:else}
|
2024-04-26 17:54:11 +01:00
|
|
|
{$t('ai.insert')}
|
2023-09-24 07:08:37 +00:00
|
|
|
{/if}
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
2025-11-01 15:49:29 +01:00
|
|
|
class="cursor-pointer rounded-md border-[1px] px-4 py-2 text-xs font-medium {$isLoading &&
|
|
|
|
|
'cursor-not-allowed opacity-25'}"
|
|
|
|
|
onclick={preventDefault(() => callAI(prompt, true))}
|
2023-09-24 07:08:37 +00:00
|
|
|
type="button"
|
|
|
|
|
disabled={$isLoading}
|
|
|
|
|
>
|
2024-04-26 17:54:11 +01:00
|
|
|
{$t('ai.rephrase')}
|
2023-09-24 07:08:37 +00:00
|
|
|
</button>
|
|
|
|
|
{#if !$isLoading}
|
|
|
|
|
<button
|
2025-11-01 15:49:29 +01:00
|
|
|
class="cursor-pointer rounded-md border-[1px] px-4 py-2 text-xs font-medium"
|
|
|
|
|
onclick={preventDefault(restart)}
|
2023-09-24 07:08:37 +00:00
|
|
|
type="button"
|
|
|
|
|
>
|
2024-04-26 17:54:11 +01:00
|
|
|
{$t('ai.reset')}
|
2023-09-24 07:08:37 +00:00
|
|
|
</button>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="h-full">
|
2025-11-01 15:49:29 +01:00
|
|
|
<p class="mb-2 ml-1 text-sm font-medium">{$t('ai.help_me')}</p>
|
2023-09-24 07:08:37 +00:00
|
|
|
<textarea
|
|
|
|
|
bind:value={prompt}
|
2025-11-01 15:49:29 +01:00
|
|
|
class="m-0 h-[65%] w-full rounded-lg border-0 text-sm dark:text-black"
|
2024-04-26 17:54:11 +01:00
|
|
|
placeholder={$t('ai.placeholder')}
|
2025-11-01 15:49:29 +01:00
|
|
|
></textarea>
|
2023-09-24 07:08:37 +00:00
|
|
|
<button
|
2025-11-01 15:49:29 +01:00
|
|
|
class="m-0 flex rounded-md border px-4 py-2 text-xs font-medium"
|
|
|
|
|
onclick={preventDefault(() => callAI(prompt, false))}
|
2023-09-24 07:08:37 +00:00
|
|
|
type="button"
|
|
|
|
|
>
|
2024-04-26 17:54:11 +01:00
|
|
|
{$t('ai.text')}
|
2023-09-24 07:08:37 +00:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2025-11-01 15:49:29 +01:00
|
|
|
</div>
|
2023-09-24 07:08:37 +00:00
|
|
|
</Popover>
|
|
|
|
|
</IconButton>
|
2025-11-01 15:49:29 +01:00
|
|
|
</div> -->
|