Skip to content

Commit

Permalink
Merge pull request #238 from getmaxun/cap-list-select
Browse files Browse the repository at this point in the history
feat: apply conditional visual containment
  • Loading branch information
amhsirak authored Dec 9, 2024
2 parents 4f8b1d0 + f561ef7 commit 14c9626
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions server/src/workflow-management/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,28 @@ export const getElementInformation = async (
if (originalEl) {
let element = originalEl;

if (originalEl.tagName === 'A') {
element = originalEl;
} else if (originalEl.parentElement?.tagName === 'A') {
element = originalEl.parentElement;
} else {
// if (originalEl.tagName === 'A') {
// element = originalEl;
// } else if (originalEl.parentElement?.tagName === 'A') {
// element = originalEl.parentElement;
// } else {
// Generic parent finding logic based on visual containment
const containerTags = ['DIV', 'SECTION', 'ARTICLE', 'MAIN', 'HEADER', 'FOOTER', 'NAV', 'ASIDE',
'ADDRESS', 'BLOCKQUOTE', 'DETAILS', 'DIALOG', 'FIGURE', 'FIGCAPTION', 'MAIN', 'MARK', 'SUMMARY', 'TIME',
'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TR', 'TH', 'TD', 'CAPTION', 'COLGROUP', 'COL', 'FORM', 'FIELDSET',
'LEGEND', 'LABEL', 'INPUT', 'BUTTON', 'SELECT', 'DATALIST', 'OPTGROUP', 'OPTION', 'TEXTAREA', 'OUTPUT',
'PROGRESS', 'METER', 'DETAILS', 'SUMMARY', 'MENU', 'MENUITEM', 'MENUITEM', 'APPLET', 'EMBED', 'OBJECT',
'PARAM', 'VIDEO', 'AUDIO', 'SOURCE', 'TRACK', 'CANVAS', 'MAP', 'AREA', 'SVG', 'IFRAME', 'FRAME', 'FRAMESET',
'LI', 'UL', 'OL', 'DL', 'DT', 'DD', 'HR', 'P', 'PRE', 'LISTING', 'PLAINTEXT', 'A'
];
while (element.parentElement) {
const parentRect = element.parentElement.getBoundingClientRect();
const childRect = element.getBoundingClientRect();

if (!containerTags.includes(element.parentElement.tagName)) {
break;
}

// Check if parent visually contains the child
const fullyContained =
parentRect.left <= childRect.left &&
Expand All @@ -57,7 +69,7 @@ export const getElementInformation = async (
element = element.parentElement;
} else {
break;
}
// }
} }

let info: {
Expand Down Expand Up @@ -119,15 +131,28 @@ export const getRect = async (page: Page, coordinates: Coordinates) => {
if (originalEl) {
let element = originalEl;

if (originalEl.tagName === 'A') {
element = originalEl;
} else if (originalEl.parentElement?.tagName === 'A') {
element = originalEl.parentElement;
} else {
// if (originalEl.tagName === 'A') {
// element = originalEl;
// } else if (originalEl.parentElement?.tagName === 'A') {
// element = originalEl.parentElement;
// } else {
const containerTags = ['DIV', 'SECTION', 'ARTICLE', 'MAIN', 'HEADER', 'FOOTER', 'NAV', 'ASIDE',
'ADDRESS', 'BLOCKQUOTE', 'DETAILS', 'DIALOG', 'FIGURE', 'FIGCAPTION', 'MAIN', 'MARK', 'SUMMARY', 'TIME',
'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TR', 'TH', 'TD', 'CAPTION', 'COLGROUP', 'COL', 'FORM', 'FIELDSET',
'LEGEND', 'LABEL', 'INPUT', 'BUTTON', 'SELECT', 'DATALIST', 'OPTGROUP', 'OPTION', 'TEXTAREA', 'OUTPUT',
'PROGRESS', 'METER', 'DETAILS', 'SUMMARY', 'MENU', 'MENUITEM', 'MENUITEM', 'APPLET', 'EMBED', 'OBJECT',
'PARAM', 'VIDEO', 'AUDIO', 'SOURCE', 'TRACK', 'CANVAS', 'MAP', 'AREA', 'SVG', 'IFRAME', 'FRAME', 'FRAMESET',
'LI', 'UL', 'OL', 'DL', 'DT', 'DD', 'HR', 'P', 'PRE', 'LISTING', 'PLAINTEXT', 'A'
];
while (element.parentElement) {
const parentRect = element.parentElement.getBoundingClientRect();
const childRect = element.getBoundingClientRect();

if (!containerTags.includes(element.parentElement.tagName)) {
break;
}


const fullyContained =
parentRect.left <= childRect.left &&
parentRect.right >= childRect.right &&
Expand All @@ -142,7 +167,7 @@ export const getRect = async (page: Page, coordinates: Coordinates) => {
element = element.parentElement;
} else {
break;
}
// }
}}

//element = element?.parentElement?.tagName === 'A' ? element?.parentElement : element;
Expand Down

0 comments on commit 14c9626

Please sign in to comment.