ToolMenu.svelte 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 GarbageBin from '$lib/components/icons/GarbageBin.svelte';
  7. import Pencil from '$lib/components/icons/Pencil.svelte';
  8. import Tooltip from '$lib/components/common/Tooltip.svelte';
  9. import Tags from '$lib/components/chat/Tags.svelte';
  10. import Share from '$lib/components/icons/Share.svelte';
  11. import ArchiveBox from '$lib/components/icons/ArchiveBox.svelte';
  12. import DocumentDuplicate from '$lib/components/icons/DocumentDuplicate.svelte';
  13. import ArrowDownTray from '$lib/components/icons/ArrowDownTray.svelte';
  14. import { config } from '$lib/stores';
  15. const i18n = getContext('i18n');
  16. export let editHandler: Function;
  17. export let shareHandler: Function;
  18. export let cloneHandler: Function;
  19. export let exportHandler: Function;
  20. export let deleteHandler: Function;
  21. export let onClose: Function;
  22. let show = false;
  23. </script>
  24. <Dropdown
  25. bind:show
  26. on:change={(e) => {
  27. if (e.detail === false) {
  28. onClose();
  29. }
  30. }}
  31. >
  32. <Tooltip content={$i18n.t('More')}>
  33. <slot />
  34. </Tooltip>
  35. <div slot="content">
  36. <DropdownMenu.Content
  37. class="w-full max-w-[160px] rounded-xl px-1 py-1.5 border border-gray-300/30 dark:border-gray-700/50 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-sm"
  38. sideOffset={-2}
  39. side="bottom"
  40. align="start"
  41. transition={flyAndScale}
  42. >
  43. <DropdownMenu.Item
  44. 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-md"
  45. on:click={() => {
  46. editHandler();
  47. }}
  48. >
  49. <svg
  50. xmlns="http://www.w3.org/2000/svg"
  51. fill="none"
  52. viewBox="0 0 24 24"
  53. stroke-width="1.5"
  54. stroke="currentColor"
  55. class="w-4 h-4"
  56. >
  57. <path
  58. stroke-linecap="round"
  59. stroke-linejoin="round"
  60. 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"
  61. />
  62. </svg>
  63. <div class="flex items-center">{$i18n.t('Edit')}</div>
  64. </DropdownMenu.Item>
  65. {#if $config.features.enable_community_sharing}
  66. <DropdownMenu.Item
  67. 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-md"
  68. on:click={() => {
  69. shareHandler();
  70. }}
  71. >
  72. <Share />
  73. <div class="flex items-center">{$i18n.t('Share')}</div>
  74. </DropdownMenu.Item>
  75. {/if}
  76. <DropdownMenu.Item
  77. 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-md"
  78. on:click={() => {
  79. cloneHandler();
  80. }}
  81. >
  82. <DocumentDuplicate />
  83. <div class="flex items-center">{$i18n.t('Clone')}</div>
  84. </DropdownMenu.Item>
  85. <DropdownMenu.Item
  86. 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-md"
  87. on:click={() => {
  88. exportHandler();
  89. }}
  90. >
  91. <ArrowDownTray />
  92. <div class="flex items-center">{$i18n.t('Export')}</div>
  93. </DropdownMenu.Item>
  94. <hr class="border-gray-100 dark:border-gray-850 my-1" />
  95. <DropdownMenu.Item
  96. 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-md"
  97. on:click={() => {
  98. deleteHandler();
  99. }}
  100. >
  101. <GarbageBin strokeWidth="2" />
  102. <div class="flex items-center">{$i18n.t('Delete')}</div>
  103. </DropdownMenu.Item>
  104. </DropdownMenu.Content>
  105. </div>
  106. </Dropdown>