feat: handle a & img tags attribute click selection

This commit is contained in:
karishmas6
2024-08-21 23:38:00 +05:30
parent 9d75dd156d
commit a5db763295

View File

@@ -128,36 +128,38 @@ export const BrowserWindow = () => {
clickY >= highlightRect.top && clickY >= highlightRect.top &&
clickY <= highlightRect.bottom clickY <= highlightRect.bottom
) { ) {
const options = getAttributeOptions(highlighterData.elementInfo?.tagName || '', highlighterData.elementInfo);
if (getText === true) { if (getText === true) {
const options = getAttributeOptions(highlighterData.elementInfo?.tagName || '', highlighterData.elementInfo); if (options.length === 1) {
if (options.length > 1) { // Directly use the available attribute if only one option is present
const attribute = options[0].value;
const data = attribute === 'href' ? highlighterData.elementInfo?.url || '' :
attribute === 'src' ? highlighterData.elementInfo?.imageUrl || '' :
highlighterData.elementInfo?.innerText || '';
addTextStep('', data, {
selector: highlighterData.selector,
tag: highlighterData.elementInfo?.tagName,
attribute
});
} else {
// Show the modal if there are multiple options
setAttributeOptions(options); setAttributeOptions(options);
setSelectedElement({ setSelectedElement({
selector: highlighterData.selector, selector: highlighterData.selector,
info: highlighterData.elementInfo info: highlighterData.elementInfo
}); });
setShowAttributeModal(true); setShowAttributeModal(true);
} else {
addTextStep('', highlighterData.elementInfo?.innerText || '', {
selector: highlighterData.selector,
tag: highlighterData.elementInfo?.tagName,
attribute: 'innerText'
});
} }
} }
if (getList === true && !listSelector) { if (getList === true && !listSelector) {
setListSelector(highlighterData.selector); setListSelector(highlighterData.selector);
} else if (getList === true && listSelector) { } else if (getList === true && listSelector) {
const options = getAttributeOptions(highlighterData.elementInfo?.tagName || '', highlighterData.elementInfo); if (options.length === 1) {
if (options.length > 1) { // Handle directly without showing the modal
setAttributeOptions(options); const attribute = options[0].value;
setSelectedElement({
selector: highlighterData.selector,
info: highlighterData.elementInfo
});
setShowAttributeModal(true);
} else {
const newField: TextStep = { const newField: TextStep = {
id: Date.now(), id: Date.now(),
type: 'text', type: 'text',
@@ -166,7 +168,7 @@ export const BrowserWindow = () => {
selectorObj: { selectorObj: {
selector: highlighterData.selector, selector: highlighterData.selector,
tag: highlighterData.elementInfo?.tagName, tag: highlighterData.elementInfo?.tagName,
attribute: 'innerText' attribute
} }
}; };
@@ -181,13 +183,21 @@ export const BrowserWindow = () => {
if (listSelector) { if (listSelector) {
addListStep(listSelector, { ...fields, [newField.label]: newField }); addListStep(listSelector, { ...fields, [newField.label]: newField });
} }
} else {
// Show the modal if there are multiple options
setAttributeOptions(options);
setSelectedElement({
selector: highlighterData.selector,
info: highlighterData.elementInfo
});
setShowAttributeModal(true);
} }
} }
} }
} }
}; };
const handleAttributeSelection = (attribute: string) => { const handleAttributeSelection = (attribute: string) => {
if (selectedElement) { if (selectedElement) {
let data = ''; let data = '';