diff --git a/src/components/atoms/Plugin/IFrame/hooks.ts b/src/components/atoms/Plugin/IFrame/hooks.ts index 9176826b1..05cb761a9 100644 --- a/src/components/atoms/Plugin/IFrame/hooks.ts +++ b/src/components/atoms/Plugin/IFrame/hooks.ts @@ -23,6 +23,7 @@ export default function useHook({ iFrameProps, onLoad, onMessage, + onClick, }: { autoResizeMessageKey?: string; html?: string; @@ -32,6 +33,7 @@ export default function useHook({ iFrameProps?: IframeHTMLAttributes; onLoad?: () => void; onMessage?: (message: any) => void; + onClick?: () => void; } = {}): { ref: RefObject; props: IframeHTMLAttributes; @@ -145,6 +147,18 @@ export default function useHook({ [autoResize, iFrameProps, iFrameSize, visible], ); + useEffect(() => { + const handleBlur = () => { + if (iFrameRef.current && iFrameRef.current === document.activeElement) { + onClick?.(); + } + }; + window.addEventListener("blur", handleBlur); + return () => { + window.removeEventListener("blur", handleBlur); + }; + }, [onClick]); + return { ref: iFrameRef, props, diff --git a/src/components/atoms/Plugin/IFrame/index.tsx b/src/components/atoms/Plugin/IFrame/index.tsx index 4bfce72ea..e849362cd 100644 --- a/src/components/atoms/Plugin/IFrame/index.tsx +++ b/src/components/atoms/Plugin/IFrame/index.tsx @@ -12,10 +12,11 @@ export type Props = { iFrameProps?: IframeHTMLAttributes; onLoad?: () => void; onMessage?: (message: any) => void; + onClick?: () => void; }; const IFrame: React.ForwardRefRenderFunction = ( - { autoResize, className, html, visible, iFrameProps, onLoad, onMessage }, + { autoResize, className, html, visible, iFrameProps, onLoad, onMessage, onClick }, ref, ) => { const { @@ -30,6 +31,7 @@ const IFrame: React.ForwardRefRenderFunction = ( ref, onLoad, onMessage, + onClick, }); return html ? ( diff --git a/src/components/atoms/Plugin/index.tsx b/src/components/atoms/Plugin/index.tsx index 7b27e91cc..291259fd4 100644 --- a/src/components/atoms/Plugin/index.tsx +++ b/src/components/atoms/Plugin/index.tsx @@ -21,6 +21,7 @@ export type Props = { onPreInit?: () => void; onError?: (err: any) => void; onDispose?: () => void; + onClick?: () => void; }; const Plugin: React.FC = ({ @@ -38,6 +39,7 @@ const Plugin: React.FC = ({ onPreInit, onError, onDispose, + onClick, }) => { const { iFrameRef, iFrameHtml, iFrameVisible } = useHook({ iframeCanBeVisible: canBeVisible, @@ -60,6 +62,7 @@ const Plugin: React.FC = ({ visible={iFrameVisible} onMessage={onMessage} iFrameProps={iFrameProps} + onClick={onClick} /> ) : renderPlaceholder ? ( <>{renderPlaceholder} diff --git a/src/components/molecules/Visualizer/Block/index.tsx b/src/components/molecules/Visualizer/Block/index.tsx index 07012a8fe..d136f7aec 100644 --- a/src/components/molecules/Visualizer/Block/index.tsx +++ b/src/components/molecules/Visualizer/Block/index.tsx @@ -54,6 +54,7 @@ export default function BlockComponent

({ pluginProperty={props.pluginProperty} layer={props.layer} block={props.block} + onClick={props.onClick} /> ); @@ -62,7 +63,7 @@ export default function BlockComponent

({ const Wrapper = styled.div<{ editable?: boolean; selected?: boolean }>` border: 1px solid ${({ selected, editable, theme }) => - editable && selected ? theme.infoBox.accent2 : "transparent"}; + editable && selected ? theme.infoBox.accent2 : "transparent"}; border-radius: 6px; &:hover { diff --git a/src/components/molecules/Visualizer/Plugin/index.tsx b/src/components/molecules/Visualizer/Plugin/index.tsx index 66d131c14..30c91e565 100644 --- a/src/components/molecules/Visualizer/Plugin/index.tsx +++ b/src/components/molecules/Visualizer/Plugin/index.tsx @@ -31,6 +31,7 @@ export type Props = { layer?: Layer; widget?: Widget; block?: Block; + onClick?: () => void; }; export default function Plugin({ @@ -46,6 +47,7 @@ export default function Plugin({ widget, block, pluginProperty, + onClick, }: Props): JSX.Element | null { const { skip, src, isMarshalable, onPreInit, onDispose, exposed, onError, onMessage } = useHooks({ pluginId, @@ -72,6 +74,7 @@ export default function Plugin({ onMessage={onMessage} onPreInit={onPreInit} onDispose={onDispose} + onClick={onClick} /> ) : null; }