From 721da6f34c8ab93aaa5d4dd6bb422a74480397fc Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 15 Jul 2023 16:33:01 +0800 Subject: [PATCH] perf: use group extra to storage custom web panel html and compatible with old meta webpanel storage --- .../src/group/GroupCustomWebPanelRender.tsx | 77 +++++++++++++++++-- .../plugins/com.msgbyte.webview/src/index.tsx | 10 +-- .../com.msgbyte.webview/src/translate.ts | 8 +- client/web/src/plugin/common/index.ts | 1 + client/web/src/plugin/common/reg.ts | 2 +- website/docs/plugins/api/common.md | 10 +-- 6 files changed, 83 insertions(+), 25 deletions(-) diff --git a/client/web/plugins/com.msgbyte.webview/src/group/GroupCustomWebPanelRender.tsx b/client/web/plugins/com.msgbyte.webview/src/group/GroupCustomWebPanelRender.tsx index 31fc1fc7..9452a873 100644 --- a/client/web/plugins/com.msgbyte.webview/src/group/GroupCustomWebPanelRender.tsx +++ b/client/web/plugins/com.msgbyte.webview/src/group/GroupCustomWebPanelRender.tsx @@ -1,6 +1,28 @@ -import React, { useEffect, useRef } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { Translate } from '../translate'; import xss from 'xss'; +import { useWatch } from '@capital/common'; +import { GroupExtraDataPanel, TextArea } from '@capital/component'; +import styled from 'styled-components'; + +const EditModalContent = styled.div` + padding: 10px; + width: 80vw; + height: 80vh; + display: flex; + flex-direction: column; + overflow: hidden; + + .main { + flex: 1; + overflow: hidden; + + > textarea { + height: 100%; + resize: none; + } + } +`; function getInjectedStyle() { try { @@ -15,10 +37,9 @@ function getInjectedStyle() { } } -const GroupCustomWebPanelRender: React.FC<{ panelInfo: any }> = (props) => { - const panelInfo = props.panelInfo; +const GroupCustomWebPanelRender: React.FC<{ html: string }> = (props) => { const ref = useRef(null); - const html = panelInfo?.meta?.html; + const html = props.html; useEffect(() => { if (!ref.current || !html) { @@ -31,7 +52,7 @@ const GroupCustomWebPanelRender: React.FC<{ panelInfo: any }> = (props) => { doc.close(); }, [html]); - if (!panelInfo) { + if (!html) { return
{Translate.notfound}
; } @@ -39,4 +60,48 @@ const GroupCustomWebPanelRender: React.FC<{ panelInfo: any }> = (props) => { }; GroupCustomWebPanelRender.displayName = 'GroupCustomWebPanelRender'; -export default GroupCustomWebPanelRender; +const GroupCustomWebPanelEditor: React.FC<{ + initValue: string; + onChange: (html: string) => void; +}> = React.memo((props) => { + const [html, setHtml] = useState(() => props.initValue ?? ''); + + useWatch([html], () => { + props.onChange(html); + }); + + return