Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

fix: enable to select blocks of plugins #162

Merged
merged 3 commits into from Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/atoms/Plugin/IFrame/hooks.ts
Expand Up @@ -23,6 +23,7 @@ export default function useHook({
iFrameProps,
onLoad,
onMessage,
onClick,
}: {
autoResizeMessageKey?: string;
html?: string;
Expand All @@ -32,6 +33,7 @@ export default function useHook({
iFrameProps?: IframeHTMLAttributes<HTMLIFrameElement>;
onLoad?: () => void;
onMessage?: (message: any) => void;
onClick?: () => void;
} = {}): {
ref: RefObject<HTMLIFrameElement>;
props: IframeHTMLAttributes<HTMLIFrameElement>;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/components/atoms/Plugin/IFrame/index.tsx
Expand Up @@ -12,10 +12,11 @@ export type Props = {
iFrameProps?: IframeHTMLAttributes<HTMLIFrameElement>;
onLoad?: () => void;
onMessage?: (message: any) => void;
onClick?: () => void;
};

const IFrame: React.ForwardRefRenderFunction<Ref, Props> = (
{ autoResize, className, html, visible, iFrameProps, onLoad, onMessage },
{ autoResize, className, html, visible, iFrameProps, onLoad, onMessage, onClick },
ref,
) => {
const {
Expand All @@ -30,6 +31,7 @@ const IFrame: React.ForwardRefRenderFunction<Ref, Props> = (
ref,
onLoad,
onMessage,
onClick,
});

return html ? (
Expand Down
3 changes: 3 additions & 0 deletions src/components/atoms/Plugin/index.tsx
Expand Up @@ -21,6 +21,7 @@ export type Props = {
onPreInit?: () => void;
onError?: (err: any) => void;
onDispose?: () => void;
onClick?: () => void;
};

const Plugin: React.FC<Props> = ({
Expand All @@ -38,6 +39,7 @@ const Plugin: React.FC<Props> = ({
onPreInit,
onError,
onDispose,
onClick,
}) => {
const { iFrameRef, iFrameHtml, iFrameVisible } = useHook({
iframeCanBeVisible: canBeVisible,
Expand All @@ -60,6 +62,7 @@ const Plugin: React.FC<Props> = ({
visible={iFrameVisible}
onMessage={onMessage}
iFrameProps={iFrameProps}
onClick={onClick}
/>
) : renderPlaceholder ? (
<>{renderPlaceholder}</>
Expand Down
1 change: 1 addition & 0 deletions src/components/molecules/Visualizer/Block/index.tsx
Expand Up @@ -54,6 +54,7 @@ export default function BlockComponent<P = any, PP = any>({
pluginProperty={props.pluginProperty}
layer={props.layer}
block={props.block}
onClick={props.onClick}
/>
</Wrapper>
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/molecules/Visualizer/Plugin/index.tsx
Expand Up @@ -31,6 +31,7 @@ export type Props = {
layer?: Layer;
widget?: Widget;
block?: Block;
onClick?: () => void;
};

export default function Plugin({
Expand All @@ -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,
Expand All @@ -72,6 +74,7 @@ export default function Plugin({
onMessage={onMessage}
onPreInit={onPreInit}
onDispose={onDispose}
onClick={onClick}
/>
) : null;
}