2024-06-10 23:35:42 +00:00
|
|
|
<script>
|
|
|
|
import { getContext } from 'svelte';
|
|
|
|
|
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
|
|
import CodeEditor from './Tools/CodeEditor.svelte';
|
|
|
|
|
|
|
|
let loading = false;
|
|
|
|
|
2024-06-11 00:52:12 +00:00
|
|
|
let name = '';
|
2024-06-11 02:19:53 +00:00
|
|
|
let id = '';
|
|
|
|
|
|
|
|
$: if (name) {
|
|
|
|
id = name.replace(/\s+/g, '_').toLowerCase();
|
|
|
|
}
|
2024-06-11 00:52:12 +00:00
|
|
|
|
2024-06-11 00:30:07 +00:00
|
|
|
let codeEditor;
|
|
|
|
|
2024-06-11 02:19:53 +00:00
|
|
|
const saveHandler = async () => {
|
2024-06-10 23:35:42 +00:00
|
|
|
loading = true;
|
2024-06-11 02:19:53 +00:00
|
|
|
// Call the API to save the toolkit
|
2024-06-11 00:30:07 +00:00
|
|
|
|
2024-06-11 02:19:53 +00:00
|
|
|
console.log('saveHandler');
|
|
|
|
};
|
|
|
|
|
|
|
|
const submitHandler = async () => {
|
2024-06-11 00:30:07 +00:00
|
|
|
if (codeEditor) {
|
2024-06-11 02:19:53 +00:00
|
|
|
const res = await codeEditor.formatHandler();
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
console.log('Code formatted successfully');
|
|
|
|
saveHandler();
|
|
|
|
}
|
2024-06-11 00:30:07 +00:00
|
|
|
}
|
2024-06-10 23:35:42 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class=" flex flex-col justify-between w-full overflow-y-auto h-full">
|
|
|
|
<div class="mx-auto w-full md:px-0 h-full">
|
|
|
|
<div class=" flex flex-col max-h-[100dvh] h-full">
|
2024-06-11 00:52:12 +00:00
|
|
|
<div class="">
|
|
|
|
<div class="flex justify-between items-center">
|
|
|
|
<div class=" text-lg font-semibold self-center">{$i18n.t('Tools')}</div>
|
|
|
|
</div>
|
2024-06-10 23:35:42 +00:00
|
|
|
</div>
|
2024-06-11 00:52:12 +00:00
|
|
|
|
|
|
|
<hr class=" dark:border-gray-850 my-2" />
|
|
|
|
|
|
|
|
<div class="flex flex-col flex-1 overflow-auto h-0 rounded-lg">
|
2024-06-11 02:19:53 +00:00
|
|
|
<div class="w-full flex gap-2 mb-2">
|
2024-06-11 00:52:12 +00:00
|
|
|
<!-- Toolkit Name Input -->
|
|
|
|
<input
|
2024-06-11 02:19:53 +00:00
|
|
|
class="w-full px-3 py-2 text-sm font-medium bg-gray-50 dark:bg-gray-850 dark:text-gray-200 rounded-lg outline-none"
|
2024-06-11 00:52:12 +00:00
|
|
|
type="text"
|
2024-06-11 02:19:53 +00:00
|
|
|
placeholder="Toolkit Name (e.g. My ToolKit)"
|
2024-06-11 00:52:12 +00:00
|
|
|
bind:value={name}
|
2024-06-11 02:19:53 +00:00
|
|
|
required
|
|
|
|
/>
|
|
|
|
|
|
|
|
<input
|
|
|
|
class="w-full px-3 py-2 text-sm font-medium bg-gray-50 dark:bg-gray-850 dark:text-gray-200 rounded-lg outline-none"
|
|
|
|
type="text"
|
|
|
|
placeholder="Toolkit ID (e.g. my_toolkit)"
|
|
|
|
bind:value={id}
|
|
|
|
required
|
2024-06-11 00:52:12 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mb-2 flex-1 overflow-auto h-0 rounded-lg">
|
2024-06-11 02:19:53 +00:00
|
|
|
<CodeEditor bind:this={codeEditor} {saveHandler} />
|
2024-06-11 00:52:12 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="pb-3 flex justify-end">
|
|
|
|
<button
|
|
|
|
class="px-3 py-1.5 text-sm font-medium bg-emerald-600 hover:bg-emerald-700 text-gray-50 transition rounded-lg"
|
|
|
|
on:click={() => {
|
|
|
|
submitHandler();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{$i18n.t('Save')}
|
|
|
|
</button>
|
|
|
|
</div>
|
2024-06-10 23:35:42 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|