Skip to content

Commit

Permalink
Hide drop selector on scroll in iframe (UI builder) (#14443)
Browse files Browse the repository at this point in the history
* Hide drop selector on scroll in canvas

* Added Changelog entry
  • Loading branch information
vyhnalekl authored Aug 14, 2020
1 parent 06437d2 commit 2b472d6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
1 change: 1 addition & 0 deletions packages/fluentui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Move component in iframe by drag and drop @vyhnalekl ([#14432](https://github.com/microsoft/fluentui/pull/14432))
- Removed props JSON from right side menu @vyhnalekl ([#14503](https://github.com/microsoft/fluentui/pull/14503))
- Fixed top's component debug frame above iframe @vyhnalekl ([#14329](https://github.com/microsoft/fluentui/pull/14329))
- Hide drop selector on scroll in iframe (UI builder) @vyhnalekl ([#14443](https://github.com/microsoft/fluentui/pull/14443))

<!--------------------------------[ v0.51.0 ]------------------------------- -->
## [v0.51.0](https://github.com/OfficeDev/office-ui-fabric-react/tree/fluentui_v0.51.0) (2020-07-27)
Expand Down
16 changes: 14 additions & 2 deletions packages/fluentui/react-builder/src/components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const Canvas: React.FunctionComponent<CanvasProps> = ({
renderJSONTreeElement,
style,
}) => {
const [hideDropSelector, setHideDropSelector] = React.useState(false);

const iframeId = React.useMemo(
() =>
`frame-${Math.random()
Expand All @@ -68,9 +70,10 @@ export const Canvas: React.FunctionComponent<CanvasProps> = ({

const handleMouseMove = React.useCallback(
(e: MouseEvent) => {
hideDropSelector && setHideDropSelector(false);
onMouseMove?.(iframeCoordinatesToWindowCoordinates(e));
},
[iframeCoordinatesToWindowCoordinates, onMouseMove],
[iframeCoordinatesToWindowCoordinates, onMouseMove, hideDropSelector],
);

const handleMouseUp = React.useCallback(
Expand All @@ -80,9 +83,10 @@ export const Canvas: React.FunctionComponent<CanvasProps> = ({
e.preventDefault();
e.stopPropagation();

hideDropSelector && setHideDropSelector(false);
onMouseUp();
},
[onMouseUp],
[onMouseUp, hideDropSelector],
);

const handleSelectComponent = React.useCallback(
Expand Down Expand Up @@ -287,12 +291,20 @@ export const Canvas: React.FunctionComponent<CanvasProps> = ({
jsonTree={jsonTree}
mountDocument={document}
onDropPositionChange={onDropPositionChange}
hideSelector={hideDropSelector}
/>
)}
<EventListener type="keydown" listener={onKeyDown} target={document} />
<Provider theme={teamsTheme} target={document}>
{draggingElement && <EventListener type="mousemove" listener={handleMouseMove} target={document} />}
{draggingElement && <EventListener type="mouseup" listener={handleMouseUp} target={document} />}
{draggingElement && (
<EventListener
type="scroll"
listener={() => !hideDropSelector && setHideDropSelector(true)}
target={document}
/>
)}
{renderJSONTreeToJSXElement(jsonTree, renderJSONTreeElement)}
</Provider>
</>
Expand Down
58 changes: 32 additions & 26 deletions packages/fluentui/react-builder/src/components/DropSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type DropSelectorProps = {
filter?;
jsonTree: JSONTreeElement;
mountDocument?: Document;
hideSelector?: Boolean;
};

type InElementPosition = 'top' | 'right' | 'bottom' | 'left' | 'center';
Expand Down Expand Up @@ -66,6 +67,7 @@ export const DropSelector: React.FunctionComponent<DropSelectorProps> = ({
onDropPositionChange,
mountDocument = isBrowser() ? window.document : null,
filter = fiberNav => fiberNav,
hideSelector = false,
}) => {
const selectorRef = React.createRef<HTMLDivElement>();
const mouseRef = React.createRef<HTMLDivElement>();
Expand Down Expand Up @@ -158,32 +160,36 @@ export const DropSelector: React.FunctionComponent<DropSelectorProps> = ({

return (
<>
<div
ref={selectorRef}
style={{
position: 'fixed',
zIndex: 99999999,
pointerEvents: 'none',
userSelect: 'none',
outlineOffset: '-1px',
}}
/>
<div
ref={mouseRef}
style={{
position: 'fixed',
width: '8px',
height: '8px',
borderRadius: '50%',
border: '2px solid red',
margin: '-5px 0 0 -5px',
zIndex: 99999999,
pointerEvents: 'none',
userSelect: 'none',
}}
/>
<EventListener listener={handleMouseMove} target={mountDocument.body} type="mousemove" />
<EventListener listener={handleMouseLeave} target={mountDocument.body} type="mouseleave" />
{!hideSelector && (
<>
<div
ref={selectorRef}
style={{
position: 'fixed',
zIndex: 99999999,
pointerEvents: 'none',
userSelect: 'none',
outlineOffset: '-1px',
}}
/>
<div
ref={mouseRef}
style={{
position: 'fixed',
width: '8px',
height: '8px',
borderRadius: '50%',
border: '2px solid red',
margin: '-5px 0 0 -5px',
zIndex: 99999999,
pointerEvents: 'none',
userSelect: 'none',
}}
/>
<EventListener listener={handleMouseMove} target={mountDocument.body} type="mousemove" />
<EventListener listener={handleMouseLeave} target={mountDocument.body} type="mouseleave" />
</>
)}
</>
);
};

0 comments on commit 2b472d6

Please sign in to comment.