@myrialabs/clopen 0.2.16 → 0.2.18
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/.env.example +4 -4
- package/backend/utils/env.ts +5 -5
- package/bin/clopen.ts +21 -298
- package/dist/assets/addon-clipboard-wHJhZAA4.js +1 -0
- package/dist/assets/addon-fit-DX4qG4td.js +1 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js +2 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js +7 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js +1 -0
- package/dist/assets/index-C-eR9PGW.js +2 -0
- package/dist/assets/main-D1IISCsM.js +247 -0
- package/dist/assets/main-DzSwlujO.css +1 -0
- package/dist/assets/xterm-B-qIQCd3.js +16 -0
- package/{index.html → dist/index.html} +2 -1
- package/package.json +12 -2
- package/scripts/start.ts +3 -3
- package/shared/utils/logger.ts +1 -1
- package/.dockerignore +0 -5
- package/.github/workflows/ci.yml +0 -86
- package/CONTRIBUTING.md +0 -188
- package/bun.lock +0 -1127
- package/docker-compose.yml +0 -31
- package/frontend/App.svelte +0 -77
- package/frontend/app-environment.ts +0 -10
- package/frontend/app.css +0 -313
- package/frontend/components/auth/InvitePage.svelte +0 -215
- package/frontend/components/auth/LoginPage.svelte +0 -129
- package/frontend/components/auth/SetupPage.svelte +0 -1054
- package/frontend/components/chat/ChatInterface.svelte +0 -426
- package/frontend/components/chat/formatters/ErrorMessage.svelte +0 -57
- package/frontend/components/chat/formatters/MessageFormatter.svelte +0 -244
- package/frontend/components/chat/formatters/TextMessage.svelte +0 -383
- package/frontend/components/chat/formatters/Tools.svelte +0 -79
- package/frontend/components/chat/formatters/index.ts +0 -3
- package/frontend/components/chat/input/ChatInput.svelte +0 -492
- package/frontend/components/chat/input/components/ChatInputActions.svelte +0 -88
- package/frontend/components/chat/input/components/DragDropOverlay.svelte +0 -30
- package/frontend/components/chat/input/components/EditModeIndicator.svelte +0 -33
- package/frontend/components/chat/input/components/EngineModelPicker.svelte +0 -642
- package/frontend/components/chat/input/components/FileAttachmentPreview.svelte +0 -48
- package/frontend/components/chat/input/components/LoadingIndicator.svelte +0 -43
- package/frontend/components/chat/input/composables/use-animations.svelte.ts +0 -217
- package/frontend/components/chat/input/composables/use-chat-actions.svelte.ts +0 -152
- package/frontend/components/chat/input/composables/use-file-handling.svelte.ts +0 -216
- package/frontend/components/chat/input/composables/use-input-state.svelte.ts +0 -357
- package/frontend/components/chat/input/composables/use-textarea-resize.svelte.ts +0 -69
- package/frontend/components/chat/message/ChatMessage.svelte +0 -509
- package/frontend/components/chat/message/ChatMessages.svelte +0 -553
- package/frontend/components/chat/message/DateSeparator.svelte +0 -86
- package/frontend/components/chat/message/MessageBubble.svelte +0 -114
- package/frontend/components/chat/message/MessageHeader.svelte +0 -143
- package/frontend/components/chat/modal/DebugModal.svelte +0 -59
- package/frontend/components/chat/shared/index.ts +0 -2
- package/frontend/components/chat/shared/utils.ts +0 -116
- package/frontend/components/chat/tools/AgentTool.svelte +0 -96
- package/frontend/components/chat/tools/AskUserQuestionTool.svelte +0 -391
- package/frontend/components/chat/tools/BashOutputTool.svelte +0 -35
- package/frontend/components/chat/tools/BashTool.svelte +0 -51
- package/frontend/components/chat/tools/CustomMcpTool.svelte +0 -141
- package/frontend/components/chat/tools/EditTool.svelte +0 -48
- package/frontend/components/chat/tools/EnterPlanModeTool.svelte +0 -24
- package/frontend/components/chat/tools/ExitPlanModeTool.svelte +0 -29
- package/frontend/components/chat/tools/GlobTool.svelte +0 -51
- package/frontend/components/chat/tools/GrepTool.svelte +0 -90
- package/frontend/components/chat/tools/ListMcpResourcesTool.svelte +0 -31
- package/frontend/components/chat/tools/NotebookEditTool.svelte +0 -38
- package/frontend/components/chat/tools/ReadMcpResourceTool.svelte +0 -34
- package/frontend/components/chat/tools/ReadTool.svelte +0 -41
- package/frontend/components/chat/tools/SkillTool.svelte +0 -21
- package/frontend/components/chat/tools/TaskStopTool.svelte +0 -26
- package/frontend/components/chat/tools/TaskTool.svelte +0 -64
- package/frontend/components/chat/tools/TodoWriteTool.svelte +0 -75
- package/frontend/components/chat/tools/WebFetchTool.svelte +0 -35
- package/frontend/components/chat/tools/WebSearchTool.svelte +0 -84
- package/frontend/components/chat/tools/WriteTool.svelte +0 -33
- package/frontend/components/chat/tools/components/CodeBlock.svelte +0 -79
- package/frontend/components/chat/tools/components/DiffBlock.svelte +0 -408
- package/frontend/components/chat/tools/components/FileHeader.svelte +0 -59
- package/frontend/components/chat/tools/components/InfoLine.svelte +0 -19
- package/frontend/components/chat/tools/components/StatsBadges.svelte +0 -27
- package/frontend/components/chat/tools/components/TerminalCommand.svelte +0 -61
- package/frontend/components/chat/tools/components/index.ts +0 -7
- package/frontend/components/chat/tools/index.ts +0 -30
- package/frontend/components/chat/widgets/ContextIndicator.svelte +0 -186
- package/frontend/components/chat/widgets/FloatingTodoList.svelte +0 -367
- package/frontend/components/checkpoint/ConflictResolutionModal.svelte +0 -189
- package/frontend/components/checkpoint/TimelineModal.svelte +0 -447
- package/frontend/components/checkpoint/timeline/TimelineEdge.svelte +0 -26
- package/frontend/components/checkpoint/timeline/TimelineGraph.svelte +0 -87
- package/frontend/components/checkpoint/timeline/TimelineNode.svelte +0 -119
- package/frontend/components/checkpoint/timeline/TimelineVersionGroup.svelte +0 -59
- package/frontend/components/checkpoint/timeline/animation.ts +0 -168
- package/frontend/components/checkpoint/timeline/config.ts +0 -44
- package/frontend/components/checkpoint/timeline/graph-builder.ts +0 -304
- package/frontend/components/checkpoint/timeline/types.ts +0 -69
- package/frontend/components/checkpoint/timeline/utils.ts +0 -53
- package/frontend/components/common/display/AvatarBubble.svelte +0 -56
- package/frontend/components/common/display/Button.svelte +0 -71
- package/frontend/components/common/display/Card.svelte +0 -102
- package/frontend/components/common/display/Icon.svelte +0 -58
- package/frontend/components/common/display/PageTemplate.svelte +0 -76
- package/frontend/components/common/display/ProjectUserAvatars.svelte +0 -79
- package/frontend/components/common/display/ThemeToggle.svelte +0 -44
- package/frontend/components/common/editor/MonacoEditor.svelte +0 -583
- package/frontend/components/common/feedback/Alert.svelte +0 -139
- package/frontend/components/common/feedback/ConnectionBanner.svelte +0 -55
- package/frontend/components/common/feedback/LoadingScreen.svelte +0 -52
- package/frontend/components/common/feedback/LoadingSpinner.svelte +0 -48
- package/frontend/components/common/feedback/NotificationToast.svelte +0 -128
- package/frontend/components/common/feedback/RestartRequiredModal.svelte +0 -53
- package/frontend/components/common/feedback/UpdateBanner.svelte +0 -99
- package/frontend/components/common/form/Checkbox.svelte +0 -48
- package/frontend/components/common/form/FolderBrowser.svelte +0 -856
- package/frontend/components/common/form/Input.svelte +0 -72
- package/frontend/components/common/form/ModelSelector.svelte +0 -110
- package/frontend/components/common/form/Select.svelte +0 -98
- package/frontend/components/common/form/Textarea.svelte +0 -80
- package/frontend/components/common/lucide-icons.ts +0 -1642
- package/frontend/components/common/material-icons.ts +0 -1082
- package/frontend/components/common/media/MediaPreview.svelte +0 -187
- package/frontend/components/common/overlay/Dialog.svelte +0 -251
- package/frontend/components/common/overlay/Lightbox.svelte +0 -233
- package/frontend/components/common/overlay/Modal.svelte +0 -177
- package/frontend/components/common/overlay/ModalProvider.svelte +0 -28
- package/frontend/components/common/xterm/XTerm.svelte +0 -743
- package/frontend/components/common/xterm/index.ts +0 -16
- package/frontend/components/common/xterm/terminal-config.ts +0 -68
- package/frontend/components/common/xterm/types.ts +0 -32
- package/frontend/components/common/xterm/xterm-service.ts +0 -437
- package/frontend/components/files/FileNode.svelte +0 -327
- package/frontend/components/files/FileTree.svelte +0 -690
- package/frontend/components/files/FileViewer.svelte +0 -551
- package/frontend/components/files/SearchResults.svelte +0 -303
- package/frontend/components/git/BranchManager.svelte +0 -446
- package/frontend/components/git/ChangesSection.svelte +0 -196
- package/frontend/components/git/CommitForm.svelte +0 -128
- package/frontend/components/git/ConflictResolver.svelte +0 -158
- package/frontend/components/git/DiffViewer.svelte +0 -298
- package/frontend/components/git/FileChangeItem.svelte +0 -119
- package/frontend/components/git/GitButton.svelte +0 -33
- package/frontend/components/git/GitLog.svelte +0 -401
- package/frontend/components/git/GitModal.svelte +0 -80
- package/frontend/components/history/HistoryModal.svelte +0 -602
- package/frontend/components/history/HistoryView.svelte +0 -561
- package/frontend/components/index.ts +0 -34
- package/frontend/components/preview/browser/BrowserPreview.svelte +0 -558
- package/frontend/components/preview/browser/components/Canvas.svelte +0 -1523
- package/frontend/components/preview/browser/components/ConsolePanel.svelte +0 -757
- package/frontend/components/preview/browser/components/Container.svelte +0 -507
- package/frontend/components/preview/browser/components/ContextMenu.svelte +0 -236
- package/frontend/components/preview/browser/components/SelectDropdown.svelte +0 -224
- package/frontend/components/preview/browser/components/Toolbar.svelte +0 -358
- package/frontend/components/preview/browser/components/VirtualCursor.svelte +0 -36
- package/frontend/components/preview/browser/core/cleanup.svelte.ts +0 -155
- package/frontend/components/preview/browser/core/coordinator.svelte.ts +0 -885
- package/frontend/components/preview/browser/core/interactions.svelte.ts +0 -113
- package/frontend/components/preview/browser/core/mcp-handlers.svelte.ts +0 -331
- package/frontend/components/preview/browser/core/native-ui-handlers.svelte.ts +0 -391
- package/frontend/components/preview/browser/core/stream-handler.svelte.ts +0 -288
- package/frontend/components/preview/browser/core/tab-manager.svelte.ts +0 -210
- package/frontend/components/preview/browser/core/tab-operations.svelte.ts +0 -241
- package/frontend/components/preview/index.ts +0 -2
- package/frontend/components/settings/SettingsModal.svelte +0 -268
- package/frontend/components/settings/SettingsView.svelte +0 -54
- package/frontend/components/settings/account/AccountSettings.svelte +0 -5
- package/frontend/components/settings/admin/InviteManagement.svelte +0 -239
- package/frontend/components/settings/admin/UserManagement.svelte +0 -127
- package/frontend/components/settings/appearance/AppearanceSettings.svelte +0 -104
- package/frontend/components/settings/appearance/LayoutPresetSettings.svelte +0 -160
- package/frontend/components/settings/appearance/LayoutPreview.svelte +0 -76
- package/frontend/components/settings/engines/AIEnginesSettings.svelte +0 -917
- package/frontend/components/settings/general/AdvancedSettings.svelte +0 -193
- package/frontend/components/settings/general/AuthModeSettings.svelte +0 -229
- package/frontend/components/settings/general/DataManagementSettings.svelte +0 -89
- package/frontend/components/settings/general/GeneralSettings.svelte +0 -20
- package/frontend/components/settings/general/UpdateSettings.svelte +0 -130
- package/frontend/components/settings/git/GitSettings.svelte +0 -392
- package/frontend/components/settings/model/EngineModelPicker.svelte +0 -284
- package/frontend/components/settings/model/ModelSettings.svelte +0 -240
- package/frontend/components/settings/notifications/NotificationSettings.svelte +0 -205
- package/frontend/components/settings/security/SecuritySettings.svelte +0 -10
- package/frontend/components/settings/system/SystemSettings.svelte +0 -10
- package/frontend/components/settings/tunnel/TunnelSettings.svelte +0 -1060
- package/frontend/components/settings/user/UserSettings.svelte +0 -270
- package/frontend/components/terminal/Terminal.svelte +0 -338
- package/frontend/components/terminal/TerminalTabs.svelte +0 -88
- package/frontend/components/terminal/TerminalView.svelte +0 -55
- package/frontend/components/tunnel/TunnelActive.svelte +0 -218
- package/frontend/components/tunnel/TunnelButton.svelte +0 -60
- package/frontend/components/tunnel/TunnelInactive.svelte +0 -260
- package/frontend/components/tunnel/TunnelModal.svelte +0 -101
- package/frontend/components/tunnel/TunnelQRCode.svelte +0 -49
- package/frontend/components/workspace/DesktopNavigator.svelte +0 -445
- package/frontend/components/workspace/MobileNavigator.svelte +0 -427
- package/frontend/components/workspace/PanelContainer.svelte +0 -100
- package/frontend/components/workspace/PanelHeader.svelte +0 -664
- package/frontend/components/workspace/ViewMenu.svelte +0 -146
- package/frontend/components/workspace/WorkspaceLayout.svelte +0 -199
- package/frontend/components/workspace/layout/DesktopLayout.svelte +0 -15
- package/frontend/components/workspace/layout/MobileLayout.svelte +0 -17
- package/frontend/components/workspace/layout/split-pane/Container.svelte +0 -42
- package/frontend/components/workspace/layout/split-pane/Handle.svelte +0 -85
- package/frontend/components/workspace/layout/split-pane/Layout.svelte +0 -62
- package/frontend/components/workspace/panels/ChatPanel.svelte +0 -282
- package/frontend/components/workspace/panels/FilesPanel.svelte +0 -1376
- package/frontend/components/workspace/panels/GitPanel.svelte +0 -1601
- package/frontend/components/workspace/panels/PreviewPanel.svelte +0 -153
- package/frontend/components/workspace/panels/TerminalPanel.svelte +0 -73
- package/frontend/main.ts +0 -17
- package/frontend/services/chat/chat.service.ts +0 -975
- package/frontend/services/chat/index.ts +0 -7
- package/frontend/services/favicon.service.ts +0 -103
- package/frontend/services/notification/global-stream-monitor.ts +0 -120
- package/frontend/services/notification/index.ts +0 -8
- package/frontend/services/notification/push.service.ts +0 -144
- package/frontend/services/notification/sound.service.ts +0 -127
- package/frontend/services/preview/browser/browser-console.service.ts +0 -61
- package/frontend/services/preview/browser/browser-webcodecs.service.ts +0 -1643
- package/frontend/services/preview/browser/mcp-integration.svelte.ts +0 -67
- package/frontend/services/preview/index.ts +0 -23
- package/frontend/services/project/index.ts +0 -8
- package/frontend/services/project/status.service.ts +0 -170
- package/frontend/services/snapshot/snapshot.service.ts +0 -86
- package/frontend/services/terminal/background/index.ts +0 -130
- package/frontend/services/terminal/background/session-restore.ts +0 -274
- package/frontend/services/terminal/background/stream-manager.ts +0 -286
- package/frontend/services/terminal/index.ts +0 -14
- package/frontend/services/terminal/persistence.service.ts +0 -260
- package/frontend/services/terminal/project.service.ts +0 -1004
- package/frontend/services/terminal/session.service.ts +0 -364
- package/frontend/services/terminal/terminal.service.ts +0 -379
- package/frontend/stores/core/app.svelte.ts +0 -296
- package/frontend/stores/core/files.svelte.ts +0 -87
- package/frontend/stores/core/presence.svelte.ts +0 -128
- package/frontend/stores/core/projects.svelte.ts +0 -325
- package/frontend/stores/core/sessions.svelte.ts +0 -452
- package/frontend/stores/features/auth.svelte.ts +0 -336
- package/frontend/stores/features/claude-accounts.svelte.ts +0 -58
- package/frontend/stores/features/models.svelte.ts +0 -89
- package/frontend/stores/features/settings.svelte.ts +0 -151
- package/frontend/stores/features/terminal.svelte.ts +0 -747
- package/frontend/stores/features/tunnel-config.svelte.ts +0 -205
- package/frontend/stores/features/tunnel.svelte.ts +0 -277
- package/frontend/stores/features/user.svelte.ts +0 -54
- package/frontend/stores/ui/chat-input.svelte.ts +0 -57
- package/frontend/stores/ui/chat-model.svelte.ts +0 -61
- package/frontend/stores/ui/connection.svelte.ts +0 -40
- package/frontend/stores/ui/dialog.svelte.ts +0 -59
- package/frontend/stores/ui/edit-mode.svelte.ts +0 -214
- package/frontend/stores/ui/notification.svelte.ts +0 -169
- package/frontend/stores/ui/settings-modal.svelte.ts +0 -116
- package/frontend/stores/ui/theme.svelte.ts +0 -179
- package/frontend/stores/ui/todo-panel.svelte.ts +0 -39
- package/frontend/stores/ui/update.svelte.ts +0 -159
- package/frontend/stores/ui/workspace.svelte.ts +0 -798
- package/frontend/utils/chat/date-separator.ts +0 -39
- package/frontend/utils/chat/message-grouper.ts +0 -329
- package/frontend/utils/chat/message-processor.ts +0 -169
- package/frontend/utils/chat/tool-handler.ts +0 -287
- package/frontend/utils/chat/virtual-scroll.svelte.ts +0 -142
- package/frontend/utils/click-outside.ts +0 -20
- package/frontend/utils/context-manager.ts +0 -55
- package/frontend/utils/file-icon-mappings.ts +0 -769
- package/frontend/utils/file-type.ts +0 -68
- package/frontend/utils/folder-icon-mappings.ts +0 -1030
- package/frontend/utils/git-status.ts +0 -68
- package/frontend/utils/native-ui.ts +0 -73
- package/frontend/utils/platform.ts +0 -113
- package/frontend/utils/port-check.ts +0 -65
- package/frontend/utils/preview-constants.ts +0 -45
- package/frontend/utils/terminal-formatter.ts +0 -207
- package/frontend/utils/theme.ts +0 -6
- package/frontend/utils/tree-visualizer.ts +0 -320
- package/frontend/utils/ws.ts +0 -90
- package/scripts/dev.ts +0 -46
- package/scripts/generate-icons.ts +0 -87
- package/svelte.config.js +0 -20
- package/vite.config.ts +0 -51
- /package/{static → dist}/audio/notification.ogg +0 -0
- /package/{static → dist}/favicon.svg +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-italic-latin-ext.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-italic-latin.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-normal-latin-ext.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-normal-latin.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans.css +0 -0
- /package/{static → dist}/manifest.json +0 -0
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { appState } from '$frontend/stores/core/app.svelte';
|
|
3
|
-
import Icon from '$frontend/components/common/display/Icon.svelte';
|
|
4
|
-
import { fly } from 'svelte/transition';
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
visibleLoadingText: string;
|
|
8
|
-
isWelcomeState: boolean;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const { visibleLoadingText, isWelcomeState }: Props = $props();
|
|
12
|
-
</script>
|
|
13
|
-
|
|
14
|
-
{#if appState.isLoading}
|
|
15
|
-
<div
|
|
16
|
-
class="absolute z-20 h-9 {isWelcomeState ? '-top-16' : '-top-14'} left-0 right-0 flex justify-center pointer-events-none"
|
|
17
|
-
transition:fly={{ y: 100, duration: 300 }}
|
|
18
|
-
>
|
|
19
|
-
{#if appState.isWaitingInput}
|
|
20
|
-
<!-- Waiting for user input state -->
|
|
21
|
-
<div class="flex items-center gap-2.5 px-4 py-2 bg-amber-50 dark:bg-amber-950 rounded-full border border-amber-200 dark:border-amber-900 shadow-sm">
|
|
22
|
-
<Icon name="lucide:message-circle-question-mark" class="w-4 h-4 text-amber-600 dark:text-amber-400" />
|
|
23
|
-
<span class="text-sm font-medium text-amber-700 dark:text-amber-300">
|
|
24
|
-
Waiting for your input...
|
|
25
|
-
</span>
|
|
26
|
-
</div>
|
|
27
|
-
{:else}
|
|
28
|
-
<!-- Normal loading state -->
|
|
29
|
-
<div class="flex items-center gap-2.5 px-4 py-2 bg-slate-100 dark:bg-slate-800 rounded-full border border-slate-300 dark:border-slate-600 shadow-sm">
|
|
30
|
-
<!-- Simple spinner -->
|
|
31
|
-
<svg class="animate-spin h-4 w-4 text-slate-700 dark:text-slate-300" viewBox="0 0 24 24">
|
|
32
|
-
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none"></circle>
|
|
33
|
-
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
|
34
|
-
</svg>
|
|
35
|
-
|
|
36
|
-
<!-- Text with typewriter effect -->
|
|
37
|
-
<span class="text-sm font-medium text-slate-700 dark:text-slate-300 capitalize">
|
|
38
|
-
{visibleLoadingText}
|
|
39
|
-
</span>
|
|
40
|
-
</div>
|
|
41
|
-
{/if}
|
|
42
|
-
</div>
|
|
43
|
-
{/if}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { onDestroy } from 'svelte';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Composable for managing placeholder and loading text animations
|
|
5
|
-
* Combines placeholder typewriter effect and loading text rotation
|
|
6
|
-
*
|
|
7
|
-
* Both animations use a `destroyed` flag to prevent interval callbacks
|
|
8
|
-
* from mutating state after the owning component is torn down (HMR / navigation).
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// ============================================================================
|
|
12
|
-
// PLACEHOLDER ANIMATION
|
|
13
|
-
// ============================================================================
|
|
14
|
-
|
|
15
|
-
export function usePlaceholderAnimation(placeholderTexts: string[]) {
|
|
16
|
-
let currentPlaceholderIndex = $state(0);
|
|
17
|
-
let placeholderText = $state('');
|
|
18
|
-
let destroyed = false;
|
|
19
|
-
|
|
20
|
-
// Track every active timer so stopPlaceholderAnimation can clear them all
|
|
21
|
-
let typewriterInterval: number | null = null;
|
|
22
|
-
let rotationInterval: number | null = null;
|
|
23
|
-
let deleteTimeout: number | null = null;
|
|
24
|
-
let deleteInterval: number | null = null;
|
|
25
|
-
|
|
26
|
-
function typewritePlaceholder(text: string) {
|
|
27
|
-
if (typewriterInterval) clearInterval(typewriterInterval);
|
|
28
|
-
typewriterInterval = null;
|
|
29
|
-
|
|
30
|
-
let idx = 0;
|
|
31
|
-
placeholderText = '';
|
|
32
|
-
|
|
33
|
-
typewriterInterval = window.setInterval(() => {
|
|
34
|
-
if (destroyed) { clearInterval(typewriterInterval!); typewriterInterval = null; return; }
|
|
35
|
-
if (idx < text.length) {
|
|
36
|
-
placeholderText = text.substring(0, idx + 1);
|
|
37
|
-
idx++;
|
|
38
|
-
} else {
|
|
39
|
-
clearInterval(typewriterInterval!);
|
|
40
|
-
typewriterInterval = null;
|
|
41
|
-
}
|
|
42
|
-
}, 20);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function updatePlaceholder() {
|
|
46
|
-
const fullText = placeholderTexts[currentPlaceholderIndex];
|
|
47
|
-
|
|
48
|
-
if (deleteTimeout) clearTimeout(deleteTimeout);
|
|
49
|
-
if (deleteInterval) clearInterval(deleteInterval);
|
|
50
|
-
deleteTimeout = null;
|
|
51
|
-
deleteInterval = null;
|
|
52
|
-
|
|
53
|
-
deleteTimeout = window.setTimeout(() => {
|
|
54
|
-
if (destroyed) return;
|
|
55
|
-
deleteTimeout = null;
|
|
56
|
-
|
|
57
|
-
deleteInterval = window.setInterval(() => {
|
|
58
|
-
if (destroyed) { clearInterval(deleteInterval!); deleteInterval = null; return; }
|
|
59
|
-
if (placeholderText.length > 0) {
|
|
60
|
-
placeholderText = placeholderText.substring(0, placeholderText.length - 1);
|
|
61
|
-
} else {
|
|
62
|
-
clearInterval(deleteInterval!);
|
|
63
|
-
deleteInterval = null;
|
|
64
|
-
typewritePlaceholder(fullText);
|
|
65
|
-
}
|
|
66
|
-
}, 15);
|
|
67
|
-
}, 2000);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function startPlaceholderAnimation() {
|
|
71
|
-
stopPlaceholderAnimation();
|
|
72
|
-
destroyed = false;
|
|
73
|
-
|
|
74
|
-
currentPlaceholderIndex = Math.floor(Math.random() * placeholderTexts.length);
|
|
75
|
-
typewritePlaceholder(placeholderTexts[currentPlaceholderIndex]);
|
|
76
|
-
|
|
77
|
-
rotationInterval = window.setInterval(() => {
|
|
78
|
-
if (destroyed) { clearInterval(rotationInterval!); rotationInterval = null; return; }
|
|
79
|
-
currentPlaceholderIndex = (currentPlaceholderIndex + 1) % placeholderTexts.length;
|
|
80
|
-
updatePlaceholder();
|
|
81
|
-
}, 7000);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function stopPlaceholderAnimation() {
|
|
85
|
-
if (typewriterInterval) { clearInterval(typewriterInterval); typewriterInterval = null; }
|
|
86
|
-
if (rotationInterval) { clearInterval(rotationInterval); rotationInterval = null; }
|
|
87
|
-
if (deleteTimeout) { clearTimeout(deleteTimeout); deleteTimeout = null; }
|
|
88
|
-
if (deleteInterval) { clearInterval(deleteInterval); deleteInterval = null; }
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function setStaticPlaceholder(text: string) {
|
|
92
|
-
stopPlaceholderAnimation();
|
|
93
|
-
placeholderText = text;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
onDestroy(() => {
|
|
97
|
-
destroyed = true;
|
|
98
|
-
stopPlaceholderAnimation();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
get placeholderText() { return placeholderText; },
|
|
103
|
-
startAnimation: startPlaceholderAnimation,
|
|
104
|
-
stopAnimation: stopPlaceholderAnimation,
|
|
105
|
-
setStaticPlaceholder
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// ============================================================================
|
|
110
|
-
// LOADING TEXT ANIMATION
|
|
111
|
-
// ============================================================================
|
|
112
|
-
|
|
113
|
-
export function useLoadingTextAnimation(loadingTexts: string[]) {
|
|
114
|
-
let visibleLoadingText = $state('');
|
|
115
|
-
let currentFullText = '';
|
|
116
|
-
let destroyed = false;
|
|
117
|
-
|
|
118
|
-
let typewriterInterval: number | null = null;
|
|
119
|
-
let rotationInterval: number | null = null;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Typewriter: type characters one-by-one.
|
|
123
|
-
* Calls `onDone` when the full text has been typed.
|
|
124
|
-
*/
|
|
125
|
-
function typeText(text: string, onDone?: () => void) {
|
|
126
|
-
if (typewriterInterval) clearInterval(typewriterInterval);
|
|
127
|
-
typewriterInterval = null;
|
|
128
|
-
|
|
129
|
-
let idx = 0;
|
|
130
|
-
visibleLoadingText = '';
|
|
131
|
-
|
|
132
|
-
typewriterInterval = window.setInterval(() => {
|
|
133
|
-
if (destroyed) { clearInterval(typewriterInterval!); typewriterInterval = null; return; }
|
|
134
|
-
if (idx < text.length) {
|
|
135
|
-
visibleLoadingText = text.substring(0, idx + 1);
|
|
136
|
-
idx++;
|
|
137
|
-
} else {
|
|
138
|
-
clearInterval(typewriterInterval!);
|
|
139
|
-
typewriterInterval = null;
|
|
140
|
-
onDone?.();
|
|
141
|
-
}
|
|
142
|
-
}, 40);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Backspace: delete characters one-by-one from the current visible text.
|
|
147
|
-
* Calls `onDone` when the text is fully erased.
|
|
148
|
-
*/
|
|
149
|
-
function deleteText(onDone?: () => void) {
|
|
150
|
-
if (typewriterInterval) clearInterval(typewriterInterval);
|
|
151
|
-
typewriterInterval = null;
|
|
152
|
-
|
|
153
|
-
const snapshot = visibleLoadingText;
|
|
154
|
-
let len = snapshot.length;
|
|
155
|
-
|
|
156
|
-
typewriterInterval = window.setInterval(() => {
|
|
157
|
-
if (destroyed) { clearInterval(typewriterInterval!); typewriterInterval = null; return; }
|
|
158
|
-
if (len > 0) {
|
|
159
|
-
len--;
|
|
160
|
-
visibleLoadingText = snapshot.substring(0, len);
|
|
161
|
-
} else {
|
|
162
|
-
clearInterval(typewriterInterval!);
|
|
163
|
-
typewriterInterval = null;
|
|
164
|
-
onDone?.();
|
|
165
|
-
}
|
|
166
|
-
}, 40);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function pickNextText(): string {
|
|
170
|
-
let next = currentFullText;
|
|
171
|
-
while (next === currentFullText && loadingTexts.length > 1) {
|
|
172
|
-
next = loadingTexts[Math.floor(Math.random() * loadingTexts.length)];
|
|
173
|
-
}
|
|
174
|
-
return next;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** Delete current text, then type new text */
|
|
178
|
-
function transitionTo(newText: string) {
|
|
179
|
-
currentFullText = newText;
|
|
180
|
-
deleteText(() => {
|
|
181
|
-
if (destroyed) return;
|
|
182
|
-
typeText(newText);
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function startLoadingAnimation() {
|
|
187
|
-
stopLoadingAnimation();
|
|
188
|
-
destroyed = false;
|
|
189
|
-
|
|
190
|
-
// Type the initial text character-by-character
|
|
191
|
-
currentFullText = loadingTexts[Math.floor(Math.random() * loadingTexts.length)];
|
|
192
|
-
typeText(currentFullText);
|
|
193
|
-
|
|
194
|
-
// Rotate to a new random text periodically
|
|
195
|
-
rotationInterval = window.setInterval(() => {
|
|
196
|
-
if (destroyed) { clearInterval(rotationInterval!); rotationInterval = null; return; }
|
|
197
|
-
transitionTo(pickNextText());
|
|
198
|
-
}, 15000);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function stopLoadingAnimation() {
|
|
202
|
-
if (typewriterInterval) { clearInterval(typewriterInterval); typewriterInterval = null; }
|
|
203
|
-
if (rotationInterval) { clearInterval(rotationInterval); rotationInterval = null; }
|
|
204
|
-
visibleLoadingText = '';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
onDestroy(() => {
|
|
208
|
-
destroyed = true;
|
|
209
|
-
stopLoadingAnimation();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
get visibleLoadingText() { return visibleLoadingText; },
|
|
214
|
-
startAnimation: startLoadingAnimation,
|
|
215
|
-
stopAnimation: stopLoadingAnimation
|
|
216
|
-
};
|
|
217
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { appState } from '$frontend/stores/core/app.svelte';
|
|
2
|
-
import { sessionState, loadMessagesForSession } from '$frontend/stores/core/sessions.svelte';
|
|
3
|
-
import { chatService } from '$frontend/services/chat/chat.service';
|
|
4
|
-
import { snapshotService } from '$frontend/services/snapshot/snapshot.service';
|
|
5
|
-
import { soundNotification } from '$frontend/services/notification';
|
|
6
|
-
import { addNotification } from '$frontend/stores/ui/notification.svelte';
|
|
7
|
-
import { editModeState, cancelEdit } from '$frontend/stores/ui/edit-mode.svelte';
|
|
8
|
-
import { clearInput, setSkipNextRestore } from '$frontend/stores/ui/chat-input.svelte';
|
|
9
|
-
import { debug } from '$shared/utils/logger';
|
|
10
|
-
import type { FileAttachment } from './use-file-handling.svelte';
|
|
11
|
-
|
|
12
|
-
interface ChatActionsParams {
|
|
13
|
-
attachedFiles: FileAttachment[];
|
|
14
|
-
clearAllAttachments: () => void;
|
|
15
|
-
adjustTextareaHeight: () => void;
|
|
16
|
-
focusTextarea: () => void;
|
|
17
|
-
startLoadingAnimation: () => void;
|
|
18
|
-
stopLoadingAnimation: () => void;
|
|
19
|
-
clearDraft: () => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function useChatActions(params: ChatActionsParams) {
|
|
23
|
-
let isInputComposing = $state(false);
|
|
24
|
-
|
|
25
|
-
// Handle cancel edit
|
|
26
|
-
function handleCancelEdit() {
|
|
27
|
-
cancelEdit();
|
|
28
|
-
clearInput();
|
|
29
|
-
params.clearAllAttachments();
|
|
30
|
-
params.adjustTextareaHeight();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Handle send message with SDK streaming
|
|
34
|
-
async function sendMessage(messageText: string, setMessageText: (value: string) => void) {
|
|
35
|
-
if ((!messageText.trim() && params.attachedFiles.length === 0) || appState.isLoading || appState.isWaitingInput) return;
|
|
36
|
-
|
|
37
|
-
// Initialize sound notifications on first user interaction (browser policy requirement)
|
|
38
|
-
soundNotification.initialize();
|
|
39
|
-
|
|
40
|
-
const userMessage = messageText.trim();
|
|
41
|
-
const files = [...params.attachedFiles]; // Copy current attachments
|
|
42
|
-
|
|
43
|
-
// If in edit mode, restore to parent of edited message first
|
|
44
|
-
if (editModeState.isEditing) {
|
|
45
|
-
try {
|
|
46
|
-
if (sessionState.currentSession?.id) {
|
|
47
|
-
// Restore to parent of edited message (state before the edited message)
|
|
48
|
-
// When parentMessageId is null (editing first message), restore to initial state
|
|
49
|
-
const restoreTargetId = editModeState.parentMessageId || '__initial__';
|
|
50
|
-
await snapshotService.restore(restoreTargetId, sessionState.currentSession.id);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Set skip and clear draft BEFORE reloading messages — editing the first message
|
|
54
|
-
// causes messages to become empty (welcome state), which remounts ChatInput.
|
|
55
|
-
// Without this, the new instance restores stale server state into the input.
|
|
56
|
-
setSkipNextRestore(true);
|
|
57
|
-
params.clearDraft();
|
|
58
|
-
|
|
59
|
-
// Reload messages from database to update UI
|
|
60
|
-
if (sessionState.currentSession?.id) {
|
|
61
|
-
await loadMessagesForSession(sessionState.currentSession.id);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Exit edit mode
|
|
65
|
-
cancelEdit();
|
|
66
|
-
} catch (error) {
|
|
67
|
-
debug.error('chat', 'Edit restore error:', error);
|
|
68
|
-
addNotification({
|
|
69
|
-
type: 'error',
|
|
70
|
-
title: 'Edit Failed',
|
|
71
|
-
message: error instanceof Error ? error.message : 'Unknown error',
|
|
72
|
-
duration: 5000
|
|
73
|
-
});
|
|
74
|
-
return; // Don't send message if restore failed
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Clear input and attachments
|
|
79
|
-
// Set skip flag BEFORE clearing - prevents stale input restoration
|
|
80
|
-
// when ChatInput is remounted during welcome→chat transition
|
|
81
|
-
setSkipNextRestore(true);
|
|
82
|
-
params.clearDraft();
|
|
83
|
-
setMessageText('');
|
|
84
|
-
params.clearAllAttachments();
|
|
85
|
-
params.adjustTextareaHeight();
|
|
86
|
-
|
|
87
|
-
// Focus back to textarea
|
|
88
|
-
params.focusTextarea();
|
|
89
|
-
|
|
90
|
-
// Start loading text rotation with typewriter effect
|
|
91
|
-
params.startLoadingAnimation();
|
|
92
|
-
|
|
93
|
-
// Send message via WebSocket with file attachments
|
|
94
|
-
const attachedFiles = files
|
|
95
|
-
.filter(f => f.base64)
|
|
96
|
-
.map(f => ({
|
|
97
|
-
type: f.type,
|
|
98
|
-
data: f.base64!,
|
|
99
|
-
mediaType: f.file.type,
|
|
100
|
-
fileName: f.file.name
|
|
101
|
-
}));
|
|
102
|
-
|
|
103
|
-
await chatService.sendMessage(userMessage, {
|
|
104
|
-
attachedFiles: attachedFiles.length > 0 ? attachedFiles : undefined,
|
|
105
|
-
onStreamEnd: () => {
|
|
106
|
-
params.stopLoadingAnimation();
|
|
107
|
-
},
|
|
108
|
-
onError: () => {
|
|
109
|
-
params.stopLoadingAnimation();
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Cancel current request
|
|
115
|
-
async function cancelRequest() {
|
|
116
|
-
chatService.cancelRequest();
|
|
117
|
-
params.stopLoadingAnimation();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Handle key press
|
|
121
|
-
function handleKeyPress(
|
|
122
|
-
event: KeyboardEvent,
|
|
123
|
-
messageText: string,
|
|
124
|
-
setMessageText: (value: string) => void
|
|
125
|
-
) {
|
|
126
|
-
if (event.key === 'Enter' && !event.shiftKey && !isInputComposing) {
|
|
127
|
-
event.preventDefault();
|
|
128
|
-
sendMessage(messageText, setMessageText);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Handle composition events for international keyboards
|
|
133
|
-
function handleCompositionStart() {
|
|
134
|
-
isInputComposing = true;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function handleCompositionEnd() {
|
|
138
|
-
isInputComposing = false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
get isInputComposing() {
|
|
143
|
-
return isInputComposing;
|
|
144
|
-
},
|
|
145
|
-
handleCancelEdit,
|
|
146
|
-
sendMessage,
|
|
147
|
-
cancelRequest,
|
|
148
|
-
handleKeyPress,
|
|
149
|
-
handleCompositionStart,
|
|
150
|
-
handleCompositionEnd
|
|
151
|
-
};
|
|
152
|
-
}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { addNotification } from '$frontend/stores/ui/notification.svelte';
|
|
2
|
-
import { debug } from '$shared/utils/logger';
|
|
3
|
-
|
|
4
|
-
// File attachments interface
|
|
5
|
-
export interface FileAttachment {
|
|
6
|
-
id: string;
|
|
7
|
-
file: File;
|
|
8
|
-
type: 'image' | 'document';
|
|
9
|
-
base64?: string;
|
|
10
|
-
previewUrl?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Maximum file size (10MB)
|
|
14
|
-
const MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
15
|
-
|
|
16
|
-
// Supported file types - Images and PDF only
|
|
17
|
-
const SUPPORTED_IMAGE_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
|
|
18
|
-
const SUPPORTED_DOCUMENT_TYPES = ['application/pdf'];
|
|
19
|
-
|
|
20
|
-
export function useFileHandling() {
|
|
21
|
-
let attachedFiles = $state<FileAttachment[]>([]);
|
|
22
|
-
let isDragging = $state(false);
|
|
23
|
-
let isProcessingFiles = $state(false);
|
|
24
|
-
|
|
25
|
-
function getFileType(mimeType: string): 'image' | 'document' {
|
|
26
|
-
if (SUPPORTED_IMAGE_TYPES.includes(mimeType)) return 'image';
|
|
27
|
-
return 'document';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function fileToBase64(file: File): Promise<string> {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
const reader = new FileReader();
|
|
33
|
-
reader.onload = () => {
|
|
34
|
-
const base64 = reader.result as string;
|
|
35
|
-
// Remove the data:type/subtype;base64, prefix
|
|
36
|
-
const base64Data = base64.split(',')[1];
|
|
37
|
-
resolve(base64Data);
|
|
38
|
-
};
|
|
39
|
-
reader.onerror = reject;
|
|
40
|
-
reader.readAsDataURL(file);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function processFiles(files: FileList | File[]) {
|
|
45
|
-
isProcessingFiles = true;
|
|
46
|
-
const fileArray = Array.from(files);
|
|
47
|
-
|
|
48
|
-
for (const file of fileArray) {
|
|
49
|
-
// Check file size
|
|
50
|
-
if (file.size > MAX_FILE_SIZE) {
|
|
51
|
-
addNotification({
|
|
52
|
-
type: 'error',
|
|
53
|
-
title: 'File Too Large',
|
|
54
|
-
message: `${file.name} exceeds the 10MB limit`,
|
|
55
|
-
duration: 3000
|
|
56
|
-
});
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Check if file type is supported
|
|
61
|
-
const isSupported = [...SUPPORTED_IMAGE_TYPES, ...SUPPORTED_DOCUMENT_TYPES].includes(
|
|
62
|
-
file.type
|
|
63
|
-
);
|
|
64
|
-
if (!isSupported) {
|
|
65
|
-
addNotification({
|
|
66
|
-
type: 'error',
|
|
67
|
-
title: 'Unsupported File Type',
|
|
68
|
-
message: `${file.name} is not supported. Only images (JPEG, PNG, GIF, WebP) and PDF documents are allowed.`,
|
|
69
|
-
duration: 4000
|
|
70
|
-
});
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Check for duplicates
|
|
75
|
-
if (attachedFiles.some((f) => f.file.name === file.name && f.file.size === file.size)) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const fileType = getFileType(file.type);
|
|
80
|
-
const attachment: FileAttachment = {
|
|
81
|
-
id: crypto.randomUUID(),
|
|
82
|
-
file,
|
|
83
|
-
type: fileType
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// Convert to base64
|
|
87
|
-
try {
|
|
88
|
-
attachment.base64 = await fileToBase64(file);
|
|
89
|
-
|
|
90
|
-
// Create preview URL for images
|
|
91
|
-
if (fileType === 'image') {
|
|
92
|
-
attachment.previewUrl = URL.createObjectURL(file);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
attachedFiles = [...attachedFiles, attachment];
|
|
96
|
-
} catch (error) {
|
|
97
|
-
debug.error('chat', 'Error processing file:', error);
|
|
98
|
-
addNotification({
|
|
99
|
-
type: 'error',
|
|
100
|
-
title: 'File Processing Error',
|
|
101
|
-
message: `Failed to process ${file.name}`,
|
|
102
|
-
duration: 3000
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
isProcessingFiles = false;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function removeAttachment(id: string) {
|
|
111
|
-
const attachment = attachedFiles.find((f) => f.id === id);
|
|
112
|
-
if (attachment?.previewUrl) {
|
|
113
|
-
URL.revokeObjectURL(attachment.previewUrl);
|
|
114
|
-
}
|
|
115
|
-
attachedFiles = attachedFiles.filter((f) => f.id !== id);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function clearAllAttachments() {
|
|
119
|
-
attachedFiles.forEach((attachment) => {
|
|
120
|
-
if (attachment.previewUrl) {
|
|
121
|
-
URL.revokeObjectURL(attachment.previewUrl);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
attachedFiles = [];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// File input handlers
|
|
128
|
-
function handleFileSelect(fileInputElement: HTMLInputElement | undefined) {
|
|
129
|
-
fileInputElement?.click();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function handleFileInputChange(event: Event) {
|
|
133
|
-
const input = event.target as HTMLInputElement;
|
|
134
|
-
if (input.files && input.files.length > 0) {
|
|
135
|
-
await processFiles(input.files);
|
|
136
|
-
// Reset input so same file can be selected again
|
|
137
|
-
input.value = '';
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Drag and drop handlers
|
|
142
|
-
function handleDragOver(event: DragEvent) {
|
|
143
|
-
event.preventDefault();
|
|
144
|
-
isDragging = true;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function handleDragLeave(event: DragEvent) {
|
|
148
|
-
event.preventDefault();
|
|
149
|
-
isDragging = false;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async function handleDrop(event: DragEvent) {
|
|
153
|
-
event.preventDefault();
|
|
154
|
-
isDragging = false;
|
|
155
|
-
|
|
156
|
-
if (event.dataTransfer?.files && event.dataTransfer.files.length > 0) {
|
|
157
|
-
await processFiles(event.dataTransfer.files);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Paste handler for images and documents
|
|
162
|
-
async function handlePaste(event: ClipboardEvent) {
|
|
163
|
-
const items = event.clipboardData?.items;
|
|
164
|
-
if (!items) return;
|
|
165
|
-
|
|
166
|
-
const files: File[] = [];
|
|
167
|
-
|
|
168
|
-
for (let i = 0; i < items.length; i++) {
|
|
169
|
-
const item = items[i];
|
|
170
|
-
|
|
171
|
-
// Check if the item is a file
|
|
172
|
-
if (item.kind === 'file') {
|
|
173
|
-
const file = item.getAsFile();
|
|
174
|
-
if (file) {
|
|
175
|
-
files.push(file);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Process the pasted files if any
|
|
181
|
-
if (files.length > 0) {
|
|
182
|
-
event.preventDefault(); // Prevent default paste behavior for files
|
|
183
|
-
await processFiles(files);
|
|
184
|
-
}
|
|
185
|
-
// If no files, let the default paste behavior handle text
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
// State
|
|
190
|
-
get attachedFiles() {
|
|
191
|
-
return attachedFiles;
|
|
192
|
-
},
|
|
193
|
-
set attachedFiles(value: FileAttachment[]) {
|
|
194
|
-
attachedFiles = value;
|
|
195
|
-
},
|
|
196
|
-
get isDragging() {
|
|
197
|
-
return isDragging;
|
|
198
|
-
},
|
|
199
|
-
get isProcessingFiles() {
|
|
200
|
-
return isProcessingFiles;
|
|
201
|
-
},
|
|
202
|
-
// Methods
|
|
203
|
-
processFiles,
|
|
204
|
-
removeAttachment,
|
|
205
|
-
clearAllAttachments,
|
|
206
|
-
handleFileSelect,
|
|
207
|
-
handleFileInputChange,
|
|
208
|
-
handleDragOver,
|
|
209
|
-
handleDragLeave,
|
|
210
|
-
handleDrop,
|
|
211
|
-
handlePaste,
|
|
212
|
-
// Constants
|
|
213
|
-
SUPPORTED_IMAGE_TYPES,
|
|
214
|
-
SUPPORTED_DOCUMENT_TYPES
|
|
215
|
-
};
|
|
216
|
-
}
|