Skip to content

Commit

Permalink
Merge pull request #269 from iceljc/features/refine-chat-window
Browse files Browse the repository at this point in the history
Features/refine chat window
  • Loading branch information
iceljc authored Nov 7, 2024
2 parents 21cdc87 + 64e2cc4 commit 68e9cef
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 48 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"svelte-json-tree": "^2.2.0",
"svelte-jsoneditor": "^0.21.1",
"svelte-link": "^1.4.0",
"svelte-markdown": "^0.4.1",
"svelte-player": "^0.0.21",
"svelte-select": "^5.7.0",
"svelte-splitpanes": "^8.0.5",
Expand Down
31 changes: 0 additions & 31 deletions src/lib/common/Markdown.svelte

This file was deleted.

57 changes: 57 additions & 0 deletions src/lib/common/markdown/CodeBlock.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<script>
/** @type {string} */
export let lang;
/** @type {string} */
export let text;
/** @type {boolean} */
let copied = false;
function copyToClipboard() {
navigator.clipboard.writeText(text).then(() => {
setTimeout(() => {
copied = false;
}, 800);
});
}
</script>


<div class="code-block">
<div class="code-header">
<div class="line-align-center fw-bold">
{lang || ''}
</div>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="line-align-center copy-btn"
data-bs-toggle="tooltip"
data-bs-placement="top"
title="Copy"
on:mouseup={() => copyToClipboard()}
on:mousedown={() => copied = true}
>
{#if copied}
<div class="div-center">
<div class="line-align-center">
<i class="bx bx-check" style="font-size: 18px;" />
</div>
<div class="line-align-center">
<span style="font-size: 10px;">{'Copied!'}</span>
</div>
</div>
{:else}
<i class="bx bx-copy clickable" />
{/if}
</div>
</div>
<pre>
<code class={`language-${lang}`}>
<div>{text}</div>
</code>
</pre>
</div>
35 changes: 35 additions & 0 deletions src/lib/common/markdown/Markdown.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script>
import SvelteMarkdown from 'svelte-markdown';
import { replaceMarkdown, replaceNewLine } from '$lib/helpers/http';
import CodeBlock from './CodeBlock.svelte';
/** @type {string} */
export let text;
/** @type {string} */
export let containerClasses = "";
/** @type {string} */
export let containerStyles = "";
/** @type {boolean} */
export let rawText = false;
let innerText = '';
$: {
innerText = !rawText ? replaceNewLine(replaceMarkdown(text || '')) : text;
}
</script>

<div
class={`markdown-container markdown-lite ${containerClasses || 'text-white'}`}
style={`${containerStyles}`}
>
<!-- {@html innerText} -->
<SvelteMarkdown
source={innerText}
renderers={{
code: CodeBlock
}}
/>
</div>
1 change: 1 addition & 0 deletions src/lib/scss/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ File: Main Css File
@import "custom/components/audio";
@import "custom/components/text";
@import "custom/components/multiselect";
@import "custom/components/markdown";

// Plugins
@import "custom/plugins/custom-scrollbar";
Expand Down
13 changes: 0 additions & 13 deletions src/lib/scss/custom/common/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,6 @@ button:focus {
white-space: pre-wrap;
margin-top: 1em;
margin-bottom: 1em;

&:has(.language-sql),
&:has(.language-java),
&:has(.language-javascript),
&:has(.language-typescript),
&:has(.language-csharp),
&:has(.language-python),
&:has(.language-json) {
background-color: black;
color: white;
border-radius: 5px;
padding: 5px 10px;
}
}

pre::-webkit-scrollbar {
Expand Down
20 changes: 20 additions & 0 deletions src/lib/scss/custom/components/_markdown.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.code-block {
position: relative;
background-color: black;
color: white;
border-radius: 5px;
padding: 5px 10px;

pre {
margin: 0px !important;
white-space: pre !important;
overflow-x: auto;
scrollbar-width: thin;
max-width: 100%;
}

.code-header {
display: flex;
justify-content: space-between;
}
}
1 change: 1 addition & 0 deletions src/lib/scss/custom/pages/_conversation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 10;
max-height: 300px;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { Button } from '@sveltestrap/sveltestrap';
import Link from 'svelte-link/src/Link.svelte';
import Markdown from "$lib/common/Markdown.svelte";
import Markdown from "$lib/common/markdown/Markdown.svelte";
import { ContentLogSource } from '$lib/helpers/enums';
import { utcToLocal } from '$lib/helpers/datetime';
import { directToAgentPage } from '$lib/helpers/utils/common';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import Markdown from "$lib/common/Markdown.svelte";
import Markdown from "$lib/common/markdown/Markdown.svelte";
/** @type {any} */
export let message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import RcPlainOptions from "./rc-plain-options.svelte";
import RcComplexOptions from "./rc-complex-options.svelte";
import ChatAttachmentOptions from "../chat-util/chat-attachment-options.svelte";
import { afterUpdate, tick } from "svelte";
/** @type {import('$conversationTypes').ChatResponseModel?} */
export let message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import Markdown from '$lib/common/Markdown.svelte';
import Markdown from '$lib/common/markdown/Markdown.svelte';
import { Button } from '@sveltestrap/sveltestrap';
/** @type {import('$conversationTypes').ChatResponseModel} */
Expand Down

0 comments on commit 68e9cef

Please sign in to comment.