pi-ele-picker 0.1.0 → 0.1.2
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/LICENSE +1 -1
- package/client/picker.js +31 -3
- package/package.json +10 -2
package/LICENSE
CHANGED
package/client/picker.js
CHANGED
|
@@ -125,6 +125,9 @@
|
|
|
125
125
|
var picking = false;
|
|
126
126
|
var target = null;
|
|
127
127
|
var shots = [];
|
|
128
|
+
// Set when a pick commits on pointerdown; swallows the follow-up click so the
|
|
129
|
+
// page (links, buttons) never reacts to the click that finished the pick.
|
|
130
|
+
var swallowClick = false;
|
|
128
131
|
|
|
129
132
|
document.documentElement.appendChild(host);
|
|
130
133
|
|
|
@@ -288,15 +291,34 @@
|
|
|
288
291
|
showHighlight(el);
|
|
289
292
|
}
|
|
290
293
|
|
|
291
|
-
|
|
294
|
+
/**
|
|
295
|
+
* Commit the pick on `pointerdown`, not `click`: disabled form controls never
|
|
296
|
+
* dispatch `click` (so they could never be picked), but `pointerdown` still
|
|
297
|
+
* fires on them with the correct target.
|
|
298
|
+
*/
|
|
299
|
+
function onPointerDown(e) {
|
|
300
|
+
if (e.button !== 0) return;
|
|
292
301
|
var el = elFromEvent(e);
|
|
293
302
|
if (!el) return;
|
|
294
303
|
e.preventDefault();
|
|
295
304
|
e.stopPropagation();
|
|
305
|
+
// preventDefault above only cancels the compat mousedown/mouseup, not the
|
|
306
|
+
// click, so flag it for the one-shot click swallower below. The flag is
|
|
307
|
+
// cleared at the start of every pointerdown (see the always-on listener at
|
|
308
|
+
// the bottom), so it can never strand on a disabled target — which fires
|
|
309
|
+
// pointerdown but no click at all — and eat an unrelated later click.
|
|
310
|
+
swallowClick = true;
|
|
296
311
|
setPicking(false);
|
|
297
312
|
select(el);
|
|
298
313
|
}
|
|
299
314
|
|
|
315
|
+
function onClick(e) {
|
|
316
|
+
if (!swallowClick) return;
|
|
317
|
+
swallowClick = false;
|
|
318
|
+
e.preventDefault();
|
|
319
|
+
e.stopPropagation();
|
|
320
|
+
}
|
|
321
|
+
|
|
300
322
|
function onKey(e) {
|
|
301
323
|
if (e.key === 'Escape') {
|
|
302
324
|
setPicking(false);
|
|
@@ -311,11 +333,11 @@
|
|
|
311
333
|
trigger.style.display = on ? 'none' : 'flex';
|
|
312
334
|
if (on) {
|
|
313
335
|
window.addEventListener('mousemove', onMove, true);
|
|
314
|
-
window.addEventListener('
|
|
336
|
+
window.addEventListener('pointerdown', onPointerDown, true);
|
|
315
337
|
window.addEventListener('keydown', onKey, true);
|
|
316
338
|
} else {
|
|
317
339
|
window.removeEventListener('mousemove', onMove, true);
|
|
318
|
-
window.removeEventListener('
|
|
340
|
+
window.removeEventListener('pointerdown', onPointerDown, true);
|
|
319
341
|
window.removeEventListener('keydown', onKey, true);
|
|
320
342
|
hideHighlight();
|
|
321
343
|
}
|
|
@@ -562,6 +584,12 @@
|
|
|
562
584
|
});
|
|
563
585
|
}
|
|
564
586
|
|
|
587
|
+
// Always-on. The first one resets the swallow flag before `onPointerDown`
|
|
588
|
+
// runs (registered earlier, so same-node capture listeners fire in order);
|
|
589
|
+
// the second consumes the flag to cancel the click that finishes a pick.
|
|
590
|
+
window.addEventListener('pointerdown', function () { swallowClick = false; }, true);
|
|
591
|
+
window.addEventListener('click', onClick, true);
|
|
592
|
+
|
|
565
593
|
trigger.addEventListener('click', function () {
|
|
566
594
|
if (suppressClick) {
|
|
567
595
|
suppressClick = false;
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ele-picker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Pick an element in your running page, describe the change, and send it to a pi session. Ships a Vite dev plugin (browser picker + discovery endpoint) and the matching pi bridge extension.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"author": "
|
|
7
|
+
"author": "Himangguo",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Himangguo/pi-ele-picker.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/Himangguo/pi-ele-picker#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Himangguo/pi-ele-picker/issues"
|
|
15
|
+
},
|
|
8
16
|
"keywords": [
|
|
9
17
|
"vite",
|
|
10
18
|
"vite-plugin",
|