Documents.svelte 19 KB

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