浏览代码

Feat: Adjust the EmbedDialog style #3221 (#8911)

### What problem does this PR solve?

Feat: Adjust the EmbedDialog style #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
tags/v0.20.0
balibabu 3 个月前
父节点
当前提交
3722fec921
没有帐户链接到提交者的电子邮件

+ 4
- 1
web/src/components/highlight-markdown/index.tsx 查看文件

import classNames from 'classnames'; import classNames from 'classnames';
import Markdown from 'react-markdown'; import Markdown from 'react-markdown';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
import rehypeKatex from 'rehype-katex'; import rehypeKatex from 'rehype-katex';
import rehypeRaw from 'rehype-raw'; import rehypeRaw from 'rehype-raw';
import remarkGfm from 'remark-gfm'; import remarkGfm from 'remark-gfm';


const HightLightMarkdown = ({ const HightLightMarkdown = ({
children, children,
dark = false,
}: { }: {
children: string | null | undefined; children: string | null | undefined;
dark?: boolean;
}) => { }) => {
return ( return (
<Markdown <Markdown
{...rest} {...rest}
PreTag="div" PreTag="div"
language={match[1]} language={match[1]}
// style={dark}
style={dark && oneDark}
> >
{String(children).replace(/\n$/, '')} {String(children).replace(/\n$/, '')}
</SyntaxHighlighter> </SyntaxHighlighter>

+ 1
- 1
web/src/components/ui/dialog.tsx 查看文件

<DialogPrimitive.Content <DialogPrimitive.Content
ref={ref} ref={ref}
className={cn( className={cn(
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-2xl translate-x-[-50%] translate-y-[-50%] gap-4 border bg-colors-background-neutral-standard p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg',
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-xl translate-x-[-50%] translate-y-[-50%] gap-4 border bg-colors-background-neutral-standard p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg',
className, className,
)} )}
{...props} {...props}

+ 84
- 46
web/src/pages/agent/embed-dialog/index.tsx 查看文件

import CopyToClipboard from '@/components/copy-to-clipboard'; import CopyToClipboard from '@/components/copy-to-clipboard';
import HightLightMarkdown from '@/components/highlight-markdown'; import HightLightMarkdown from '@/components/highlight-markdown';
import {
UnderlineTabs,
UnderlineTabsContent,
UnderlineTabsList,
UnderlineTabsTrigger,
} from '@/components/originui/underline-tabs';
import { SelectWithSearch } from '@/components/originui/select-with-search';
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from '@/components/ui/dialog'; } from '@/components/ui/dialog';
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '@/components/ui/form';
import { Switch } from '@/components/ui/switch';
import { SharedFrom } from '@/constants/chat'; import { SharedFrom } from '@/constants/chat';
import { import {
LanguageAbbreviation, LanguageAbbreviation,
} from '@/constants/common'; } from '@/constants/common';
import { useTranslate } from '@/hooks/common-hooks'; import { useTranslate } from '@/hooks/common-hooks';
import { IModalProps } from '@/interfaces/common'; import { IModalProps } from '@/interfaces/common';
import { memo, useMemo, useState } from 'react';
import { zodResolver } from '@hookform/resolvers/zod';
import { memo, useCallback, useMemo } from 'react';
import { useForm, useWatch } from 'react-hook-form';
import { z } from 'zod';

const FormSchema = z.object({
visibleAvatar: z.boolean(),
locale: z.string(),
});


type IProps = IModalProps<any> & { type IProps = IModalProps<any> & {
token: string; token: string;
form: SharedFrom;
from: SharedFrom;
beta: string; beta: string;
isAgent: boolean; isAgent: boolean;
}; };
function EmbedDialog({ function EmbedDialog({
hideModal, hideModal,
token = '', token = '',
form,
from,
beta = '', beta = '',
isAgent, isAgent,
}: IProps) { }: IProps) {
const { t } = useTranslate('chat'); const { t } = useTranslate('chat');


const [visibleAvatar, setVisibleAvatar] = useState(false);
const [locale, setLocale] = useState('');
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
visibleAvatar: false,
locale: '',
},
});

const values = useWatch({ control: form.control });


const languageOptions = useMemo(() => { const languageOptions = useMemo(() => {
return Object.values(LanguageAbbreviation).map((x) => ({ return Object.values(LanguageAbbreviation).map((x) => ({
})); }));
}, []); }, []);


const generateIframeSrc = () => {
let src = `${location.origin}/chat/share?shared_id=${token}&from=${form}&auth=${beta}`;
const generateIframeSrc = useCallback(() => {
const { visibleAvatar, locale } = values;
let src = `${location.origin}/chat/share?shared_id=${token}&from=${from}&auth=${beta}`;
if (visibleAvatar) { if (visibleAvatar) {
src += '&visible_avatar=1'; src += '&visible_avatar=1';
} }
src += `&locale=${locale}`; src += `&locale=${locale}`;
} }
return src; return src;
};

const iframeSrc = generateIframeSrc();
}, [beta, from, token, values]);


const text = `
const text = useMemo(() => {
const iframeSrc = generateIframeSrc();
return `
~~~ html ~~~ html
<iframe <iframe
src="${iframeSrc}" src="${iframeSrc}"
</iframe> </iframe>
~~~ ~~~
`; `;
}, [generateIframeSrc]);


return ( return (
<Dialog open onOpenChange={hideModal}> <Dialog open onOpenChange={hideModal}>
{t('embedIntoSite', { keyPrefix: 'common' })} {t('embedIntoSite', { keyPrefix: 'common' })}
</DialogTitle> </DialogTitle>
</DialogHeader> </DialogHeader>
<section className="w-full overflow-auto">
<UnderlineTabs defaultValue="1" className="w-full">
<UnderlineTabsList>
<UnderlineTabsTrigger value="1">
{t('fullScreenTitle')}
</UnderlineTabsTrigger>
<UnderlineTabsTrigger value="2">
{t('partialTitle')}
</UnderlineTabsTrigger>
<UnderlineTabsTrigger value="3">
{t('extensionTitle')}
</UnderlineTabsTrigger>
</UnderlineTabsList>
<UnderlineTabsContent value="1">
<section>
<HightLightMarkdown>{text}</HightLightMarkdown>
</section>
</UnderlineTabsContent>
<UnderlineTabsContent value="2">
{t('comingSoon')}
</UnderlineTabsContent>
<UnderlineTabsContent value="3">
{t('comingSoon')}
</UnderlineTabsContent>
</UnderlineTabs>
<div className="text-base font-medium mt-4 mb-1">
<section className="w-full overflow-auto space-y-5 text-sm text-text-sub-title">
<Form {...form}>
<form className="space-y-5">
<FormField
control={form.control}
name="visibleAvatar"
render={({ field }) => (
<FormItem>
<FormLabel>{t('avatarHidden')}</FormLabel>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
></Switch>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="locale"
render={({ field }) => (
<FormItem>
<FormLabel>{t('locale')}</FormLabel>
<FormControl>
<SelectWithSearch
{...field}
options={languageOptions}
></SelectWithSearch>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</form>
</Form>
<div>
<span>Embed code</span>
<HightLightMarkdown dark>{text}</HightLightMarkdown>
</div>
<div className=" font-medium mt-4 mb-1">
{t(isAgent ? 'flow' : 'chat', { keyPrefix: 'header' })} {t(isAgent ? 'flow' : 'chat', { keyPrefix: 'header' })}
<span className="ml-1 inline-block">ID</span> <span className="ml-1 inline-block">ID</span>
</div> </div>
<div className="bg-background-card rounded-md p-2 ">
{token} <CopyToClipboard text={token}></CopyToClipboard>
<div className="bg-background-card rounded-lg flex justify-between p-2">
<span>{token} </span>
<CopyToClipboard text={token}></CopyToClipboard>
</div> </div>
<a <a
className="pt-3 cursor-pointer text-background-checked inline-block"
className="cursor-pointer text-background-checked inline-block"
href={ href={
isAgent isAgent
? 'https://ragflow.io/docs/dev/http_api_reference#create-session-with-agent' ? 'https://ragflow.io/docs/dev/http_api_reference#create-session-with-agent'

+ 1
- 1
web/src/pages/agent/index.tsx 查看文件

visible={embedVisible} visible={embedVisible}
hideModal={hideEmbedModal} hideModal={hideEmbedModal}
token={id!} token={id!}
form={SharedFrom.Agent}
from={SharedFrom.Agent}
beta={beta} beta={beta}
isAgent isAgent
></EmbedDialog> ></EmbedDialog>

正在加载...
取消
保存