Documents.svelte 19 KB

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