mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-30 17:05:16 -05:00
refac
This commit is contained in:
1 parent
404a328a58
commit
e7c8e58e9c
4 files changed
+636
-15
No files matched your search
@@ -69,6 +69,7 @@
|
||||
import { fileIconName } from './FileNav/fileIcon';
|
||||
import UntitledFile from './ChatTabs/UntitledFile.svelte';
|
||||
import QuickOpen from './ChatTabs/QuickOpen.svelte';
|
||||
import VoiceNote from './ChatTabs/VoiceNote.svelte';
|
||||
import Browser from './ChatTabs/Browser.svelte';
|
||||
import Desktop from './ChatTabs/Desktop.svelte';
|
||||
import XTerminal from './XTerminal.svelte';
|
||||
@@ -167,6 +168,29 @@
|
||||
let navigationApproved = false;
|
||||
let selectedConnection: TerminalConnection | null = null;
|
||||
let showQuickOpen = false;
|
||||
let voiceNote: VoiceNote;
|
||||
let voiceNoteTarget: {
|
||||
connection: TerminalConnection;
|
||||
chatId: string | null;
|
||||
directory?: string;
|
||||
} | null = null;
|
||||
$: canVoiceNote = terminalFilesAvailable && !!$user;
|
||||
$: canTranscribeVoiceNote = $user?.role === 'admin' || ($user?.permissions?.chat?.stt ?? true);
|
||||
const openVoiceNote = () => {
|
||||
if (voiceNoteTarget) {
|
||||
voiceNote?.finishRecording();
|
||||
return;
|
||||
}
|
||||
if (!canVoiceNote || !selectedConnection || !$user) return;
|
||||
voiceNoteTarget = {
|
||||
connection: selectedConnection,
|
||||
chatId,
|
||||
directory:
|
||||
contextTab?.terminalId === selectedConnection.selector
|
||||
? terminalContext?.currentDirectory
|
||||
: undefined
|
||||
};
|
||||
};
|
||||
$: if (!terminalFilesAvailable) showQuickOpen = false;
|
||||
let terminalEnabled = false;
|
||||
let desktopEnabled = false;
|
||||
@@ -740,6 +764,9 @@
|
||||
const shortcut = matchKeybinding(event);
|
||||
let action: (() => void) | undefined;
|
||||
switch (shortcut) {
|
||||
case Shortcut.VOICE_NOTE:
|
||||
if (voiceNoteTarget || canVoiceNote) action = openVoiceNote;
|
||||
break;
|
||||
case Shortcut.QUICK_OPEN:
|
||||
if (terminalFilesAvailable && selectedConnection)
|
||||
action = () => {
|
||||
@@ -839,20 +866,20 @@
|
||||
chatId;
|
||||
pruneTabs();
|
||||
}
|
||||
$: selectedConnection =
|
||||
terminalFilesAvailable && mounted
|
||||
? resolveTerminalConnection(
|
||||
$selectedTerminalId,
|
||||
$terminalServers ?? [],
|
||||
directTerminals,
|
||||
localStorage.token ?? ''
|
||||
)
|
||||
: null;
|
||||
const checkTerminal = async () => {
|
||||
const version = ++featureVersion;
|
||||
terminalEnabled = false;
|
||||
desktopEnabled = false;
|
||||
browserEnabled = false;
|
||||
selectedConnection =
|
||||
terminalFilesAvailable && mounted
|
||||
? resolveTerminalConnection(
|
||||
$selectedTerminalId,
|
||||
$terminalServers ?? [],
|
||||
directTerminals,
|
||||
localStorage.token ?? ''
|
||||
)
|
||||
: null;
|
||||
if (!selectedConnection) return;
|
||||
try {
|
||||
const result = await terminalRequest<{
|
||||
@@ -868,11 +895,7 @@
|
||||
}
|
||||
};
|
||||
$: {
|
||||
terminalFilesAvailable;
|
||||
$selectedTerminalId;
|
||||
$terminalServers;
|
||||
$settings;
|
||||
mounted;
|
||||
selectedConnection;
|
||||
chatId;
|
||||
void checkTerminal();
|
||||
}
|
||||
@@ -1077,6 +1100,19 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if voiceNoteTarget}
|
||||
{@const target = voiceNoteTarget}
|
||||
<VoiceNote
|
||||
bind:this={voiceNote}
|
||||
{...target}
|
||||
canTranscribe={canTranscribeVoiceNote}
|
||||
onclose={() => {
|
||||
voiceNoteTarget = null;
|
||||
}}
|
||||
onsaved={(path) => openFile(path, target.connection.selector)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if showQuickOpen && terminalFilesAvailable && selectedConnection}
|
||||
{#key `${selectedConnection.selector}:${chatId}`}
|
||||
<QuickOpen
|
||||
@@ -1518,6 +1554,13 @@
|
||||
>{$i18n.t('Desktop')}</span
|
||||
><HotkeyHint name="openDesktop" className="ms-auto" /></button
|
||||
>{/if}
|
||||
{#if canVoiceNote}
|
||||
<button on:click={openVoiceNote}>
|
||||
<Icon name="microphone" size={14} />
|
||||
<span class="flex-1 text-start">{$i18n.t('Voice Note')}</span>
|
||||
<HotkeyHint name="voiceNote" className="ms-auto" />
|
||||
</button>
|
||||
{/if}
|
||||
{#each newTabViews as view}
|
||||
<button
|
||||
on:click={() =>
|
||||
|
||||
@@ -0,0 +1,557 @@
|
||||
<script lang="ts">
|
||||
import { getContext, onMount, onDestroy, tick } from 'svelte';
|
||||
import { config, settings } from '$lib/stores';
|
||||
import { transcribeAudio } from '$lib/apis/audio';
|
||||
import { getCwd, uploadNewFileToTerminal, type TerminalConnection } from '$lib/apis/terminal';
|
||||
import { matchKeybinding, Shortcut } from '$lib/shortcuts';
|
||||
import Icon from '../FileNav/Icon.svelte';
|
||||
type VoiceNoteDraft = {
|
||||
name: string;
|
||||
directory: string;
|
||||
audio: Blob;
|
||||
duration: number;
|
||||
transcript: string;
|
||||
audioPath?: string;
|
||||
};
|
||||
|
||||
const validVoiceNoteName = (name: string) =>
|
||||
!!name.trim() && !['.', '..'].includes(name.trim()) && !/[\\/\0]/.test(name);
|
||||
|
||||
const voiceNoteExtension = (type: string) =>
|
||||
type.includes('mp4')
|
||||
? 'm4a'
|
||||
: type.includes('ogg')
|
||||
? 'ogg'
|
||||
: type.includes('wav')
|
||||
? 'wav'
|
||||
: 'webm';
|
||||
|
||||
const voiceNoteMarkdown = (draft: VoiceNoteDraft) => {
|
||||
const audioName = draft.audioPath!.replace(/\\/g, '/').split('/').pop()!;
|
||||
const link = encodeURIComponent(audioName).replace(
|
||||
/[()]/g,
|
||||
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`
|
||||
);
|
||||
return `# ${draft.name.trim()}\n\n${draft.transcript.trim() ? `${draft.transcript.trim()}\n\n` : ''}[Audio](./${link})\n`;
|
||||
};
|
||||
|
||||
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
|
||||
export let connection: TerminalConnection;
|
||||
export let chatId: string | null = null;
|
||||
export let directory: string | undefined = undefined;
|
||||
export let canTranscribe = false;
|
||||
export let onclose: () => void;
|
||||
export let onsaved: (path: string) => void;
|
||||
|
||||
let panel: HTMLElement;
|
||||
let nameInput: HTMLInputElement;
|
||||
let returnFocus: HTMLElement | null = null;
|
||||
let position: { x: number; y: number } | null = null;
|
||||
let drag: { pointerId: number; startX: number; startY: number; x: number; y: number } | null =
|
||||
null;
|
||||
let dragged = false;
|
||||
let draft: VoiceNoteDraft | undefined;
|
||||
let initializing = true;
|
||||
let recording = false;
|
||||
let busy = false;
|
||||
let error = '';
|
||||
let elapsed = 0;
|
||||
let levels = Array(38).fill(2);
|
||||
let recorder: MediaRecorder | undefined;
|
||||
let stream: MediaStream | undefined;
|
||||
let audioContext: AudioContext | undefined;
|
||||
let frame = 0;
|
||||
let timer: ReturnType<typeof setInterval>;
|
||||
let disposed = false;
|
||||
let player: HTMLAudioElement;
|
||||
let playing = false;
|
||||
let audioUrl = '';
|
||||
let previewBlob: Blob | undefined;
|
||||
const buttonClass =
|
||||
'flex h-7 min-w-7 shrink-0 items-center justify-center gap-1.5 rounded-lg px-1.5 text-xs text-gray-500 hover:bg-gray-50/60 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-gray-800/60 dark:hover:text-gray-200 disabled:opacity-40';
|
||||
const primaryButtonClass =
|
||||
'flex h-7 items-center justify-center rounded-lg bg-gray-100 px-2.5 text-xs font-normal text-gray-700 transition hover:bg-gray-200/60 disabled:opacity-40 dark:bg-gray-800 dark:text-gray-200 dark:hover:bg-gray-700/60';
|
||||
$: transcriptionAvailable =
|
||||
canTranscribe &&
|
||||
!!$config?.audio?.stt &&
|
||||
$config?.audio?.stt?.engine !== 'web' &&
|
||||
($settings?.audio?.stt?.engine ?? '') !== 'web';
|
||||
$: if (!disposed && draft?.audio && draft.audio !== previewBlob) {
|
||||
if (audioUrl) URL.revokeObjectURL(audioUrl);
|
||||
previewBlob = draft.audio;
|
||||
audioUrl = URL.createObjectURL(draft.audio);
|
||||
}
|
||||
const duration = (seconds: number) =>
|
||||
`${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`;
|
||||
const releaseMicrophone = () => {
|
||||
clearInterval(timer);
|
||||
cancelAnimationFrame(frame);
|
||||
stream?.getTracks().forEach((track) => track.stop());
|
||||
stream = undefined;
|
||||
void audioContext?.close().catch(() => {});
|
||||
audioContext = undefined;
|
||||
};
|
||||
const stop = () => {
|
||||
if (recorder?.state === 'recording') {
|
||||
busy = true;
|
||||
recorder.stop();
|
||||
}
|
||||
};
|
||||
const start = async () => {
|
||||
error = '';
|
||||
player?.pause();
|
||||
playing = false;
|
||||
initializing = true;
|
||||
try {
|
||||
if (!directory) {
|
||||
const cwd = await getCwd(connection.baseUrl, connection.key, chatId ?? undefined);
|
||||
if (!cwd) throw new Error($i18n.t('Could not load the recording folder.'));
|
||||
directory = cwd.cwd ?? cwd.home ?? cwd.root?.path;
|
||||
if (!directory) throw new Error($i18n.t('Could not load the recording folder.'));
|
||||
}
|
||||
if (disposed) return;
|
||||
stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||
if (disposed) {
|
||||
releaseMicrophone();
|
||||
return;
|
||||
}
|
||||
const mimeType = ['audio/webm;codecs=opus', 'audio/webm', 'audio/mp4', 'audio/ogg'].find(
|
||||
(type) => MediaRecorder.isTypeSupported(type)
|
||||
);
|
||||
recorder = new MediaRecorder(stream, mimeType ? { mimeType } : undefined);
|
||||
const chunks: Blob[] = [];
|
||||
recorder.ondataavailable = (event) => {
|
||||
if (event.data.size) chunks.push(event.data);
|
||||
};
|
||||
recorder.onstop = () => {
|
||||
recording = false;
|
||||
releaseMicrophone();
|
||||
if (disposed) return;
|
||||
const audio = new Blob(chunks, {
|
||||
type: recorder?.mimeType || chunks[0]?.type || 'audio/webm'
|
||||
});
|
||||
if (!audio.size) {
|
||||
error = $i18n.t('No audio was recorded.');
|
||||
busy = false;
|
||||
return;
|
||||
}
|
||||
draft = {
|
||||
name: draft?.name || $i18n.t('Voice Note'),
|
||||
directory: directory!,
|
||||
audio,
|
||||
duration: elapsed,
|
||||
transcript: ''
|
||||
};
|
||||
busy = false;
|
||||
void tick().then(() => {
|
||||
if (!disposed) nameInput?.focus();
|
||||
});
|
||||
};
|
||||
recorder.onerror = () => {
|
||||
error = $i18n.t('Error starting recording.');
|
||||
stop();
|
||||
releaseMicrophone();
|
||||
};
|
||||
recorder.start(250);
|
||||
recording = true;
|
||||
elapsed = 0;
|
||||
timer = setInterval(() => elapsed++, 1000);
|
||||
try {
|
||||
audioContext = new AudioContext();
|
||||
const analyser = audioContext.createAnalyser();
|
||||
analyser.fftSize = 256;
|
||||
audioContext.createMediaStreamSource(stream).connect(analyser);
|
||||
void audioContext.resume().catch(() => {});
|
||||
const samples = new Uint8Array(analyser.fftSize);
|
||||
let lastSample = 0;
|
||||
levels = Array(38).fill(2);
|
||||
const draw = (time: number) => {
|
||||
if (time - lastSample >= 60) {
|
||||
analyser.getByteTimeDomainData(samples);
|
||||
const energy = samples.reduce((sum, sample) => sum + ((sample - 128) / 128) ** 2, 0);
|
||||
const height = Math.max(2, Math.min(28, Math.sqrt(energy / samples.length) * 200));
|
||||
levels = [...levels.slice(1), height];
|
||||
lastSample = time;
|
||||
}
|
||||
frame = requestAnimationFrame(draw);
|
||||
};
|
||||
frame = requestAnimationFrame(draw);
|
||||
} catch {
|
||||
/* Recording still works when visualisation is unavailable. */
|
||||
}
|
||||
} catch (reason) {
|
||||
releaseMicrophone();
|
||||
error = reason instanceof Error ? reason.message : $i18n.t('Error accessing media devices.');
|
||||
} finally {
|
||||
initializing = false;
|
||||
}
|
||||
};
|
||||
const close = () => {
|
||||
if (!busy) onclose();
|
||||
};
|
||||
const transcribe = async () => {
|
||||
if (!draft || busy || !transcriptionAvailable) return;
|
||||
busy = true;
|
||||
error = '';
|
||||
try {
|
||||
const result = await transcribeAudio(
|
||||
localStorage.token,
|
||||
new File([draft.audio], `recording.${voiceNoteExtension(draft.audio.type)}`, {
|
||||
type: draft.audio.type
|
||||
}),
|
||||
$settings?.audio?.stt?.language
|
||||
);
|
||||
if (!result || typeof result.text !== 'string')
|
||||
throw new Error($i18n.t('Could not transcribe the recording.'));
|
||||
draft.transcript = result.text;
|
||||
} catch {
|
||||
error = $i18n.t('Could not transcribe the recording.');
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
};
|
||||
const save = async () => {
|
||||
if (!draft || busy) return;
|
||||
if (!validVoiceNoteName(draft.name)) {
|
||||
error = $i18n.t('Enter a file name without slashes.');
|
||||
return;
|
||||
}
|
||||
busy = true;
|
||||
error = '';
|
||||
playing = false;
|
||||
player?.pause();
|
||||
try {
|
||||
if (!draft.audioPath) {
|
||||
const result = await uploadNewFileToTerminal(
|
||||
connection.baseUrl,
|
||||
connection.key,
|
||||
draft.directory,
|
||||
new File([draft.audio], `${draft.name.trim()}.${voiceNoteExtension(draft.audio.type)}`, {
|
||||
type: draft.audio.type
|
||||
}),
|
||||
chatId ?? undefined
|
||||
);
|
||||
if (!result?.path) throw new Error();
|
||||
draft.audioPath = result.path;
|
||||
}
|
||||
const note = await uploadNewFileToTerminal(
|
||||
connection.baseUrl,
|
||||
connection.key,
|
||||
draft.directory,
|
||||
new File([voiceNoteMarkdown(draft)], `${draft.name.trim()}.md`, { type: 'text/markdown' }),
|
||||
chatId ?? undefined
|
||||
);
|
||||
if (!note?.path) throw new Error();
|
||||
draft = undefined;
|
||||
onclose();
|
||||
onsaved(note.path);
|
||||
} catch {
|
||||
error = $i18n.t('Could not save the voice note. Retry or download the recording.');
|
||||
} finally {
|
||||
busy = false;
|
||||
}
|
||||
};
|
||||
const fitPosition = () => {
|
||||
if (!position || !panel) return;
|
||||
const { width, height } = panel.getBoundingClientRect();
|
||||
const margin = recording || initializing ? 48 : 12;
|
||||
const x = Math.max(margin, Math.min(position.x, window.innerWidth - width - margin));
|
||||
const y = Math.max(12, Math.min(position.y, window.innerHeight - height - 24));
|
||||
if (x !== position.x || y !== position.y) position = { x, y };
|
||||
};
|
||||
const beginDrag = (event: PointerEvent) => {
|
||||
if (event.button !== 0) return;
|
||||
const { left: x, top: y } = panel.getBoundingClientRect();
|
||||
dragged = false;
|
||||
drag = { pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, x, y };
|
||||
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
||||
};
|
||||
const moveDrag = (event: PointerEvent) => {
|
||||
if (!drag || event.pointerId !== drag.pointerId) return;
|
||||
const dx = event.clientX - drag.startX;
|
||||
const dy = event.clientY - drag.startY;
|
||||
if (!dragged && Math.hypot(dx, dy) < 5) return;
|
||||
dragged = true;
|
||||
position = { x: drag.x + dx, y: drag.y + dy };
|
||||
fitPosition();
|
||||
};
|
||||
const endDrag = (event: PointerEvent) => {
|
||||
if (event.pointerId !== drag?.pointerId) return;
|
||||
drag = null;
|
||||
if (event.type === 'pointercancel') dragged = false;
|
||||
const target = event.currentTarget as HTMLElement;
|
||||
if (target.hasPointerCapture(event.pointerId)) target.releasePointerCapture(event.pointerId);
|
||||
};
|
||||
const moveWithKeyboard = (event: KeyboardEvent) => {
|
||||
const directions = {
|
||||
ArrowLeft: [-1, 0],
|
||||
ArrowRight: [1, 0],
|
||||
ArrowUp: [0, -1],
|
||||
ArrowDown: [0, 1]
|
||||
};
|
||||
const direction = directions[event.key as keyof typeof directions];
|
||||
if (!direction) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const { left: x, top: y } = panel.getBoundingClientRect();
|
||||
position = { x: x + direction[0] * 16, y: y + direction[1] * 16 };
|
||||
fitPosition();
|
||||
};
|
||||
const portal = (node: HTMLElement) => {
|
||||
document.body.appendChild(node);
|
||||
const observer = new ResizeObserver(fitPosition);
|
||||
observer.observe(node);
|
||||
window.addEventListener('resize', fitPosition);
|
||||
return {
|
||||
destroy: () => {
|
||||
observer.disconnect();
|
||||
window.removeEventListener('resize', fitPosition);
|
||||
node.remove();
|
||||
}
|
||||
};
|
||||
};
|
||||
export const finishRecording = () => {
|
||||
if (recording) stop();
|
||||
else nameInput?.focus();
|
||||
};
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.defaultPrevented || event.repeat || event.isComposing) return;
|
||||
if (document.querySelector('.modal, [role="alertdialog"], [role="menu"], [role="listbox"]'))
|
||||
return;
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
close();
|
||||
} else if (
|
||||
panel?.contains(event.target as Node) &&
|
||||
$settings?.keyboardShortcuts !== false &&
|
||||
matchKeybinding(event) === Shortcut.VOICE_NOTE
|
||||
) {
|
||||
event.preventDefault();
|
||||
finishRecording();
|
||||
}
|
||||
};
|
||||
onMount(() => {
|
||||
returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
void start();
|
||||
});
|
||||
onDestroy(() => {
|
||||
disposed = true;
|
||||
stop();
|
||||
releaseMicrophone();
|
||||
if (audioUrl) URL.revokeObjectURL(audioUrl);
|
||||
if (panel?.contains(document.activeElement) && returnFocus?.isConnected) {
|
||||
returnFocus.focus({ preventScroll: true });
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={handleKeyDown} />
|
||||
|
||||
<div
|
||||
use:portal
|
||||
bind:this={panel}
|
||||
role="dialog"
|
||||
aria-modal="false"
|
||||
aria-label={$i18n.t('Voice Note')}
|
||||
tabindex="-1"
|
||||
style:left={position ? `${position.x}px` : undefined}
|
||||
style:top={position ? `${position.y}px` : undefined}
|
||||
style:bottom={position ? 'auto' : undefined}
|
||||
style:translate={position ? 'none' : undefined}
|
||||
class="voice-note-panel fixed bottom-6 left-1/2 z-[9998] max-w-[calc(100vw-2rem)] -translate-x-1/2 font-normal text-gray-700 outline-none dark:text-gray-200"
|
||||
>
|
||||
<span id="voice-note-move-hint" class="sr-only">{$i18n.t('Use arrow keys to move.')}</span>
|
||||
{#if recording || initializing}
|
||||
<div class="group relative">
|
||||
<button
|
||||
class="absolute -left-9 top-1/2 flex size-7 -translate-y-1/2 items-center justify-center rounded-lg text-gray-500 opacity-0 transition-opacity hover:bg-gray-50/60 focus-visible:opacity-100 group-hover:opacity-100 group-focus-within:opacity-100 dark:text-gray-400 dark:hover:bg-gray-800/60 max-sm:opacity-100"
|
||||
aria-label={$i18n.t('Cancel')}
|
||||
title={`${$i18n.t('Cancel')} (Esc)`}
|
||||
aria-disabled={busy}
|
||||
on:click={close}><Icon name="xmark" size={14} /></button
|
||||
>
|
||||
<button
|
||||
class="voice-note-pill relative flex h-14 w-56 items-center justify-center touch-none select-none cursor-grab active:cursor-grabbing rounded-full border border-gray-100 bg-white shadow-lg transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-gray-400 dark:border-gray-800 dark:bg-gray-850"
|
||||
disabled={busy || initializing}
|
||||
aria-label={$i18n.t(initializing ? 'Loading...' : 'Stop recording')}
|
||||
title={`${$i18n.t('Stop recording')} · ${$i18n.t('Drag to move')}`}
|
||||
aria-describedby="voice-note-move-hint"
|
||||
on:pointerdown={beginDrag}
|
||||
on:pointermove={moveDrag}
|
||||
on:pointerup={endDrag}
|
||||
on:pointercancel={endDrag}
|
||||
on:keydown={moveWithKeyboard}
|
||||
on:click={(event) => {
|
||||
if (dragged) {
|
||||
event.preventDefault();
|
||||
dragged = false;
|
||||
return;
|
||||
}
|
||||
stop();
|
||||
}}
|
||||
>
|
||||
{#if initializing}
|
||||
<span role="status" class="text-xs text-gray-500 dark:text-gray-400"
|
||||
>{$i18n.t('Loading...')}</span
|
||||
>
|
||||
{:else}
|
||||
<div
|
||||
class="voice-note-wave flex h-8 w-[11.5rem] items-center gap-[0.1875rem] transition-opacity"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{#each levels as height}<span
|
||||
class="min-w-0 flex-1 rounded-full bg-gray-500 dark:bg-gray-400"
|
||||
style:height={`${height / 16}rem`}
|
||||
></span>{/each}
|
||||
</div>
|
||||
<span
|
||||
class="voice-note-stop pointer-events-none absolute flex size-6 items-center justify-center rounded-lg bg-white text-gray-700 opacity-0 transition-opacity dark:bg-gray-850 dark:text-gray-300"
|
||||
aria-hidden="true"><span class="size-2.5 rounded-[0.125rem] bg-current"></span></span
|
||||
>
|
||||
{/if}
|
||||
</button>
|
||||
{#if recording}<span
|
||||
class="pointer-events-none absolute top-full left-1/2 mt-1 -translate-x-1/2 text-[0.6875rem] leading-4 tabular-nums text-gray-500 dark:text-gray-400"
|
||||
>{duration(elapsed)}</span
|
||||
>{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="voice-note-review w-[22rem] max-w-full max-h-[calc(100dvh-3rem)] overflow-y-auto rounded-xl border border-gray-100 bg-white px-3 py-2 shadow-lg dark:border-gray-800 dark:bg-gray-850"
|
||||
>
|
||||
{#if draft}
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
id="voice-note-name"
|
||||
bind:this={nameInput}
|
||||
bind:value={draft.name}
|
||||
disabled={busy}
|
||||
spellcheck="false"
|
||||
autocomplete="off"
|
||||
aria-label={$i18n.t('File name')}
|
||||
class="h-7 min-w-0 flex-1 bg-transparent text-[0.8125rem] leading-5 outline-none"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={$i18n.t('Move')}
|
||||
aria-describedby="voice-note-move-hint"
|
||||
title={$i18n.t('Drag to move')}
|
||||
class="flex h-4 w-5 touch-none select-none cursor-grab items-center justify-center rounded text-gray-400 hover:text-gray-600 active:cursor-grabbing dark:text-gray-500 dark:hover:text-gray-300"
|
||||
on:pointerdown={beginDrag}
|
||||
on:pointermove={moveDrag}
|
||||
on:pointerup={endDrag}
|
||||
on:pointercancel={endDrag}
|
||||
on:keydown={moveWithKeyboard}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"
|
||||
><circle cx="9" cy="5" r="1.5" /><circle cx="15" cy="5" r="1.5" /><circle
|
||||
cx="9"
|
||||
cy="12"
|
||||
r="1.5"
|
||||
/><circle cx="15" cy="12" r="1.5" /><circle cx="9" cy="19" r="1.5" /><circle
|
||||
cx="15"
|
||||
cy="19"
|
||||
r="1.5"
|
||||
/></svg
|
||||
>
|
||||
</button>
|
||||
</div>
|
||||
<p
|
||||
class="truncate text-[0.6875rem] leading-4 text-gray-500 dark:text-gray-400"
|
||||
title={draft.directory}
|
||||
>
|
||||
{draft.directory}
|
||||
</p>
|
||||
<audio
|
||||
bind:this={player}
|
||||
src={audioUrl}
|
||||
on:ended={() => {
|
||||
playing = false;
|
||||
}}
|
||||
></audio>
|
||||
{#if draft.transcript}<textarea
|
||||
aria-label={$i18n.t('Transcript')}
|
||||
bind:value={draft.transcript}
|
||||
disabled={busy}
|
||||
rows="2"
|
||||
class="mt-2 max-h-24 w-full resize-y bg-transparent text-xs leading-5 text-gray-600 dark:text-gray-300 outline-none"
|
||||
></textarea>{/if}
|
||||
<div class="mt-2 flex items-center gap-1">
|
||||
<button
|
||||
class={buttonClass}
|
||||
disabled={busy}
|
||||
aria-label={$i18n.t(playing ? 'Pause' : 'Play')}
|
||||
title={$i18n.t(playing ? 'Pause' : 'Play')}
|
||||
on:click={async () => {
|
||||
if (playing) player.pause();
|
||||
else await player.play().catch(() => {});
|
||||
playing = !player.paused;
|
||||
}}
|
||||
>
|
||||
{#if playing}<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
aria-hidden="true"><path d="M8 5v14M16 5v14" /></svg
|
||||
>{:else}<Icon name="play" size={14} />{/if}
|
||||
</button>
|
||||
<span class="text-xs leading-4 tabular-nums text-gray-500 dark:text-gray-400"
|
||||
>{duration(draft.duration)}</span
|
||||
>
|
||||
<div class="ms-auto flex items-center gap-0.5">
|
||||
{#if transcriptionAvailable}<button
|
||||
class={buttonClass}
|
||||
disabled={busy}
|
||||
aria-label={$i18n.t('Transcribe')}
|
||||
title={$i18n.t('Transcribe')}
|
||||
on:click={transcribe}><Icon name="page-text" size={14} /></button
|
||||
>{/if}
|
||||
<a
|
||||
class={buttonClass}
|
||||
href={audioUrl}
|
||||
aria-label={$i18n.t('Download')}
|
||||
title={$i18n.t('Download')}
|
||||
download={`${draft.name || 'recording'}.${voiceNoteExtension(draft.audio.type)}`}
|
||||
><Icon name="download" size={14} /></a
|
||||
>
|
||||
</div>
|
||||
<div class="ms-1 flex items-center gap-1.5">
|
||||
<button class={buttonClass} aria-disabled={busy} on:click={close}
|
||||
>{$i18n.t('Cancel')}</button
|
||||
>
|
||||
<button class={primaryButtonClass} disabled={busy || !draft.name.trim()} on:click={save}
|
||||
>{$i18n.t(busy ? 'Processing...' : 'Save')}</button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-end gap-1.5">
|
||||
<button class={buttonClass} on:click={close}>{$i18n.t('Cancel')}</button>
|
||||
<button class={primaryButtonClass} on:click={start}>{$i18n.t('Record')}</button>
|
||||
</div>
|
||||
{/if}
|
||||
{#if error}<p role="alert" class="mt-3 text-xs text-red-500">{error}</p>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.voice-note-pill:hover .voice-note-wave,
|
||||
.voice-note-pill:focus-visible .voice-note-wave {
|
||||
opacity: 0.35;
|
||||
}
|
||||
.voice-note-pill:hover .voice-note-stop,
|
||||
.voice-note-pill:focus-visible .voice-note-stop {
|
||||
opacity: 1;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.voice-note-panel :global(*) {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -4543,5 +4543,17 @@
|
||||
"Zoom in": "",
|
||||
"Zoom out": "",
|
||||
"Searching...": "Searching...",
|
||||
"Type a file name or path to search.": "Type a file name or path to search."
|
||||
"Type a file name or path to search.": "Type a file name or path to search.",
|
||||
"Voice Note": "Voice Note",
|
||||
"Use arrow keys to move.": "Use arrow keys to move.",
|
||||
"Record again": "Record again",
|
||||
"Transcribe": "Transcribe",
|
||||
"Transcript": "Transcript",
|
||||
"Processing...": "Processing...",
|
||||
"Could not load the recording folder.": "Could not load the recording folder.",
|
||||
"No audio was recorded.": "No audio was recorded.",
|
||||
"Could not transcribe the recording.": "Could not transcribe the recording.",
|
||||
"Could not save the voice note. Retry or download the recording.": "Could not save the voice note. Retry or download the recording.",
|
||||
"settings.personal.shortcuts.voiceNote.label": "Voice Note",
|
||||
"Stop recording": "Stop recording"
|
||||
}
|
||||
@@ -19,6 +19,7 @@ type ShortcutRegistry = {
|
||||
export enum Shortcut {
|
||||
// Workspace tabs
|
||||
QUICK_OPEN = 'quickOpen',
|
||||
VOICE_NOTE = 'voiceNote',
|
||||
OPEN_FILES = 'openFiles',
|
||||
OPEN_DESKTOP = 'openDesktop',
|
||||
NEW_CHAT_TAB = 'newChatTab',
|
||||
@@ -73,6 +74,7 @@ export enum Shortcut {
|
||||
|
||||
export const CONFIGURABLE_SHORTCUTS = [
|
||||
Shortcut.QUICK_OPEN,
|
||||
Shortcut.VOICE_NOTE,
|
||||
Shortcut.OPEN_FILES,
|
||||
Shortcut.OPEN_DESKTOP,
|
||||
Shortcut.NEW_CHAT_TAB,
|
||||
@@ -114,6 +116,7 @@ export type KeybindingsMap = Record<ConfigurableShortcut, string>;
|
||||
|
||||
export const DEFAULT_KEYBINDINGS: KeybindingsMap = {
|
||||
[Shortcut.QUICK_OPEN]: 'Cmd+P',
|
||||
[Shortcut.VOICE_NOTE]: 'Cmd+Alt+M',
|
||||
[Shortcut.OPEN_FILES]: 'Cmd+Shift+E',
|
||||
[Shortcut.OPEN_DESKTOP]: 'Cmd+Alt+D',
|
||||
[Shortcut.NEW_CHAT_TAB]: 'Cmd+Alt+O',
|
||||
@@ -260,6 +263,12 @@ export function matchKeybinding(event: KeyboardEvent): ConfigurableShortcut | nu
|
||||
}
|
||||
|
||||
export const shortcuts: ShortcutRegistry = {
|
||||
[Shortcut.VOICE_NOTE]: {
|
||||
name: (t) => t('settings.personal.shortcuts.voiceNote.label'),
|
||||
keys: [],
|
||||
category: 'Tabs',
|
||||
configurable: true
|
||||
},
|
||||
[Shortcut.QUICK_OPEN]: {
|
||||
name: (t) => t('settings.personal.shortcuts.quickOpen.label'),
|
||||
keys: [],
|
||||
|
||||
Reference in new issue
Block a user