CitationsModal.svelte 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <script lang="ts">
  2. import { getContext, onMount, tick } from 'svelte';
  3. import Modal from '$lib/components/common/Modal.svelte';
  4. import Tooltip from '$lib/components/common/Tooltip.svelte';
  5. const i18n = getContext('i18n');
  6. export let show = false;
  7. export let citation;
  8. let mergedDocuments = [];
  9. $: if (citation) {
  10. mergedDocuments = citation.document?.map((c, i) => {
  11. return {
  12. source: citation.source,
  13. document: c,
  14. metadata: citation.metadata?.[i]
  15. };
  16. });
  17. }
  18. </script>
  19. <Modal size="lg" bind:show>
  20. <div>
  21. <div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-2">
  22. <div class=" text-lg font-medium self-center capitalize">
  23. {$i18n.t('Citation')}
  24. </div>
  25. <button
  26. class="self-center"
  27. on:click={() => {
  28. show = false;
  29. }}
  30. >
  31. <svg
  32. xmlns="http://www.w3.org/2000/svg"
  33. viewBox="0 0 20 20"
  34. fill="currentColor"
  35. class="w-5 h-5"
  36. >
  37. <path
  38. 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"
  39. />
  40. </svg>
  41. </button>
  42. </div>
  43. <div class="flex flex-col md:flex-row w-full px-6 pb-5 md:space-x-4">
  44. <div
  45. class="flex flex-col w-full dark:text-gray-200 overflow-y-scroll max-h-[22rem] scrollbar-hidden"
  46. >
  47. {#each mergedDocuments as document, documentIdx}
  48. <div class="flex flex-col w-full">
  49. <div class="text-sm font-medium dark:text-gray-300">
  50. {$i18n.t('Source')}
  51. </div>
  52. {#if document.source?.name}
  53. <Tooltip
  54. content={$i18n.t('Open file')}
  55. placement="left"
  56. tippyOptions={{ duration: [500, 0], animation: 'perspective' }}
  57. >
  58. <div class="text-sm dark:text-gray-400">
  59. <a
  60. class="hover:text-gray-500 hover:dark:text-gray-100 underline"
  61. href={document?.metadata?.file_id
  62. ? `/api/v1/files/${document?.metadata?.file_id}/content${document?.metadata?.page !== undefined ? `#page=${document.metadata.page + 1}` : ''}`
  63. : document.source.name.includes('http')
  64. ? document.source.name
  65. : `#`}
  66. target="_blank"
  67. >
  68. {document?.metadata?.name ?? document.source.name}
  69. </a>
  70. {document?.metadata?.page
  71. ? `(${$i18n.t('page')} ${document.metadata.page + 1})`
  72. : ''}
  73. </div>
  74. </Tooltip>
  75. {:else}
  76. <div class="text-sm dark:text-gray-400">
  77. {$i18n.t('No source available')}
  78. </div>
  79. {/if}
  80. </div>
  81. <div class="flex flex-col w-full">
  82. <div class=" text-sm font-medium dark:text-gray-300">
  83. {$i18n.t('Content')}
  84. </div>
  85. <pre class="text-sm dark:text-gray-400 whitespace-pre-line">
  86. {document.document}
  87. </pre>
  88. </div>
  89. {#if documentIdx !== mergedDocuments.length - 1}
  90. <hr class=" dark:border-gray-850 my-3" />
  91. {/if}
  92. {/each}
  93. </div>
  94. </div>
  95. </div>
  96. </Modal>