mirror of
https://github.com/open-webui/open-webui
synced 2025-06-09 07:56:42 +00:00
refac
This commit is contained in:
parent
1d82a1c8c4
commit
4acd278624
@ -357,14 +357,14 @@
|
|||||||
{#if recording}
|
{#if recording}
|
||||||
<VoiceRecording
|
<VoiceRecording
|
||||||
bind:recording
|
bind:recording
|
||||||
on:cancel={async () => {
|
onCancel={async () => {
|
||||||
recording = false;
|
recording = false;
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
document.getElementById(`chat-input-${id}`)?.focus();
|
document.getElementById(`chat-input-${id}`)?.focus();
|
||||||
}}
|
}}
|
||||||
on:confirm={async (e) => {
|
onConfirm={async (data) => {
|
||||||
const { text, filename } = e.detail;
|
const { text, filename } = data;
|
||||||
content = `${content}${text} `;
|
content = `${content}${text} `;
|
||||||
recording = false;
|
recording = false;
|
||||||
|
|
||||||
|
@ -479,14 +479,14 @@
|
|||||||
{#if recording}
|
{#if recording}
|
||||||
<VoiceRecording
|
<VoiceRecording
|
||||||
bind:recording
|
bind:recording
|
||||||
on:cancel={async () => {
|
onCancel={async () => {
|
||||||
recording = false;
|
recording = false;
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
document.getElementById('chat-input')?.focus();
|
document.getElementById('chat-input')?.focus();
|
||||||
}}
|
}}
|
||||||
on:confirm={async (e) => {
|
onConfirm={async (data) => {
|
||||||
const { text, filename } = e.detail;
|
const { text, filename } = data;
|
||||||
prompt = `${prompt}${text} `;
|
prompt = `${prompt}${text} `;
|
||||||
|
|
||||||
recording = false;
|
recording = false;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import { createEventDispatcher, tick, getContext, onMount, onDestroy } from 'svelte';
|
import { tick, getContext, onMount, onDestroy } from 'svelte';
|
||||||
import { config, settings } from '$lib/stores';
|
import { config, settings } from '$lib/stores';
|
||||||
import { blobToFile, calculateSHA256, extractCurlyBraceWords } from '$lib/utils';
|
import { blobToFile, calculateSHA256, extractCurlyBraceWords } from '$lib/utils';
|
||||||
|
|
||||||
@ -8,11 +8,13 @@
|
|||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
export let recording = false;
|
export let recording = false;
|
||||||
|
export let transcribe = true;
|
||||||
export let className = ' p-2.5 w-full max-w-full';
|
export let className = ' p-2.5 w-full max-w-full';
|
||||||
|
|
||||||
|
export let onCancel = () => {};
|
||||||
|
export let onConfirm = (data) => {};
|
||||||
|
|
||||||
let loading = false;
|
let loading = false;
|
||||||
let confirmed = false;
|
let confirmed = false;
|
||||||
|
|
||||||
@ -130,20 +132,32 @@
|
|||||||
detectSound();
|
detectSound();
|
||||||
};
|
};
|
||||||
|
|
||||||
const transcribeHandler = async (audioBlob) => {
|
const onStopHandler = async (audioBlob) => {
|
||||||
// Create a blob from the audio chunks
|
// Create a blob from the audio chunks
|
||||||
|
|
||||||
await tick();
|
await tick();
|
||||||
const file = blobToFile(audioBlob, 'recording.wav');
|
const file = blobToFile(audioBlob, 'recording.wav');
|
||||||
|
|
||||||
const res = await transcribeAudio(localStorage.token, file).catch((error) => {
|
if (transcribe) {
|
||||||
toast.error(`${error}`);
|
if ($config.audio.stt.engine === 'web' || ($settings?.audio?.stt?.engine ?? '') === 'web') {
|
||||||
return null;
|
// with web stt, we don't need to send the file to the server
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (res) {
|
const res = await transcribeAudio(localStorage.token, file).catch((error) => {
|
||||||
console.log(res);
|
toast.error(`${error}`);
|
||||||
dispatch('confirm', res);
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
console.log(res);
|
||||||
|
onConfirm(res);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onConfirm({
|
||||||
|
file: file,
|
||||||
|
blob: audioBlob
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -168,6 +182,7 @@
|
|||||||
autoGainControl: true
|
autoGainControl: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mediaRecorder = new MediaRecorder(stream);
|
mediaRecorder = new MediaRecorder(stream);
|
||||||
mediaRecorder.onstart = () => {
|
mediaRecorder.onstart = () => {
|
||||||
console.log('Recording started');
|
console.log('Recording started');
|
||||||
@ -180,77 +195,79 @@
|
|||||||
mediaRecorder.ondataavailable = (event) => audioChunks.push(event.data);
|
mediaRecorder.ondataavailable = (event) => audioChunks.push(event.data);
|
||||||
mediaRecorder.onstop = async () => {
|
mediaRecorder.onstop = async () => {
|
||||||
console.log('Recording stopped');
|
console.log('Recording stopped');
|
||||||
if ($config.audio.stt.engine === 'web' || ($settings?.audio?.stt?.engine ?? '') === 'web') {
|
|
||||||
audioChunks = [];
|
|
||||||
} else {
|
|
||||||
if (confirmed) {
|
|
||||||
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
|
||||||
|
|
||||||
await transcribeHandler(audioBlob);
|
if (confirmed) {
|
||||||
|
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
||||||
|
await onStopHandler(audioBlob);
|
||||||
|
|
||||||
confirmed = false;
|
confirmed = false;
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
|
||||||
audioChunks = [];
|
|
||||||
recording = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
audioChunks = [];
|
||||||
|
recording = false;
|
||||||
};
|
};
|
||||||
mediaRecorder.start();
|
mediaRecorder.start();
|
||||||
if ($config.audio.stt.engine === 'web' || ($settings?.audio?.stt?.engine ?? '') === 'web') {
|
|
||||||
if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
|
|
||||||
// Create a SpeechRecognition object
|
|
||||||
speechRecognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
|
||||||
|
|
||||||
// Set continuous to true for continuous recognition
|
if (transcribe) {
|
||||||
speechRecognition.continuous = true;
|
if ($config.audio.stt.engine === 'web' || ($settings?.audio?.stt?.engine ?? '') === 'web') {
|
||||||
|
if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
|
||||||
|
// Create a SpeechRecognition object
|
||||||
|
speechRecognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
||||||
|
|
||||||
// Set the timeout for turning off the recognition after inactivity (in milliseconds)
|
// Set continuous to true for continuous recognition
|
||||||
const inactivityTimeout = 2000; // 3 seconds
|
speechRecognition.continuous = true;
|
||||||
|
|
||||||
let timeoutId;
|
// Set the timeout for turning off the recognition after inactivity (in milliseconds)
|
||||||
// Start recognition
|
const inactivityTimeout = 2000; // 3 seconds
|
||||||
speechRecognition.start();
|
|
||||||
|
|
||||||
// Event triggered when speech is recognized
|
let timeoutId;
|
||||||
speechRecognition.onresult = async (event) => {
|
// Start recognition
|
||||||
// Clear the inactivity timeout
|
speechRecognition.start();
|
||||||
clearTimeout(timeoutId);
|
|
||||||
|
|
||||||
// Handle recognized speech
|
// Event triggered when speech is recognized
|
||||||
console.log(event);
|
speechRecognition.onresult = async (event) => {
|
||||||
const transcript = event.results[Object.keys(event.results).length - 1][0].transcript;
|
// Clear the inactivity timeout
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
transcription = `${transcription}${transcript}`;
|
// Handle recognized speech
|
||||||
|
console.log(event);
|
||||||
|
const transcript = event.results[Object.keys(event.results).length - 1][0].transcript;
|
||||||
|
|
||||||
await tick();
|
transcription = `${transcription}${transcript}`;
|
||||||
document.getElementById('chat-input')?.focus();
|
|
||||||
|
|
||||||
// Restart the inactivity timeout
|
await tick();
|
||||||
timeoutId = setTimeout(() => {
|
document.getElementById('chat-input')?.focus();
|
||||||
console.log('Speech recognition turned off due to inactivity.');
|
|
||||||
speechRecognition.stop();
|
|
||||||
}, inactivityTimeout);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Event triggered when recognition is ended
|
// Restart the inactivity timeout
|
||||||
speechRecognition.onend = function () {
|
timeoutId = setTimeout(() => {
|
||||||
// Restart recognition after it ends
|
console.log('Speech recognition turned off due to inactivity.');
|
||||||
console.log('recognition ended');
|
speechRecognition.stop();
|
||||||
|
}, inactivityTimeout);
|
||||||
|
};
|
||||||
|
|
||||||
confirmRecording();
|
// Event triggered when recognition is ended
|
||||||
dispatch('confirm', { text: transcription });
|
speechRecognition.onend = function () {
|
||||||
confirmed = false;
|
// Restart recognition after it ends
|
||||||
loading = false;
|
console.log('recognition ended');
|
||||||
};
|
|
||||||
|
|
||||||
// Event triggered when an error occurs
|
confirmRecording();
|
||||||
speechRecognition.onerror = function (event) {
|
onConfirm({
|
||||||
console.log(event);
|
text: transcription
|
||||||
toast.error($i18n.t(`Speech recognition error: {{error}}`, { error: event.error }));
|
});
|
||||||
dispatch('cancel');
|
confirmed = false;
|
||||||
|
loading = false;
|
||||||
|
};
|
||||||
|
|
||||||
stopRecording();
|
// Event triggered when an error occurs
|
||||||
};
|
speechRecognition.onerror = function (event) {
|
||||||
|
console.log(event);
|
||||||
|
toast.error($i18n.t(`Speech recognition error: {{error}}`, { error: event.error }));
|
||||||
|
onCancel();
|
||||||
|
|
||||||
|
stopRecording();
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -339,7 +356,7 @@
|
|||||||
rounded-full"
|
rounded-full"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
stopRecording();
|
stopRecording();
|
||||||
dispatch('cancel');
|
onCancel();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
|
@ -29,15 +29,19 @@
|
|||||||
|
|
||||||
export let oncompositionstart = (e) => {};
|
export let oncompositionstart = (e) => {};
|
||||||
export let oncompositionend = (e) => {};
|
export let oncompositionend = (e) => {};
|
||||||
|
export let onChange = (e) => {};
|
||||||
|
|
||||||
// create a lowlight instance with all languages loaded
|
// create a lowlight instance with all languages loaded
|
||||||
const lowlight = createLowlight(all);
|
const lowlight = createLowlight(all);
|
||||||
|
|
||||||
export let className = 'input-prose';
|
export let className = 'input-prose';
|
||||||
export let placeholder = 'Type here...';
|
export let placeholder = 'Type here...';
|
||||||
export let value = '';
|
|
||||||
export let id = '';
|
|
||||||
|
|
||||||
|
export let id = '';
|
||||||
|
export let value = '';
|
||||||
|
export let html = '';
|
||||||
|
|
||||||
|
export let json = false;
|
||||||
export let raw = false;
|
export let raw = false;
|
||||||
|
|
||||||
export let preserveBreaks = false;
|
export let preserveBreaks = false;
|
||||||
@ -128,41 +132,43 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
console.log(value);
|
|
||||||
|
|
||||||
if (preserveBreaks) {
|
|
||||||
turndownService.addRule('preserveBreaks', {
|
|
||||||
filter: 'br', // Target <br> elements
|
|
||||||
replacement: function (content) {
|
|
||||||
return '<br/>';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let content = value;
|
let content = value;
|
||||||
|
|
||||||
if (!raw) {
|
if (!json) {
|
||||||
async function tryParse(value, attempts = 3, interval = 100) {
|
if (preserveBreaks) {
|
||||||
try {
|
turndownService.addRule('preserveBreaks', {
|
||||||
// Try parsing the value
|
filter: 'br', // Target <br> elements
|
||||||
return marked.parse(value.replaceAll(`\n<br/>`, `<br/>`), {
|
replacement: function (content) {
|
||||||
breaks: false
|
return '<br/>';
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
// If no attempts remain, fallback to plain text
|
|
||||||
if (attempts <= 1) {
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
// Wait for the interval, then retry
|
});
|
||||||
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
||||||
return tryParse(value, attempts - 1, interval); // Recursive call
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Usage example
|
if (!raw) {
|
||||||
content = await tryParse(value);
|
async function tryParse(value, attempts = 3, interval = 100) {
|
||||||
|
try {
|
||||||
|
// Try parsing the value
|
||||||
|
return marked.parse(value.replaceAll(`\n<br/>`, `<br/>`), {
|
||||||
|
breaks: false
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// If no attempts remain, fallback to plain text
|
||||||
|
if (attempts <= 1) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
// Wait for the interval, then retry
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, interval));
|
||||||
|
return tryParse(value, attempts - 1, interval); // Recursive call
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Usage example
|
||||||
|
content = await tryParse(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('content', content);
|
||||||
|
|
||||||
editor = new Editor({
|
editor = new Editor({
|
||||||
element: element,
|
element: element,
|
||||||
extensions: [
|
extensions: [
|
||||||
@ -198,32 +204,44 @@
|
|||||||
// force re-render so `editor.isActive` works as expected
|
// force re-render so `editor.isActive` works as expected
|
||||||
editor = editor;
|
editor = editor;
|
||||||
|
|
||||||
if (!raw) {
|
html = editor.getHTML();
|
||||||
let newValue = turndownService
|
|
||||||
.turndown(
|
|
||||||
editor
|
|
||||||
.getHTML()
|
|
||||||
.replace(/<p><\/p>/g, '<br/>')
|
|
||||||
.replace(/ {2,}/g, (m) => m.replace(/ /g, '\u00a0'))
|
|
||||||
)
|
|
||||||
.replace(/\u00a0/g, ' ');
|
|
||||||
|
|
||||||
if (!preserveBreaks) {
|
onChange({
|
||||||
newValue = newValue.replace(/<br\/>/g, '');
|
html: editor.getHTML(),
|
||||||
}
|
json: editor.getJSON(),
|
||||||
|
md: turndownService.turndown(editor.getHTML())
|
||||||
|
});
|
||||||
|
|
||||||
if (value !== newValue) {
|
if (json) {
|
||||||
value = newValue;
|
value = editor.getJSON();
|
||||||
|
} else {
|
||||||
|
if (!raw) {
|
||||||
|
let newValue = turndownService
|
||||||
|
.turndown(
|
||||||
|
editor
|
||||||
|
.getHTML()
|
||||||
|
.replace(/<p><\/p>/g, '<br/>')
|
||||||
|
.replace(/ {2,}/g, (m) => m.replace(/ /g, '\u00a0'))
|
||||||
|
)
|
||||||
|
.replace(/\u00a0/g, ' ');
|
||||||
|
|
||||||
// check if the node is paragraph as well
|
if (!preserveBreaks) {
|
||||||
if (editor.isActive('paragraph')) {
|
newValue = newValue.replace(/<br\/>/g, '');
|
||||||
if (value === '') {
|
}
|
||||||
editor.commands.clearContent();
|
|
||||||
|
if (value !== newValue) {
|
||||||
|
value = newValue;
|
||||||
|
|
||||||
|
// check if the node is paragraph as well
|
||||||
|
if (editor.isActive('paragraph')) {
|
||||||
|
if (value === '') {
|
||||||
|
editor.commands.clearContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
value = editor.getHTML();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
value = editor.getHTML();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
editorProps: {
|
editorProps: {
|
||||||
@ -356,35 +374,25 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update the editor content if the external `value` changes
|
$: if (value && editor) {
|
||||||
$: if (
|
onValueChange();
|
||||||
editor &&
|
|
||||||
(raw
|
|
||||||
? value !== editor.getHTML()
|
|
||||||
: value !==
|
|
||||||
turndownService
|
|
||||||
.turndown(
|
|
||||||
(preserveBreaks
|
|
||||||
? editor.getHTML().replace(/<p><\/p>/g, '<br/>')
|
|
||||||
: editor.getHTML()
|
|
||||||
).replace(/ {2,}/g, (m) => m.replace(/ /g, '\u00a0'))
|
|
||||||
)
|
|
||||||
.replace(/\u00a0/g, ' '))
|
|
||||||
) {
|
|
||||||
if (raw) {
|
|
||||||
editor.commands.setContent(value);
|
|
||||||
} else {
|
|
||||||
preserveBreaks
|
|
||||||
? editor.commands.setContent(value)
|
|
||||||
: editor.commands.setContent(
|
|
||||||
marked.parse(value.replaceAll(`\n<br/>`, `<br/>`), {
|
|
||||||
breaks: false
|
|
||||||
})
|
|
||||||
); // Update editor content
|
|
||||||
}
|
|
||||||
|
|
||||||
selectTemplate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onValueChange = () => {
|
||||||
|
if (!editor) return;
|
||||||
|
|
||||||
|
if (json) {
|
||||||
|
if (JSON.stringify(value) !== JSON.stringify(editor.getJSON())) {
|
||||||
|
editor.commands.setContent(value);
|
||||||
|
selectTemplate();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (value !== editor.getHTML()) {
|
||||||
|
editor.commands.setContent(value);
|
||||||
|
selectTemplate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div bind:this={element} class="relative w-full min-w-full h-full min-h-fit {className}" />
|
<div bind:this={element} class="relative w-full min-w-full h-full min-h-fit {className}" />
|
||||||
|
19
src/lib/components/icons/Calendar.svelte
Normal file
19
src/lib/components/icons/Calendar.svelte
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let className = 'size-3';
|
||||||
|
export let strokeWidth = '1.5';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-width={strokeWidth}
|
||||||
|
stroke="currentColor"
|
||||||
|
class={className}
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5"
|
||||||
|
/>
|
||||||
|
</svg>
|
11
src/lib/components/icons/CalendarSolid.svelte
Normal file
11
src/lib/components/icons/CalendarSolid.svelte
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let className = 'size-4';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class={className}>
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
d="M6.75 2.25A.75.75 0 0 1 7.5 3v1.5h9V3A.75.75 0 0 1 18 3v1.5h.75a3 3 0 0 1 3 3v11.25a3 3 0 0 1-3 3H5.25a3 3 0 0 1-3-3V7.5a3 3 0 0 1 3-3H6V3a.75.75 0 0 1 .75-.75Zm13.5 9a1.5 1.5 0 0 0-1.5-1.5H5.25a1.5 1.5 0 0 0-1.5 1.5v7.5a1.5 1.5 0 0 0 1.5 1.5h13.5a1.5 1.5 0 0 0 1.5-1.5v-7.5Z"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
19
src/lib/components/icons/Users.svelte
Normal file
19
src/lib/components/icons/Users.svelte
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
export let className = 'size-3';
|
||||||
|
export let strokeWidth = '1.5';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke-width={strokeWidth}
|
||||||
|
stroke="currentColor"
|
||||||
|
class={className}
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
d="M15 19.128a9.38 9.38 0 0 0 2.625.372 9.337 9.337 0 0 0 4.121-.952 4.125 4.125 0 0 0-7.533-2.493M15 19.128v-.003c0-1.113-.285-2.16-.786-3.07M15 19.128v.106A12.318 12.318 0 0 1 8.624 21c-2.331 0-4.512-.645-6.374-1.766l-.001-.109a6.375 6.375 0 0 1 11.964-3.07M12 6.375a3.375 3.375 0 1 1-6.75 0 3.375 3.375 0 0 1 6.75 0Zm8.25 2.25a2.625 2.625 0 1 1-5.25 0 2.625 2.625 0 0 1 5.25 0Z"
|
||||||
|
/>
|
||||||
|
</svg>
|
@ -3,26 +3,58 @@
|
|||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import { getNoteById } from '$lib/apis/notes';
|
|
||||||
|
import { showSidebar } from '$lib/stores';
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
|
import dayjs from '$lib/dayjs';
|
||||||
|
import calendar from 'dayjs/plugin/calendar';
|
||||||
|
import duration from 'dayjs/plugin/duration';
|
||||||
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||||
|
|
||||||
|
dayjs.extend(calendar);
|
||||||
|
dayjs.extend(duration);
|
||||||
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
|
async function loadLocale(locales) {
|
||||||
|
for (const locale of locales) {
|
||||||
|
try {
|
||||||
|
dayjs.locale(locale);
|
||||||
|
break; // Stop after successfully loading the first available locale
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Could not load locale '${locale}':`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assuming $i18n.languages is an array of language codes
|
||||||
|
$: loadLocale($i18n.languages);
|
||||||
|
|
||||||
|
import { getNoteById, updateNoteById } from '$lib/apis/notes';
|
||||||
|
|
||||||
import RichTextInput from '../common/RichTextInput.svelte';
|
import RichTextInput from '../common/RichTextInput.svelte';
|
||||||
import Spinner from '../common/Spinner.svelte';
|
import Spinner from '../common/Spinner.svelte';
|
||||||
import Sparkles from '../icons/Sparkles.svelte';
|
|
||||||
import SparklesSolid from '../icons/SparklesSolid.svelte';
|
|
||||||
import Mic from '../icons/Mic.svelte';
|
import Mic from '../icons/Mic.svelte';
|
||||||
import VoiceRecording from '../chat/MessageInput/VoiceRecording.svelte';
|
import VoiceRecording from '../chat/MessageInput/VoiceRecording.svelte';
|
||||||
import Tooltip from '../common/Tooltip.svelte';
|
import Tooltip from '../common/Tooltip.svelte';
|
||||||
import { showSidebar } from '$lib/stores';
|
|
||||||
|
import Calendar from '../icons/Calendar.svelte';
|
||||||
|
import Users from '../icons/Users.svelte';
|
||||||
|
|
||||||
export let id: null | string = null;
|
export let id: null | string = null;
|
||||||
|
|
||||||
let title = '';
|
let note = {
|
||||||
let data = {
|
title: '',
|
||||||
content: '',
|
data: {
|
||||||
files: []
|
content: {
|
||||||
|
json: null,
|
||||||
|
html: '',
|
||||||
|
md: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
meta: null,
|
||||||
|
access_control: null
|
||||||
};
|
};
|
||||||
let meta = null;
|
|
||||||
let accessControl = null;
|
|
||||||
|
|
||||||
let voiceInput = false;
|
let voiceInput = false;
|
||||||
let loading = false;
|
let loading = false;
|
||||||
@ -35,15 +67,38 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
title = res.title;
|
note = res;
|
||||||
data = res.data;
|
} else {
|
||||||
meta = res.meta;
|
toast.error($i18n.t('Note not found'));
|
||||||
accessControl = res.access_control;
|
goto('/notes');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loading = false;
|
loading = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let debounceTimeout: NodeJS.Timeout | null = null;
|
||||||
|
|
||||||
|
const changeDebounceHandler = () => {
|
||||||
|
console.log('debounce');
|
||||||
|
if (debounceTimeout) {
|
||||||
|
clearTimeout(debounceTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
debounceTimeout = setTimeout(async () => {
|
||||||
|
const res = await updateNoteById(localStorage.token, id, {
|
||||||
|
...note,
|
||||||
|
title: note.title === '' ? $i18n.t('Untitled') : note.title
|
||||||
|
}).catch((e) => {
|
||||||
|
toast.error(`${e}`);
|
||||||
|
});
|
||||||
|
}, 200);
|
||||||
|
};
|
||||||
|
|
||||||
|
$: if (note) {
|
||||||
|
changeDebounceHandler();
|
||||||
|
}
|
||||||
|
|
||||||
$: if (id) {
|
$: if (id) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
@ -56,35 +111,55 @@
|
|||||||
<Spinner />
|
<Spinner />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{:else}
|
||||||
|
<div class=" w-full flex flex-col {loading ? 'opacity-20' : ''}">
|
||||||
|
<div class="shrink-0 w-full flex justify-between items-center px-4.5 mb-1">
|
||||||
|
<div class="w-full">
|
||||||
|
<input
|
||||||
|
class="w-full text-2xl font-medium bg-transparent outline-hidden"
|
||||||
|
type="text"
|
||||||
|
bind:value={note.title}
|
||||||
|
placeholder={$i18n.t('Title')}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class=" w-full flex flex-col gap-2 {loading ? 'opacity-20' : ''}">
|
<div
|
||||||
<div class="shrink-0 w-full flex justify-between items-center px-4.5">
|
class="flex gap-1 px-3.5 items-center text-xs font-medium text-gray-500 dark:text-gray-500 mb-4"
|
||||||
<div class="w-full">
|
>
|
||||||
<input
|
<button class=" flex items-center gap-1 w-fit py-1 px-1.5 rounded-lg">
|
||||||
class="w-full text-2xl font-medium bg-transparent outline-hidden"
|
<Calendar className="size-3.5" strokeWidth="2" />
|
||||||
type="text"
|
|
||||||
bind:value={title}
|
<span>{dayjs(note.created_at / 1000000).calendar()}</span>
|
||||||
placeholder={$i18n.t('Title')}
|
</button>
|
||||||
required
|
|
||||||
|
<button class=" flex items-center gap-1 w-fit py-1 px-1.5 rounded-lg">
|
||||||
|
<Users className="size-3.5" strokeWidth="2" />
|
||||||
|
|
||||||
|
<span> You </span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class=" flex-1 w-full h-full overflow-auto px-4.5 pb-5">
|
||||||
|
<RichTextInput
|
||||||
|
className="input-prose-sm"
|
||||||
|
bind:value={note.data.content.json}
|
||||||
|
placeholder={$i18n.t('Write something...')}
|
||||||
|
json={true}
|
||||||
|
onChange={(content) => {
|
||||||
|
note.data.html = content.html;
|
||||||
|
note.data.md = content.md;
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
<div class=" flex-1 w-full h-full overflow-auto px-4.5">
|
|
||||||
<RichTextInput
|
|
||||||
className="input-prose-sm"
|
|
||||||
bind:value={data.content}
|
|
||||||
placeholder={$i18n.t('Write something...')}
|
|
||||||
preserveBreaks={true}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="absolute bottom-0 left-0 right-0 p-5 max-w-full flex justify-end">
|
<div class="absolute bottom-0 right-0 p-5 max-w-full flex justify-end">
|
||||||
<div
|
<div
|
||||||
class="flex gap-0.5 justify-end w-full {$showSidebar
|
class="flex gap-0.5 justify-end w-full {$showSidebar && voiceInput
|
||||||
? 'md:max-w-[calc(100%-260px)]'
|
? 'md:max-w-[calc(100%-260px)]'
|
||||||
: ''} max-w-full"
|
: ''} max-w-full"
|
||||||
>
|
>
|
||||||
@ -93,24 +168,12 @@
|
|||||||
<VoiceRecording
|
<VoiceRecording
|
||||||
bind:recording={voiceInput}
|
bind:recording={voiceInput}
|
||||||
className="p-1 w-full max-w-full"
|
className="p-1 w-full max-w-full"
|
||||||
on:cancel={() => {
|
transcribe={false}
|
||||||
|
onCancel={() => {
|
||||||
voiceInput = false;
|
voiceInput = false;
|
||||||
}}
|
}}
|
||||||
on:confirm={(e) => {
|
onConfirm={(data) => {
|
||||||
const { text, filename } = e.detail;
|
console.log(data);
|
||||||
|
|
||||||
// url is hostname + /cache/audio/transcription/ + filename
|
|
||||||
const url = `${window.location.origin}/cache/audio/transcription/${filename}`;
|
|
||||||
|
|
||||||
// Open in new tab
|
|
||||||
|
|
||||||
if (content.trim() !== '') {
|
|
||||||
content = `${content}\n\n${text}\n\nRecording: ${url}\n\n`;
|
|
||||||
} else {
|
|
||||||
content = `${content}${text}\n\nRecording: ${url}\n\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
voiceInput = false;
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -58,7 +58,11 @@
|
|||||||
const res = await createNewNote(localStorage.token, {
|
const res = await createNewNote(localStorage.token, {
|
||||||
title: $i18n.t('New Note'),
|
title: $i18n.t('New Note'),
|
||||||
data: {
|
data: {
|
||||||
content: ''
|
content: {
|
||||||
|
json: null,
|
||||||
|
html: '',
|
||||||
|
md: ''
|
||||||
|
}
|
||||||
},
|
},
|
||||||
meta: null,
|
meta: null,
|
||||||
access_control: null
|
access_control: null
|
||||||
@ -95,30 +99,37 @@
|
|||||||
</div>
|
</div>
|
||||||
</DeleteConfirmDialog>
|
</DeleteConfirmDialog>
|
||||||
|
|
||||||
<div class="px-4.5">
|
<div class="px-4.5 @container h-full">
|
||||||
{#if Object.keys(notes).length > 0}
|
{#if Object.keys(notes).length > 0}
|
||||||
{#each Object.keys(notes) as timeRange}
|
{#each Object.keys(notes) as timeRange}
|
||||||
<div class="w-full text-xs text-gray-500 dark:text-gray-500 font-medium pb-2">
|
<div class="w-full text-xs text-gray-500 dark:text-gray-500 font-medium pb-2">
|
||||||
{$i18n.t(timeRange)}
|
{$i18n.t(timeRange)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-5 gap-2 grid @lg:grid-cols-2 @2xl:grid-cols-3">
|
<div class="mb-5 gap-2 grid grid-cols-1 lg:grid-cols-3 xl:grid-cols-4">
|
||||||
{#each notes[timeRange] as note, idx (note.id)}
|
{#each notes[timeRange] as note, idx (note.id)}
|
||||||
<div
|
<div
|
||||||
class=" flex space-x-4 cursor-pointer w-full px-4 py-3.5 bg-gray-50 dark:bg-gray-850 dark:hover:bg-white/5 hover:bg-black/5 rounded-xl transition"
|
class=" flex space-x-4 cursor-pointer w-full px-4.5 py-4 bg-gray-50 dark:bg-gray-850 dark:hover:bg-white/5 hover:bg-black/5 rounded-xl transition"
|
||||||
>
|
>
|
||||||
<div class=" flex flex-1 space-x-4 cursor-pointer w-full">
|
<div class=" flex flex-1 space-x-4 cursor-pointer w-full">
|
||||||
<a href={`/notes/${note.id}`} class="w-full -translate-y-0.5">
|
<a
|
||||||
<div class=" flex-1 flex items-center gap-2 self-center">
|
href={`/notes/${note.id}`}
|
||||||
<div class=" font-semibold line-clamp-1 capitalize">{note.title}</div>
|
class="w-full -translate-y-0.5 flex flex-col justify-between"
|
||||||
</div>
|
>
|
||||||
|
<div class="flex-1">
|
||||||
|
<div class=" flex items-center gap-2 self-center mb-1">
|
||||||
|
<div class=" font-semibold line-clamp-1 capitalize">{note.title}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class=" text-xs text-gray-500 dark:text-gray-500 line-clamp-2 pb-2">
|
<div
|
||||||
{#if note.data?.content}
|
class=" text-xs text-gray-500 dark:text-gray-500 mb-3 line-clamp-5 min-h-18"
|
||||||
{note.data?.content}
|
>
|
||||||
{:else}
|
{#if note.data?.md}
|
||||||
{$i18n.t('No content')}
|
{note.data?.md}
|
||||||
{/if}
|
{:else}
|
||||||
|
{$i18n.t('No content')}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class=" text-xs px-0.5 w-full flex justify-between items-center">
|
<div class=" text-xs px-0.5 w-full flex justify-between items-center">
|
||||||
|
@ -57,11 +57,11 @@
|
|||||||
<VoiceRecording
|
<VoiceRecording
|
||||||
bind:recording={voiceInput}
|
bind:recording={voiceInput}
|
||||||
className="p-1 w-full max-w-full"
|
className="p-1 w-full max-w-full"
|
||||||
on:cancel={() => {
|
onCancel={() => {
|
||||||
voiceInput = false;
|
voiceInput = false;
|
||||||
}}
|
}}
|
||||||
on:confirm={(e) => {
|
onConfirm={(data) => {
|
||||||
const { text, filename } = e.detail;
|
const { text, filename } = data;
|
||||||
|
|
||||||
// url is hostname + /cache/audio/transcription/ + filename
|
// url is hostname + /cache/audio/transcription/ + filename
|
||||||
const url = `${window.location.origin}/cache/audio/transcription/${filename}`;
|
const url = `${window.location.origin}/cache/audio/transcription/${filename}`;
|
||||||
|
@ -85,11 +85,11 @@
|
|||||||
<VoiceRecording
|
<VoiceRecording
|
||||||
bind:recording={voiceInput}
|
bind:recording={voiceInput}
|
||||||
className="p-1"
|
className="p-1"
|
||||||
on:cancel={() => {
|
onCancel={() => {
|
||||||
voiceInput = false;
|
voiceInput = false;
|
||||||
}}
|
}}
|
||||||
on:confirm={(e) => {
|
onConfirm={(data) => {
|
||||||
const { text, filename } = e.detail;
|
const { text, filename } = data;
|
||||||
content = `${content}${text} `;
|
content = `${content}${text} `;
|
||||||
|
|
||||||
voiceInput = false;
|
voiceInput = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user