-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: 优化 plugin 文件夹命名以支持 standalone 类型的插件
- Loading branch information
Showing
16 changed files
with
153 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 15 additions & 14 deletions
29
src/app/chat/features/Conversation/ChatList/Messages/Function.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import { RenderMessage } from '@lobehub/ui'; | ||
import isEqual from 'fast-deep-equal'; | ||
import { memo } from 'react'; | ||
import { Flexbox } from 'react-layout-kit'; | ||
|
||
import { useSessionStore } from '@/store/session'; | ||
import { chatSelectors } from '@/store/session/selectors'; | ||
|
||
import FunctionCall from '../Plugins/FunctionCall'; | ||
import PluginMessage from '../Plugins/PluginMessage'; | ||
import Inspector from '../Plugins/Inspector'; | ||
import PluginRender from '../Plugins/Render'; | ||
|
||
export const FunctionMessage: RenderMessage = memo( | ||
({ id, content, plugin, function_call, name }) => { | ||
const genFunctionCallProps = useSessionStore(chatSelectors.getFunctionMessageParams); | ||
const fcProps = genFunctionCallProps({ content, function_call, id, plugin }); | ||
export const FunctionMessage: RenderMessage = memo(({ id, content, plugin, name }) => { | ||
const fcProps = useSessionStore( | ||
chatSelectors.getFunctionMessageProps({ content, id, plugin }), | ||
isEqual, | ||
); | ||
|
||
return ( | ||
<Flexbox gap={12} id={id}> | ||
<FunctionCall {...fcProps} /> | ||
<PluginMessage content={content} loading={fcProps.loading} name={name} /> | ||
</Flexbox> | ||
); | ||
}, | ||
); | ||
return ( | ||
<Flexbox gap={12} id={id}> | ||
<Inspector {...fcProps} /> | ||
<PluginRender content={content} loading={fcProps.loading} name={name} type={fcProps.type} /> | ||
</Flexbox> | ||
); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/app/chat/features/Conversation/ChatList/Plugins/Render/StandaloneType/Iframe.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Skeleton } from 'antd'; | ||
import { memo, useRef, useState } from 'react'; | ||
|
||
interface IFrameRenderProps { | ||
height?: number; | ||
url: string; | ||
width?: number; | ||
} | ||
|
||
const IFrameRender = memo<IFrameRenderProps>(({ url, width = 600, height = 300 }) => { | ||
const [loading, setLoading] = useState(true); | ||
|
||
const iframeRef = useRef<HTMLIFrameElement>(null); | ||
|
||
return ( | ||
<> | ||
{loading && <Skeleton active style={{ width }} />} | ||
<iframe | ||
// @ts-ignore | ||
allowtransparency="true" | ||
height={height} | ||
hidden={loading} | ||
onLoad={() => { | ||
setLoading(false); | ||
}} | ||
ref={iframeRef} | ||
src={url} | ||
style={{ | ||
border: 0, | ||
// iframe 在 color-scheme:dark 模式下无法透明 | ||
// refs: https://www.jianshu.com/p/bc5a37bb6a7b | ||
colorScheme: 'light', | ||
}} | ||
width={width} | ||
/> | ||
</> | ||
); | ||
}); | ||
export default IFrameRender; |
23 changes: 23 additions & 0 deletions
23
src/app/chat/features/Conversation/ChatList/Plugins/Render/StandaloneType/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { memo } from 'react'; | ||
|
||
import { usePluginStore } from '@/store/plugin'; | ||
|
||
import IFrameRender from './Iframe'; | ||
|
||
export interface PluginStandaloneTypeProps { | ||
name?: string; | ||
} | ||
|
||
const PluginDefaultType = memo<PluginStandaloneTypeProps>(({ name = 'unknown' }) => { | ||
const manifest = usePluginStore((s) => s.pluginManifestMap[name]); | ||
|
||
if (!manifest?.ui) return; | ||
|
||
const ui = manifest.ui; | ||
|
||
if (!ui.url) return; | ||
|
||
return <IFrameRender height={ui.height} url={ui.url} width={ui.width} />; | ||
}); | ||
|
||
export default PluginDefaultType; |
26 changes: 26 additions & 0 deletions
26
src/app/chat/features/Conversation/ChatList/Plugins/Render/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { LobePluginType } from '@lobehub/chat-plugin-sdk'; | ||
import { memo } from 'react'; | ||
|
||
import DefaultType from './DefaultType'; | ||
import Standalone from './StandaloneType'; | ||
|
||
export interface PluginRenderProps { | ||
content: string; | ||
loading?: boolean; | ||
name?: string; | ||
type?: LobePluginType; | ||
} | ||
|
||
const PluginRender = memo<PluginRenderProps>(({ content, name, type }) => { | ||
switch (type) { | ||
case 'standalone': { | ||
return <Standalone name={name} />; | ||
} | ||
|
||
default: { | ||
return <DefaultType content={content} name={name} />; | ||
} | ||
} | ||
}); | ||
|
||
export default PluginRender; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters