browser-assistant 2.9.24 → 2.9.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extension/editor-bridge.js +45 -7
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/server/main.py +1 -1
|
@@ -327,11 +327,32 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
327
327
|
const rect = node.getBoundingClientRect();
|
|
328
328
|
return { node, clientX: rect.left + rect.width / 2, clientY: rect.top + rect.height / 2 };
|
|
329
329
|
};
|
|
330
|
-
|
|
330
|
+
const unchangedRows = () => {
|
|
331
331
|
const current = rows();
|
|
332
|
-
|
|
332
|
+
return current.length === before.length && current.every((row, index) => row.text === expectedTexts[index]) ? current : [];
|
|
333
|
+
};
|
|
334
|
+
const pressHandle = (original, pressed) => {
|
|
335
|
+
const point = () => center(findRow(moving)?.handle || original);
|
|
336
|
+
const init = {
|
|
337
|
+
bubbles: true, cancelable: true, button: 0, buttons: pressed ? 1 : 0,
|
|
338
|
+
};
|
|
339
|
+
const pointer = point();
|
|
340
|
+
if (typeof PointerEvent === 'function' && !pointer.node.dispatchEvent(new PointerEvent(pressed ? 'pointerdown' : 'pointerup', { ...init, clientX: pointer.clientX, clientY: pointer.clientY, pointerType: 'mouse', pointerId: 1, isPrimary: true })) && pressed)
|
|
341
|
+
return;
|
|
342
|
+
const mouse = point();
|
|
343
|
+
mouse.node.dispatchEvent(new MouseEvent(pressed ? 'mousedown' : 'mouseup', {
|
|
344
|
+
...init, clientX: mouse.clientX, clientY: mouse.clientY,
|
|
345
|
+
}));
|
|
346
|
+
};
|
|
347
|
+
for (const mode of ['row', 'handle', 'press']) {
|
|
348
|
+
if (mode === 'press' && typeof MouseEvent !== 'function')
|
|
333
349
|
break;
|
|
334
|
-
const
|
|
350
|
+
const current = unchangedRows();
|
|
351
|
+
if (!current.length)
|
|
352
|
+
break;
|
|
353
|
+
const handle = current[from].handle;
|
|
354
|
+
let source = handle;
|
|
355
|
+
let started = false;
|
|
335
356
|
const dataTransfer = new DataTransfer();
|
|
336
357
|
dataTransfer.setData('text/plain', moving);
|
|
337
358
|
dataTransfer.effectAllowed = 'move';
|
|
@@ -342,7 +363,7 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
342
363
|
const row = findRow(destination);
|
|
343
364
|
if (!row)
|
|
344
365
|
return null;
|
|
345
|
-
if (
|
|
366
|
+
if (mode === 'handle')
|
|
346
367
|
return center(row.handle);
|
|
347
368
|
const { clientX } = center(row.label);
|
|
348
369
|
const rect = row.row.getBoundingClientRect();
|
|
@@ -350,9 +371,20 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
350
371
|
const hit = document.elementFromPoint?.(clientX, clientY);
|
|
351
372
|
return { node: hit && row.row.contains(hit) ? hit : row.label, clientX, clientY };
|
|
352
373
|
};
|
|
353
|
-
if (!send(center(source), 'dragstart'))
|
|
354
|
-
break;
|
|
355
374
|
try {
|
|
375
|
+
if (mode === 'press') {
|
|
376
|
+
// Some practice rows become draggable only after the handle is pressed.
|
|
377
|
+
pressHandle(handle, true);
|
|
378
|
+
await wait(100);
|
|
379
|
+
const armed = unchangedRows()[from];
|
|
380
|
+
if (!armed?.row.matches('[draggable="true"]'))
|
|
381
|
+
break;
|
|
382
|
+
source = armed.row;
|
|
383
|
+
}
|
|
384
|
+
started = send({ ...center(findRow(moving)?.handle || handle), node: source }, 'dragstart');
|
|
385
|
+
// A cancelled start can mean the row has yet to be enabled by its handle.
|
|
386
|
+
if (!started)
|
|
387
|
+
continue;
|
|
356
388
|
// A drag handler can render fresh row nodes between events.
|
|
357
389
|
await wait(220);
|
|
358
390
|
dataTransfer.dropEffect = 'move';
|
|
@@ -371,7 +403,13 @@ async function browserAssistantOrderingDrag(prompt, optionTexts, from, to) {
|
|
|
371
403
|
send(dropped, 'drop');
|
|
372
404
|
}
|
|
373
405
|
finally {
|
|
374
|
-
|
|
406
|
+
if (started) {
|
|
407
|
+
const latest = findRow(moving);
|
|
408
|
+
const endSource = latest && (source.matches('.drag-icon-container') ? latest.handle : latest.row);
|
|
409
|
+
send(center(endSource || source), 'dragend');
|
|
410
|
+
}
|
|
411
|
+
if (mode === 'press')
|
|
412
|
+
pressHandle(handle, false);
|
|
375
413
|
}
|
|
376
414
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
377
415
|
await wait(160);
|
package/extension/manifest.json
CHANGED
package/package.json
CHANGED
package/server/main.py
CHANGED
|
@@ -194,7 +194,7 @@ async def lifespan(_app: FastAPI):
|
|
|
194
194
|
client.close()
|
|
195
195
|
|
|
196
196
|
|
|
197
|
-
app = FastAPI(title="Browser Assistant API", version="2.9.
|
|
197
|
+
app = FastAPI(title="Browser Assistant API", version="2.9.25", lifespan=lifespan)
|
|
198
198
|
install_local_guards(app)
|
|
199
199
|
|
|
200
200
|
@app.exception_handler(HTTPException)
|