@joewinke/jatui 0.1.11 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -0
- package/package.json +2 -1
- package/src/lib/actions/railNav.ts +473 -0
- package/src/lib/components/AnnotationLayer.svelte +108 -0
- package/src/lib/components/AnnotationPanel.svelte +319 -0
- package/src/lib/components/AudioWaveform.svelte +9 -5
- package/src/lib/components/AvailabilityModal.svelte +7 -3
- package/src/lib/components/AvatarUpload.svelte +27 -4
- package/src/lib/components/BookingForm.svelte +11 -9
- package/src/lib/components/BurndownChart.svelte +778 -0
- package/src/lib/components/Button.svelte +10 -1
- package/src/lib/components/CalendarPicker.svelte +3 -3
- package/src/lib/components/Card.svelte +2 -2
- package/src/lib/components/ChipInput.svelte +21 -15
- package/src/lib/components/ColorSelector.svelte +17 -13
- package/src/lib/components/CommentThread.svelte +773 -0
- package/src/lib/components/ConfirmDialog.svelte +348 -0
- package/src/lib/components/ConfirmModal.svelte +78 -11
- package/src/lib/components/ContextMenu.svelte +59 -19
- package/src/lib/components/CountdownTimer.svelte +1 -1
- package/src/lib/components/DateRangePicker.svelte +6 -4
- package/src/lib/components/Drawer.svelte +36 -3
- package/src/lib/components/EntityPreviewCard.svelte +104 -0
- package/src/lib/components/FileDropzone.svelte +493 -0
- package/src/lib/components/FilePicker.svelte +83 -14
- package/src/lib/components/FileThumbnail.svelte +80 -0
- package/src/lib/components/FilterDropdown.svelte +11 -11
- package/src/lib/components/HunkDiffView.svelte +348 -0
- package/src/lib/components/ImageLightbox.svelte +274 -0
- package/src/lib/components/ImageUpload.svelte +58 -9
- package/src/lib/components/InlineEdit.svelte +15 -9
- package/src/lib/components/InputDialog.svelte +327 -0
- package/src/lib/components/LazyImage.svelte +1 -0
- package/src/lib/components/LinkShortener.svelte +1 -1
- package/src/lib/components/LoadingSpinner.svelte +6 -2
- package/src/lib/components/MarkupEditor.svelte +485 -0
- package/src/lib/components/MarkupOverlay.svelte +55 -0
- package/src/lib/components/MediaWorkbench.svelte +871 -0
- package/src/lib/components/MilestoneCard.svelte +1 -1
- package/src/lib/components/MilestoneTimeline.svelte +1 -1
- package/src/lib/components/Modal.svelte +39 -4
- package/src/lib/components/PDFViewer.svelte +105 -0
- package/src/lib/components/PdfThumbnail.svelte +3 -1
- package/src/lib/components/PhoneInput.svelte +1 -1
- package/src/lib/components/ResizablePanel.svelte +4 -4
- package/src/lib/components/SearchDropdown.svelte +26 -13
- package/src/lib/components/SelectInput.svelte +26 -4
- package/src/lib/components/SidebarUserFooter.svelte +1 -1
- package/src/lib/components/SignaturePad.svelte +8 -4
- package/src/lib/components/SmartImageEditor.svelte +720 -0
- package/src/lib/components/SortDropdown.svelte +9 -3
- package/src/lib/components/Sparkline.svelte +9 -0
- package/src/lib/components/StatusBadge.svelte +20 -18
- package/src/lib/components/TextArea.svelte +24 -5
- package/src/lib/components/TextInput.svelte +29 -6
- package/src/lib/components/ThemeSelector.svelte +15 -4
- package/src/lib/components/TimeSlotPicker.svelte +7 -7
- package/src/lib/components/UserAvatar.svelte +14 -1
- package/src/lib/components/VariablePicker.svelte +170 -0
- package/src/lib/components/VoicePlayer.svelte +4 -3
- package/src/lib/components/markup.ts +287 -0
- package/src/lib/components/messaging/ChannelInfoModal.svelte +9 -9
- package/src/lib/components/messaging/ChannelList.svelte +1 -1
- package/src/lib/components/messaging/ChannelMembersModal.svelte +1 -1
- package/src/lib/components/messaging/CreateChannelModal.svelte +1 -1
- package/src/lib/components/messaging/DirectMessageList.svelte +1 -1
- package/src/lib/components/messaging/EmojiSelector.svelte +2 -1
- package/src/lib/components/messaging/MentionAutocomplete.svelte +1 -1
- package/src/lib/components/messaging/MessageAttachment.svelte +3 -3
- package/src/lib/components/messaging/MessageAttachmentUpload.svelte +3 -3
- package/src/lib/components/messaging/MessageInput.svelte +1 -1
- package/src/lib/components/messaging/MessageItem.svelte +6 -3
- package/src/lib/components/messaging/NotificationSettingsModal.svelte +1 -1
- package/src/lib/components/messaging/QuotedMessageDisplay.svelte +6 -1
- package/src/lib/components/messaging/StartDMModal.svelte +1 -1
- package/src/lib/components/pipeline/Pipeline.svelte +4 -4
- package/src/lib/components/pipeline/PipelineCard.svelte +1 -1
- package/src/lib/components/pipeline/PipelineColumn.svelte +8 -3
- package/src/lib/index.ts +91 -0
- package/src/lib/stores/confirmDialog.svelte.ts +48 -0
- package/src/lib/stores/inputDialog.svelte.ts +51 -0
- package/src/lib/styles/rail.css +63 -0
- package/src/lib/types/annotation.ts +38 -0
- package/src/lib/types/comments.ts +97 -0
- package/src/lib/types/entityPreview.ts +45 -0
- package/src/lib/types/filePicker.ts +2 -0
- package/src/lib/types/smartImageEditor.ts +39 -0
- package/src/lib/types/templateVars.ts +36 -0
- package/src/lib/utils/dateFormatters.ts +12 -10
- package/src/lib/utils/taskUtils.ts +21 -7
|
@@ -14,6 +14,18 @@
|
|
|
14
14
|
size?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | 'full';
|
|
15
15
|
showCloseButton?: boolean;
|
|
16
16
|
contentClass?: string;
|
|
17
|
+
/**
|
|
18
|
+
* When true (default), keydown events fired inside the drawer panel are
|
|
19
|
+
* stopped from propagating to window — preventing page-level list/keyboard
|
|
20
|
+
* navigation handlers (listNav-style) from receiving arrow keys, j/k, vim
|
|
21
|
+
* chords, digit counts, etc. while the drawer is open.
|
|
22
|
+
*
|
|
23
|
+
* Free-text fields (INPUT, TEXTAREA, contentEditable) are intentionally
|
|
24
|
+
* excluded so normal typing still works. Set to false only when the
|
|
25
|
+
* consumer needs custom window-level key handling even while the drawer
|
|
26
|
+
* is open.
|
|
27
|
+
*/
|
|
28
|
+
trapKeys?: boolean;
|
|
17
29
|
onclose?: () => void;
|
|
18
30
|
class?: string;
|
|
19
31
|
headerActions?: Snippet;
|
|
@@ -27,6 +39,7 @@
|
|
|
27
39
|
size = 'md',
|
|
28
40
|
showCloseButton = true,
|
|
29
41
|
contentClass = '',
|
|
42
|
+
trapKeys = true,
|
|
30
43
|
onclose,
|
|
31
44
|
class: className = '',
|
|
32
45
|
headerActions,
|
|
@@ -54,14 +67,33 @@
|
|
|
54
67
|
handleClose();
|
|
55
68
|
}
|
|
56
69
|
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Stop keydown events from bubbling to window while the drawer is open.
|
|
73
|
+
* This prevents page-level keyboard navigation (listNav-style handlers on
|
|
74
|
+
* window) from reacting to arrow keys, j/k, vim chords, digit counts, etc.
|
|
75
|
+
* typed inside the drawer.
|
|
76
|
+
*
|
|
77
|
+
* Free-text fields are excluded: page-level handlers already ignore them,
|
|
78
|
+
* and we must not interfere with normal typing or textarea shortcuts.
|
|
79
|
+
*/
|
|
80
|
+
function handlePanelKeydown(e: KeyboardEvent) {
|
|
81
|
+
if (!trapKeys) return;
|
|
82
|
+
const el = document.activeElement as HTMLElement | null;
|
|
83
|
+
const tag = el?.tagName;
|
|
84
|
+
const isTextField =
|
|
85
|
+
!!el && (tag === 'INPUT' || tag === 'TEXTAREA' || el.isContentEditable === true);
|
|
86
|
+
if (!isTextField) e.stopPropagation();
|
|
87
|
+
}
|
|
57
88
|
</script>
|
|
58
89
|
|
|
59
90
|
<svelte:window onkeydown={handleKeydown} />
|
|
60
91
|
|
|
61
92
|
<div
|
|
62
|
-
class="fixed inset-0
|
|
93
|
+
class="fixed inset-0 transition-opacity duration-300 {open
|
|
63
94
|
? 'z-[100] opacity-100'
|
|
64
95
|
: 'opacity-0 pointer-events-none -z-10'}"
|
|
96
|
+
style="background: color-mix(in oklch, var(--color-primary) 55%, transparent)"
|
|
65
97
|
onclick={open ? handleClose : undefined}
|
|
66
98
|
role={open ? 'presentation' : undefined}
|
|
67
99
|
></div>
|
|
@@ -69,16 +101,17 @@
|
|
|
69
101
|
<div
|
|
70
102
|
class="fixed top-0 {position === 'right'
|
|
71
103
|
? 'right-0'
|
|
72
|
-
: 'left-0'} h-full bg-base-
|
|
104
|
+
: 'left-0'} h-full bg-base-200 {position === 'right' ? 'border-l' : 'border-r'} border-base-300 {sizeClasses[size]} flex flex-col transition-all duration-300 {open
|
|
73
105
|
? 'z-[101] translate-x-0'
|
|
74
106
|
: '-z-10 ' + (position === 'right' ? 'translate-x-full' : '-translate-x-full')} {className}"
|
|
75
107
|
role="dialog"
|
|
76
108
|
aria-modal={open}
|
|
77
109
|
aria-label={title}
|
|
78
110
|
aria-hidden={!open}
|
|
111
|
+
onkeydown={handlePanelKeydown}
|
|
79
112
|
>
|
|
80
113
|
{#if title || showCloseButton || headerActions}
|
|
81
|
-
<div class="flex items-center justify-between p-6 border-b border-base-
|
|
114
|
+
<div class="flex items-center justify-between p-6 border-b border-base-content/10 flex-shrink-0">
|
|
82
115
|
{#if title}
|
|
83
116
|
<h2 class="text-xl font-semibold">{title}</h2>
|
|
84
117
|
{/if}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { EntityPreviewData, EntityPreviewBadge } from "../types/entityPreview"
|
|
3
|
+
|
|
4
|
+
let {
|
|
5
|
+
data,
|
|
6
|
+
loading = false,
|
|
7
|
+
error = false,
|
|
8
|
+
}: {
|
|
9
|
+
data: EntityPreviewData | null
|
|
10
|
+
loading?: boolean
|
|
11
|
+
error?: boolean
|
|
12
|
+
} = $props()
|
|
13
|
+
|
|
14
|
+
// First letter monogram fallback when there's no image.
|
|
15
|
+
const monogram = $derived((data?.title ?? "?").trim().charAt(0).toUpperCase() || "?")
|
|
16
|
+
|
|
17
|
+
function toneClass(tone: EntityPreviewBadge["tone"]): string {
|
|
18
|
+
switch (tone) {
|
|
19
|
+
case "primary":
|
|
20
|
+
return "badge-primary"
|
|
21
|
+
case "info":
|
|
22
|
+
return "badge-info"
|
|
23
|
+
case "success":
|
|
24
|
+
return "badge-success"
|
|
25
|
+
case "warning":
|
|
26
|
+
return "badge-warning"
|
|
27
|
+
case "error":
|
|
28
|
+
return "badge-error"
|
|
29
|
+
default:
|
|
30
|
+
return "badge-ghost"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<div
|
|
36
|
+
class="bg-base-100 border-base-content/10 rounded-box w-72 overflow-hidden border text-left"
|
|
37
|
+
>
|
|
38
|
+
{#if loading}
|
|
39
|
+
<div class="space-y-2 p-4">
|
|
40
|
+
<div class="bg-base-300 h-3 w-20 animate-pulse rounded"></div>
|
|
41
|
+
<div class="bg-base-300 h-4 w-40 animate-pulse rounded"></div>
|
|
42
|
+
<div class="bg-base-300 h-3 w-full animate-pulse rounded"></div>
|
|
43
|
+
</div>
|
|
44
|
+
{:else if error || !data}
|
|
45
|
+
<div class="text-base-content/50 p-4 text-sm">Preview unavailable.</div>
|
|
46
|
+
{:else}
|
|
47
|
+
{#if data.imageUrl}
|
|
48
|
+
<div class="bg-base-200 aspect-[16/9] w-full overflow-hidden">
|
|
49
|
+
<img src={data.imageUrl} alt={data.title} class="size-full object-cover" />
|
|
50
|
+
</div>
|
|
51
|
+
{/if}
|
|
52
|
+
|
|
53
|
+
<div class="space-y-2 p-4">
|
|
54
|
+
<div class="flex items-start gap-3">
|
|
55
|
+
{#if !data.imageUrl}
|
|
56
|
+
<div
|
|
57
|
+
class="bg-primary/10 text-primary rounded-box flex size-9 shrink-0 items-center justify-center text-sm font-bold"
|
|
58
|
+
aria-hidden="true"
|
|
59
|
+
>
|
|
60
|
+
{monogram}
|
|
61
|
+
</div>
|
|
62
|
+
{/if}
|
|
63
|
+
<div class="min-w-0 flex-1">
|
|
64
|
+
<div class="text-base-content/45 text-[10px] font-medium uppercase tracking-wide">
|
|
65
|
+
{data.typeLabel}
|
|
66
|
+
</div>
|
|
67
|
+
<div class="truncate text-sm font-semibold leading-tight">
|
|
68
|
+
{#if data.href}
|
|
69
|
+
<a href={data.href} class="hover:underline">{data.title}</a>
|
|
70
|
+
{:else}
|
|
71
|
+
{data.title}
|
|
72
|
+
{/if}
|
|
73
|
+
</div>
|
|
74
|
+
{#if data.subtitle}
|
|
75
|
+
<div class="text-base-content/55 truncate text-xs">{data.subtitle}</div>
|
|
76
|
+
{/if}
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
|
|
80
|
+
{#if data.summary}
|
|
81
|
+
<p class="text-base-content/70 line-clamp-2 text-xs">{data.summary}</p>
|
|
82
|
+
{/if}
|
|
83
|
+
|
|
84
|
+
{#if data.badges && data.badges.length > 0}
|
|
85
|
+
<div class="flex flex-wrap gap-1">
|
|
86
|
+
{#each data.badges as badge}
|
|
87
|
+
<span class="badge {toneClass(badge.tone)} badge-sm capitalize">{badge.label}</span>
|
|
88
|
+
{/each}
|
|
89
|
+
</div>
|
|
90
|
+
{/if}
|
|
91
|
+
|
|
92
|
+
{#if data.stats && data.stats.length > 0}
|
|
93
|
+
<div class="border-base-content/10 grid grid-cols-2 gap-x-4 gap-y-1 border-t pt-2">
|
|
94
|
+
{#each data.stats.slice(0, 4) as stat}
|
|
95
|
+
<div>
|
|
96
|
+
<div class="text-base-content/45 text-[10px] uppercase tracking-wide">{stat.label}</div>
|
|
97
|
+
<div class="text-xs font-semibold tabular-nums">{stat.value}</div>
|
|
98
|
+
</div>
|
|
99
|
+
{/each}
|
|
100
|
+
</div>
|
|
101
|
+
{/if}
|
|
102
|
+
</div>
|
|
103
|
+
{/if}
|
|
104
|
+
</div>
|
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export interface FileDropzoneFile {
|
|
3
|
+
/** The raw File object for pending (pre-upload) files */
|
|
4
|
+
file?: File
|
|
5
|
+
/** Name to display */
|
|
6
|
+
name: string
|
|
7
|
+
/** MIME type */
|
|
8
|
+
mimeType: string
|
|
9
|
+
/** File size in bytes */
|
|
10
|
+
size?: number
|
|
11
|
+
/** URL for already-uploaded files (for FileThumbnail) */
|
|
12
|
+
url?: string
|
|
13
|
+
/** Arbitrary metadata for the consumer */
|
|
14
|
+
meta?: Record<string, unknown>
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import FileThumbnail from "./FileThumbnail.svelte"
|
|
20
|
+
|
|
21
|
+
// Lightweight extension→MIME map (avoids mime-types dependency)
|
|
22
|
+
const EXT_TO_MIME: Record<string, string> = {
|
|
23
|
+
png: "image/png",
|
|
24
|
+
jpg: "image/jpeg",
|
|
25
|
+
jpeg: "image/jpeg",
|
|
26
|
+
gif: "image/gif",
|
|
27
|
+
webp: "image/webp",
|
|
28
|
+
svg: "image/svg+xml",
|
|
29
|
+
avif: "image/avif",
|
|
30
|
+
bmp: "image/bmp",
|
|
31
|
+
ico: "image/x-icon",
|
|
32
|
+
tiff: "image/tiff",
|
|
33
|
+
tif: "image/tiff",
|
|
34
|
+
pdf: "application/pdf",
|
|
35
|
+
zip: "application/zip",
|
|
36
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
37
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
38
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
39
|
+
doc: "application/msword",
|
|
40
|
+
xls: "application/vnd.ms-excel",
|
|
41
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
42
|
+
txt: "text/plain",
|
|
43
|
+
csv: "text/csv",
|
|
44
|
+
mp4: "video/mp4",
|
|
45
|
+
mp3: "audio/mpeg",
|
|
46
|
+
wav: "audio/wav",
|
|
47
|
+
dwg: "image/vnd.dwg",
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const ZIP_TYPES = new Set([
|
|
51
|
+
"application/zip",
|
|
52
|
+
"application/x-zip-compressed",
|
|
53
|
+
"application/x-zip",
|
|
54
|
+
])
|
|
55
|
+
|
|
56
|
+
function extToMime(filename: string): string | false {
|
|
57
|
+
const ext = filename.split(".").pop()?.toLowerCase() ?? ""
|
|
58
|
+
return EXT_TO_MIME[ext] ?? false
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function mimeToExt(mime: string): string | false {
|
|
62
|
+
for (const [ext, m] of Object.entries(EXT_TO_MIME)) {
|
|
63
|
+
if (m === mime) return ext
|
|
64
|
+
}
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface Props {
|
|
69
|
+
/** MIME types to accept, e.g. ["image/png","application/pdf"] */
|
|
70
|
+
accept?: string[]
|
|
71
|
+
/** Max file size in bytes (default 50 MB) */
|
|
72
|
+
maxSize?: number
|
|
73
|
+
/** Max number of files (default 10) */
|
|
74
|
+
maxFiles?: number
|
|
75
|
+
disabled?: boolean
|
|
76
|
+
/** Allow selecting multiple files */
|
|
77
|
+
multiple?: boolean
|
|
78
|
+
/** Already-uploaded files to show in the grid below the dropzone */
|
|
79
|
+
uploadedFiles?: FileDropzoneFile[]
|
|
80
|
+
/** Whether an upload is in flight */
|
|
81
|
+
isUploading?: boolean
|
|
82
|
+
/** Whether a ZIP extraction is in flight */
|
|
83
|
+
isExtracting?: boolean
|
|
84
|
+
/** Label shown in the dropzone (default: "Drop files or folders here") */
|
|
85
|
+
dropLabel?: string
|
|
86
|
+
/** Subtext shown below the label */
|
|
87
|
+
dropSubtext?: string
|
|
88
|
+
/** Called when the user selects or drops files (after validation) */
|
|
89
|
+
onFilesSelected?: (files: File[], errors: string[]) => void
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let {
|
|
93
|
+
accept = [
|
|
94
|
+
"image/png",
|
|
95
|
+
"image/jpeg",
|
|
96
|
+
"application/pdf",
|
|
97
|
+
"application/zip",
|
|
98
|
+
"application/x-zip-compressed",
|
|
99
|
+
],
|
|
100
|
+
maxSize = 50 * 1024 * 1024,
|
|
101
|
+
maxFiles = 10,
|
|
102
|
+
disabled = false,
|
|
103
|
+
multiple = true,
|
|
104
|
+
uploadedFiles = [],
|
|
105
|
+
isUploading = false,
|
|
106
|
+
isExtracting = false,
|
|
107
|
+
dropLabel = "Upload files",
|
|
108
|
+
dropSubtext,
|
|
109
|
+
onFilesSelected,
|
|
110
|
+
}: Props = $props()
|
|
111
|
+
|
|
112
|
+
let isDragOver = $state(false)
|
|
113
|
+
let fileInput = $state<HTMLInputElement>(undefined!)
|
|
114
|
+
let dropzoneRef = $state<HTMLElement>(undefined!)
|
|
115
|
+
let selectedFiles = $state<File[]>([])
|
|
116
|
+
|
|
117
|
+
// Human-readable accepted extensions for display
|
|
118
|
+
const acceptedExtensions = $derived(
|
|
119
|
+
accept
|
|
120
|
+
.map((type) => {
|
|
121
|
+
if (ZIP_TYPES.has(type)) return ".zip"
|
|
122
|
+
const ext = mimeToExt(type)
|
|
123
|
+
return ext ? `.${ext}` : type
|
|
124
|
+
})
|
|
125
|
+
.filter((v, i, a) => a.indexOf(v) === i) // dedupe
|
|
126
|
+
.join(", ")
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
function validateFile(file: File): string | null {
|
|
130
|
+
if (file.type && !accept.includes(file.type)) {
|
|
131
|
+
// Try to infer from extension for files where browser didn't set MIME
|
|
132
|
+
const inferred = extToMime(file.name)
|
|
133
|
+
if (!inferred || !accept.includes(inferred)) {
|
|
134
|
+
return `File type not supported. Accepted: ${acceptedExtensions}`
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (file.size > maxSize) {
|
|
138
|
+
const sizeMB = Math.round(maxSize / (1024 * 1024))
|
|
139
|
+
return `File too large (max ${sizeMB} MB)`
|
|
140
|
+
}
|
|
141
|
+
return null
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function processFiles(files: FileList | File[]): { validFiles: File[]; errors: string[] } {
|
|
145
|
+
const fileArray = Array.from(files)
|
|
146
|
+
const validFiles: File[] = []
|
|
147
|
+
const errors: string[] = []
|
|
148
|
+
|
|
149
|
+
if (fileArray.length > maxFiles) {
|
|
150
|
+
errors.push(`Too many files. Maximum ${maxFiles} files allowed.`)
|
|
151
|
+
return { validFiles: [], errors }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
for (const file of fileArray) {
|
|
155
|
+
const error = validateFile(file)
|
|
156
|
+
if (error) {
|
|
157
|
+
errors.push(`${file.name}: ${error}`)
|
|
158
|
+
} else {
|
|
159
|
+
validFiles.push(file)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return { validFiles, errors }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Recursively read all files from a directory entry
|
|
166
|
+
async function readDirectoryEntries(entry: FileSystemDirectoryEntry): Promise<File[]> {
|
|
167
|
+
const files: File[] = []
|
|
168
|
+
const reader = entry.createReader()
|
|
169
|
+
|
|
170
|
+
const readBatch = (): Promise<FileSystemEntry[]> =>
|
|
171
|
+
new Promise((resolve, reject) => reader.readEntries(resolve, reject))
|
|
172
|
+
|
|
173
|
+
let batch: FileSystemEntry[]
|
|
174
|
+
do {
|
|
175
|
+
batch = await readBatch()
|
|
176
|
+
for (const child of batch) {
|
|
177
|
+
if (child.isFile) {
|
|
178
|
+
const file = await new Promise<File>((resolve, reject) =>
|
|
179
|
+
(child as FileSystemFileEntry).file(resolve, reject),
|
|
180
|
+
)
|
|
181
|
+
files.push(file)
|
|
182
|
+
} else if (child.isDirectory) {
|
|
183
|
+
const subFiles = await readDirectoryEntries(child as FileSystemDirectoryEntry)
|
|
184
|
+
files.push(...subFiles)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
} while (batch.length > 0)
|
|
188
|
+
|
|
189
|
+
return files
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Collect files from DataTransfer items (handles folders)
|
|
193
|
+
async function collectDroppedFiles(dataTransfer: DataTransfer): Promise<File[]> {
|
|
194
|
+
const items = dataTransfer.items
|
|
195
|
+
if (!items || items.length === 0) {
|
|
196
|
+
return Array.from(dataTransfer.files)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const allFiles: File[] = []
|
|
200
|
+
const entries: FileSystemEntry[] = []
|
|
201
|
+
|
|
202
|
+
// Grab entries synchronously — they become invalid after await
|
|
203
|
+
for (let i = 0; i < items.length; i++) {
|
|
204
|
+
const entry = items[i].webkitGetAsEntry?.()
|
|
205
|
+
if (entry) entries.push(entry)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
for (const entry of entries) {
|
|
209
|
+
if (entry.isFile) {
|
|
210
|
+
const file = await new Promise<File>((resolve, reject) =>
|
|
211
|
+
(entry as FileSystemFileEntry).file(resolve, reject),
|
|
212
|
+
)
|
|
213
|
+
allFiles.push(file)
|
|
214
|
+
} else if (entry.isDirectory) {
|
|
215
|
+
const dirFiles = await readDirectoryEntries(entry as FileSystemDirectoryEntry)
|
|
216
|
+
allFiles.push(...dirFiles)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return allFiles
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function handleFileSelect(event: Event) {
|
|
224
|
+
const target = event.target as HTMLInputElement
|
|
225
|
+
if (target.files && target.files.length > 0) {
|
|
226
|
+
const { validFiles, errors } = processFiles(target.files)
|
|
227
|
+
selectedFiles = validFiles
|
|
228
|
+
onFilesSelected?.(validFiles, errors)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function handleDragEnter(event: DragEvent) {
|
|
233
|
+
event.preventDefault()
|
|
234
|
+
isDragOver = true
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function handleDragLeave(event: DragEvent) {
|
|
238
|
+
event.preventDefault()
|
|
239
|
+
if (!dropzoneRef.contains(event.relatedTarget as Node)) {
|
|
240
|
+
isDragOver = false
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function handleDragOver(event: DragEvent) {
|
|
245
|
+
event.preventDefault()
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function handleDrop(event: DragEvent) {
|
|
249
|
+
event.preventDefault()
|
|
250
|
+
isDragOver = false
|
|
251
|
+
|
|
252
|
+
if (disabled || !event.dataTransfer) return
|
|
253
|
+
|
|
254
|
+
const allFiles = await collectDroppedFiles(event.dataTransfer)
|
|
255
|
+
// Filter hidden / macOS artifact files
|
|
256
|
+
const filtered = allFiles.filter(
|
|
257
|
+
(f) => !f.name.startsWith(".") && !f.name.startsWith("__MACOSX"),
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
if (filtered.length > 0) {
|
|
261
|
+
const { validFiles, errors } = processFiles(filtered)
|
|
262
|
+
selectedFiles = validFiles
|
|
263
|
+
onFilesSelected?.(validFiles, errors)
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function openFileDialog() {
|
|
268
|
+
if (!disabled) fileInput.click()
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function formatFileSize(bytes: number): string {
|
|
272
|
+
if (bytes === 0) return "0 B"
|
|
273
|
+
const k = 1024
|
|
274
|
+
const sizes = ["B", "KB", "MB", "GB"]
|
|
275
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
276
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + " " + sizes[i]
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function fileIcon(file: File) {
|
|
280
|
+
if (file.type.startsWith("image/")) return "image"
|
|
281
|
+
if (file.type === "application/pdf") return "pdf"
|
|
282
|
+
if (ZIP_TYPES.has(file.type)) return "zip"
|
|
283
|
+
return "generic"
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Clear selected files when upload completes
|
|
287
|
+
$effect(() => {
|
|
288
|
+
if (!isUploading && uploadedFiles.length > 0) {
|
|
289
|
+
selectedFiles = []
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
</script>
|
|
293
|
+
|
|
294
|
+
<div class="w-full">
|
|
295
|
+
<!-- Hidden file input -->
|
|
296
|
+
<input
|
|
297
|
+
bind:this={fileInput}
|
|
298
|
+
type="file"
|
|
299
|
+
accept={accept.join(",")}
|
|
300
|
+
{multiple}
|
|
301
|
+
{disabled}
|
|
302
|
+
onchange={handleFileSelect}
|
|
303
|
+
class="hidden"
|
|
304
|
+
aria-hidden="true"
|
|
305
|
+
/>
|
|
306
|
+
|
|
307
|
+
<!-- Dropzone -->
|
|
308
|
+
<div
|
|
309
|
+
bind:this={dropzoneRef}
|
|
310
|
+
class="relative border-2 border-dashed rounded-lg p-6 transition-all duration-200 cursor-pointer
|
|
311
|
+
{isDragOver
|
|
312
|
+
? 'border-primary bg-primary/5 scale-[1.02]'
|
|
313
|
+
: disabled
|
|
314
|
+
? 'border-base-300 bg-base-200 cursor-not-allowed'
|
|
315
|
+
: 'border-base-300 hover:border-primary hover:bg-primary/5'}"
|
|
316
|
+
onclick={openFileDialog}
|
|
317
|
+
ondragenter={handleDragEnter}
|
|
318
|
+
ondragleave={handleDragLeave}
|
|
319
|
+
ondragover={handleDragOver}
|
|
320
|
+
ondrop={handleDrop}
|
|
321
|
+
role="button"
|
|
322
|
+
tabindex="0"
|
|
323
|
+
aria-label={dropLabel}
|
|
324
|
+
onkeydown={(e) => {
|
|
325
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
326
|
+
e.preventDefault()
|
|
327
|
+
openFileDialog()
|
|
328
|
+
}
|
|
329
|
+
}}
|
|
330
|
+
>
|
|
331
|
+
<div class="text-center">
|
|
332
|
+
<!-- Upload icon -->
|
|
333
|
+
<svg
|
|
334
|
+
class="mx-auto h-12 w-12 {disabled ? 'text-base-content/40' : 'text-base-content/50'}"
|
|
335
|
+
stroke="currentColor"
|
|
336
|
+
fill="none"
|
|
337
|
+
viewBox="0 0 48 48"
|
|
338
|
+
aria-hidden="true"
|
|
339
|
+
>
|
|
340
|
+
<path
|
|
341
|
+
d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02"
|
|
342
|
+
stroke-width="2"
|
|
343
|
+
stroke-linecap="round"
|
|
344
|
+
stroke-linejoin="round"
|
|
345
|
+
/>
|
|
346
|
+
</svg>
|
|
347
|
+
|
|
348
|
+
<div class="mt-4">
|
|
349
|
+
<p class="text-lg font-medium {disabled ? 'text-base-content/40' : 'text-base-content'}">
|
|
350
|
+
{isDragOver ? "Drop files or folders here" : dropLabel}
|
|
351
|
+
</p>
|
|
352
|
+
<p class="mt-2 text-sm {disabled ? 'text-base-content/40' : 'text-base-content/50'}">
|
|
353
|
+
{#if !disabled}
|
|
354
|
+
{#if dropSubtext}
|
|
355
|
+
{dropSubtext}
|
|
356
|
+
{:else}
|
|
357
|
+
Drag and drop files, folders, or ZIP archives, or
|
|
358
|
+
<span class="font-medium text-primary underline">click to browse</span>
|
|
359
|
+
{/if}
|
|
360
|
+
{:else}
|
|
361
|
+
File upload is disabled
|
|
362
|
+
{/if}
|
|
363
|
+
</p>
|
|
364
|
+
</div>
|
|
365
|
+
|
|
366
|
+
{#if !disabled}
|
|
367
|
+
<div class="mt-4 text-xs text-base-content/50 space-y-1">
|
|
368
|
+
<p>Accepted: {acceptedExtensions}</p>
|
|
369
|
+
<p>Max size: {formatFileSize(maxSize)} · Max files: {maxFiles}</p>
|
|
370
|
+
<p>You can drop a folder or ZIP archive</p>
|
|
371
|
+
</div>
|
|
372
|
+
{/if}
|
|
373
|
+
</div>
|
|
374
|
+
|
|
375
|
+
<!-- Drag overlay -->
|
|
376
|
+
{#if isDragOver}
|
|
377
|
+
<div
|
|
378
|
+
class="absolute inset-0 bg-primary/10 rounded-lg border-2 border-primary border-dashed flex items-center justify-center"
|
|
379
|
+
>
|
|
380
|
+
<div class="text-center">
|
|
381
|
+
<svg
|
|
382
|
+
class="mx-auto h-16 w-16 text-primary"
|
|
383
|
+
fill="none"
|
|
384
|
+
stroke="currentColor"
|
|
385
|
+
viewBox="0 0 24 24"
|
|
386
|
+
aria-hidden="true"
|
|
387
|
+
>
|
|
388
|
+
<path
|
|
389
|
+
stroke-linecap="round"
|
|
390
|
+
stroke-linejoin="round"
|
|
391
|
+
stroke-width="2"
|
|
392
|
+
d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"
|
|
393
|
+
/>
|
|
394
|
+
</svg>
|
|
395
|
+
<p class="mt-2 text-lg font-medium text-primary">Drop files or folders here</p>
|
|
396
|
+
</div>
|
|
397
|
+
</div>
|
|
398
|
+
{/if}
|
|
399
|
+
</div>
|
|
400
|
+
|
|
401
|
+
<!-- Selected Files (before upload) -->
|
|
402
|
+
{#if selectedFiles.length > 0 && !isUploading && uploadedFiles.length === 0}
|
|
403
|
+
<div class="mt-4 space-y-2">
|
|
404
|
+
<h4 class="text-sm font-medium text-base-content/70">
|
|
405
|
+
Selected ({selectedFiles.length})
|
|
406
|
+
</h4>
|
|
407
|
+
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-3">
|
|
408
|
+
{#each selectedFiles as file}
|
|
409
|
+
<div class="flex flex-col items-center p-3 bg-base-200 rounded-lg border border-base-300">
|
|
410
|
+
<div class="w-12 h-12 bg-base-100 rounded border border-base-300 flex items-center justify-center mb-2">
|
|
411
|
+
{#if fileIcon(file) === "image"}
|
|
412
|
+
<svg class="h-6 w-6 text-info" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
413
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
|
414
|
+
</svg>
|
|
415
|
+
{:else if fileIcon(file) === "pdf"}
|
|
416
|
+
<svg class="h-6 w-6 text-error" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
417
|
+
<path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20M10.92,12.31C10.68,11.54 10.15,9.08 11.55,9.04C12.95,9 12.03,12.16 12.03,12.16C12.42,13.65 14.05,14.72 14.05,14.72C14.55,14.57 17.4,14.24 17,15.72C16.57,17.2 13.5,15.81 13.5,15.81C11.55,15.95 10.09,16.47 10.09,16.47C8.96,18.58 7.64,19.5 7.1,18.61C6.43,17.5 9.23,16.07 9.23,16.07C10.68,13.67 10.92,12.31 10.92,12.31Z" />
|
|
418
|
+
</svg>
|
|
419
|
+
{:else if fileIcon(file) === "zip"}
|
|
420
|
+
<svg class="h-6 w-6 text-warning" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
421
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4" />
|
|
422
|
+
</svg>
|
|
423
|
+
{:else}
|
|
424
|
+
<svg class="h-6 w-6 text-base-content/40" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
425
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
|
426
|
+
</svg>
|
|
427
|
+
{/if}
|
|
428
|
+
</div>
|
|
429
|
+
<span class="text-xs text-base-content/60 text-center font-medium truncate w-full" title={file.name}>
|
|
430
|
+
{file.name}
|
|
431
|
+
</span>
|
|
432
|
+
<span class="text-xs text-base-content/50 mt-1">{formatFileSize(file.size)}</span>
|
|
433
|
+
</div>
|
|
434
|
+
{/each}
|
|
435
|
+
</div>
|
|
436
|
+
</div>
|
|
437
|
+
{/if}
|
|
438
|
+
|
|
439
|
+
<!-- Upload / extraction progress -->
|
|
440
|
+
{#if isExtracting}
|
|
441
|
+
<div class="mt-4">
|
|
442
|
+
<div class="flex items-center justify-center p-6 bg-warning/10 rounded-lg border border-warning/30">
|
|
443
|
+
<div class="text-center">
|
|
444
|
+
<span class="loading loading-spinner loading-lg text-warning"></span>
|
|
445
|
+
<p class="mt-3 text-sm font-medium text-warning-content">Extracting ZIP file…</p>
|
|
446
|
+
<p class="text-xs text-warning-content/70">Unpacking and uploading files from archive</p>
|
|
447
|
+
</div>
|
|
448
|
+
</div>
|
|
449
|
+
</div>
|
|
450
|
+
{:else if isUploading}
|
|
451
|
+
<div class="mt-4">
|
|
452
|
+
<div class="flex items-center justify-center p-6 bg-info/10 rounded-lg border border-info/30">
|
|
453
|
+
<div class="text-center">
|
|
454
|
+
<span class="loading loading-spinner loading-lg text-primary"></span>
|
|
455
|
+
<p class="mt-3 text-sm font-medium text-info-content">Uploading files…</p>
|
|
456
|
+
<p class="text-xs text-info-content/70">Please wait while files are uploaded</p>
|
|
457
|
+
</div>
|
|
458
|
+
</div>
|
|
459
|
+
</div>
|
|
460
|
+
{/if}
|
|
461
|
+
|
|
462
|
+
<!-- Uploaded Files (after successful upload) -->
|
|
463
|
+
{#if uploadedFiles.length > 0}
|
|
464
|
+
<div class="mt-4 space-y-2">
|
|
465
|
+
<h4 class="text-sm font-medium text-base-content/70">
|
|
466
|
+
Uploaded ({uploadedFiles.length})
|
|
467
|
+
</h4>
|
|
468
|
+
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-3">
|
|
469
|
+
{#each uploadedFiles as file}
|
|
470
|
+
<div class="flex flex-col items-center p-3 bg-success/10 rounded-lg border border-success/30">
|
|
471
|
+
<FileThumbnail
|
|
472
|
+
name={file.name}
|
|
473
|
+
mimeType={file.mimeType}
|
|
474
|
+
url={file.url}
|
|
475
|
+
size="md"
|
|
476
|
+
/>
|
|
477
|
+
<span class="text-xs text-base-content/60 text-center font-medium truncate w-full mt-2" title={file.name}>
|
|
478
|
+
{file.name}
|
|
479
|
+
</span>
|
|
480
|
+
<span class="text-xs text-success font-medium mt-1">✓ Uploaded</span>
|
|
481
|
+
</div>
|
|
482
|
+
{/each}
|
|
483
|
+
</div>
|
|
484
|
+
</div>
|
|
485
|
+
{/if}
|
|
486
|
+
</div>
|
|
487
|
+
|
|
488
|
+
<style>
|
|
489
|
+
div[role="button"]:focus {
|
|
490
|
+
outline: 2px solid var(--color-primary);
|
|
491
|
+
outline-offset: 2px;
|
|
492
|
+
}
|
|
493
|
+
</style>
|