Knowledge.svelte 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <script lang="ts">
  2. import { getContext } from 'svelte';
  3. import Selector from './Knowledge/Selector.svelte';
  4. export let knowledge = [];
  5. const i18n = getContext('i18n');
  6. </script>
  7. <div>
  8. <div class="flex w-full justify-between mb-1">
  9. <div class=" self-center text-sm font-semibold">{$i18n.t('Knowledge')}</div>
  10. </div>
  11. <div class=" text-xs dark:text-gray-500">
  12. To add documents here, upload them to the "Documents" workspace first.
  13. </div>
  14. <div class="flex flex-col">
  15. {#if knowledge.length > 0}
  16. <div class=" flex items-center gap-2 mt-2">
  17. {#each knowledge as file, fileIdx}
  18. <div class=" relative group">
  19. <div
  20. class="h-16 w-[15rem] flex items-center space-x-3 px-2.5 dark:bg-gray-600 rounded-xl border border-gray-200 dark:border-none"
  21. >
  22. <div class="p-2.5 bg-red-400 text-white rounded-lg">
  23. {#if (file?.type ?? 'doc') === 'doc'}
  24. <svg
  25. xmlns="http://www.w3.org/2000/svg"
  26. viewBox="0 0 24 24"
  27. fill="currentColor"
  28. class="size-6"
  29. >
  30. <path
  31. fill-rule="evenodd"
  32. 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"
  33. clip-rule="evenodd"
  34. />
  35. <path
  36. 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"
  37. />
  38. </svg>
  39. {:else if file.type === 'collection'}
  40. <svg
  41. xmlns="http://www.w3.org/2000/svg"
  42. viewBox="0 0 24 24"
  43. fill="currentColor"
  44. class="size-6"
  45. >
  46. <path
  47. d="M7.5 3.375c0-1.036.84-1.875 1.875-1.875h.375a3.75 3.75 0 0 1 3.75 3.75v1.875C13.5 8.161 14.34 9 15.375 9h1.875A3.75 3.75 0 0 1 21 12.75v3.375C21 17.16 20.16 18 19.125 18h-9.75A1.875 1.875 0 0 1 7.5 16.125V3.375Z"
  48. />
  49. <path
  50. d="M15 5.25a5.23 5.23 0 0 0-1.279-3.434 9.768 9.768 0 0 1 6.963 6.963A5.23 5.23 0 0 0 17.25 7.5h-1.875A.375.375 0 0 1 15 7.125V5.25ZM4.875 6H6v10.125A3.375 3.375 0 0 0 9.375 19.5H16.5v1.125c0 1.035-.84 1.875-1.875 1.875h-9.75A1.875 1.875 0 0 1 3 20.625V7.875C3 6.839 3.84 6 4.875 6Z"
  51. />
  52. </svg>
  53. {/if}
  54. </div>
  55. <div class="flex flex-col justify-center -space-y-0.5">
  56. <div class=" dark:text-gray-100 text-sm font-medium line-clamp-1">
  57. {file?.title ?? `#${file.name}`}
  58. </div>
  59. <div class=" text-gray-500 text-sm">{$i18n.t(file?.type ?? 'Document')}</div>
  60. </div>
  61. </div>
  62. <div class=" absolute -top-1 -right-1">
  63. <button
  64. class=" bg-gray-400 text-white border border-white rounded-full group-hover:visible invisible transition"
  65. type="button"
  66. on:click={() => {
  67. knowledge.splice(fileIdx, 1);
  68. knowledge = knowledge;
  69. }}
  70. >
  71. <svg
  72. xmlns="http://www.w3.org/2000/svg"
  73. viewBox="0 0 20 20"
  74. fill="currentColor"
  75. class="w-4 h-4"
  76. >
  77. <path
  78. 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"
  79. />
  80. </svg>
  81. </button>
  82. </div>
  83. </div>
  84. {/each}
  85. </div>
  86. {/if}
  87. <div class="flex flex-wrap text-sm font-medium gap-1.5 mt-2">
  88. <Selector bind:knowledge>
  89. <button
  90. class=" px-3.5 py-1.5 font-medium hover:bg-black/5 dark:hover:bg-white/5 outline outline-1 outline-gray-300 dark:outline-gray-800 rounded-3xl"
  91. type="button">Select Documents</button
  92. >
  93. </Selector>
  94. </div>
  95. <!-- {knowledge} -->
  96. </div>
  97. </div>