-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): playwright integration (#5)
* feat: use a resizable layout * feat: update visualizer * fix: resize bug * feat: add .query for playwright integration * fix: ts error
- Loading branch information
1 parent
47178bd
commit 49cb1ac
Showing
27 changed files
with
601 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ | |
@weak-bg: #F3F3F3; | ||
|
||
@side-horizontal-padding: 10px; | ||
@side-vertical-spacing: 8px; | ||
@side-vertical-spacing: 10px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/visualizer/src/component/global-hover-preview.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@import './common.less'; | ||
|
||
@max-size: 400px; | ||
.global-hover-preview { | ||
position: fixed; | ||
display: block; | ||
max-width: @max-size; | ||
max-height: @max-size; | ||
overflow: hidden; | ||
z-index: 10; | ||
text-align: center; | ||
border: 1px solid @border-color; | ||
box-sizing: border-box; | ||
background: @side-bg; | ||
box-shadow: 1px 1px 5px 0 rgba(0, 0, 0, 0.2); | ||
|
||
img { | ||
max-width: @max-size; | ||
max-height: @max-size; | ||
width: auto; | ||
height: auto; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/visualizer/src/component/global-hover-preview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useRef, useState } from 'react'; | ||
import { useExecutionDump } from './store'; | ||
import './global-hover-preview.less'; | ||
|
||
const size = 400; // @max-size | ||
const GlobalHoverPreview = () => { | ||
const wrapperRef = useRef<HTMLDivElement>(null); | ||
const hoverTask = useExecutionDump((store) => store.hoverTask); | ||
const hoverPreviewConfig = useExecutionDump((store) => store.hoverPreviewConfig); | ||
const [imageW, setImageW] = useState(size); | ||
const [imageH, setImageH] = useState(size); | ||
|
||
const images = hoverTask?.recorder | ||
?.filter((item) => { | ||
return item.screenshot; | ||
}) | ||
.map((item) => item.screenshot); | ||
|
||
const { x, y } = hoverPreviewConfig || {}; | ||
let left = 0; | ||
let top = 0; | ||
|
||
const shouldShow = images?.length && typeof x !== 'undefined' && typeof y !== 'undefined'; | ||
if (shouldShow) { | ||
const { clientWidth, clientHeight } = document.body; | ||
const widthInPractice = imageW >= imageH ? size : size * (imageW / imageH); | ||
const heightInPractice = imageW >= imageH ? size * (imageH / imageW) : size; | ||
left = x + widthInPractice > clientWidth ? clientWidth - widthInPractice : x; | ||
top = y + heightInPractice > clientHeight ? clientHeight - heightInPractice : y; | ||
} | ||
// if x + size exceed the screen width, use (screenWidth - size) instead | ||
|
||
return shouldShow ? ( | ||
<div className="global-hover-preview" style={{ left, top }} ref={wrapperRef}> | ||
{images?.length ? ( | ||
<img | ||
src={images[0]} | ||
onLoad={(img) => { | ||
const imgElement = img.target as HTMLImageElement; | ||
const width = imgElement.naturalWidth; | ||
const height = imgElement.naturalHeight; | ||
setImageW(width); | ||
setImageH(height); | ||
}} | ||
/> | ||
) : null} | ||
</div> | ||
) : null; | ||
}; | ||
export default GlobalHoverPreview; |
Oops, something went wrong.