2024-07-17 09:39:37 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { createEventDispatcher, getContext } from 'svelte';
|
2024-09-28 08:53:25 +00:00
|
|
|
import { formatFileSize } from '$lib/utils';
|
|
|
|
|
|
|
|
|
|
import FileItemModal from './FileItemModal.svelte';
|
2024-10-03 13:45:29 +00:00
|
|
|
import GarbageBin from '../icons/GarbageBin.svelte';
|
2024-10-05 17:18:43 +00:00
|
|
|
import Spinner from './Spinner.svelte';
|
2024-11-30 23:44:04 +00:00
|
|
|
import Tooltip from './Tooltip.svelte';
|
2025-06-25 22:44:45 +00:00
|
|
|
import XMark from '$lib/components/icons/XMark.svelte';
|
2025-07-01 11:15:38 +00:00
|
|
|
import { settings } from '$lib/stores';
|
2024-07-17 09:39:37 +00:00
|
|
|
|
|
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
2024-10-03 13:45:29 +00:00
|
|
|
export let className = 'w-60';
|
2025-09-12 16:31:57 +00:00
|
|
|
export let colorClassName =
|
2025-11-30 08:56:12 +00:00
|
|
|
'bg-white dark:bg-gray-850 border border-gray-50/30 dark:border-gray-800/30';
|
2024-07-17 09:39:37 +00:00
|
|
|
export let url: string | null = null;
|
|
|
|
|
|
2024-07-17 09:53:49 +00:00
|
|
|
export let dismissible = false;
|
2025-07-08 21:29:49 +00:00
|
|
|
export let modal = false;
|
2024-10-05 17:18:43 +00:00
|
|
|
export let loading = false;
|
2024-07-17 09:39:37 +00:00
|
|
|
|
2024-10-04 05:22:22 +00:00
|
|
|
export let item = null;
|
2024-09-29 20:52:27 +00:00
|
|
|
export let edit = false;
|
2024-11-30 23:44:04 +00:00
|
|
|
export let small = false;
|
2024-09-28 08:53:25 +00:00
|
|
|
|
2024-07-17 09:39:37 +00:00
|
|
|
export let name: string;
|
|
|
|
|
export let type: string;
|
2024-08-02 01:46:16 +00:00
|
|
|
export let size: number;
|
|
|
|
|
|
2025-09-12 16:31:57 +00:00
|
|
|
import DocumentPage from '../icons/DocumentPage.svelte';
|
|
|
|
|
import Database from '../icons/Database.svelte';
|
2025-09-14 08:06:02 +00:00
|
|
|
import PageEdit from '../icons/PageEdit.svelte';
|
|
|
|
|
import ChatBubble from '../icons/ChatBubble.svelte';
|
2025-10-05 07:48:08 +00:00
|
|
|
import Folder from '../icons/Folder.svelte';
|
2024-09-28 08:53:25 +00:00
|
|
|
let showModal = false;
|
2025-04-11 22:27:25 +00:00
|
|
|
|
|
|
|
|
const decodeString = (str: string) => {
|
|
|
|
|
try {
|
|
|
|
|
return decodeURIComponent(str);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-07-17 09:39:37 +00:00
|
|
|
</script>
|
|
|
|
|
|
2024-10-04 05:22:22 +00:00
|
|
|
{#if item}
|
|
|
|
|
<FileItemModal bind:show={showModal} bind:item {edit} />
|
2024-09-28 08:53:25 +00:00
|
|
|
{/if}
|
|
|
|
|
|
2024-10-03 13:45:29 +00:00
|
|
|
<button
|
2024-12-01 08:42:14 +00:00
|
|
|
class="relative group p-1.5 {className} flex items-center gap-1 {colorClassName} {small
|
2025-09-12 16:31:57 +00:00
|
|
|
? 'rounded-xl p-2'
|
2024-12-01 08:42:14 +00:00
|
|
|
: 'rounded-2xl'} text-left"
|
2024-10-03 13:45:29 +00:00
|
|
|
type="button"
|
|
|
|
|
on:click={async () => {
|
2025-08-27 22:59:45 +00:00
|
|
|
if (item?.file?.data?.content || item?.type === 'file' || modal) {
|
2024-10-03 13:45:29 +00:00
|
|
|
showModal = !showModal;
|
|
|
|
|
} else {
|
|
|
|
|
if (url) {
|
|
|
|
|
if (type === 'file') {
|
|
|
|
|
window.open(`${url}/content`, '_blank').focus();
|
|
|
|
|
} else {
|
|
|
|
|
window.open(`${url}`, '_blank').focus();
|
2024-09-29 16:33:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-10-03 13:45:29 +00:00
|
|
|
}
|
2024-09-29 16:33:16 +00:00
|
|
|
|
2024-10-03 13:45:29 +00:00
|
|
|
dispatch('click');
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-11-30 23:44:04 +00:00
|
|
|
{#if !small}
|
2025-08-19 19:28:05 +00:00
|
|
|
<div
|
|
|
|
|
class="size-10 shrink-0 flex justify-center items-center bg-black/20 dark:bg-white/10 text-white rounded-xl"
|
|
|
|
|
>
|
2024-11-30 23:44:04 +00:00
|
|
|
{#if !loading}
|
|
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
fill="currentColor"
|
2025-07-01 11:16:18 +00:00
|
|
|
aria-hidden="true"
|
2025-08-19 19:28:05 +00:00
|
|
|
class=" size-4.5"
|
2024-11-30 23:44:04 +00:00
|
|
|
>
|
|
|
|
|
<path
|
|
|
|
|
fill-rule="evenodd"
|
|
|
|
|
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"
|
|
|
|
|
clip-rule="evenodd"
|
|
|
|
|
/>
|
|
|
|
|
<path
|
|
|
|
|
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"
|
|
|
|
|
/>
|
|
|
|
|
</svg>
|
2024-10-03 13:45:29 +00:00
|
|
|
{:else}
|
2024-11-30 23:44:04 +00:00
|
|
|
<Spinner />
|
2024-10-03 13:45:29 +00:00
|
|
|
{/if}
|
2024-07-17 09:39:37 +00:00
|
|
|
</div>
|
2025-09-12 16:31:57 +00:00
|
|
|
{:else}
|
2025-09-14 08:07:21 +00:00
|
|
|
<div class="pl-1.5">
|
2025-09-12 16:31:57 +00:00
|
|
|
{#if !loading}
|
|
|
|
|
<Tooltip
|
2025-09-14 08:06:02 +00:00
|
|
|
content={type === 'collection'
|
|
|
|
|
? $i18n.t('Collection')
|
|
|
|
|
: type === 'note'
|
|
|
|
|
? $i18n.t('Note')
|
|
|
|
|
: type === 'chat'
|
|
|
|
|
? $i18n.t('Chat')
|
|
|
|
|
: type === 'file'
|
|
|
|
|
? $i18n.t('File')
|
|
|
|
|
: $i18n.t('Document')}
|
2025-09-12 16:31:57 +00:00
|
|
|
placement="top"
|
|
|
|
|
>
|
|
|
|
|
{#if type === 'collection'}
|
|
|
|
|
<Database />
|
2025-09-14 08:06:02 +00:00
|
|
|
{:else if type === 'note'}
|
|
|
|
|
<PageEdit />
|
|
|
|
|
{:else if type === 'chat'}
|
|
|
|
|
<ChatBubble />
|
2025-10-05 07:48:08 +00:00
|
|
|
{:else if type === 'folder'}
|
|
|
|
|
<Folder />
|
2025-09-12 16:31:57 +00:00
|
|
|
{:else}
|
|
|
|
|
<DocumentPage />
|
|
|
|
|
{/if}
|
|
|
|
|
</Tooltip>
|
|
|
|
|
{:else}
|
|
|
|
|
<Spinner />
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2024-11-30 23:44:04 +00:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if !small}
|
|
|
|
|
<div class="flex flex-col justify-center -space-y-0.5 px-2.5 w-full">
|
|
|
|
|
<div class=" dark:text-gray-100 text-sm font-medium line-clamp-1 mb-1">
|
2025-04-11 22:27:25 +00:00
|
|
|
{decodeString(name)}
|
2024-11-30 23:44:04 +00:00
|
|
|
</div>
|
|
|
|
|
|
2025-07-01 11:15:38 +00:00
|
|
|
<div
|
|
|
|
|
class=" flex justify-between text-xs line-clamp-1 {($settings?.highContrastMode ?? false)
|
|
|
|
|
? 'text-gray-800 dark:text-gray-100'
|
|
|
|
|
: 'text-gray-500'}"
|
|
|
|
|
>
|
2024-11-30 23:44:04 +00:00
|
|
|
{#if type === 'file'}
|
|
|
|
|
{$i18n.t('File')}
|
2025-09-14 08:06:02 +00:00
|
|
|
{:else if type === 'note'}
|
|
|
|
|
{$i18n.t('Note')}
|
2024-11-30 23:44:04 +00:00
|
|
|
{:else if type === 'doc'}
|
|
|
|
|
{$i18n.t('Document')}
|
|
|
|
|
{:else if type === 'collection'}
|
|
|
|
|
{$i18n.t('Collection')}
|
|
|
|
|
{:else}
|
|
|
|
|
<span class=" capitalize line-clamp-1">{type}</span>
|
|
|
|
|
{/if}
|
|
|
|
|
{#if size}
|
|
|
|
|
<span class="capitalize">{formatFileSize(size)}</span>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
2025-04-11 22:27:25 +00:00
|
|
|
<Tooltip content={decodeString(name)} className="flex flex-col w-full" placement="top-start">
|
2025-09-12 16:31:57 +00:00
|
|
|
<div class="flex flex-col justify-center -space-y-0.5 px-1 w-full">
|
2024-11-30 23:44:04 +00:00
|
|
|
<div class=" dark:text-gray-100 text-sm flex justify-between items-center">
|
2025-09-12 16:35:14 +00:00
|
|
|
<div class="font-medium line-clamp-1 flex-1 pr-1">{decodeString(name)}</div>
|
2025-09-12 16:31:57 +00:00
|
|
|
{#if size}
|
|
|
|
|
<div class="text-gray-500 text-xs capitalize shrink-0">{formatFileSize(size)}</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="text-gray-500 text-xs capitalize shrink-0">{type}</div>
|
|
|
|
|
{/if}
|
2024-11-30 23:44:04 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
{/if}
|
2024-07-17 09:39:37 +00:00
|
|
|
|
|
|
|
|
{#if dismissible}
|
2024-10-04 04:34:53 +00:00
|
|
|
<div class=" absolute -top-1 -right-1">
|
2024-07-17 09:39:37 +00:00
|
|
|
<button
|
2025-07-01 11:21:40 +00:00
|
|
|
aria-label={$i18n.t('Remove File')}
|
2025-07-01 11:15:38 +00:00
|
|
|
class=" bg-white text-black border border-gray-50 rounded-full {($settings?.highContrastMode ??
|
|
|
|
|
false)
|
|
|
|
|
? ''
|
|
|
|
|
: 'outline-hidden focus:outline-hidden group-hover:visible invisible transition'}"
|
2024-07-17 09:39:37 +00:00
|
|
|
type="button"
|
2024-10-04 04:12:35 +00:00
|
|
|
on:click|stopPropagation={() => {
|
2024-07-17 09:39:37 +00:00
|
|
|
dispatch('dismiss');
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-06-27 11:44:26 +00:00
|
|
|
<XMark className={'size-4'} />
|
2024-07-17 09:39:37 +00:00
|
|
|
</button>
|
2024-10-04 04:10:33 +00:00
|
|
|
|
|
|
|
|
<!-- <button
|
|
|
|
|
class=" p-1 dark:text-gray-300 dark:hover:text-white hover:bg-black/5 dark:hover:bg-white/5 rounded-full group-hover:visible invisible transition"
|
|
|
|
|
type="button"
|
|
|
|
|
on:click={() => {
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<GarbageBin />
|
|
|
|
|
</button> -->
|
2024-07-17 09:39:37 +00:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
2024-10-03 13:45:29 +00:00
|
|
|
</button>
|