react-grab 0.0.44 → 0.0.45
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/dist/index.cjs +277 -34
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.global.js +31 -25
- package/dist/index.js +278 -35
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { render, createComponent, memo, template, effect, style, insert, setStyleProperty, use } from 'solid-js/web';
|
|
1
|
+
import { delegateEvents, render, createComponent, memo, template, effect, style, insert, setStyleProperty, use } from 'solid-js/web';
|
|
2
2
|
import { createRoot, createSignal, createMemo, createEffect, on, onCleanup, Show, For, onMount } from 'solid-js';
|
|
3
3
|
import { getFiberFromHostInstance, traverseFiber, isCompositeFiber, getDisplayName, isFiber, getLatestFiber, isHostFiber } from 'bippy';
|
|
4
4
|
import { isSourceFile, normalizeFileName, getSource } from 'bippy/source';
|
|
@@ -98,6 +98,8 @@ var SELECTION_LERP_FACTOR = 0.95;
|
|
|
98
98
|
var SUCCESS_LABEL_DURATION_MS = 1700;
|
|
99
99
|
var PROGRESS_INDICATOR_DELAY_MS = 150;
|
|
100
100
|
var DRAG_THRESHOLD_PX = 2;
|
|
101
|
+
var AUTO_SCROLL_EDGE_THRESHOLD_PX = 25;
|
|
102
|
+
var AUTO_SCROLL_SPEED_PX = 10;
|
|
101
103
|
var Z_INDEX_LABEL = 2147483647;
|
|
102
104
|
|
|
103
105
|
// src/utils/lerp.ts
|
|
@@ -580,6 +582,87 @@ var Crosshair = (props) => {
|
|
|
580
582
|
}
|
|
581
583
|
});
|
|
582
584
|
};
|
|
585
|
+
var _tmpl$10 = /* @__PURE__ */ template(`<div data-react-grab-input style="position:fixed;background-color:#fde7f7;color:#b21c8e;border:1px solid #f7c5ec;border-radius:4px;font-size:11px;font-weight:500;font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;max-width:calc(100vw - (16px + env(safe-area-inset-left) + env(safe-area-inset-right)));overflow:hidden"><div style="position:relative;padding:2px 3px;display:flex;flex-direction:column;gap:2px"><textarea placeholder="e.g., Make this button larger"rows=1 style="width:240px;padding:2px 4px;background-color:#ffffff;color:#b21c8e;border:1px solid #f7c5ec;border-radius:3px;font-size:11px;line-height:1.2;font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;outline:none;resize:vertical;min-height:18px"></textarea><div style=font-size:9px;opacity:0.6;text-align:center>Enter \u23CE to submit, Escape to cancel`);
|
|
586
|
+
var InputOverlay = (props) => {
|
|
587
|
+
let containerRef;
|
|
588
|
+
let inputRef;
|
|
589
|
+
const position = useAnimatedPosition({
|
|
590
|
+
x: () => props.x,
|
|
591
|
+
y: () => props.y,
|
|
592
|
+
lerpFactor: 0.3
|
|
593
|
+
});
|
|
594
|
+
const containerBoundingRect = () => containerRef?.getBoundingClientRect();
|
|
595
|
+
const computedPosition = () => {
|
|
596
|
+
const boundingRect = containerBoundingRect();
|
|
597
|
+
if (!boundingRect) return {
|
|
598
|
+
left: position.x(),
|
|
599
|
+
top: position.y()
|
|
600
|
+
};
|
|
601
|
+
const viewportWidth = window.innerWidth;
|
|
602
|
+
const viewportHeight = window.innerHeight;
|
|
603
|
+
const quadrants = getCursorQuadrants(position.x(), position.y(), boundingRect.width, boundingRect.height, CURSOR_OFFSET_PX);
|
|
604
|
+
for (const position2 of quadrants) {
|
|
605
|
+
const fitsHorizontally = position2.left >= VIEWPORT_MARGIN_PX && position2.left + boundingRect.width <= viewportWidth - VIEWPORT_MARGIN_PX;
|
|
606
|
+
const fitsVertically = position2.top >= VIEWPORT_MARGIN_PX && position2.top + boundingRect.height <= viewportHeight - VIEWPORT_MARGIN_PX;
|
|
607
|
+
if (fitsHorizontally && fitsVertically) {
|
|
608
|
+
return position2;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const fallback = getClampedElementPosition(quadrants[0].left, quadrants[0].top, boundingRect.width, boundingRect.height);
|
|
612
|
+
fallback.left += INDICATOR_CLAMP_PADDING_PX;
|
|
613
|
+
fallback.top += INDICATOR_CLAMP_PADDING_PX;
|
|
614
|
+
return fallback;
|
|
615
|
+
};
|
|
616
|
+
const handleKeyDown = (event) => {
|
|
617
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
618
|
+
event.preventDefault();
|
|
619
|
+
event.stopPropagation();
|
|
620
|
+
props.onSubmit();
|
|
621
|
+
} else if (event.key === "Escape") {
|
|
622
|
+
event.preventDefault();
|
|
623
|
+
event.stopPropagation();
|
|
624
|
+
props.onCancel();
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
const handleInput = (event) => {
|
|
628
|
+
const target = event.target;
|
|
629
|
+
props.onInput(target.value);
|
|
630
|
+
};
|
|
631
|
+
createEffect(() => {
|
|
632
|
+
if (props.visible && inputRef) {
|
|
633
|
+
inputRef.focus();
|
|
634
|
+
} else if (!props.visible && inputRef) {
|
|
635
|
+
inputRef.blur();
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
return (() => {
|
|
639
|
+
var _el$ = _tmpl$10(), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild; _el$3.nextSibling;
|
|
640
|
+
var _ref$ = containerRef;
|
|
641
|
+
typeof _ref$ === "function" ? use(_ref$, _el$) : containerRef = _el$;
|
|
642
|
+
_el$3.$$keydown = handleKeyDown;
|
|
643
|
+
_el$3.$$input = handleInput;
|
|
644
|
+
var _ref$2 = inputRef;
|
|
645
|
+
typeof _ref$2 === "function" ? use(_ref$2, _el$3) : inputRef = _el$3;
|
|
646
|
+
effect((_p$) => {
|
|
647
|
+
var _v$ = props.visible ? "block" : "none", _v$2 = `${computedPosition().top}px`, _v$3 = `${computedPosition().left}px`, _v$4 = props.zIndex?.toString() ?? "2147483647", _v$5 = props.visible ? "auto" : "none";
|
|
648
|
+
_v$ !== _p$.e && setStyleProperty(_el$, "display", _p$.e = _v$);
|
|
649
|
+
_v$2 !== _p$.t && setStyleProperty(_el$, "top", _p$.t = _v$2);
|
|
650
|
+
_v$3 !== _p$.a && setStyleProperty(_el$, "left", _p$.a = _v$3);
|
|
651
|
+
_v$4 !== _p$.o && setStyleProperty(_el$, "z-index", _p$.o = _v$4);
|
|
652
|
+
_v$5 !== _p$.i && setStyleProperty(_el$, "pointer-events", _p$.i = _v$5);
|
|
653
|
+
return _p$;
|
|
654
|
+
}, {
|
|
655
|
+
e: void 0,
|
|
656
|
+
t: void 0,
|
|
657
|
+
a: void 0,
|
|
658
|
+
o: void 0,
|
|
659
|
+
i: void 0
|
|
660
|
+
});
|
|
661
|
+
effect(() => _el$3.value = props.value);
|
|
662
|
+
return _el$;
|
|
663
|
+
})();
|
|
664
|
+
};
|
|
665
|
+
delegateEvents(["input", "keydown"]);
|
|
583
666
|
|
|
584
667
|
// src/components/renderer.tsx
|
|
585
668
|
var ReactGrabRenderer = (props) => {
|
|
@@ -696,6 +779,31 @@ var ReactGrabRenderer = (props) => {
|
|
|
696
779
|
}
|
|
697
780
|
});
|
|
698
781
|
}
|
|
782
|
+
}), createComponent(InputOverlay, {
|
|
783
|
+
get x() {
|
|
784
|
+
return props.inputX ?? 0;
|
|
785
|
+
},
|
|
786
|
+
get y() {
|
|
787
|
+
return props.inputY ?? 0;
|
|
788
|
+
},
|
|
789
|
+
get zIndex() {
|
|
790
|
+
return props.labelZIndex;
|
|
791
|
+
},
|
|
792
|
+
get value() {
|
|
793
|
+
return props.inputValue ?? "";
|
|
794
|
+
},
|
|
795
|
+
get visible() {
|
|
796
|
+
return props.inputVisible ?? false;
|
|
797
|
+
},
|
|
798
|
+
get onInput() {
|
|
799
|
+
return props.onInputChange;
|
|
800
|
+
},
|
|
801
|
+
get onSubmit() {
|
|
802
|
+
return props.onInputSubmit;
|
|
803
|
+
},
|
|
804
|
+
get onCancel() {
|
|
805
|
+
return props.onInputCancel;
|
|
806
|
+
}
|
|
699
807
|
})];
|
|
700
808
|
};
|
|
701
809
|
|
|
@@ -1065,7 +1173,7 @@ var createElementBounds = (element) => {
|
|
|
1065
1173
|
};
|
|
1066
1174
|
|
|
1067
1175
|
// src/core.tsx
|
|
1068
|
-
var
|
|
1176
|
+
var hasInited = false;
|
|
1069
1177
|
var init = (rawOptions) => {
|
|
1070
1178
|
const options = {
|
|
1071
1179
|
enabled: true,
|
|
@@ -1074,7 +1182,7 @@ var init = (rawOptions) => {
|
|
|
1074
1182
|
playCopySound: false,
|
|
1075
1183
|
...rawOptions
|
|
1076
1184
|
};
|
|
1077
|
-
if (options.enabled === false) {
|
|
1185
|
+
if (options.enabled === false || hasInited) {
|
|
1078
1186
|
return {
|
|
1079
1187
|
activate: () => {
|
|
1080
1188
|
},
|
|
@@ -1087,11 +1195,10 @@ var init = (rawOptions) => {
|
|
|
1087
1195
|
}
|
|
1088
1196
|
};
|
|
1089
1197
|
}
|
|
1198
|
+
hasInited = true;
|
|
1090
1199
|
const logIntro = () => {
|
|
1091
|
-
if (hasLoggedIntro) return;
|
|
1092
|
-
hasLoggedIntro = true;
|
|
1093
1200
|
try {
|
|
1094
|
-
const version = "0.0.
|
|
1201
|
+
const version = "0.0.45";
|
|
1095
1202
|
const logoSvg = `<svg width="294" height="294" viewBox="0 0 294 294" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_0_3)"><mask id="mask0_0_3" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="294" height="294"><path d="M294 0H0V294H294V0Z" fill="white"/></mask><g mask="url(#mask0_0_3)"><path d="M144.599 47.4924C169.712 27.3959 194.548 20.0265 212.132 30.1797C227.847 39.2555 234.881 60.3243 231.926 89.516C231.677 92.0069 231.328 94.5423 230.94 97.1058L228.526 110.14C228.517 110.136 228.505 110.132 228.495 110.127C228.486 110.165 228.479 110.203 228.468 110.24L216.255 105.741C216.256 105.736 216.248 105.728 216.248 105.723C207.915 103.125 199.421 101.075 190.82 99.5888L190.696 99.5588L173.526 97.2648L173.511 97.2631C173.492 97.236 173.467 97.2176 173.447 97.1905C163.862 96.2064 154.233 95.7166 144.599 95.7223C134.943 95.7162 125.295 96.219 115.693 97.2286C110.075 105.033 104.859 113.118 100.063 121.453C95.2426 129.798 90.8624 138.391 86.939 147.193C90.8624 155.996 95.2426 164.588 100.063 172.933C104.866 181.302 110.099 189.417 115.741 197.245C115.749 197.245 115.758 197.246 115.766 197.247L115.752 197.27L115.745 197.283L115.754 197.296L126.501 211.013L126.574 211.089C132.136 217.767 138.126 224.075 144.507 229.974L144.609 230.082L154.572 238.287C154.539 238.319 154.506 238.35 154.472 238.38C154.485 238.392 154.499 238.402 154.513 238.412L143.846 247.482L143.827 247.497C126.56 261.128 109.472 268.745 94.8019 268.745C88.5916 268.837 82.4687 267.272 77.0657 264.208C61.3496 255.132 54.3164 234.062 57.2707 204.871C57.528 202.307 57.8806 199.694 58.2904 197.054C28.3363 185.327 9.52301 167.51 9.52301 147.193C9.52301 129.042 24.2476 112.396 50.9901 100.375C53.3443 99.3163 55.7938 98.3058 58.2904 97.3526C57.8806 94.7023 57.528 92.0803 57.2707 89.516C54.3164 60.3243 61.3496 39.2555 77.0657 30.1797C94.6494 20.0265 119.486 27.3959 144.599 47.4924ZM70.6423 201.315C70.423 202.955 70.2229 204.566 70.0704 206.168C67.6686 229.567 72.5478 246.628 83.3615 252.988L83.5176 253.062C95.0399 259.717 114.015 254.426 134.782 238.38C125.298 229.45 116.594 219.725 108.764 209.314C95.8516 207.742 83.0977 205.066 70.6423 201.315ZM80.3534 163.438C77.34 171.677 74.8666 180.104 72.9484 188.664C81.1787 191.224 89.5657 193.247 98.0572 194.724L98.4618 194.813C95.2115 189.865 92.0191 184.66 88.9311 179.378C85.8433 174.097 83.003 168.768 80.3534 163.438ZM60.759 110.203C59.234 110.839 57.7378 111.475 56.27 112.11C34.7788 121.806 22.3891 134.591 22.3891 147.193C22.3891 160.493 36.4657 174.297 60.7494 184.26C63.7439 171.581 67.8124 159.182 72.9104 147.193C67.822 135.23 63.7566 122.855 60.759 110.203ZM98.4137 99.6404C89.8078 101.145 81.3075 103.206 72.9676 105.809C74.854 114.203 77.2741 122.468 80.2132 130.554L80.3059 130.939C82.9938 125.6 85.8049 120.338 88.8834 115.008C91.9618 109.679 95.1544 104.569 98.4137 99.6404ZM94.9258 38.5215C90.9331 38.4284 86.9866 39.3955 83.4891 41.3243C72.6291 47.6015 67.6975 64.5954 70.0424 87.9446L70.0416 88.2194C70.194 89.8208 70.3941 91.4325 70.6134 93.0624C83.0737 89.3364 95.8263 86.6703 108.736 85.0924C116.57 74.6779 125.28 64.9532 134.773 56.0249C119.877 44.5087 105.895 38.5215 94.9258 38.5215ZM205.737 41.3148C202.268 39.398 198.355 38.4308 194.394 38.5099L194.29 38.512C183.321 38.512 169.34 44.4991 154.444 56.0153C163.93 64.9374 172.634 74.6557 180.462 85.064C193.375 86.6345 206.128 89.3102 218.584 93.0624C218.812 91.4325 219.003 89.8118 219.165 88.2098C221.548 64.7099 216.65 47.6164 205.737 41.3148ZM144.552 64.3097C138.104 70.2614 132.054 76.6306 126.443 83.3765C132.39 82.995 138.426 82.8046 144.552 82.8046C150.727 82.8046 156.778 83.0143 162.707 83.3765C157.08 76.6293 151.015 70.2596 144.552 64.3097Z" fill="white"/><path d="M144.598 47.4924C169.712 27.3959 194.547 20.0265 212.131 30.1797C227.847 39.2555 234.88 60.3243 231.926 89.516C231.677 92.0069 231.327 94.5423 230.941 97.1058L228.526 110.14L228.496 110.127C228.487 110.165 228.478 110.203 228.469 110.24L216.255 105.741L216.249 105.723C207.916 103.125 199.42 101.075 190.82 99.5888L190.696 99.5588L173.525 97.2648L173.511 97.263C173.492 97.236 173.468 97.2176 173.447 97.1905C163.863 96.2064 154.234 95.7166 144.598 95.7223C134.943 95.7162 125.295 96.219 115.693 97.2286C110.075 105.033 104.859 113.118 100.063 121.453C95.2426 129.798 90.8622 138.391 86.939 147.193C90.8622 155.996 95.2426 164.588 100.063 172.933C104.866 181.302 110.099 189.417 115.741 197.245L115.766 197.247L115.752 197.27L115.745 197.283L115.754 197.296L126.501 211.013L126.574 211.089C132.136 217.767 138.126 224.075 144.506 229.974L144.61 230.082L154.572 238.287C154.539 238.319 154.506 238.35 154.473 238.38L154.512 238.412L143.847 247.482L143.827 247.497C126.56 261.13 109.472 268.745 94.8018 268.745C88.5915 268.837 82.4687 267.272 77.0657 264.208C61.3496 255.132 54.3162 234.062 57.2707 204.871C57.528 202.307 57.8806 199.694 58.2904 197.054C28.3362 185.327 9.52298 167.51 9.52298 147.193C9.52298 129.042 24.2476 112.396 50.9901 100.375C53.3443 99.3163 55.7938 98.3058 58.2904 97.3526C57.8806 94.7023 57.528 92.0803 57.2707 89.516C54.3162 60.3243 61.3496 39.2555 77.0657 30.1797C94.6493 20.0265 119.486 27.3959 144.598 47.4924ZM70.6422 201.315C70.423 202.955 70.2229 204.566 70.0704 206.168C67.6686 229.567 72.5478 246.628 83.3615 252.988L83.5175 253.062C95.0399 259.717 114.015 254.426 134.782 238.38C125.298 229.45 116.594 219.725 108.764 209.314C95.8515 207.742 83.0977 205.066 70.6422 201.315ZM80.3534 163.438C77.34 171.677 74.8666 180.104 72.9484 188.664C81.1786 191.224 89.5657 193.247 98.0572 194.724L98.4618 194.813C95.2115 189.865 92.0191 184.66 88.931 179.378C85.8433 174.097 83.003 168.768 80.3534 163.438ZM60.7589 110.203C59.234 110.839 57.7378 111.475 56.2699 112.11C34.7788 121.806 22.3891 134.591 22.3891 147.193C22.3891 160.493 36.4657 174.297 60.7494 184.26C63.7439 171.581 67.8124 159.182 72.9103 147.193C67.822 135.23 63.7566 122.855 60.7589 110.203ZM98.4137 99.6404C89.8078 101.145 81.3075 103.206 72.9676 105.809C74.8539 114.203 77.2741 122.468 80.2132 130.554L80.3059 130.939C82.9938 125.6 85.8049 120.338 88.8834 115.008C91.9618 109.679 95.1544 104.569 98.4137 99.6404ZM94.9258 38.5215C90.9331 38.4284 86.9866 39.3955 83.4891 41.3243C72.629 47.6015 67.6975 64.5954 70.0424 87.9446L70.0415 88.2194C70.194 89.8208 70.3941 91.4325 70.6134 93.0624C83.0737 89.3364 95.8262 86.6703 108.736 85.0924C116.57 74.6779 125.28 64.9532 134.772 56.0249C119.877 44.5087 105.895 38.5215 94.9258 38.5215ZM205.737 41.3148C202.268 39.398 198.355 38.4308 194.394 38.5099L194.291 38.512C183.321 38.512 169.34 44.4991 154.443 56.0153C163.929 64.9374 172.634 74.6557 180.462 85.064C193.374 86.6345 206.129 89.3102 218.584 93.0624C218.813 91.4325 219.003 89.8118 219.166 88.2098C221.548 64.7099 216.65 47.6164 205.737 41.3148ZM144.551 64.3097C138.103 70.2614 132.055 76.6306 126.443 83.3765C132.389 82.995 138.427 82.8046 144.551 82.8046C150.727 82.8046 156.779 83.0143 162.707 83.3765C157.079 76.6293 151.015 70.2596 144.551 64.3097Z" fill="#FF40E0"/></g><mask id="mask1_0_3" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="102" y="84" width="161" height="162"><path d="M235.282 84.827L102.261 112.259L129.693 245.28L262.714 217.848L235.282 84.827Z" fill="white"/></mask><g mask="url(#mask1_0_3)"><path d="M136.863 129.916L213.258 141.224C220.669 142.322 222.495 152.179 215.967 155.856L187.592 171.843L184.135 204.227C183.339 211.678 173.564 213.901 169.624 207.526L129.021 141.831C125.503 136.14 130.245 128.936 136.863 129.916Z" fill="#FF40E0" stroke="#FF40E0" stroke-width="0.817337" stroke-linecap="round" stroke-linejoin="round"/></g></g><defs><clipPath id="clip0_0_3"><rect width="294" height="294" fill="white"/></clipPath></defs></svg>`;
|
|
1096
1203
|
const logoDataUri = `data:image/svg+xml;base64,${btoa(logoSvg)}`;
|
|
1097
1204
|
console.log(`%cReact Grab${version ? ` v${version}` : ""}%c
|
|
@@ -1121,21 +1228,34 @@ https://react-grab.com`, `background: #330039; color: #ffffff; border: 1px solid
|
|
|
1121
1228
|
const [copyStartX, setCopyStartX] = createSignal(OFFSCREEN_POSITION);
|
|
1122
1229
|
const [copyStartY, setCopyStartY] = createSignal(OFFSCREEN_POSITION);
|
|
1123
1230
|
const [mouseHasSettled, setMouseHasSettled] = createSignal(false);
|
|
1231
|
+
const [viewportVersion, setViewportVersion] = createSignal(0);
|
|
1232
|
+
const [isInputMode, setIsInputMode] = createSignal(false);
|
|
1233
|
+
const [inputText, setInputText] = createSignal("");
|
|
1124
1234
|
let holdTimerId = null;
|
|
1125
1235
|
let progressAnimationId = null;
|
|
1126
1236
|
let progressDelayTimerId = null;
|
|
1127
1237
|
let keydownSpamTimerId = null;
|
|
1128
1238
|
let mouseSettleTimerId = null;
|
|
1239
|
+
let autoScrollAnimationId = null;
|
|
1129
1240
|
const isRendererActive = createMemo(() => isActivated() && !isCopying());
|
|
1130
1241
|
const hasValidMousePosition = createMemo(() => mouseX() > OFFSCREEN_POSITION && mouseY() > OFFSCREEN_POSITION);
|
|
1131
1242
|
const isTargetKeyCombination = (event) => (event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "c";
|
|
1132
|
-
const
|
|
1243
|
+
const getAutoScrollDirection = (clientX, clientY) => {
|
|
1244
|
+
return {
|
|
1245
|
+
top: clientY < AUTO_SCROLL_EDGE_THRESHOLD_PX,
|
|
1246
|
+
bottom: clientY > window.innerHeight - AUTO_SCROLL_EDGE_THRESHOLD_PX,
|
|
1247
|
+
left: clientX < AUTO_SCROLL_EDGE_THRESHOLD_PX,
|
|
1248
|
+
right: clientX > window.innerWidth - AUTO_SCROLL_EDGE_THRESHOLD_PX
|
|
1249
|
+
};
|
|
1250
|
+
};
|
|
1251
|
+
const showTemporaryGrabbedBox = (bounds, element) => {
|
|
1133
1252
|
const boxId = `grabbed-${Date.now()}-${Math.random()}`;
|
|
1134
1253
|
const createdAt = Date.now();
|
|
1135
1254
|
const newBox = {
|
|
1136
1255
|
id: boxId,
|
|
1137
1256
|
bounds,
|
|
1138
|
-
createdAt
|
|
1257
|
+
createdAt,
|
|
1258
|
+
element
|
|
1139
1259
|
};
|
|
1140
1260
|
const currentBoxes = grabbedBoxes();
|
|
1141
1261
|
setGrabbedBoxes([...currentBoxes, newBox]);
|
|
@@ -1190,11 +1310,7 @@ ${context}
|
|
|
1190
1310
|
setIsCopying(false);
|
|
1191
1311
|
stopProgressAnimation();
|
|
1192
1312
|
if (isToggleMode()) {
|
|
1193
|
-
|
|
1194
|
-
deactivateRenderer();
|
|
1195
|
-
} else {
|
|
1196
|
-
setIsToggleMode(false);
|
|
1197
|
-
}
|
|
1313
|
+
deactivateRenderer();
|
|
1198
1314
|
}
|
|
1199
1315
|
});
|
|
1200
1316
|
};
|
|
@@ -1206,7 +1322,7 @@ ${context}
|
|
|
1206
1322
|
return element.textContent ?? "";
|
|
1207
1323
|
};
|
|
1208
1324
|
const createCombinedTextContent = (elements) => elements.map((element) => extractElementTextContent(element).trim()).filter((textContent) => textContent.length > 0).join("\n\n");
|
|
1209
|
-
const tryCopyWithFallback = async (elements) => {
|
|
1325
|
+
const tryCopyWithFallback = async (elements, extraPrompt) => {
|
|
1210
1326
|
let didCopy = false;
|
|
1211
1327
|
try {
|
|
1212
1328
|
const elementSnippetResults = await Promise.allSettled(elements.map(async (element) => `## HTML Frame:
|
|
@@ -1216,27 +1332,36 @@ ${getHTMLPreview(element)}
|
|
|
1216
1332
|
${formatStack(await getStack(element))}`));
|
|
1217
1333
|
const elementSnippets = elementSnippetResults.map((result) => result.status === "fulfilled" ? result.value : "").filter((snippet) => snippet.trim());
|
|
1218
1334
|
if (elementSnippets.length > 0) {
|
|
1219
|
-
const
|
|
1335
|
+
const wrappedSnippets = elementSnippets.map((snippet) => wrapInSelectedElementTags(snippet)).join("\n\n");
|
|
1336
|
+
const plainTextContent = extraPrompt ? `${extraPrompt}
|
|
1337
|
+
|
|
1338
|
+
${wrappedSnippets}` : wrappedSnippets;
|
|
1220
1339
|
didCopy = await copyContent(plainTextContent, options.playCopySound ? playCopySound : void 0);
|
|
1221
1340
|
}
|
|
1222
1341
|
if (!didCopy) {
|
|
1223
1342
|
const plainTextContentOnly = createCombinedTextContent(elements);
|
|
1224
1343
|
if (plainTextContentOnly.length > 0) {
|
|
1225
|
-
|
|
1344
|
+
const contentWithPrompt = extraPrompt ? `${extraPrompt}
|
|
1345
|
+
|
|
1346
|
+
${plainTextContentOnly}` : plainTextContentOnly;
|
|
1347
|
+
didCopy = await copyContent(contentWithPrompt, options.playCopySound ? playCopySound : void 0);
|
|
1226
1348
|
}
|
|
1227
1349
|
}
|
|
1228
1350
|
} catch {
|
|
1229
1351
|
const plainTextContentOnly = createCombinedTextContent(elements);
|
|
1230
1352
|
if (plainTextContentOnly.length > 0) {
|
|
1231
|
-
|
|
1353
|
+
const contentWithPrompt = extraPrompt ? `${extraPrompt}
|
|
1354
|
+
|
|
1355
|
+
${plainTextContentOnly}` : plainTextContentOnly;
|
|
1356
|
+
didCopy = await copyContent(contentWithPrompt, options.playCopySound ? playCopySound : void 0);
|
|
1232
1357
|
}
|
|
1233
1358
|
}
|
|
1234
1359
|
return didCopy;
|
|
1235
1360
|
};
|
|
1236
|
-
const copySingleElementToClipboard = async (targetElement2) => {
|
|
1237
|
-
showTemporaryGrabbedBox(createElementBounds(targetElement2));
|
|
1361
|
+
const copySingleElementToClipboard = async (targetElement2, extraPrompt) => {
|
|
1362
|
+
showTemporaryGrabbedBox(createElementBounds(targetElement2), targetElement2);
|
|
1238
1363
|
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
1239
|
-
const didCopy = await tryCopyWithFallback([targetElement2]);
|
|
1364
|
+
const didCopy = await tryCopyWithFallback([targetElement2], extraPrompt);
|
|
1240
1365
|
if (didCopy) {
|
|
1241
1366
|
showTemporarySuccessLabel(extractElementLabelText(targetElement2));
|
|
1242
1367
|
}
|
|
@@ -1245,7 +1370,7 @@ ${formatStack(await getStack(element))}`));
|
|
|
1245
1370
|
const copyMultipleElementsToClipboard = async (targetElements) => {
|
|
1246
1371
|
if (targetElements.length === 0) return;
|
|
1247
1372
|
for (const element of targetElements) {
|
|
1248
|
-
showTemporaryGrabbedBox(createElementBounds(element));
|
|
1373
|
+
showTemporaryGrabbedBox(createElementBounds(element), element);
|
|
1249
1374
|
}
|
|
1250
1375
|
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
1251
1376
|
const didCopy = await tryCopyWithFallback(targetElements);
|
|
@@ -1259,6 +1384,7 @@ ${formatStack(await getStack(element))}`));
|
|
|
1259
1384
|
return getElementAtPosition(mouseX(), mouseY());
|
|
1260
1385
|
});
|
|
1261
1386
|
const selectionBounds = createMemo(() => {
|
|
1387
|
+
viewportVersion();
|
|
1262
1388
|
const element = targetElement();
|
|
1263
1389
|
if (!element) return void 0;
|
|
1264
1390
|
const elementBounds = element.getBoundingClientRect();
|
|
@@ -1272,23 +1398,29 @@ ${formatStack(await getStack(element))}`));
|
|
|
1272
1398
|
y: elementBounds.top
|
|
1273
1399
|
};
|
|
1274
1400
|
});
|
|
1275
|
-
const calculateDragDistance = (endX, endY) =>
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1401
|
+
const calculateDragDistance = (endX, endY) => {
|
|
1402
|
+
const endPageX = endX + window.scrollX;
|
|
1403
|
+
const endPageY = endY + window.scrollY;
|
|
1404
|
+
return {
|
|
1405
|
+
x: Math.abs(endPageX - dragStartX()),
|
|
1406
|
+
y: Math.abs(endPageY - dragStartY())
|
|
1407
|
+
};
|
|
1408
|
+
};
|
|
1279
1409
|
const isDraggingBeyondThreshold = createMemo(() => {
|
|
1280
1410
|
if (!isDragging()) return false;
|
|
1281
1411
|
const dragDistance = calculateDragDistance(mouseX(), mouseY());
|
|
1282
1412
|
return dragDistance.x > DRAG_THRESHOLD_PX || dragDistance.y > DRAG_THRESHOLD_PX;
|
|
1283
1413
|
});
|
|
1284
1414
|
const calculateDragRectangle = (endX, endY) => {
|
|
1285
|
-
const
|
|
1286
|
-
const
|
|
1287
|
-
const
|
|
1288
|
-
const
|
|
1415
|
+
const endPageX = endX + window.scrollX;
|
|
1416
|
+
const endPageY = endY + window.scrollY;
|
|
1417
|
+
const dragPageX = Math.min(dragStartX(), endPageX);
|
|
1418
|
+
const dragPageY = Math.min(dragStartY(), endPageY);
|
|
1419
|
+
const dragWidth = Math.abs(endPageX - dragStartX());
|
|
1420
|
+
const dragHeight = Math.abs(endPageY - dragStartY());
|
|
1289
1421
|
return {
|
|
1290
|
-
x:
|
|
1291
|
-
y:
|
|
1422
|
+
x: dragPageX - window.scrollX,
|
|
1423
|
+
y: dragPageY - window.scrollY,
|
|
1292
1424
|
width: dragWidth,
|
|
1293
1425
|
height: dragHeight
|
|
1294
1426
|
};
|
|
@@ -1328,6 +1460,15 @@ ${formatStack(await getStack(element))}`));
|
|
|
1328
1460
|
setLastGrabbedElement(null);
|
|
1329
1461
|
}
|
|
1330
1462
|
}));
|
|
1463
|
+
createEffect(on(() => viewportVersion(), () => {
|
|
1464
|
+
const currentBoxes = grabbedBoxes();
|
|
1465
|
+
if (currentBoxes.length === 0) return;
|
|
1466
|
+
const updatedBoxes = currentBoxes.map((box) => ({
|
|
1467
|
+
...box,
|
|
1468
|
+
bounds: createElementBounds(box.element)
|
|
1469
|
+
}));
|
|
1470
|
+
setGrabbedBoxes(updatedBoxes);
|
|
1471
|
+
}));
|
|
1331
1472
|
const startProgressAnimation = () => {
|
|
1332
1473
|
const startTime = Date.now();
|
|
1333
1474
|
setProgressStartTime(startTime);
|
|
@@ -1364,6 +1505,31 @@ ${formatStack(await getStack(element))}`));
|
|
|
1364
1505
|
setProgress(1);
|
|
1365
1506
|
setShowProgressIndicator(false);
|
|
1366
1507
|
};
|
|
1508
|
+
const startAutoScroll = () => {
|
|
1509
|
+
const scroll = () => {
|
|
1510
|
+
if (!isDragging()) {
|
|
1511
|
+
stopAutoScroll();
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
const direction = getAutoScrollDirection(mouseX(), mouseY());
|
|
1515
|
+
if (direction.top) window.scrollBy(0, -AUTO_SCROLL_SPEED_PX);
|
|
1516
|
+
if (direction.bottom) window.scrollBy(0, AUTO_SCROLL_SPEED_PX);
|
|
1517
|
+
if (direction.left) window.scrollBy(-AUTO_SCROLL_SPEED_PX, 0);
|
|
1518
|
+
if (direction.right) window.scrollBy(AUTO_SCROLL_SPEED_PX, 0);
|
|
1519
|
+
if (direction.top || direction.bottom || direction.left || direction.right) {
|
|
1520
|
+
autoScrollAnimationId = requestAnimationFrame(scroll);
|
|
1521
|
+
} else {
|
|
1522
|
+
autoScrollAnimationId = null;
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
scroll();
|
|
1526
|
+
};
|
|
1527
|
+
const stopAutoScroll = () => {
|
|
1528
|
+
if (autoScrollAnimationId !== null) {
|
|
1529
|
+
cancelAnimationFrame(autoScrollAnimationId);
|
|
1530
|
+
autoScrollAnimationId = null;
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1367
1533
|
const activateRenderer = () => {
|
|
1368
1534
|
stopProgressAnimation();
|
|
1369
1535
|
setIsActivated(true);
|
|
@@ -1374,6 +1540,8 @@ ${formatStack(await getStack(element))}`));
|
|
|
1374
1540
|
setIsToggleMode(false);
|
|
1375
1541
|
setIsHoldingKeys(false);
|
|
1376
1542
|
setIsActivated(false);
|
|
1543
|
+
setIsInputMode(false);
|
|
1544
|
+
setInputText("");
|
|
1377
1545
|
document.body.style.cursor = "";
|
|
1378
1546
|
if (isDragging()) {
|
|
1379
1547
|
setIsDragging(false);
|
|
@@ -1386,17 +1554,44 @@ ${formatStack(await getStack(element))}`));
|
|
|
1386
1554
|
mouseSettleTimerId = null;
|
|
1387
1555
|
}
|
|
1388
1556
|
setMouseHasSettled(false);
|
|
1557
|
+
stopAutoScroll();
|
|
1389
1558
|
stopProgressAnimation();
|
|
1390
1559
|
options.onDeactivate?.();
|
|
1391
1560
|
};
|
|
1561
|
+
const handleInputChange = (value) => {
|
|
1562
|
+
setInputText(value);
|
|
1563
|
+
};
|
|
1564
|
+
const handleInputSubmit = () => {
|
|
1565
|
+
if (!isInputMode()) return;
|
|
1566
|
+
const element = targetElement();
|
|
1567
|
+
const prompt = inputText().trim();
|
|
1568
|
+
const currentX = mouseX();
|
|
1569
|
+
const currentY = mouseY();
|
|
1570
|
+
setIsInputMode(false);
|
|
1571
|
+
setInputText("");
|
|
1572
|
+
if (element) {
|
|
1573
|
+
void executeCopyOperation(currentX, currentY, () => copySingleElementToClipboard(element, prompt || void 0)).then(() => {
|
|
1574
|
+
deactivateRenderer();
|
|
1575
|
+
});
|
|
1576
|
+
} else {
|
|
1577
|
+
deactivateRenderer();
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
const handleInputCancel = () => {
|
|
1581
|
+
if (!isInputMode()) return;
|
|
1582
|
+
deactivateRenderer();
|
|
1583
|
+
};
|
|
1392
1584
|
const abortController = new AbortController();
|
|
1393
1585
|
const eventListenerSignal = abortController.signal;
|
|
1394
1586
|
window.addEventListener("keydown", (event) => {
|
|
1395
1587
|
if (event.key === "Escape" && isHoldingKeys()) {
|
|
1588
|
+
if (isInputMode()) {
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1396
1591
|
deactivateRenderer();
|
|
1397
1592
|
return;
|
|
1398
1593
|
}
|
|
1399
|
-
if (event.key === "Enter" && isHoldingKeys()) {
|
|
1594
|
+
if (event.key === "Enter" && isHoldingKeys() && !isInputMode()) {
|
|
1400
1595
|
setIsToggleMode(true);
|
|
1401
1596
|
if (keydownSpamTimerId !== null) {
|
|
1402
1597
|
window.clearTimeout(keydownSpamTimerId);
|
|
@@ -1406,6 +1601,7 @@ ${formatStack(await getStack(element))}`));
|
|
|
1406
1601
|
if (holdTimerId) window.clearTimeout(holdTimerId);
|
|
1407
1602
|
activateRenderer();
|
|
1408
1603
|
}
|
|
1604
|
+
setIsInputMode(true);
|
|
1409
1605
|
return;
|
|
1410
1606
|
}
|
|
1411
1607
|
if (!options.allowActivationInsideInput && isKeyboardEventTriggeredByInput(event)) {
|
|
@@ -1459,15 +1655,32 @@ ${formatStack(await getStack(element))}`));
|
|
|
1459
1655
|
setMouseHasSettled(true);
|
|
1460
1656
|
mouseSettleTimerId = null;
|
|
1461
1657
|
}, 300);
|
|
1658
|
+
if (isDragging()) {
|
|
1659
|
+
const direction = getAutoScrollDirection(event.clientX, event.clientY);
|
|
1660
|
+
const isNearEdge = direction.top || direction.bottom || direction.left || direction.right;
|
|
1661
|
+
if (isNearEdge && autoScrollAnimationId === null) {
|
|
1662
|
+
startAutoScroll();
|
|
1663
|
+
} else if (!isNearEdge && autoScrollAnimationId !== null) {
|
|
1664
|
+
stopAutoScroll();
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1462
1667
|
}, {
|
|
1463
1668
|
signal: eventListenerSignal
|
|
1464
1669
|
});
|
|
1465
1670
|
window.addEventListener("mousedown", (event) => {
|
|
1671
|
+
if (isInputMode()) {
|
|
1672
|
+
const target = event.target;
|
|
1673
|
+
const isClickingInput = target.closest("[data-react-grab-input]");
|
|
1674
|
+
if (!isClickingInput) {
|
|
1675
|
+
handleInputCancel();
|
|
1676
|
+
}
|
|
1677
|
+
return;
|
|
1678
|
+
}
|
|
1466
1679
|
if (!isRendererActive() || isCopying()) return;
|
|
1467
1680
|
event.preventDefault();
|
|
1468
1681
|
setIsDragging(true);
|
|
1469
|
-
setDragStartX(event.clientX);
|
|
1470
|
-
setDragStartY(event.clientY);
|
|
1682
|
+
setDragStartX(event.clientX + window.scrollX);
|
|
1683
|
+
setDragStartY(event.clientY + window.scrollY);
|
|
1471
1684
|
document.body.style.userSelect = "none";
|
|
1472
1685
|
}, {
|
|
1473
1686
|
signal: eventListenerSignal
|
|
@@ -1477,6 +1690,7 @@ ${formatStack(await getStack(element))}`));
|
|
|
1477
1690
|
const dragDistance = calculateDragDistance(event.clientX, event.clientY);
|
|
1478
1691
|
const wasDragGesture = dragDistance.x > DRAG_THRESHOLD_PX || dragDistance.y > DRAG_THRESHOLD_PX;
|
|
1479
1692
|
setIsDragging(false);
|
|
1693
|
+
stopAutoScroll();
|
|
1480
1694
|
document.body.style.userSelect = "";
|
|
1481
1695
|
if (wasDragGesture) {
|
|
1482
1696
|
setDidJustDrag(true);
|
|
@@ -1526,11 +1740,23 @@ ${formatStack(await getStack(element))}`));
|
|
|
1526
1740
|
}, {
|
|
1527
1741
|
signal: eventListenerSignal
|
|
1528
1742
|
});
|
|
1743
|
+
window.addEventListener("scroll", () => {
|
|
1744
|
+
setViewportVersion((version) => version + 1);
|
|
1745
|
+
}, {
|
|
1746
|
+
signal: eventListenerSignal,
|
|
1747
|
+
capture: true
|
|
1748
|
+
});
|
|
1749
|
+
window.addEventListener("resize", () => {
|
|
1750
|
+
setViewportVersion((version) => version + 1);
|
|
1751
|
+
}, {
|
|
1752
|
+
signal: eventListenerSignal
|
|
1753
|
+
});
|
|
1529
1754
|
onCleanup(() => {
|
|
1530
1755
|
abortController.abort();
|
|
1531
1756
|
if (holdTimerId) window.clearTimeout(holdTimerId);
|
|
1532
1757
|
if (keydownSpamTimerId) window.clearTimeout(keydownSpamTimerId);
|
|
1533
1758
|
if (mouseSettleTimerId) window.clearTimeout(mouseSettleTimerId);
|
|
1759
|
+
stopAutoScroll();
|
|
1534
1760
|
stopProgressAnimation();
|
|
1535
1761
|
document.body.style.userSelect = "";
|
|
1536
1762
|
document.body.style.cursor = "";
|
|
@@ -1540,12 +1766,14 @@ ${formatStack(await getStack(element))}`));
|
|
|
1540
1766
|
const dragVisible = createMemo(() => isRendererActive() && isDraggingBeyondThreshold());
|
|
1541
1767
|
const labelVariant = createMemo(() => isCopying() ? "processing" : "hover");
|
|
1542
1768
|
const labelVisible = createMemo(() => {
|
|
1769
|
+
if (isInputMode()) return false;
|
|
1543
1770
|
if (isCopying()) return true;
|
|
1544
1771
|
if (successLabels().length > 0) return false;
|
|
1545
1772
|
return isRendererActive() && !isDragging() && Boolean(targetElement());
|
|
1546
1773
|
});
|
|
1547
1774
|
const progressVisible = createMemo(() => isCopying() && showProgressIndicator() && hasValidMousePosition());
|
|
1548
1775
|
const crosshairVisible = createMemo(() => isRendererActive() && !isDragging());
|
|
1776
|
+
const inputVisible = createMemo(() => isInputMode());
|
|
1549
1777
|
render(() => createComponent(ReactGrabRenderer, {
|
|
1550
1778
|
get selectionVisible() {
|
|
1551
1779
|
return selectionVisible();
|
|
@@ -1598,7 +1826,22 @@ ${formatStack(await getStack(element))}`));
|
|
|
1598
1826
|
},
|
|
1599
1827
|
get crosshairVisible() {
|
|
1600
1828
|
return crosshairVisible();
|
|
1601
|
-
}
|
|
1829
|
+
},
|
|
1830
|
+
get inputVisible() {
|
|
1831
|
+
return inputVisible();
|
|
1832
|
+
},
|
|
1833
|
+
get inputX() {
|
|
1834
|
+
return mouseX();
|
|
1835
|
+
},
|
|
1836
|
+
get inputY() {
|
|
1837
|
+
return mouseY();
|
|
1838
|
+
},
|
|
1839
|
+
get inputValue() {
|
|
1840
|
+
return inputText();
|
|
1841
|
+
},
|
|
1842
|
+
onInputChange: handleInputChange,
|
|
1843
|
+
onInputSubmit: handleInputSubmit,
|
|
1844
|
+
onInputCancel: handleInputCancel
|
|
1602
1845
|
}), rendererRoot);
|
|
1603
1846
|
return {
|
|
1604
1847
|
activate: () => {
|