From cd84d42eaea2ca0e64d57e61cf876ea048b124ae Mon Sep 17 00:00:00 2001 From: lhbxs <596850703@qq.com> Date: Mon, 13 Nov 2023 02:35:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20schema-builder=20g?= =?UTF-8?q?etValue=E3=80=81setValue=E3=80=81=E7=AD=89=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/schema-builder/index.md | 11 +++++++++-- tools/schema-builder/src/createIframe.ts | 2 +- tools/schema-builder/src/main.tsx | 20 ++++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/docs/schema-builder/index.md b/docs/schema-builder/index.md index e3a2fdcc4..492f6b39e 100644 --- a/docs/schema-builder/index.md +++ b/docs/schema-builder/index.md @@ -56,13 +56,20 @@ externals: { * background: 'rgb(204,204,204, .33)' * padding: 20px */ -import React from 'react'; +import React, { useRef, useEffect } from 'react'; import SchemaBuilder from '@xrenders/schema-builder'; const Demo = () => { + + const domRef = useRef (); + + useEffect(() => { + + }, []) + return (
- +
); }; diff --git a/tools/schema-builder/src/createIframe.ts b/tools/schema-builder/src/createIframe.ts index 8f4b7a37c..8bb6ab74d 100644 --- a/tools/schema-builder/src/createIframe.ts +++ b/tools/schema-builder/src/createIframe.ts @@ -30,7 +30,7 @@ const createIframeContent = () => {
- + `; diff --git a/tools/schema-builder/src/main.tsx b/tools/schema-builder/src/main.tsx index aeedc8f0d..784d462a5 100644 --- a/tools/schema-builder/src/main.tsx +++ b/tools/schema-builder/src/main.tsx @@ -1,19 +1,31 @@ -import React, { useEffect, useRef } from 'react'; +import React, { useEffect, useRef, useImperativeHandle, forwardRef } from 'react'; import createIframe from './createIframe'; interface IProps { widgets: any settings: any + [key: string]: any } let iframe: any; -const Design = (props: IProps) => { +const Design = (props: IProps, ref: any) => { const { widgets, settings, ...restProps } = props; const containerRef: any = useRef(); + useImperativeHandle(ref, () => ({ + getValue: () => { + return iframe?.contentWindow?.__FR_ENGINE__?.expotSchema(); + }, + setValue: (schema: any) => { + return iframe?.contentWindow?.__FR_ENGINE__?.impotSchema(schema); + }, + copyValue: () => { + return iframe?.contentWindow?.__FR_ENGINE__?.copySchema(); + } + })) + useEffect(() => { initIframe(); - window.addEventListener('message', engineOnLoad); return () => { window.removeEventListener('message', engineOnLoad); @@ -46,4 +58,4 @@ const Design = (props: IProps) => { ); } -export default Design; \ No newline at end of file +export default forwardRef(Design); \ No newline at end of file