|
|
|
@ -12,6 +12,7 @@ const useStateRef = require("./use-state-ref");
|
|
|
|
|
const useMemoizedPosition = require("./use-memoized-position");
|
|
|
|
|
const elementsFromPoint = require("./elements-from-point");
|
|
|
|
|
const uniqueElementId = require("./unique-element-id");
|
|
|
|
|
const getElementPosition = require("./get-element-position");
|
|
|
|
|
|
|
|
|
|
function Overlay() {
|
|
|
|
|
let [ scrollX, setScrollX ] = React.useState();
|
|
|
|
@ -72,6 +73,23 @@ function Overlay() {
|
|
|
|
|
let pickedPosition = useMemoizedPosition(pickedElement, [ scrollX, scrollY ]);
|
|
|
|
|
let pickHoveredPosition = useMemoizedPosition(pickHoveredElement, [ scrollX, scrollY ]);
|
|
|
|
|
|
|
|
|
|
let secondaryMatches = React.useMemo(() => {
|
|
|
|
|
if (selectedElement != null) {
|
|
|
|
|
let elements = Array.from(document.querySelectorAll(generateSelector(selectedElement)));
|
|
|
|
|
|
|
|
|
|
return elements
|
|
|
|
|
.filter((element) => element !== selectedElement)
|
|
|
|
|
.map((element) => {
|
|
|
|
|
return {
|
|
|
|
|
element: element,
|
|
|
|
|
position: getElementPosition(element)
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}, [ selectedElement, scrollX, scrollY ]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="___scraping___tool___overlay active">
|
|
|
|
|
{(hoveredPosition != null && isHovering)
|
|
|
|
@ -94,6 +112,13 @@ function Overlay() {
|
|
|
|
|
? <Picker candidates={elementList} onHover={setPickHoveredElement} />
|
|
|
|
|
: null
|
|
|
|
|
}
|
|
|
|
|
{secondaryMatches.map((element) => {
|
|
|
|
|
return <SecondarySelectionHighlight
|
|
|
|
|
key={uniqueElementId(element)}
|
|
|
|
|
element={element.element}
|
|
|
|
|
{... element.position}
|
|
|
|
|
/>
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
@ -142,6 +167,14 @@ function PrimarySelectionHighlight({ x, y, width, height, element }) {
|
|
|
|
|
</>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function SecondarySelectionHighlight({ x, y, width, height, element }) {
|
|
|
|
|
let boxStyle = { left: x, top: y, width: width, height: height };
|
|
|
|
|
|
|
|
|
|
return (<>
|
|
|
|
|
<div className="___scraping___tool___secondarySelection" style={boxStyle} />
|
|
|
|
|
</>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Promise.try(() => {
|
|
|
|
|
return documentReadyPromise();
|
|
|
|
|
}).then(() => {
|
|
|
|
|