A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: Add useRenderPlugin to Editor component
robin7c59d3f3cb16
diff --git a/ui/src/components/Editor/index.tsx b/ui/src/components/Editor/index.tsxindex dd004021..ead37653 100644--- a/ui/src/components/Editor/index.tsx+++ b/ui/src/components/Editor/index.tsx@@ -27,7 +27,7 @@ import {import classNames from 'classnames';-import { PluginType } from '@/utils/pluginKit';+import { PluginType, useRenderPlugin } from '@/utils/pluginKit';import PluginRender from '../PluginRender';import {@@ -84,6 +84,8 @@ const MDEditor: ForwardRefRenderFunction<EditorRef, Props> = (const editorRef = useRef<HTMLDivElement>(null);const previewRef = useRef<{ getHtml; element } | null>(null);+ useRenderPlugin(previewRef.current?.element);+const editor = useEditor({editorRef,onChange,diff --git a/ui/src/utils/pluginKit/index.ts b/ui/src/utils/pluginKit/index.tsindex 26e3a288..6d0e9878 100644--- a/ui/src/utils/pluginKit/index.ts+++ b/ui/src/utils/pluginKit/index.ts@@ -232,6 +232,26 @@ const useRenderHtmlPlugin = (});};+// Only for render type plugins+const useRenderPlugin = (+ element: HTMLElement | RefObject<HTMLElement> | null,+) => {+ return plugins+ .getPlugins()+ .filter((plugin) => {+ return (+ plugin.activated &&+ plugin.hooks?.useRender &&+ plugin.info.type === PluginType.Render+ );+ })+ .forEach((plugin) => {+ plugin.hooks?.useRender?.forEach((hook) => {+ hook(element);+ });+ });+};+// Only one captcha type plug-in can be enabled at the same timeconst useCaptchaPlugin = (key: Type.CaptchaKey) => {const captcha = plugins@@ -248,5 +268,11 @@ const useCaptchaPlugin = (key: Type.CaptchaKey) => {export type { Plugin, PluginInfo };-export { useRenderHtmlPlugin, mergeRoutePlugins, useCaptchaPlugin, PluginType };+export {+ useRenderHtmlPlugin,+ mergeRoutePlugins,+ useCaptchaPlugin,+ useRenderPlugin,+ PluginType,+};export default plugins;diff --git a/ui/src/utils/pluginKit/interface.ts b/ui/src/utils/pluginKit/interface.tsindex 462ae47b..880a524a 100644--- a/ui/src/utils/pluginKit/interface.ts+++ b/ui/src/utils/pluginKit/interface.ts@@ -46,7 +46,7 @@ export interface Plugin {useRender?: Array<(element: HTMLElement | RefObject<HTMLElement> | null) => void>;- useCaptcha?: (props: { captchaKey: Type.CaptchaKey; commonProps: any; }) => {+ useCaptcha?: (props: { captchaKey: Type.CaptchaKey; commonProps: any }) => {getCaptcha: () => Record<string, any>;check: (t: () => void) => void;handleCaptchaError: (error) => any;