Skip to content

Commit

Permalink
Merge pull request #1111 from ManishMadan2882/main
Browse files Browse the repository at this point in the history
Widget: Replaced deprecated dependency
  • Loading branch information
dartpain authored Sep 2, 2024
2 parents b630be8 + d4042eb commit 736add0
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 14 deletions.
87 changes: 77 additions & 10 deletions extensions/react-widget/package-lock.json

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

3 changes: 2 additions & 1 deletion extensions/react-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
},
"dependencies": {
"@babel/plugin-transform-flow-strip-types": "^7.23.3",
"@bpmn-io/snarkdown": "^2.2.0",
"@parcel/resolver-glob": "^2.12.0",
"@parcel/transformer-svg-react": "^2.12.0",
"@parcel/transformer-typescript-tsc": "^2.12.0",
Expand All @@ -52,6 +51,7 @@
"flow-bin": "^0.229.2",
"i": "^0.3.7",
"install": "^0.13.0",
"markdown-it": "^14.1.0",
"npm": "^10.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -64,6 +64,7 @@
"@parcel/packager-ts": "^2.12.0",
"@parcel/transformer-typescript-types": "^2.12.0",
"@types/dompurify": "^3.0.5",
"@types/markdown-it": "^14.1.2",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"babel-loader": "^8.0.4",
Expand Down
16 changes: 13 additions & 3 deletions extensions/react-widget/src/components/DocsGPTWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use client";
import React from 'react'
import DOMPurify from 'dompurify';
import snarkdown from '@bpmn-io/snarkdown';
import styled, { keyframes, createGlobalStyle } from 'styled-components';
import { PaperPlaneIcon, RocketIcon, ExclamationTriangleIcon, Cross2Icon } from '@radix-ui/react-icons';
import { MESSAGE_TYPE, Query, Status, WidgetProps } from '../types/index';
import { fetchAnswerStreaming } from '../requests/streamingApi';
import { ThemeProvider } from 'styled-components';
import MarkdownIt from 'markdown-it';
const themes = {
dark: {
bg: '#222327',
Expand Down Expand Up @@ -41,6 +41,7 @@ const GlobalStyles = createGlobalStyle`
border-radius: 6px;
overflow-x: auto;
background-color: #1B1C1F;
color: #fff !important;
}
.response h1{
font-size: 20px;
Expand All @@ -51,12 +52,16 @@ const GlobalStyles = createGlobalStyle`
.response h3{
font-size: 16px;
}
.response p{
margin:0px;
}
.response code:not(pre code){
border-radius: 6px;
padding: 1px 3px 1px 3px;
font-size: 12px;
display: inline-block;
background-color: #646464;
color: #fff !important;
}
`;
const Overlay = styled.div`
Expand Down Expand Up @@ -338,7 +343,7 @@ export const DocsGPTWidget = ({
heroTitle = 'Welcome to DocsGPT !',
heroDescription = 'This chatbot is built with DocsGPT and utilises GenAI, please review important information using sources.',
size = 'small',
theme = 'light',
theme = 'dark',
buttonIcon = 'https://d3dg1063dc54p9.cloudfront.net/widget/message.svg',
buttonBg = 'linear-gradient(to bottom right, #5AF0EC, #E80D9D)'
}: WidgetProps) => {
Expand All @@ -349,6 +354,8 @@ export const DocsGPTWidget = ({
const [open, setOpen] = React.useState<boolean>(false)
const [eventInterrupt, setEventInterrupt] = React.useState<boolean>(false); //click or scroll by user while autoScrolling
const endMessageRef = React.useRef<HTMLDivElement | null>(null);
const md = new MarkdownIt();

const handleUserInterrupt = () => {
(status === 'loading') && setEventInterrupt(true);
}
Expand Down Expand Up @@ -471,7 +478,10 @@ export const DocsGPTWidget = ({
type='ANSWER'
ref={(index === queries.length - 1) ? endMessageRef : null}
>
<div className="response" dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(snarkdown(query.response)) }} />
<div
className="response"
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(md.render(query.response)) }}
/>
</Message>
</MessageBubble>
: <div>
Expand Down

0 comments on commit 736add0

Please sign in to comment.