Documents.svelte 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import fileSaver from 'file-saver';
  4. const { saveAs } = fileSaver;
  5. import { onMount, getContext } from 'svelte';
  6. import { WEBUI_NAME, documents, showSidebar } from '$lib/stores';
  7. import { createNewDoc, deleteDocByName, getDocs } from '$lib/apis/documents';
  8. import { SUPPORTED_FILE_TYPE, SUPPORTED_FILE_EXTENSIONS } from '$lib/constants';
  9. import { getFileLimitSettings, processDocToVectorDB, uploadDocToVectorDB } from '$lib/apis/rag';
  10. import { blobToFile, transformFileName } from '$lib/utils';
  11. import Checkbox from '$lib/components/common/Checkbox.svelte';
  12. import EditDocModal from '$lib/components/documents/EditDocModal.svelte';
  13. import AddFilesPlaceholder from '$lib/components/AddFilesPlaceholder.svelte';
  14. import AddDocModal from '$lib/components/documents/AddDocModal.svelte';
  15. import { transcribeAudio } from '$lib/apis/audio';
  16. import { uploadFile } from '$lib/apis/files';
  17. const i18n = getContext('i18n');
  18. let importFiles = '';
  19. let inputFiles = '';
  20. let fileLimitSettings;
  21. let query = '';
  22. let documentsImportInputElement: HTMLInputElement;
  23. let tags = [];
  24. let showSettingsModal = false;
  25. let showAddDocModal = false;
  26. let showEditDocModal = false;
  27. let selectedDoc;
  28. let selectedTag = '';
  29. let dragged = false;
  30. const deleteDoc = async (name) => {
  31. await deleteDocByName(localStorage.token, name);
  32. await documents.set(await getDocs(localStorage.token));
  33. };
  34. const deleteDocs = async (docs) => {
  35. const res = await Promise.all(
  36. docs.map(async (doc) => {
  37. return await deleteDocByName(localStorage.token, doc.name);
  38. })
  39. );
  40. await documents.set(await getDocs(localStorage.token));
  41. };
  42. const uploadDoc = async (file, tags?: object) => {
  43. console.log(file);
  44. // Check if the file is an audio file and transcribe/convert it to text file
  45. if (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
  46. const transcribeRes = await transcribeAudio(localStorage.token, file).catch((error) => {
  47. toast.error(error);
  48. return null;
  49. });
  50. if (transcribeRes) {
  51. console.log(transcribeRes);
  52. const blob = new Blob([transcribeRes.text], { type: 'text/plain' });
  53. file = blobToFile(blob, `${file.name}.txt`);
  54. }
  55. }
  56. // Upload the file to the server
  57. const uploadedFile = await uploadFile(localStorage.token, file).catch((error) => {
  58. toast.error(error);
  59. return null;
  60. });
  61. const res = await processDocToVectorDB(localStorage.token, uploadedFile.id).catch((error) => {
  62. toast.error(error);
  63. return null;
  64. });
  65. if (res) {
  66. await createNewDoc(
  67. localStorage.token,
  68. res.collection_name,
  69. res.filename,
  70. transformFileName(res.filename),
  71. res.filename,
  72. tags?.length > 0
  73. ? {
  74. tags: tags
  75. }
  76. : null
  77. ).catch((error) => {
  78. toast.error(error);
  79. return null;
  80. });
  81. await documents.set(await getDocs(localStorage.token));
  82. }
  83. };
  84. const initFileLimitSettings = async () => {
  85. try {
  86. fileLimitSettings = await getFileLimitSettings(localStorage.token);
  87. } catch (error) {
  88. console.error('Error fetching query settings:', error);
  89. }
  90. };
  91. onMount(() => {
  92. initFileLimitSettings();
  93. documents.subscribe((docs) => {
  94. tags = docs.reduce((a, e, i, arr) => {
  95. return [...new Set([...a, ...(e?.content?.tags ?? []).map((tag) => tag.name)])];
  96. }, []);
  97. });
  98. const dropZone = document.querySelector('body');
  99. const onDragOver = (e) => {
  100. e.preventDefault();
  101. dragged = true;
  102. };
  103. const onDragLeave = () => {
  104. dragged = false;
  105. };
  106. const onDrop = async (e) => {
  107. e.preventDefault();
  108. if (e.dataTransfer?.files) {
  109. let reader = new FileReader();
  110. reader.onload = (event) => {
  111. files = [
  112. ...files,
  113. {
  114. type: 'image',
  115. url: `${event.target.result}`
  116. }
  117. ];
  118. };
  119. const inputFiles = e.dataTransfer?.files;
  120. if (inputFiles && inputFiles.length > 0) {
  121. for (const file of inputFiles) {
  122. console.log(file, file.name.split('.').at(-1));
  123. if (file.size <= fileLimitSettings.max_file_size * 1024 * 1024) {
  124. if (
  125. SUPPORTED_FILE_TYPE.includes(file['type']) ||
  126. SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
  127. ) {
  128. uploadDoc(file);
  129. } else {
  130. toast.error(
  131. `Unknown File Type '${file['type']}', but accepting and treating as plain text`
  132. );
  133. uploadDoc(file);
  134. }
  135. } else {
  136. toast.error(
  137. $i18n.t('File size exceeds the limit of {{size}}MB', {
  138. size: fileLimitSettings.max_file_size
  139. })
  140. );
  141. }
  142. }
  143. } else {
  144. toast.error($i18n.t(`File not found.`));
  145. }
  146. }
  147. dragged = false;
  148. };
  149. dropZone?.addEventListener('dragover', onDragOver);
  150. dropZone?.addEventListener('drop', onDrop);
  151. dropZone?.addEventListener('dragleave', onDragLeave);
  152. return () => {
  153. dropZone?.removeEventListener('dragover', onDragOver);
  154. dropZone?.removeEventListener('drop', onDrop);
  155. dropZone?.removeEventListener('dragleave', onDragLeave);
  156. };
  157. });
  158. let filteredDocs;
  159. $: filteredDocs = $documents.filter(
  160. (doc) =>
  161. (selectedTag === '' ||
  162. (doc?.content?.tags ?? []).map((tag) => tag.name).includes(selectedTag)) &&
  163. (query === '' || doc.name.includes(query))
  164. );
  165. </script>
  166. <svelte:head>
  167. <title>
  168. {$i18n.t('Documents')} | {$WEBUI_NAME}
  169. </title>
  170. </svelte:head>
  171. {#if dragged}
  172. <div
  173. class="fixed {$showSidebar
  174. ? 'left-0 md:left-[260px] md:w-[calc(100%-260px)]'
  175. : 'left-0'} w-full h-full flex z-50 touch-none pointer-events-none"
  176. id="dropzone"
  177. role="region"
  178. aria-label="Drag and Drop Container"
  179. >
  180. <div class="absolute w-full h-full backdrop-blur bg-gray-800/40 flex justify-center">
  181. <div class="m-auto pt-64 flex flex-col justify-center">
  182. <div class="max-w-md">
  183. <AddFilesPlaceholder>
  184. <div class=" mt-2 text-center text-sm dark:text-gray-200 w-full">
  185. Drop any files here to add to my documents
  186. </div>
  187. </AddFilesPlaceholder>
  188. </div>
  189. </div>
  190. </div>
  191. </div>
  192. {/if}
  193. {#key selectedDoc}
  194. <EditDocModal bind:show={showEditDocModal} {selectedDoc} />
  195. {/key}
  196. <AddDocModal bind:show={showAddDocModal} {uploadDoc} />
  197. <div class="mb-3">
  198. <div class="flex justify-between items-center">
  199. <div class=" text-lg font-semibold self-center">{$i18n.t('Documents')}</div>
  200. </div>
  201. </div>
  202. <div class=" flex w-full space-x-2">
  203. <div class="flex flex-1">
  204. <div class=" self-center ml-1 mr-3">
  205. <svg
  206. xmlns="http://www.w3.org/2000/svg"
  207. viewBox="0 0 20 20"
  208. fill="currentColor"
  209. class="w-4 h-4"
  210. >
  211. <path
  212. fill-rule="evenodd"
  213. d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
  214. clip-rule="evenodd"
  215. />
  216. </svg>
  217. </div>
  218. <input
  219. class=" w-full text-sm pr-4 py-1 rounded-r-xl outline-none bg-transparent"
  220. bind:value={query}
  221. placeholder={$i18n.t('Search Documents')}
  222. />
  223. </div>
  224. <div>
  225. <button
  226. class=" px-2 py-2 rounded-xl border border-gray-200 dark:border-gray-600 dark:border-0 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 transition font-medium text-sm flex items-center space-x-1"
  227. aria-label={$i18n.t('Add Docs')}
  228. on:click={() => {
  229. showAddDocModal = true;
  230. }}
  231. >
  232. <svg
  233. xmlns="http://www.w3.org/2000/svg"
  234. viewBox="0 0 16 16"
  235. fill="currentColor"
  236. class="w-4 h-4"
  237. >
  238. <path
  239. d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z"
  240. />
  241. </svg>
  242. </button>
  243. </div>
  244. </div>
  245. <!-- <div>
  246. <div
  247. class="my-3 py-16 rounded-lg border-2 border-dashed dark:border-gray-600 {dragged &&
  248. ' dark:bg-gray-700'} "
  249. role="region"
  250. on:drop={onDrop}
  251. on:dragover={onDragOver}
  252. on:dragleave={onDragLeave}
  253. >
  254. <div class=" pointer-events-none">
  255. <div class="text-center dark:text-white text-2xl font-semibold z-50">{$i18n.t('Add Files')}</div>
  256. <div class=" mt-2 text-center text-sm dark:text-gray-200 w-full">
  257. Drop any files here to add to my documents
  258. </div>
  259. </div>
  260. </div>
  261. </div> -->
  262. <hr class=" dark:border-gray-850 my-2.5" />
  263. {#if tags.length > 0}
  264. <div class="px-2.5 pt-1 flex gap-1 flex-wrap">
  265. <div class="ml-0.5 pr-3 my-auto flex items-center">
  266. <Checkbox
  267. state={filteredDocs.filter((doc) => doc?.selected === 'checked').length ===
  268. filteredDocs.length
  269. ? 'checked'
  270. : 'unchecked'}
  271. indeterminate={filteredDocs.filter((doc) => doc?.selected === 'checked').length > 0 &&
  272. filteredDocs.filter((doc) => doc?.selected === 'checked').length !== filteredDocs.length}
  273. on:change={(e) => {
  274. if (e.detail === 'checked') {
  275. filteredDocs = filteredDocs.map((doc) => ({ ...doc, selected: 'checked' }));
  276. } else if (e.detail === 'unchecked') {
  277. filteredDocs = filteredDocs.map((doc) => ({ ...doc, selected: 'unchecked' }));
  278. }
  279. }}
  280. />
  281. </div>
  282. {#if filteredDocs.filter((doc) => doc?.selected === 'checked').length === 0}
  283. <button
  284. class="px-2 py-0.5 space-x-1 flex h-fit items-center rounded-full transition bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:text-white"
  285. on:click={async () => {
  286. selectedTag = '';
  287. // await chats.set(await getChatListByTagName(localStorage.token, tag.name));
  288. }}
  289. >
  290. <div class=" text-xs font-medium self-center line-clamp-1">{$i18n.t('all')}</div>
  291. </button>
  292. {#each tags as tag}
  293. <button
  294. class="px-2 py-0.5 space-x-1 flex h-fit items-center rounded-full transition bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:text-white"
  295. on:click={async () => {
  296. selectedTag = tag;
  297. // await chats.set(await getChatListByTagName(localStorage.token, tag.name));
  298. }}
  299. >
  300. <div class=" text-xs font-medium self-center line-clamp-1">
  301. #{tag}
  302. </div>
  303. </button>
  304. {/each}
  305. {:else}
  306. <div class="flex-1 flex w-full justify-between items-center">
  307. <div class="text-xs font-medium py-0.5 self-center mr-1">
  308. {filteredDocs.filter((doc) => doc?.selected === 'checked').length} Selected
  309. </div>
  310. <div class="flex gap-1">
  311. <!-- <button
  312. class="px-2 py-0.5 space-x-1 flex h-fit items-center rounded-full transition bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:text-white"
  313. on:click={async () => {
  314. selectedTag = '';
  315. // await chats.set(await getChatListByTagName(localStorage.token, tag.name));
  316. }}
  317. >
  318. <div class=" text-xs font-medium self-center line-clamp-1">add tags</div>
  319. </button> -->
  320. <button
  321. class="px-2 py-0.5 space-x-1 flex h-fit items-center rounded-full transition bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:text-white"
  322. on:click={async () => {
  323. deleteDocs(filteredDocs.filter((doc) => doc.selected === 'checked'));
  324. // await chats.set(await getChatListByTagName(localStorage.token, tag.name));
  325. }}
  326. >
  327. <div class=" text-xs font-medium self-center line-clamp-1">
  328. {$i18n.t('delete')}
  329. </div>
  330. </button>
  331. </div>
  332. </div>
  333. {/if}
  334. </div>
  335. {/if}
  336. <div class="my-3 mb-5">
  337. {#each filteredDocs as doc}
  338. <button
  339. class=" flex space-x-4 cursor-pointer text-left w-full px-3 py-2 dark:hover:bg-white/5 hover:bg-black/5 rounded-xl"
  340. on:click={() => {
  341. if (doc?.selected === 'checked') {
  342. doc.selected = 'unchecked';
  343. } else {
  344. doc.selected = 'checked';
  345. }
  346. }}
  347. >
  348. <div class="my-auto flex items-center">
  349. <Checkbox state={doc?.selected ?? 'unchecked'} />
  350. </div>
  351. <div class=" flex flex-1 space-x-4 cursor-pointer w-full">
  352. <div class=" flex items-center space-x-3">
  353. <div class="p-2.5 bg-red-400 text-white rounded-lg">
  354. {#if doc}
  355. <svg
  356. xmlns="http://www.w3.org/2000/svg"
  357. viewBox="0 0 24 24"
  358. fill="currentColor"
  359. class="w-6 h-6"
  360. >
  361. <path
  362. fill-rule="evenodd"
  363. d="M5.625 1.5c-1.036 0-1.875.84-1.875 1.875v17.25c0 1.035.84 1.875 1.875 1.875h12.75c1.035 0 1.875-.84 1.875-1.875V12.75A3.75 3.75 0 0 0 16.5 9h-1.875a1.875 1.875 0 0 1-1.875-1.875V5.25A3.75 3.75 0 0 0 9 1.5H5.625ZM7.5 15a.75.75 0 0 1 .75-.75h7.5a.75.75 0 0 1 0 1.5h-7.5A.75.75 0 0 1 7.5 15Zm.75 2.25a.75.75 0 0 0 0 1.5H12a.75.75 0 0 0 0-1.5H8.25Z"
  364. clip-rule="evenodd"
  365. />
  366. <path
  367. d="M12.971 1.816A5.23 5.23 0 0 1 14.25 5.25v1.875c0 .207.168.375.375.375H16.5a5.23 5.23 0 0 1 3.434 1.279 9.768 9.768 0 0 0-6.963-6.963Z"
  368. />
  369. </svg>
  370. {:else}
  371. <svg
  372. class=" w-6 h-6 translate-y-[0.5px]"
  373. fill="currentColor"
  374. viewBox="0 0 24 24"
  375. xmlns="http://www.w3.org/2000/svg"
  376. ><style>
  377. .spinner_qM83 {
  378. animation: spinner_8HQG 1.05s infinite;
  379. }
  380. .spinner_oXPr {
  381. animation-delay: 0.1s;
  382. }
  383. .spinner_ZTLf {
  384. animation-delay: 0.2s;
  385. }
  386. @keyframes spinner_8HQG {
  387. 0%,
  388. 57.14% {
  389. animation-timing-function: cubic-bezier(0.33, 0.66, 0.66, 1);
  390. transform: translate(0);
  391. }
  392. 28.57% {
  393. animation-timing-function: cubic-bezier(0.33, 0, 0.66, 0.33);
  394. transform: translateY(-6px);
  395. }
  396. 100% {
  397. transform: translate(0);
  398. }
  399. }
  400. </style><circle class="spinner_qM83" cx="4" cy="12" r="2.5" /><circle
  401. class="spinner_qM83 spinner_oXPr"
  402. cx="12"
  403. cy="12"
  404. r="2.5"
  405. /><circle class="spinner_qM83 spinner_ZTLf" cx="20" cy="12" r="2.5" /></svg
  406. >
  407. {/if}
  408. </div>
  409. <div class=" self-center flex-1">
  410. <div class=" font-semibold line-clamp-1">#{doc.name} ({doc.filename})</div>
  411. <div class=" text-xs overflow-hidden text-ellipsis line-clamp-1">
  412. {doc.title}
  413. </div>
  414. </div>
  415. </div>
  416. </div>
  417. <div class="flex flex-row space-x-1 self-center">
  418. <button
  419. class="self-center w-fit text-sm z-20 px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
  420. type="button"
  421. aria-label={$i18n.t('Edit Doc')}
  422. on:click={async (e) => {
  423. e.stopPropagation();
  424. showEditDocModal = !showEditDocModal;
  425. selectedDoc = doc;
  426. }}
  427. >
  428. <svg
  429. xmlns="http://www.w3.org/2000/svg"
  430. fill="none"
  431. viewBox="0 0 24 24"
  432. stroke-width="1.5"
  433. stroke="currentColor"
  434. class="w-4 h-4"
  435. >
  436. <path
  437. stroke-linecap="round"
  438. stroke-linejoin="round"
  439. d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125"
  440. />
  441. </svg>
  442. </button>
  443. <!-- <button
  444. class="self-center w-fit text-sm px-2 py-2 border dark:border-gray-600 rounded-xl"
  445. type="button"
  446. on:click={() => {
  447. console.log('download file');
  448. }}
  449. >
  450. <svg
  451. xmlns="http://www.w3.org/2000/svg"
  452. viewBox="0 0 16 16"
  453. fill="currentColor"
  454. class="w-4 h-4"
  455. >
  456. <path
  457. d="M8.75 2.75a.75.75 0 0 0-1.5 0v5.69L5.03 6.22a.75.75 0 0 0-1.06 1.06l3.5 3.5a.75.75 0 0 0 1.06 0l3.5-3.5a.75.75 0 0 0-1.06-1.06L8.75 8.44V2.75Z"
  458. />
  459. <path
  460. d="M3.5 9.75a.75.75 0 0 0-1.5 0v1.5A2.75 2.75 0 0 0 4.75 14h6.5A2.75 2.75 0 0 0 14 11.25v-1.5a.75.75 0 0 0-1.5 0v1.5c0 .69-.56 1.25-1.25 1.25h-6.5c-.69 0-1.25-.56-1.25-1.25v-1.5Z"
  461. />
  462. </svg>
  463. </button> -->
  464. <button
  465. class="self-center w-fit text-sm px-2 py-2 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-xl"
  466. type="button"
  467. aria-label={$i18n.t('Delete Doc')}
  468. on:click={(e) => {
  469. e.stopPropagation();
  470. deleteDoc(doc.name);
  471. }}
  472. >
  473. <svg
  474. xmlns="http://www.w3.org/2000/svg"
  475. fill="none"
  476. viewBox="0 0 24 24"
  477. stroke-width="1.5"
  478. stroke="currentColor"
  479. class="w-4 h-4"
  480. >
  481. <path
  482. stroke-linecap="round"
  483. stroke-linejoin="round"
  484. d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"
  485. />
  486. </svg>
  487. </button>
  488. </div>
  489. </button>
  490. {/each}
  491. </div>
  492. <div class=" text-gray-500 text-xs mt-1 mb-2">
  493. ⓘ {$i18n.t("Use '#' in the prompt input to load and select your documents.")}
  494. </div>
  495. <div class=" flex justify-end w-full mb-2">
  496. <div class="flex space-x-2">
  497. <input
  498. id="documents-import-input"
  499. bind:this={documentsImportInputElement}
  500. bind:files={importFiles}
  501. type="file"
  502. accept=".json"
  503. hidden
  504. on:change={() => {
  505. console.log(importFiles);
  506. const reader = new FileReader();
  507. reader.onload = async (event) => {
  508. const savedDocs = JSON.parse(event.target.result);
  509. console.log(savedDocs);
  510. for (const doc of savedDocs) {
  511. await createNewDoc(
  512. localStorage.token,
  513. doc.collection_name,
  514. doc.filename,
  515. doc.name,
  516. doc.title,
  517. doc.content
  518. ).catch((error) => {
  519. toast.error(error);
  520. return null;
  521. });
  522. }
  523. await documents.set(await getDocs(localStorage.token));
  524. };
  525. reader.readAsText(importFiles[0]);
  526. }}
  527. />
  528. <button
  529. class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition"
  530. on:click={() => {
  531. documentsImportInputElement.click();
  532. }}
  533. >
  534. <div class=" self-center mr-2 font-medium line-clamp-1">
  535. {$i18n.t('Import Documents Mapping')}
  536. </div>
  537. <div class=" self-center">
  538. <svg
  539. xmlns="http://www.w3.org/2000/svg"
  540. viewBox="0 0 16 16"
  541. fill="currentColor"
  542. class="w-4 h-4"
  543. >
  544. <path
  545. fill-rule="evenodd"
  546. d="M4 2a1.5 1.5 0 0 0-1.5 1.5v9A1.5 1.5 0 0 0 4 14h8a1.5 1.5 0 0 0 1.5-1.5V6.621a1.5 1.5 0 0 0-.44-1.06L9.94 2.439A1.5 1.5 0 0 0 8.878 2H4Zm4 9.5a.75.75 0 0 1-.75-.75V8.06l-.72.72a.75.75 0 0 1-1.06-1.06l2-2a.75.75 0 0 1 1.06 0l2 2a.75.75 0 1 1-1.06 1.06l-.72-.72v2.69a.75.75 0 0 1-.75.75Z"
  547. clip-rule="evenodd"
  548. />
  549. </svg>
  550. </div>
  551. </button>
  552. <button
  553. class="flex text-xs items-center space-x-1 px-3 py-1.5 rounded-xl bg-gray-50 hover:bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-200 transition"
  554. on:click={async () => {
  555. let blob = new Blob([JSON.stringify($documents)], {
  556. type: 'application/json'
  557. });
  558. saveAs(blob, `documents-mapping-export-${Date.now()}.json`);
  559. }}
  560. >
  561. <div class=" self-center mr-2 font-medium line-clamp-1">
  562. {$i18n.t('Export Documents Mapping')}
  563. </div>
  564. <div class=" self-center">
  565. <svg
  566. xmlns="http://www.w3.org/2000/svg"
  567. viewBox="0 0 16 16"
  568. fill="currentColor"
  569. class="w-4 h-4"
  570. >
  571. <path
  572. fill-rule="evenodd"
  573. d="M4 2a1.5 1.5 0 0 0-1.5 1.5v9A1.5 1.5 0 0 0 4 14h8a1.5 1.5 0 0 0 1.5-1.5V6.621a1.5 1.5 0 0 0-.44-1.06L9.94 2.439A1.5 1.5 0 0 0 8.878 2H4Zm4 3.5a.75.75 0 0 1 .75.75v2.69l.72-.72a.75.75 0 1 1 1.06 1.06l-2 2a.75.75 0 0 1-1.06 0l-2-2a.75.75 0 0 1 1.06-1.06l.72.72V6.25A.75.75 0 0 1 8 5.5Z"
  574. clip-rule="evenodd"
  575. />
  576. </svg>
  577. </div>
  578. </button>
  579. </div>
  580. </div>