InputMenu.svelte 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <script lang="ts">
  2. import { DropdownMenu } from 'bits-ui';
  3. import { flyAndScale } from '$lib/utils/transitions';
  4. import { getContext } from 'svelte';
  5. import Dropdown from '$lib/components/common/Dropdown.svelte';
  6. import Tooltip from '$lib/components/common/Tooltip.svelte';
  7. import DocumentArrowUpSolid from '$lib/components/icons/DocumentArrowUpSolid.svelte';
  8. import Switch from '$lib/components/common/Switch.svelte';
  9. import GlobeAltSolid from '$lib/components/icons/GlobeAltSolid.svelte';
  10. import { config } from '$lib/stores';
  11. import WrenchSolid from '$lib/components/icons/WrenchSolid.svelte';
  12. const i18n = getContext('i18n');
  13. export let uploadFilesHandler: Function;
  14. export let selectedToolIds: string[] = [];
  15. export let webSearchEnabled: boolean;
  16. export let tools = {};
  17. export let onClose: Function;
  18. let show = false;
  19. </script>
  20. <Dropdown
  21. bind:show
  22. on:change={(e) => {
  23. if (e.detail === false) {
  24. onClose();
  25. }
  26. }}
  27. >
  28. <Tooltip content={$i18n.t('More')}>
  29. <slot />
  30. </Tooltip>
  31. <div slot="content">
  32. <DropdownMenu.Content
  33. class="w-full max-w-[190px] rounded-xl px-1 py-1 border-gray-300/30 dark:border-gray-700/50 z-50 bg-white dark:bg-gray-850 dark:text-white shadow"
  34. sideOffset={15}
  35. alignOffset={-8}
  36. side="top"
  37. align="start"
  38. transition={flyAndScale}
  39. >
  40. {#if Object.keys(tools).length > 0}
  41. {#each Object.keys(tools) as toolId}
  42. <div
  43. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer rounded-xl"
  44. >
  45. <div class="flex-1 flex items-center gap-2">
  46. <WrenchSolid />
  47. <div class="flex items-center">{tools[toolId].name}</div>
  48. </div>
  49. <Switch
  50. bind:state={tools[toolId].enabled}
  51. on:change={(e) => {
  52. selectedToolIds = e.detail
  53. ? [...selectedToolIds, toolId]
  54. : selectedToolIds.filter((id) => id !== toolId);
  55. }}
  56. />
  57. </div>
  58. {/each}
  59. <hr class="border-gray-100 dark:border-gray-800 my-1" />
  60. {/if}
  61. {#if $config?.features?.enable_web_search}
  62. <div
  63. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer rounded-xl"
  64. >
  65. <div class="flex-1 flex items-center gap-2">
  66. <GlobeAltSolid />
  67. <div class="flex items-center">{$i18n.t('Web Search')}</div>
  68. </div>
  69. <Switch bind:state={webSearchEnabled} />
  70. </div>
  71. <hr class="border-gray-100 dark:border-gray-800 my-1" />
  72. {/if}
  73. <DropdownMenu.Item
  74. class="flex gap-2 items-center px-3 py-2 text-sm font-medium cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl"
  75. on:click={() => {
  76. uploadFilesHandler();
  77. }}
  78. >
  79. <DocumentArrowUpSolid />
  80. <div class="flex items-center">{$i18n.t('Upload Files')}</div>
  81. </DropdownMenu.Item>
  82. </DropdownMenu.Content>
  83. </div>
  84. </Dropdown>