Documents.svelte 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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 { 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 query = '';
  21. let documentsImportInputElement: HTMLInputElement;
  22. let tags = [];
  23. let showSettingsModal = false;
  24. let showAddDocModal = false;
  25. let showEditDocModal = false;
  26. let selectedDoc;
  27. let selectedTag = '';
  28. let dragged = false;
  29. const deleteDoc = async (name) => {
  30. await deleteDocByName(localStorage.token, name);
  31. await documents.set(await getDocs(localStorage.token));
  32. };
  33. const deleteDocs = async (docs) => {
  34. const res = await Promise.all(
  35. docs.map(async (doc) => {
  36. return await deleteDocByName(localStorage.token, doc.name);
  37. })
  38. );
  39. await documents.set(await getDocs(localStorage.token));
  40. };
  41. const uploadDoc = async (file) => {
  42. console.log(file);
  43. // Check if the file is an audio file and transcribe/convert it to text file
  44. if (['audio/mpeg', 'audio/wav'].includes(file['type'])) {
  45. const transcribeRes = await transcribeAudio(localStorage.token, file).catch((error) => {
  46. toast.error(error);
  47. return null;
  48. });
  49. if (transcribeRes) {
  50. console.log(transcribeRes);
  51. const blob = new Blob([transcribeRes.text], { type: 'text/plain' });
  52. file = blobToFile(blob, `${file.name}.txt`);
  53. }
  54. }
  55. // Upload the file to the server
  56. const uploadedFile = await uploadFile(localStorage.token, file).catch((error) => {
  57. toast.error(error);
  58. return null;
  59. });
  60. const res = await processDocToVectorDB(localStorage.token, uploadedFile.id).catch((error) => {
  61. toast.error(error);
  62. return null;
  63. });
  64. if (res) {
  65. await createNewDoc(
  66. localStorage.token,
  67. res.collection_name,
  68. res.filename,
  69. transformFileName(res.filename),
  70. res.filename
  71. ).catch((error) => {
  72. toast.error(error);
  73. return null;
  74. });
  75. await documents.set(await getDocs(localStorage.token));
  76. }
  77. };
  78. onMount(() => {
  79. documents.subscribe((docs) => {
  80. tags = docs.reduce((a, e, i, arr) => {
  81. return [...new Set([...a, ...(e?.content?.tags ?? []).map((tag) => tag.name)])];
  82. }, []);
  83. });
  84. const dropZone = document.querySelector('body');
  85. const onDragOver = (e) => {
  86. e.preventDefault();
  87. dragged = true;
  88. };
  89. const onDragLeave = () => {
  90. dragged = false;
  91. };
  92. const onDrop = async (e) => {
  93. e.preventDefault();
  94. if (e.dataTransfer?.files) {
  95. let reader = new FileReader();
  96. reader.onload = (event) => {
  97. files = [
  98. ...files,
  99. {
  100. type: 'image',
  101. url: `${event.target.result}`
  102. }
  103. ];
  104. };
  105. const inputFiles = e.dataTransfer?.files;
  106. if (inputFiles && inputFiles.length > 0) {
  107. for (const file of inputFiles) {
  108. console.log(file, file.name.split('.').at(-1));
  109. if (
  110. SUPPORTED_FILE_TYPE.includes(file['type']) ||
  111. SUPPORTED_FILE_EXTENSIONS.includes(file.name.split('.').at(-1))
  112. ) {
  113. uploadDoc(file);
  114. } else {
  115. toast.error(
  116. `Unknown File Type '${file['type']}', but accepting and treating as plain text`
  117. );
  118. uploadDoc(file);
  119. }
  120. }
  121. } else {
  122. toast.error($i18n.t(`File not found.`));
  123. }
  124. }
  125. dragged = false;
  126. };
  127. dropZone?.addEventListener('dragover', onDragOver);
  128. dropZone?.addEventListener('drop', onDrop);
  129. dropZone?.addEventListener('dragleave', onDragLeave);
  130. return () => {
  131. dropZone?.removeEventListener('dragover', onDragOver);
  132. dropZone?.removeEventListener('drop', onDrop);
  133. dropZone?.removeEventListener('dragleave', onDragLeave);
  134. };
  135. });
  136. let filteredDocs;
  137. $: filteredDocs = $documents.filter(
  138. (doc) =>
  139. (selectedTag === '' ||
  140. (doc?.content?.tags ?? []).map((tag) => tag.name).includes(selectedTag)) &&
  141. (query === '' || doc.name.includes(query))
  142. );
  143. </script>
  144. <svelte:head>
  145. <title>
  146. {$i18n.t('Documents')} | {$WEBUI_NAME}
  147. </title>
  148. </svelte:head>
  149. {#if dragged}
  150. <div
  151. class="fixed {$showSidebar
  152. ? 'left-0 md:left-[260px] md:w-[calc(100%-260px)]'
  153. : 'left-0'} w-full h-full flex z-50 touch-none pointer-events-none"
  154. id="dropzone"
  155. role="region"
  156. aria-label="Drag and Drop Container"
  157. >
  158. <div class="absolute w-full h-full backdrop-blur bg-gray-800/40 flex justify-center">
  159. <div class="m-auto pt-64 flex flex-col justify-center">
  160. <div class="max-w-md">
  161. <AddFilesPlaceholder>
  162. <div class=" mt-2 text-center text-sm dark:text-gray-200 w-full">
  163. Drop any files here to add to my documents
  164. </div>
  165. </AddFilesPlaceholder>
  166. </div>
  167. </div>
  168. </div>
  169. </div>
  170. {/if}
  171. {#key selectedDoc}
  172. <EditDocModal bind:show={showEditDocModal} {selectedDoc} />
  173. {/key}
  174. <AddDocModal bind:show={showAddDocModal} {uploadDoc} />
  175. <div class="mb-3">
  176. <div class="flex justify-between items-center">
  177. <div class=" text-lg font-semibold self-center">{$i18n.t('Documents')}</div>
  178. </div>
  179. </div>
  180. <div class=" flex w-full space-x-2">
  181. <div class="flex flex-1">
  182. <div class=" self-center ml-1 mr-3">
  183. <svg
  184. xmlns="http://www.w3.org/2000/svg"
  185. viewBox="0 0 20 20"
  186. fill="currentColor"
  187. class="w-4 h-4"
  188. >
  189. <path
  190. fill-rule="evenodd"
  191. 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"
  192. clip-rule="evenodd"
  193. />
  194. </svg>
  195. </div>
  196. <input
  197. class=" w-full text-sm pr-4 py-1 rounded-r-xl outline-none bg-transparent"
  198. bind:value={query}
  199. placeholder={$i18n.t('Search Documents')}
  200. />
  201. </div>
  202. <div>
  203. <button
  204. 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"
  205. on:click={() => {
  206. showAddDocModal = true;
  207. }}
  208. >
  209. <svg
  210. xmlns="http://www.w3.org/2000/svg"
  211. viewBox="0 0 16 16"
  212. fill="currentColor"
  213. class="w-4 h-4"
  214. >
  215. <path
  216. 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"
  217. />
  218. </svg>
  219. </button>
  220. </div>
  221. </div>
  222. <!-- <div>
  223. <div
  224. class="my-3 py-16 rounded-lg border-2 border-dashed dark:border-gray-600 {dragged &&
  225. ' dark:bg-gray-700'} "
  226. role="region"
  227. on:drop={onDrop}
  228. on:dragover={onDragOver}
  229. on:dragleave={onDragLeave}
  230. >
  231. <div class=" pointer-events-none">
  232. <div class="text-center dark:text-white text-2xl font-semibold z-50">{$i18n.t('Add Files')}</div>
  233. <div class=" mt-2 text-center text-sm dark:text-gray-200 w-full">
  234. Drop any files here to add to my documents
  235. </div>
  236. </div>
  237. </div>
  238. </div> -->
  239. <hr class=" dark:border-gray-850 my-2.5" />
  240. {#if tags.length > 0}
  241. <div class="px-2.5 pt-1 flex gap-1 flex-wrap">
  242. <div class="ml-0.5 pr-3 my-auto flex items-center">
  243. <Checkbox
  244. state={filteredDocs.filter((doc) => doc?.selected === 'checked').length ===
  245. filteredDocs.length
  246. ? 'checked'
  247. : 'unchecked'}
  248. indeterminate={filteredDocs.filter((doc) => doc?.selected === 'checked').length > 0 &&
  249. filteredDocs.filter((doc) => doc?.selected === 'checked').length !== filteredDocs.length}
  250. on:change={(e) => {
  251. if (e.detail === 'checked') {
  252. filteredDocs = filteredDocs.map((doc) => ({ ...doc, selected: 'checked' }));
  253. } else if (e.detail === 'unchecked') {
  254. filteredDocs = filteredDocs.map((doc) => ({ ...doc, selected: 'unchecked' }));
  255. }
  256. }}
  257. />
  258. </div>
  259. {#if filteredDocs.filter((doc) => doc?.selected === 'checked').length === 0}
  260. <button
  261. 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"
  262. on:click={async () => {
  263. selectedTag = '';
  264. // await chats.set(await getChatListByTagName(localStorage.token, tag.name));
  265. }}
  266. >
  267. <div class=" text-xs font-medium self-center line-clamp-1">{$i18n.t('all')}</div>
  268. </button>
  269. {#each tags as tag}
  270. <button
  271. 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"
  272. on:click={async () => {
  273. selectedTag = tag;
  274. // await chats.set(await getChatListByTagName(localStorage.token, tag.name));
  275. }}
  276. >
  277. <div class=" text-xs font-medium self-center line-clamp-1">
  278. #{tag}
  279. </div>
  280. </button>
  281. {/each}
  282. {:else}
  283. <div class="flex-1 flex w-full justify-between items-center">
  284. <div class="text-xs font-medium py-0.5 self-center mr-1">
  285. {filteredDocs.filter((doc) => doc?.selected === 'checked').length} Selected
  286. </div>
  287. <div class="flex gap-1">
  288. <!-- <button
  289. 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"
  290. on:click={async () => {
  291. selectedTag = '';
  292. // await chats.set(await getChatListByTagName(localStorage.token, tag.name));
  293. }}
  294. >
  295. <div class=" text-xs font-medium self-center line-clamp-1">add tags</div>
  296. </button> -->
  297. <button
  298. 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"
  299. on:click={async () => {
  300. deleteDocs(filteredDocs.filter((doc) => doc.selected === 'checked'));
  301. // await chats.set(await getChatListByTagName(localStorage.token, tag.name));
  302. }}
  303. >
  304. <div class=" text-xs font-medium self-center line-clamp-1">
  305. {$i18n.t('delete')}
  306. </div>
  307. </button>
  308. </div>
  309. </div>
  310. {/if}
  311. </div>
  312. {/if}
  313. <div class="my-3 mb-5">
  314. {#each filteredDocs as doc}
  315. <button
  316. 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"
  317. on:click={() => {
  318. if (doc?.selected === 'checked') {
  319. doc.selected = 'unchecked';
  320. } else {
  321. doc.selected = 'checked';
  322. }
  323. }}
  324. >
  325. <div class="my-auto flex items-center">
  326. <Checkbox state={doc?.selected ?? 'unchecked'} />
  327. </div>
  328. <div class=" flex flex-1 space-x-4 cursor-pointer w-full">
  329. <div class=" flex items-center space-x-3">
  330. <div class="p-2.5 bg-red-400 text-white rounded-lg">
  331. {#if doc}
  332. <svg
  333. xmlns="http://www.w3.org/2000/svg"
  334. viewBox="0 0 24 24"
  335. fill="currentColor"
  336. class="w-6 h-6"
  337. >
  338. <path
  339. fill-rule="evenodd"
  340. 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"
  341. clip-rule="evenodd"
  342. />
  343. <path
  344. 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"
  345. />
  346. </svg>
  347. {:else}
  348. <svg
  349. class=" w-6 h-6 translate-y-[0.5px]"
  350. fill="currentColor"
  351. viewBox="0 0 24 24"
  352. xmlns="http://www.w3.org/2000/svg"
  353. ><style>
  354. .spinner_qM83 {
  355. animation: spinner_8HQG 1.05s infinite;
  356. }
  357. .spinner_oXPr {
  358. animation-delay: 0.1s;
  359. }
  360. .spinner_ZTLf {
  361. animation-delay: 0.2s;
  362. }
  363. @keyframes spinner_8HQG {
  364. 0%,
  365. 57.14% {
  366. animation-timing-function: cubic-bezier(0.33, 0.66, 0.66, 1);
  367. transform: translate(0);
  368. }
  369. 28.57% {
  370. animation-timing-function: cubic-bezier(0.33, 0, 0.66, 0.33);
  371. transform: translateY(-6px);
  372. }
  373. 100% {
  374. transform: translate(0);
  375. }
  376. }
  377. </style><circle class="spinner_qM83" cx="4" cy="12" r="2.5" /><circle
  378. class="spinner_qM83 spinner_oXPr"
  379. cx="12"
  380. cy="12"
  381. r="2.5"
  382. /><circle class="spinner_qM83 spinner_ZTLf" cx="20" cy="12" r="2.5" /></svg
  383. >
  384. {/if}
  385. </div>
  386. <div class=" self-center flex-1">
  387. <div class=" font-semibold line-clamp-1">#{doc.name} ({doc.filename})</div>
  388. <div class=" text-xs overflow-hidden text-ellipsis line-clamp-1">
  389. {doc.title}
  390. </div>
  391. </div>
  392. </div>
  393. </div>
  394. <div class="flex flex-row space-x-1 self-center">
  395. <button
  396. 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"
  397. type="button"
  398. on:click={async (e) => {
  399. e.stopPropagation();
  400. showEditDocModal = !showEditDocModal;
  401. selectedDoc = doc;
  402. }}
  403. >
  404. <svg
  405. xmlns="http://www.w3.org/2000/svg"
  406. fill="none"
  407. viewBox="0 0 24 24"
  408. stroke-width="1.5"
  409. stroke="currentColor"
  410. class="w-4 h-4"
  411. >
  412. <path
  413. stroke-linecap="round"
  414. stroke-linejoin="round"
  415. 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"
  416. />
  417. </svg>
  418. </button>
  419. <!-- <button
  420. class="self-center w-fit text-sm px-2 py-2 border dark:border-gray-600 rounded-xl"
  421. type="button"
  422. on:click={() => {
  423. console.log('download file');
  424. }}
  425. >
  426. <svg
  427. xmlns="http://www.w3.org/2000/svg"
  428. viewBox="0 0 16 16"
  429. fill="currentColor"
  430. class="w-4 h-4"
  431. >
  432. <path
  433. 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"
  434. />
  435. <path
  436. 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"
  437. />
  438. </svg>
  439. </button> -->
  440. <button
  441. 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"
  442. type="button"
  443. on:click={(e) => {
  444. e.stopPropagation();
  445. deleteDoc(doc.name);
  446. }}
  447. >
  448. <svg
  449. xmlns="http://www.w3.org/2000/svg"
  450. fill="none"
  451. viewBox="0 0 24 24"
  452. stroke-width="1.5"
  453. stroke="currentColor"
  454. class="w-4 h-4"
  455. >
  456. <path
  457. stroke-linecap="round"
  458. stroke-linejoin="round"
  459. 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"
  460. />
  461. </svg>
  462. </button>
  463. </div>
  464. </button>
  465. {/each}
  466. </div>
  467. <div class=" text-gray-500 text-xs mt-1 mb-2">
  468. ⓘ {$i18n.t("Use '#' in the prompt input to load and select your documents.")}
  469. </div>
  470. <div class=" flex justify-end w-full mb-2">
  471. <div class="flex space-x-2">
  472. <input
  473. id="documents-import-input"
  474. bind:this={documentsImportInputElement}
  475. bind:files={importFiles}
  476. type="file"
  477. accept=".json"
  478. hidden
  479. on:change={() => {
  480. console.log(importFiles);
  481. const reader = new FileReader();
  482. reader.onload = async (event) => {
  483. const savedDocs = JSON.parse(event.target.result);
  484. console.log(savedDocs);
  485. for (const doc of savedDocs) {
  486. await createNewDoc(
  487. localStorage.token,
  488. doc.collection_name,
  489. doc.filename,
  490. doc.name,
  491. doc.title
  492. ).catch((error) => {
  493. toast.error(error);
  494. return null;
  495. });
  496. }
  497. await documents.set(await getDocs(localStorage.token));
  498. };
  499. reader.readAsText(importFiles[0]);
  500. }}
  501. />
  502. <button
  503. 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"
  504. on:click={() => {
  505. documentsImportInputElement.click();
  506. }}
  507. >
  508. <div class=" self-center mr-2 font-medium line-clamp-1">
  509. {$i18n.t('Import Documents Mapping')}
  510. </div>
  511. <div class=" self-center">
  512. <svg
  513. xmlns="http://www.w3.org/2000/svg"
  514. viewBox="0 0 16 16"
  515. fill="currentColor"
  516. class="w-4 h-4"
  517. >
  518. <path
  519. fill-rule="evenodd"
  520. 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"
  521. clip-rule="evenodd"
  522. />
  523. </svg>
  524. </div>
  525. </button>
  526. <button
  527. 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"
  528. on:click={async () => {
  529. let blob = new Blob([JSON.stringify($documents)], {
  530. type: 'application/json'
  531. });
  532. saveAs(blob, `documents-mapping-export-${Date.now()}.json`);
  533. }}
  534. >
  535. <div class=" self-center mr-2 font-medium line-clamp-1">
  536. {$i18n.t('Export Documents Mapping')}
  537. </div>
  538. <div class=" self-center">
  539. <svg
  540. xmlns="http://www.w3.org/2000/svg"
  541. viewBox="0 0 16 16"
  542. fill="currentColor"
  543. class="w-4 h-4"
  544. >
  545. <path
  546. fill-rule="evenodd"
  547. 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"
  548. clip-rule="evenodd"
  549. />
  550. </svg>
  551. </div>
  552. </button>
  553. </div>
  554. </div>