2024-10-12 23:14:12 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { getContext } from 'svelte';
|
|
|
|
|
import CodeBlock from './CodeBlock.svelte';
|
|
|
|
|
import Modal from '$lib/components/common/Modal.svelte';
|
2024-10-14 06:49:32 +00:00
|
|
|
import Spinner from '$lib/components/common/Spinner.svelte';
|
|
|
|
|
import Badge from '$lib/components/common/Badge.svelte';
|
2025-06-25 22:44:45 +00:00
|
|
|
import XMark from '$lib/components/icons/XMark.svelte';
|
2024-10-12 23:14:12 +00:00
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
|
|
|
|
export let show = false;
|
2024-10-14 06:16:51 +00:00
|
|
|
export let codeExecution = null;
|
2024-10-12 23:14:12 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Modal size="lg" bind:show>
|
|
|
|
|
<div>
|
|
|
|
|
<div class="flex justify-between dark:text-gray-300 px-5 pt-4 pb-2">
|
2024-10-14 06:49:32 +00:00
|
|
|
<div class="text-lg font-medium self-center flex flex-col gap-0.5 capitalize">
|
|
|
|
|
{#if codeExecution?.result}
|
|
|
|
|
<div>
|
|
|
|
|
{#if codeExecution.result?.error}
|
|
|
|
|
<Badge type="error" content="error" />
|
|
|
|
|
{:else if codeExecution.result?.output}
|
|
|
|
|
<Badge type="success" content="success" />
|
|
|
|
|
{:else}
|
|
|
|
|
<Badge type="warning" content="incomplete" />
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2024-10-12 23:14:12 +00:00
|
|
|
{/if}
|
2024-10-14 06:16:51 +00:00
|
|
|
|
2024-10-14 06:49:32 +00:00
|
|
|
<div class="flex gap-2 items-center">
|
|
|
|
|
{#if !codeExecution?.result}
|
|
|
|
|
<div>
|
|
|
|
|
<Spinner className="size-4" />
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
{#if codeExecution?.name}
|
|
|
|
|
{$i18n.t('Code execution')}: {codeExecution?.name}
|
|
|
|
|
{:else}
|
|
|
|
|
{$i18n.t('Code execution')}
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-10-12 23:14:12 +00:00
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
class="self-center"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
show = false;
|
2024-10-14 06:16:51 +00:00
|
|
|
codeExecution = null;
|
2024-10-12 23:14:12 +00:00
|
|
|
}}
|
|
|
|
|
>
|
2025-06-25 22:44:45 +00:00
|
|
|
<XMark />
|
2024-10-12 23:14:12 +00:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-10-14 06:49:32 +00:00
|
|
|
<div class="flex flex-col md:flex-row w-full px-4 pb-5">
|
2024-10-12 23:14:12 +00:00
|
|
|
<div
|
|
|
|
|
class="flex flex-col w-full dark:text-gray-200 overflow-y-scroll max-h-[22rem] scrollbar-hidden"
|
|
|
|
|
>
|
|
|
|
|
<div class="flex flex-col w-full">
|
|
|
|
|
<CodeBlock
|
2024-10-14 06:49:32 +00:00
|
|
|
id="code-exec-{codeExecution?.id}-code"
|
|
|
|
|
lang={codeExecution?.language ?? ''}
|
|
|
|
|
code={codeExecution?.code ?? ''}
|
|
|
|
|
className=""
|
|
|
|
|
editorClassName={codeExecution?.result &&
|
|
|
|
|
(codeExecution?.result?.error || codeExecution?.result?.output)
|
|
|
|
|
? 'rounded-b-none'
|
|
|
|
|
: ''}
|
|
|
|
|
stickyButtonsClassName="top-0"
|
|
|
|
|
run={false}
|
2024-10-12 23:14:12 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-10-14 06:49:32 +00:00
|
|
|
{#if codeExecution?.result && (codeExecution?.result?.error || codeExecution?.result?.output)}
|
|
|
|
|
<div class="dark:bg-[#202123] dark:text-white px-4 py-4 rounded-b-lg flex flex-col gap-3">
|
|
|
|
|
{#if codeExecution?.result?.error}
|
|
|
|
|
<div>
|
|
|
|
|
<div class=" text-gray-500 text-xs mb-1">{$i18n.t('ERROR')}</div>
|
|
|
|
|
<div class="text-sm">{codeExecution?.result?.error}</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if codeExecution?.result?.output}
|
|
|
|
|
<div>
|
|
|
|
|
<div class=" text-gray-500 text-xs mb-1">{$i18n.t('OUTPUT')}</div>
|
|
|
|
|
<div class="text-sm">{codeExecution?.result?.output}</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2024-10-12 23:14:12 +00:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
2024-10-14 06:49:32 +00:00
|
|
|
{#if codeExecution?.result?.files && codeExecution?.result?.files.length > 0}
|
2024-10-12 23:14:12 +00:00
|
|
|
<div class="flex flex-col w-full">
|
2025-02-16 03:27:25 +00:00
|
|
|
<hr class="border-gray-100 dark:border-gray-850 my-2" />
|
2024-10-12 23:14:12 +00:00
|
|
|
<div class=" text-sm font-medium dark:text-gray-300">
|
|
|
|
|
{$i18n.t('Files')}
|
|
|
|
|
</div>
|
|
|
|
|
<ul class="mt-1 list-disc pl-4 text-xs">
|
2024-10-14 06:49:32 +00:00
|
|
|
{#each codeExecution?.result?.files as file}
|
2024-10-12 23:14:12 +00:00
|
|
|
<li>
|
|
|
|
|
<a href={file.url} target="_blank">{file.name}</a>
|
|
|
|
|
</li>
|
|
|
|
|
{/each}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Modal>
|