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