Skip to content

Commit

Permalink
✨🚧Implemented PythonMarkdownPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
carefree0910 committed May 21, 2023
1 parent 33d996a commit d33e097
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cfdraw/.web/src/lang/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const _pluginsLangRecords: Record<Lang, Record<AllPlugins, string>> = {
"_python.textArea": "Python 文本框",
"_python.QA": "Python 问答",
"_python.chat": "Python 对话",
"_python.markdown": "Python Markdown",
},
en: {
meta: "Meta",
Expand All @@ -50,6 +51,7 @@ const _pluginsLangRecords: Record<Lang, Record<AllPlugins, string>> = {
"_python.textArea": "Python TextArea",
"_python.QA": "Python Q & A",
"_python.chat": "Python Chat",
"_python.markdown": "Python Markdown",
},
};

Expand Down
19 changes: 19 additions & 0 deletions cfdraw/.web/src/plugins/_python/MarkdownPlugin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { observer } from "mobx-react-lite";

import type { IPythonPlugin } from "@/schema/_python";
import { drawboardPluginFactory } from "@/plugins/utils/factory";
import Render from "@/plugins/components/Render";
import { useTextTransfer } from "./hooks";
import CFMarkdown from "@/components/CFMarkdown";

const PythonMarkdownPlugin = ({ pluginInfo, ...props }: IPythonPlugin) => {
const { id, text } = useTextTransfer({ key: "markdown", plugin: { pluginInfo, ...props } });

return (
<Render id={id} {...props}>
<CFMarkdown markdown={text} />
</Render>
);
};

drawboardPluginFactory.registerPython("_python.markdown", true)(observer(PythonMarkdownPlugin));
1 change: 1 addition & 0 deletions cfdraw/.web/src/plugins/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export * from "./_python/FieldsPlugin";
export * from "./_python/TextAreaPlugin";
export * from "./_python/QAPlugin";
export * from "./_python/ChatPlugin";
export * from "./_python/MarkdownPlugin";

function MakePlugin<T extends AllPlugins>({
type,
Expand Down
3 changes: 3 additions & 0 deletions cfdraw/.web/src/schema/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { IFieldDefinition } from "./fields";
import type {
IPythonChatPlugin,
IPythonFieldsPlugin,
IPythonPlugin,
IPythonPluginGroup,
IPythonQAPlugin,
IPythonTextAreaPlugin,
Expand Down Expand Up @@ -109,6 +110,7 @@ export const allPythonPlugins = [
"_python.textArea",
"_python.QA",
"_python.chat",
"_python.markdown",
] as const;
export type ReactPlugins = (typeof allReactPlugins)[number];
export type PythonPlugins = (typeof allPythonPlugins)[number];
Expand Down Expand Up @@ -139,6 +141,7 @@ export interface IPluginProps {
"_python.textArea": IPythonTextAreaPlugin;
"_python.QA": IPythonQAPlugin;
"_python.chat": IPythonChatPlugin;
"_python.markdown": IPythonPlugin;
}

export interface IMakePlugin<T extends AllPlugins> {
Expand Down
7 changes: 7 additions & 0 deletions cfdraw/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ def type(self) -> PluginType:
return PluginType.CHAT


class IMarkdownPlugin(ISocketPlugin):
@property
def type(self) -> PluginType:
return PluginType.MARKDOWN


__all__ = [
"ISocketPlugin",
"IInternalSocketPlugin",
Expand All @@ -135,4 +141,5 @@ def type(self) -> PluginType:
"ITextAreaPlugin",
"IQAPlugin",
"IChatPlugin",
"IMarkdownPlugin",
]
1 change: 1 addition & 0 deletions cfdraw/schema/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PluginType(str, Enum):
TEXT_AREA = "_python.textArea"
QA = "_python.QA"
CHAT = "_python.chat"
MARKDOWN = "_python.markdown"

# this type of plugins will not be rendered on the drawboard 🎨
_INTERNAL = "_internal"
Expand Down

0 comments on commit d33e097

Please sign in to comment.