ModelEditor.svelte 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. <script lang="ts">
  2. import { onMount, getContext, tick } from 'svelte';
  3. import { models, tools, functions, knowledge as knowledgeCollections, user } from '$lib/stores';
  4. import AdvancedParams from '$lib/components/chat/Settings/Advanced/AdvancedParams.svelte';
  5. import Tags from '$lib/components/common/Tags.svelte';
  6. import Knowledge from '$lib/components/workspace/Models/Knowledge.svelte';
  7. import ToolsSelector from '$lib/components/workspace/Models/ToolsSelector.svelte';
  8. import FiltersSelector from '$lib/components/workspace/Models/FiltersSelector.svelte';
  9. import ActionsSelector from '$lib/components/workspace/Models/ActionsSelector.svelte';
  10. import Capabilities from '$lib/components/workspace/Models/Capabilities.svelte';
  11. import Textarea from '$lib/components/common/Textarea.svelte';
  12. import { getTools } from '$lib/apis/tools';
  13. import { getFunctions } from '$lib/apis/functions';
  14. import { getKnowledgeBases } from '$lib/apis/knowledge';
  15. import AccessControl from '../common/AccessControl.svelte';
  16. import { stringify } from 'postcss';
  17. import { toast } from 'svelte-sonner';
  18. const i18n = getContext('i18n');
  19. export let onSubmit: Function;
  20. export let onBack: null | Function = null;
  21. export let model = null;
  22. export let edit = false;
  23. export let preset = true;
  24. let loading = false;
  25. let success = false;
  26. let filesInputElement;
  27. let inputFiles;
  28. let showAdvanced = false;
  29. let showPreview = false;
  30. let loaded = false;
  31. // ///////////
  32. // model
  33. // ///////////
  34. let id = '';
  35. let name = '';
  36. let enableDescription = true;
  37. $: if (!edit) {
  38. if (name) {
  39. id = name
  40. .replace(/\s+/g, '-')
  41. .replace(/[^a-zA-Z0-9-]/g, '')
  42. .toLowerCase();
  43. }
  44. }
  45. let info = {
  46. id: '',
  47. base_model_id: null,
  48. name: '',
  49. meta: {
  50. profile_image_url: '/static/favicon.png',
  51. description: '',
  52. suggestion_prompts: null,
  53. tags: []
  54. },
  55. params: {
  56. system: ''
  57. }
  58. };
  59. let params = {
  60. system: ''
  61. };
  62. let capabilities = {
  63. vision: true,
  64. usage: undefined,
  65. citations: true
  66. };
  67. let knowledge = [];
  68. let toolIds = [];
  69. let filterIds = [];
  70. let actionIds = [];
  71. let accessControl = {};
  72. const addUsage = (base_model_id) => {
  73. const baseModel = $models.find((m) => m.id === base_model_id);
  74. if (baseModel) {
  75. if (baseModel.owned_by === 'openai') {
  76. capabilities.usage = baseModel?.meta?.capabilities?.usage ?? false;
  77. } else {
  78. delete capabilities.usage;
  79. }
  80. capabilities = capabilities;
  81. }
  82. };
  83. const submitHandler = async () => {
  84. loading = true;
  85. info.id = id;
  86. info.name = name;
  87. if (id === '') {
  88. toast.error('Model ID is required.');
  89. }
  90. if (name === '') {
  91. toast.error('Model Name is required.');
  92. }
  93. info.access_control = accessControl;
  94. info.meta.capabilities = capabilities;
  95. if (enableDescription) {
  96. info.meta.description = info.meta.description.trim() === '' ? null : info.meta.description;
  97. } else {
  98. info.meta.description = null;
  99. }
  100. if (knowledge.length > 0) {
  101. info.meta.knowledge = knowledge;
  102. } else {
  103. if (info.meta.knowledge) {
  104. delete info.meta.knowledge;
  105. }
  106. }
  107. if (toolIds.length > 0) {
  108. info.meta.toolIds = toolIds;
  109. } else {
  110. if (info.meta.toolIds) {
  111. delete info.meta.toolIds;
  112. }
  113. }
  114. if (filterIds.length > 0) {
  115. info.meta.filterIds = filterIds;
  116. } else {
  117. if (info.meta.filterIds) {
  118. delete info.meta.filterIds;
  119. }
  120. }
  121. if (actionIds.length > 0) {
  122. info.meta.actionIds = actionIds;
  123. } else {
  124. if (info.meta.actionIds) {
  125. delete info.meta.actionIds;
  126. }
  127. }
  128. info.params.stop = params.stop ? params.stop.split(',').filter((s) => s.trim()) : null;
  129. Object.keys(info.params).forEach((key) => {
  130. if (info.params[key] === '' || info.params[key] === null) {
  131. delete info.params[key];
  132. }
  133. });
  134. await onSubmit(info);
  135. loading = false;
  136. success = false;
  137. };
  138. onMount(async () => {
  139. await tools.set(await getTools(localStorage.token));
  140. await functions.set(await getFunctions(localStorage.token));
  141. await knowledgeCollections.set(await getKnowledgeBases(localStorage.token));
  142. // Scroll to top 'workspace-container' element
  143. const workspaceContainer = document.getElementById('workspace-container');
  144. if (workspaceContainer) {
  145. workspaceContainer.scrollTop = 0;
  146. }
  147. if (model) {
  148. console.log(model);
  149. name = model.name;
  150. await tick();
  151. id = model.id;
  152. enableDescription = model?.meta?.description !== null;
  153. if (model.base_model_id) {
  154. const base_model = $models
  155. .filter((m) => !m?.preset && !(m?.arena ?? false))
  156. .find((m) => [model.base_model_id, `${model.base_model_id}:latest`].includes(m.id));
  157. console.log('base_model', base_model);
  158. if (base_model) {
  159. model.base_model_id = base_model.id;
  160. } else {
  161. model.base_model_id = null;
  162. }
  163. }
  164. params = { ...params, ...model?.params };
  165. params.stop = params?.stop
  166. ? (typeof params.stop === 'string' ? params.stop.split(',') : (params?.stop ?? [])).join(
  167. ','
  168. )
  169. : null;
  170. toolIds = model?.meta?.toolIds ?? [];
  171. filterIds = model?.meta?.filterIds ?? [];
  172. actionIds = model?.meta?.actionIds ?? [];
  173. knowledge = (model?.meta?.knowledge ?? []).map((item) => {
  174. if (item?.collection_name) {
  175. return {
  176. id: item.collection_name,
  177. name: item.name,
  178. legacy: true
  179. };
  180. } else if (item?.collection_names) {
  181. return {
  182. name: item.name,
  183. type: 'collection',
  184. collection_names: item.collection_names,
  185. legacy: true
  186. };
  187. } else {
  188. return item;
  189. }
  190. });
  191. capabilities = { ...capabilities, ...(model?.meta?.capabilities ?? {}) };
  192. if ('access_control' in model) {
  193. accessControl = model.access_control;
  194. } else {
  195. accessControl = {};
  196. }
  197. console.log(model?.access_control);
  198. console.log(accessControl);
  199. info = {
  200. ...info,
  201. ...JSON.parse(
  202. JSON.stringify(
  203. model
  204. ? model
  205. : {
  206. id: model.id,
  207. name: model.name
  208. }
  209. )
  210. )
  211. };
  212. console.log(model);
  213. }
  214. loaded = true;
  215. });
  216. </script>
  217. {#if loaded}
  218. {#if onBack}
  219. <button
  220. class="flex space-x-1"
  221. on:click={() => {
  222. onBack();
  223. }}
  224. >
  225. <div class=" self-center">
  226. <svg
  227. xmlns="http://www.w3.org/2000/svg"
  228. viewBox="0 0 20 20"
  229. fill="currentColor"
  230. class="h-4 w-4"
  231. >
  232. <path
  233. fill-rule="evenodd"
  234. d="M17 10a.75.75 0 01-.75.75H5.612l4.158 3.96a.75.75 0 11-1.04 1.08l-5.5-5.25a.75.75 0 010-1.08l5.5-5.25a.75.75 0 111.04 1.08L5.612 9.25H16.25A.75.75 0 0117 10z"
  235. clip-rule="evenodd"
  236. />
  237. </svg>
  238. </div>
  239. <div class=" self-center text-sm font-medium">{'Back'}</div>
  240. </button>
  241. {/if}
  242. <div class="w-full max-h-full flex justify-center">
  243. <input
  244. bind:this={filesInputElement}
  245. bind:files={inputFiles}
  246. type="file"
  247. hidden
  248. accept="image/*"
  249. on:change={() => {
  250. let reader = new FileReader();
  251. reader.onload = (event) => {
  252. let originalImageUrl = `${event.target.result}`;
  253. const img = new Image();
  254. img.src = originalImageUrl;
  255. img.onload = function () {
  256. const canvas = document.createElement('canvas');
  257. const ctx = canvas.getContext('2d');
  258. // Calculate the aspect ratio of the image
  259. const aspectRatio = img.width / img.height;
  260. // Calculate the new width and height to fit within 100x100
  261. let newWidth, newHeight;
  262. if (aspectRatio > 1) {
  263. newWidth = 250 * aspectRatio;
  264. newHeight = 250;
  265. } else {
  266. newWidth = 250;
  267. newHeight = 250 / aspectRatio;
  268. }
  269. // Set the canvas size
  270. canvas.width = 250;
  271. canvas.height = 250;
  272. // Calculate the position to center the image
  273. const offsetX = (250 - newWidth) / 2;
  274. const offsetY = (250 - newHeight) / 2;
  275. // Draw the image on the canvas
  276. ctx.drawImage(img, offsetX, offsetY, newWidth, newHeight);
  277. // Get the base64 representation of the compressed image
  278. const compressedSrc = canvas.toDataURL();
  279. // Display the compressed image
  280. info.meta.profile_image_url = compressedSrc;
  281. inputFiles = null;
  282. filesInputElement.value = '';
  283. };
  284. };
  285. if (
  286. inputFiles &&
  287. inputFiles.length > 0 &&
  288. ['image/gif', 'image/webp', 'image/jpeg', 'image/png', 'image/svg+xml'].includes(
  289. inputFiles[0]['type']
  290. )
  291. ) {
  292. reader.readAsDataURL(inputFiles[0]);
  293. } else {
  294. console.log(`Unsupported File Type '${inputFiles[0]['type']}'.`);
  295. inputFiles = null;
  296. }
  297. }}
  298. />
  299. {#if !edit || (edit && model)}
  300. <form
  301. class="flex flex-col md:flex-row w-full gap-3 md:gap-6"
  302. on:submit|preventDefault={() => {
  303. submitHandler();
  304. }}
  305. >
  306. <div class="self-center md:self-start flex justify-center my-2 flex-shrink-0">
  307. <div class="self-center">
  308. <button
  309. class="rounded-xl flex flex-shrink-0 items-center {info.meta.profile_image_url !==
  310. '/static/favicon.png'
  311. ? 'bg-transparent'
  312. : 'bg-white'} shadow-xl group relative"
  313. type="button"
  314. on:click={() => {
  315. filesInputElement.click();
  316. }}
  317. >
  318. {#if info.meta.profile_image_url}
  319. <img
  320. src={info.meta.profile_image_url}
  321. alt="model profile"
  322. class="rounded-xl size-72 md:size-60 object-cover shrink-0"
  323. />
  324. {:else}
  325. <img
  326. src="/static/favicon.png"
  327. alt="model profile"
  328. class=" rounded-xl size-72 md:size-60 object-cover shrink-0"
  329. />
  330. {/if}
  331. <div class="absolute bottom-0 right-0 z-10">
  332. <div class="m-1.5">
  333. <div
  334. class="shadow-xl p-1 rounded-full border-2 border-white bg-gray-800 text-white group-hover:bg-gray-600 transition dark:border-black dark:bg-white dark:group-hover:bg-gray-200 dark:text-black"
  335. >
  336. <svg
  337. xmlns="http://www.w3.org/2000/svg"
  338. viewBox="0 0 16 16"
  339. fill="currentColor"
  340. class="size-5"
  341. >
  342. <path
  343. fill-rule="evenodd"
  344. d="M2 4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4Zm10.5 5.707a.5.5 0 0 0-.146-.353l-1-1a.5.5 0 0 0-.708 0L9.354 9.646a.5.5 0 0 1-.708 0L6.354 7.354a.5.5 0 0 0-.708 0l-2 2a.5.5 0 0 0-.146.353V12a.5.5 0 0 0 .5.5h8a.5.5 0 0 0 .5-.5V9.707ZM12 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
  345. clip-rule="evenodd"
  346. />
  347. </svg>
  348. </div>
  349. </div>
  350. </div>
  351. <div
  352. class="absolute top-0 bottom-0 left-0 right-0 bg-white dark:bg-black rounded-lg opacity-0 group-hover:opacity-20 transition"
  353. ></div>
  354. </button>
  355. <div class="flex w-full mt-1 justify-end">
  356. <button
  357. class="px-2 py-1 text-gray-500 rounded-lg text-xs"
  358. on:click={() => {
  359. info.meta.profile_image_url = '/static/favicon.png';
  360. }}
  361. type="button"
  362. >
  363. Reset Image</button
  364. >
  365. </div>
  366. </div>
  367. </div>
  368. <div class="w-full">
  369. <div class="mt-2 my-2 flex flex-col">
  370. <div class="flex-1">
  371. <div>
  372. <input
  373. class="text-3xl font-semibold w-full bg-transparent outline-none"
  374. placeholder={$i18n.t('Model Name')}
  375. bind:value={name}
  376. required
  377. />
  378. </div>
  379. </div>
  380. <div class="flex-1">
  381. <div>
  382. <input
  383. class="text-xs w-full bg-transparent text-gray-500 outline-none"
  384. placeholder={$i18n.t('Model ID')}
  385. bind:value={id}
  386. disabled={edit}
  387. required
  388. />
  389. </div>
  390. </div>
  391. </div>
  392. {#if preset}
  393. <div class="my-1">
  394. <div class=" text-sm font-semibold mb-1">{$i18n.t('Base Model (From)')}</div>
  395. <div>
  396. <select
  397. class="text-sm w-full bg-transparent outline-none"
  398. placeholder="Select a base model (e.g. llama3, gpt-4o)"
  399. bind:value={info.base_model_id}
  400. on:change={(e) => {
  401. addUsage(e.target.value);
  402. }}
  403. required
  404. >
  405. <option value={null} class=" text-gray-900"
  406. >{$i18n.t('Select a base model')}</option
  407. >
  408. {#each $models.filter((m) => (model ? m.id !== model.id : true) && !m?.preset && m?.owned_by !== 'arena') as model}
  409. <option value={model.id} class=" text-gray-900">{model.name}</option>
  410. {/each}
  411. </select>
  412. </div>
  413. </div>
  414. {/if}
  415. <div class="my-1">
  416. <div class="mb-1 flex w-full justify-between items-center">
  417. <div class=" self-center text-sm font-semibold">{$i18n.t('Description')}</div>
  418. <button
  419. class="p-1 text-xs flex rounded transition"
  420. type="button"
  421. on:click={() => {
  422. enableDescription = !enableDescription;
  423. }}
  424. >
  425. {#if !enableDescription}
  426. <span class="ml-2 self-center">{$i18n.t('Default')}</span>
  427. {:else}
  428. <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
  429. {/if}
  430. </button>
  431. </div>
  432. {#if enableDescription}
  433. <Textarea
  434. className=" text-sm w-full bg-transparent outline-none resize-none overflow-y-hidden "
  435. placeholder={$i18n.t('Add a short description about what this model does')}
  436. bind:value={info.meta.description}
  437. />
  438. {/if}
  439. </div>
  440. <div class=" mt-2 my-1">
  441. <div class="">
  442. <Tags
  443. tags={info?.meta?.tags ?? []}
  444. on:delete={(e) => {
  445. const tagName = e.detail;
  446. info.meta.tags = info.meta.tags.filter((tag) => tag.name !== tagName);
  447. }}
  448. on:add={(e) => {
  449. const tagName = e.detail;
  450. if (!(info?.meta?.tags ?? null)) {
  451. info.meta.tags = [{ name: tagName }];
  452. } else {
  453. info.meta.tags = [...info.meta.tags, { name: tagName }];
  454. }
  455. }}
  456. />
  457. </div>
  458. </div>
  459. <div class="my-2">
  460. <div class="px-3 py-2 bg-gray-50 dark:bg-gray-950 rounded-lg">
  461. <AccessControl
  462. bind:accessControl
  463. accessRoles={['read', 'write']}
  464. />
  465. </div>
  466. </div>
  467. <hr class=" border-gray-50 dark:border-gray-850 my-1.5" />
  468. <div class="my-2">
  469. <div class="flex w-full justify-between">
  470. <div class=" self-center text-sm font-semibold">{$i18n.t('Model Params')}</div>
  471. </div>
  472. <div class="mt-2">
  473. <div class="my-1">
  474. <div class=" text-xs font-semibold mb-2">{$i18n.t('System Prompt')}</div>
  475. <div>
  476. <Textarea
  477. className=" text-sm w-full bg-transparent outline-none resize-none overflow-y-hidden "
  478. placeholder={`Write your model system prompt content here\ne.g.) You are Mario from Super Mario Bros, acting as an assistant.`}
  479. rows={4}
  480. bind:value={info.params.system}
  481. />
  482. </div>
  483. </div>
  484. <div class="flex w-full justify-between">
  485. <div class=" self-center text-xs font-semibold">
  486. {$i18n.t('Advanced Params')}
  487. </div>
  488. <button
  489. class="p-1 px-3 text-xs flex rounded transition"
  490. type="button"
  491. on:click={() => {
  492. showAdvanced = !showAdvanced;
  493. }}
  494. >
  495. {#if showAdvanced}
  496. <span class="ml-2 self-center">{$i18n.t('Hide')}</span>
  497. {:else}
  498. <span class="ml-2 self-center">{$i18n.t('Show')}</span>
  499. {/if}
  500. </button>
  501. </div>
  502. {#if showAdvanced}
  503. <div class="my-2">
  504. <AdvancedParams
  505. admin={true}
  506. bind:params
  507. on:change={(e) => {
  508. info.params = { ...info.params, ...params };
  509. }}
  510. />
  511. </div>
  512. {/if}
  513. </div>
  514. </div>
  515. <hr class=" border-gray-50 dark:border-gray-850 my-1" />
  516. <div class="my-2">
  517. <div class="flex w-full justify-between items-center">
  518. <div class="flex w-full justify-between items-center">
  519. <div class=" self-center text-sm font-semibold">
  520. {$i18n.t('Prompt suggestions')}
  521. </div>
  522. <button
  523. class="p-1 text-xs flex rounded transition"
  524. type="button"
  525. on:click={() => {
  526. if ((info?.meta?.suggestion_prompts ?? null) === null) {
  527. info.meta.suggestion_prompts = [{ content: '' }];
  528. } else {
  529. info.meta.suggestion_prompts = null;
  530. }
  531. }}
  532. >
  533. {#if (info?.meta?.suggestion_prompts ?? null) === null}
  534. <span class="ml-2 self-center">{$i18n.t('Default')}</span>
  535. {:else}
  536. <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
  537. {/if}
  538. </button>
  539. </div>
  540. {#if (info?.meta?.suggestion_prompts ?? null) !== null}
  541. <button
  542. class="p-1 px-2 text-xs flex rounded transition"
  543. type="button"
  544. on:click={() => {
  545. if (
  546. info.meta.suggestion_prompts.length === 0 ||
  547. info.meta.suggestion_prompts.at(-1).content !== ''
  548. ) {
  549. info.meta.suggestion_prompts = [
  550. ...info.meta.suggestion_prompts,
  551. { content: '' }
  552. ];
  553. }
  554. }}
  555. >
  556. <svg
  557. xmlns="http://www.w3.org/2000/svg"
  558. viewBox="0 0 20 20"
  559. fill="currentColor"
  560. class="w-4 h-4"
  561. >
  562. <path
  563. d="M10.75 4.75a.75.75 0 00-1.5 0v4.5h-4.5a.75.75 0 000 1.5h4.5v4.5a.75.75 0 001.5 0v-4.5h4.5a.75.75 0 000-1.5h-4.5v-4.5z"
  564. />
  565. </svg>
  566. </button>
  567. {/if}
  568. </div>
  569. {#if info?.meta?.suggestion_prompts}
  570. <div class="flex flex-col space-y-1 mt-1 mb-3">
  571. {#if info.meta.suggestion_prompts.length > 0}
  572. {#each info.meta.suggestion_prompts as prompt, promptIdx}
  573. <div class=" flex rounded-lg">
  574. <input
  575. class=" text-sm w-full bg-transparent outline-none border-r border-gray-50 dark:border-gray-850"
  576. placeholder={$i18n.t('Write a prompt suggestion (e.g. Who are you?)')}
  577. bind:value={prompt.content}
  578. />
  579. <button
  580. class="px-2"
  581. type="button"
  582. on:click={() => {
  583. info.meta.suggestion_prompts.splice(promptIdx, 1);
  584. info.meta.suggestion_prompts = info.meta.suggestion_prompts;
  585. }}
  586. >
  587. <svg
  588. xmlns="http://www.w3.org/2000/svg"
  589. viewBox="0 0 20 20"
  590. fill="currentColor"
  591. class="w-4 h-4"
  592. >
  593. <path
  594. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  595. />
  596. </svg>
  597. </button>
  598. </div>
  599. {/each}
  600. {:else}
  601. <div class="text-xs text-center">No suggestion prompts</div>
  602. {/if}
  603. </div>
  604. {/if}
  605. </div>
  606. <hr class=" border-gray-50 dark:border-gray-850 my-1.5" />
  607. <div class="my-2">
  608. <Knowledge bind:selectedKnowledge={knowledge} collections={$knowledgeCollections} />
  609. </div>
  610. <div class="my-2">
  611. <ToolsSelector bind:selectedToolIds={toolIds} tools={$tools} />
  612. </div>
  613. <div class="my-2">
  614. <FiltersSelector
  615. bind:selectedFilterIds={filterIds}
  616. filters={$functions.filter((func) => func.type === 'filter')}
  617. />
  618. </div>
  619. <div class="my-2">
  620. <ActionsSelector
  621. bind:selectedActionIds={actionIds}
  622. actions={$functions.filter((func) => func.type === 'action')}
  623. />
  624. </div>
  625. <div class="my-2">
  626. <Capabilities bind:capabilities />
  627. </div>
  628. <div class="my-2 text-gray-300 dark:text-gray-700">
  629. <div class="flex w-full justify-between mb-2">
  630. <div class=" self-center text-sm font-semibold">{$i18n.t('JSON Preview')}</div>
  631. <button
  632. class="p-1 px-3 text-xs flex rounded transition"
  633. type="button"
  634. on:click={() => {
  635. showPreview = !showPreview;
  636. }}
  637. >
  638. {#if showPreview}
  639. <span class="ml-2 self-center">{$i18n.t('Hide')}</span>
  640. {:else}
  641. <span class="ml-2 self-center">{$i18n.t('Show')}</span>
  642. {/if}
  643. </button>
  644. </div>
  645. {#if showPreview}
  646. <div>
  647. <textarea
  648. class="text-sm w-full bg-transparent outline-none resize-none"
  649. rows="10"
  650. value={JSON.stringify(info, null, 2)}
  651. disabled
  652. readonly
  653. />
  654. </div>
  655. {/if}
  656. </div>
  657. <div class="my-2 flex justify-end pb-20">
  658. <button
  659. class=" text-sm px-3 py-2 transition rounded-lg {loading
  660. ? ' cursor-not-allowed bg-black hover:bg-gray-900 text-white dark:bg-white dark:hover:bg-gray-100 dark:text-black'
  661. : 'bg-black hover:bg-gray-900 text-white dark:bg-white dark:hover:bg-gray-100 dark:text-black'} flex w-full justify-center"
  662. type="submit"
  663. disabled={loading}
  664. >
  665. <div class=" self-center font-medium">
  666. {#if edit}
  667. {$i18n.t('Save & Update')}
  668. {:else}
  669. {$i18n.t('Save & Create')}
  670. {/if}
  671. </div>
  672. {#if loading}
  673. <div class="ml-1.5 self-center">
  674. <svg
  675. class=" w-4 h-4"
  676. viewBox="0 0 24 24"
  677. fill="currentColor"
  678. xmlns="http://www.w3.org/2000/svg"
  679. ><style>
  680. .spinner_ajPY {
  681. transform-origin: center;
  682. animation: spinner_AtaB 0.75s infinite linear;
  683. }
  684. @keyframes spinner_AtaB {
  685. 100% {
  686. transform: rotate(360deg);
  687. }
  688. }
  689. </style><path
  690. d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
  691. opacity=".25"
  692. /><path
  693. d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
  694. class="spinner_ajPY"
  695. /></svg
  696. >
  697. </div>
  698. {/if}
  699. </button>
  700. </div>
  701. </div>
  702. </form>
  703. {/if}
  704. </div>
  705. {/if}