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 CHANGED
@@ -100,6 +100,8 @@ var SELECTION_LERP_FACTOR = 0.95;
100
100
  var SUCCESS_LABEL_DURATION_MS = 1700;
101
101
  var PROGRESS_INDICATOR_DELAY_MS = 150;
102
102
  var DRAG_THRESHOLD_PX = 2;
103
+ var AUTO_SCROLL_EDGE_THRESHOLD_PX = 25;
104
+ var AUTO_SCROLL_SPEED_PX = 10;
103
105
  var Z_INDEX_LABEL = 2147483647;
104
106
 
105
107
  // src/utils/lerp.ts
@@ -582,6 +584,87 @@ var Crosshair = (props) => {
582
584
  }
583
585
  });
584
586
  };
587
+ var _tmpl$10 = /* @__PURE__ */ web.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`);
588
+ var InputOverlay = (props) => {
589
+ let containerRef;
590
+ let inputRef;
591
+ const position = useAnimatedPosition({
592
+ x: () => props.x,
593
+ y: () => props.y,
594
+ lerpFactor: 0.3
595
+ });
596
+ const containerBoundingRect = () => containerRef?.getBoundingClientRect();
597
+ const computedPosition = () => {
598
+ const boundingRect = containerBoundingRect();
599
+ if (!boundingRect) return {
600
+ left: position.x(),
601
+ top: position.y()
602
+ };
603
+ const viewportWidth = window.innerWidth;
604
+ const viewportHeight = window.innerHeight;
605
+ const quadrants = getCursorQuadrants(position.x(), position.y(), boundingRect.width, boundingRect.height, CURSOR_OFFSET_PX);
606
+ for (const position2 of quadrants) {
607
+ const fitsHorizontally = position2.left >= VIEWPORT_MARGIN_PX && position2.left + boundingRect.width <= viewportWidth - VIEWPORT_MARGIN_PX;
608
+ const fitsVertically = position2.top >= VIEWPORT_MARGIN_PX && position2.top + boundingRect.height <= viewportHeight - VIEWPORT_MARGIN_PX;
609
+ if (fitsHorizontally && fitsVertically) {
610
+ return position2;
611
+ }
612
+ }
613
+ const fallback = getClampedElementPosition(quadrants[0].left, quadrants[0].top, boundingRect.width, boundingRect.height);
614
+ fallback.left += INDICATOR_CLAMP_PADDING_PX;
615
+ fallback.top += INDICATOR_CLAMP_PADDING_PX;
616
+ return fallback;
617
+ };
618
+ const handleKeyDown = (event) => {
619
+ if (event.key === "Enter" && !event.shiftKey) {
620
+ event.preventDefault();
621
+ event.stopPropagation();
622
+ props.onSubmit();
623
+ } else if (event.key === "Escape") {
624
+ event.preventDefault();
625
+ event.stopPropagation();
626
+ props.onCancel();
627
+ }
628
+ };
629
+ const handleInput = (event) => {
630
+ const target = event.target;
631
+ props.onInput(target.value);
632
+ };
633
+ solidJs.createEffect(() => {
634
+ if (props.visible && inputRef) {
635
+ inputRef.focus();
636
+ } else if (!props.visible && inputRef) {
637
+ inputRef.blur();
638
+ }
639
+ });
640
+ return (() => {
641
+ var _el$ = _tmpl$10(), _el$2 = _el$.firstChild, _el$3 = _el$2.firstChild; _el$3.nextSibling;
642
+ var _ref$ = containerRef;
643
+ typeof _ref$ === "function" ? web.use(_ref$, _el$) : containerRef = _el$;
644
+ _el$3.$$keydown = handleKeyDown;
645
+ _el$3.$$input = handleInput;
646
+ var _ref$2 = inputRef;
647
+ typeof _ref$2 === "function" ? web.use(_ref$2, _el$3) : inputRef = _el$3;
648
+ web.effect((_p$) => {
649
+ 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";
650
+ _v$ !== _p$.e && web.setStyleProperty(_el$, "display", _p$.e = _v$);
651
+ _v$2 !== _p$.t && web.setStyleProperty(_el$, "top", _p$.t = _v$2);
652
+ _v$3 !== _p$.a && web.setStyleProperty(_el$, "left", _p$.a = _v$3);
653
+ _v$4 !== _p$.o && web.setStyleProperty(_el$, "z-index", _p$.o = _v$4);
654
+ _v$5 !== _p$.i && web.setStyleProperty(_el$, "pointer-events", _p$.i = _v$5);
655
+ return _p$;
656
+ }, {
657
+ e: void 0,
658
+ t: void 0,
659
+ a: void 0,
660
+ o: void 0,
661
+ i: void 0
662
+ });
663
+ web.effect(() => _el$3.value = props.value);
664
+ return _el$;
665
+ })();
666
+ };
667
+ web.delegateEvents(["input", "keydown"]);
585
668
 
586
669
  // src/components/renderer.tsx
587
670
  var ReactGrabRenderer = (props) => {
@@ -698,6 +781,31 @@ var ReactGrabRenderer = (props) => {
698
781
  }
699
782
  });
700
783
  }
784
+ }), web.createComponent(InputOverlay, {
785
+ get x() {
786
+ return props.inputX ?? 0;
787
+ },
788
+ get y() {
789
+ return props.inputY ?? 0;
790
+ },
791
+ get zIndex() {
792
+ return props.labelZIndex;
793
+ },
794
+ get value() {
795
+ return props.inputValue ?? "";
796
+ },
797
+ get visible() {
798
+ return props.inputVisible ?? false;
799
+ },
800
+ get onInput() {
801
+ return props.onInputChange;
802
+ },
803
+ get onSubmit() {
804
+ return props.onInputSubmit;
805
+ },
806
+ get onCancel() {
807
+ return props.onInputCancel;
808
+ }
701
809
  })];
702
810
  };
703
811
 
@@ -1067,7 +1175,7 @@ var createElementBounds = (element) => {
1067
1175
  };
1068
1176
 
1069
1177
  // src/core.tsx
1070
- var hasLoggedIntro = false;
1178
+ var hasInited = false;
1071
1179
  var init = (rawOptions) => {
1072
1180
  const options = {
1073
1181
  enabled: true,
@@ -1076,7 +1184,7 @@ var init = (rawOptions) => {
1076
1184
  playCopySound: false,
1077
1185
  ...rawOptions
1078
1186
  };
1079
- if (options.enabled === false) {
1187
+ if (options.enabled === false || hasInited) {
1080
1188
  return {
1081
1189
  activate: () => {
1082
1190
  },
@@ -1089,11 +1197,10 @@ var init = (rawOptions) => {
1089
1197
  }
1090
1198
  };
1091
1199
  }
1200
+ hasInited = true;
1092
1201
  const logIntro = () => {
1093
- if (hasLoggedIntro) return;
1094
- hasLoggedIntro = true;
1095
1202
  try {
1096
- const version = "0.0.44";
1203
+ const version = "0.0.45";
1097
1204
  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>`;
1098
1205
  const logoDataUri = `data:image/svg+xml;base64,${btoa(logoSvg)}`;
1099
1206
  console.log(`%cReact Grab${version ? ` v${version}` : ""}%c
@@ -1123,21 +1230,34 @@ https://react-grab.com`, `background: #330039; color: #ffffff; border: 1px solid
1123
1230
  const [copyStartX, setCopyStartX] = solidJs.createSignal(OFFSCREEN_POSITION);
1124
1231
  const [copyStartY, setCopyStartY] = solidJs.createSignal(OFFSCREEN_POSITION);
1125
1232
  const [mouseHasSettled, setMouseHasSettled] = solidJs.createSignal(false);
1233
+ const [viewportVersion, setViewportVersion] = solidJs.createSignal(0);
1234
+ const [isInputMode, setIsInputMode] = solidJs.createSignal(false);
1235
+ const [inputText, setInputText] = solidJs.createSignal("");
1126
1236
  let holdTimerId = null;
1127
1237
  let progressAnimationId = null;
1128
1238
  let progressDelayTimerId = null;
1129
1239
  let keydownSpamTimerId = null;
1130
1240
  let mouseSettleTimerId = null;
1241
+ let autoScrollAnimationId = null;
1131
1242
  const isRendererActive = solidJs.createMemo(() => isActivated() && !isCopying());
1132
1243
  const hasValidMousePosition = solidJs.createMemo(() => mouseX() > OFFSCREEN_POSITION && mouseY() > OFFSCREEN_POSITION);
1133
1244
  const isTargetKeyCombination = (event) => (event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "c";
1134
- const showTemporaryGrabbedBox = (bounds) => {
1245
+ const getAutoScrollDirection = (clientX, clientY) => {
1246
+ return {
1247
+ top: clientY < AUTO_SCROLL_EDGE_THRESHOLD_PX,
1248
+ bottom: clientY > window.innerHeight - AUTO_SCROLL_EDGE_THRESHOLD_PX,
1249
+ left: clientX < AUTO_SCROLL_EDGE_THRESHOLD_PX,
1250
+ right: clientX > window.innerWidth - AUTO_SCROLL_EDGE_THRESHOLD_PX
1251
+ };
1252
+ };
1253
+ const showTemporaryGrabbedBox = (bounds, element) => {
1135
1254
  const boxId = `grabbed-${Date.now()}-${Math.random()}`;
1136
1255
  const createdAt = Date.now();
1137
1256
  const newBox = {
1138
1257
  id: boxId,
1139
1258
  bounds,
1140
- createdAt
1259
+ createdAt,
1260
+ element
1141
1261
  };
1142
1262
  const currentBoxes = grabbedBoxes();
1143
1263
  setGrabbedBoxes([...currentBoxes, newBox]);
@@ -1192,11 +1312,7 @@ ${context}
1192
1312
  setIsCopying(false);
1193
1313
  stopProgressAnimation();
1194
1314
  if (isToggleMode()) {
1195
- if (!isHoldingKeys()) {
1196
- deactivateRenderer();
1197
- } else {
1198
- setIsToggleMode(false);
1199
- }
1315
+ deactivateRenderer();
1200
1316
  }
1201
1317
  });
1202
1318
  };
@@ -1208,7 +1324,7 @@ ${context}
1208
1324
  return element.textContent ?? "";
1209
1325
  };
1210
1326
  const createCombinedTextContent = (elements) => elements.map((element) => extractElementTextContent(element).trim()).filter((textContent) => textContent.length > 0).join("\n\n");
1211
- const tryCopyWithFallback = async (elements) => {
1327
+ const tryCopyWithFallback = async (elements, extraPrompt) => {
1212
1328
  let didCopy = false;
1213
1329
  try {
1214
1330
  const elementSnippetResults = await Promise.allSettled(elements.map(async (element) => `## HTML Frame:
@@ -1218,27 +1334,36 @@ ${getHTMLPreview(element)}
1218
1334
  ${formatStack(await getStack(element))}`));
1219
1335
  const elementSnippets = elementSnippetResults.map((result) => result.status === "fulfilled" ? result.value : "").filter((snippet) => snippet.trim());
1220
1336
  if (elementSnippets.length > 0) {
1221
- const plainTextContent = elementSnippets.map((snippet) => wrapInSelectedElementTags(snippet)).join("\n\n");
1337
+ const wrappedSnippets = elementSnippets.map((snippet) => wrapInSelectedElementTags(snippet)).join("\n\n");
1338
+ const plainTextContent = extraPrompt ? `${extraPrompt}
1339
+
1340
+ ${wrappedSnippets}` : wrappedSnippets;
1222
1341
  didCopy = await copyContent(plainTextContent, options.playCopySound ? playCopySound : void 0);
1223
1342
  }
1224
1343
  if (!didCopy) {
1225
1344
  const plainTextContentOnly = createCombinedTextContent(elements);
1226
1345
  if (plainTextContentOnly.length > 0) {
1227
- didCopy = await copyContent(plainTextContentOnly, options.playCopySound ? playCopySound : void 0);
1346
+ const contentWithPrompt = extraPrompt ? `${extraPrompt}
1347
+
1348
+ ${plainTextContentOnly}` : plainTextContentOnly;
1349
+ didCopy = await copyContent(contentWithPrompt, options.playCopySound ? playCopySound : void 0);
1228
1350
  }
1229
1351
  }
1230
1352
  } catch {
1231
1353
  const plainTextContentOnly = createCombinedTextContent(elements);
1232
1354
  if (plainTextContentOnly.length > 0) {
1233
- didCopy = await copyContent(plainTextContentOnly, options.playCopySound ? playCopySound : void 0);
1355
+ const contentWithPrompt = extraPrompt ? `${extraPrompt}
1356
+
1357
+ ${plainTextContentOnly}` : plainTextContentOnly;
1358
+ didCopy = await copyContent(contentWithPrompt, options.playCopySound ? playCopySound : void 0);
1234
1359
  }
1235
1360
  }
1236
1361
  return didCopy;
1237
1362
  };
1238
- const copySingleElementToClipboard = async (targetElement2) => {
1239
- showTemporaryGrabbedBox(createElementBounds(targetElement2));
1363
+ const copySingleElementToClipboard = async (targetElement2, extraPrompt) => {
1364
+ showTemporaryGrabbedBox(createElementBounds(targetElement2), targetElement2);
1240
1365
  await new Promise((resolve) => requestAnimationFrame(resolve));
1241
- const didCopy = await tryCopyWithFallback([targetElement2]);
1366
+ const didCopy = await tryCopyWithFallback([targetElement2], extraPrompt);
1242
1367
  if (didCopy) {
1243
1368
  showTemporarySuccessLabel(extractElementLabelText(targetElement2));
1244
1369
  }
@@ -1247,7 +1372,7 @@ ${formatStack(await getStack(element))}`));
1247
1372
  const copyMultipleElementsToClipboard = async (targetElements) => {
1248
1373
  if (targetElements.length === 0) return;
1249
1374
  for (const element of targetElements) {
1250
- showTemporaryGrabbedBox(createElementBounds(element));
1375
+ showTemporaryGrabbedBox(createElementBounds(element), element);
1251
1376
  }
1252
1377
  await new Promise((resolve) => requestAnimationFrame(resolve));
1253
1378
  const didCopy = await tryCopyWithFallback(targetElements);
@@ -1261,6 +1386,7 @@ ${formatStack(await getStack(element))}`));
1261
1386
  return getElementAtPosition(mouseX(), mouseY());
1262
1387
  });
1263
1388
  const selectionBounds = solidJs.createMemo(() => {
1389
+ viewportVersion();
1264
1390
  const element = targetElement();
1265
1391
  if (!element) return void 0;
1266
1392
  const elementBounds = element.getBoundingClientRect();
@@ -1274,23 +1400,29 @@ ${formatStack(await getStack(element))}`));
1274
1400
  y: elementBounds.top
1275
1401
  };
1276
1402
  });
1277
- const calculateDragDistance = (endX, endY) => ({
1278
- x: Math.abs(endX - dragStartX()),
1279
- y: Math.abs(endY - dragStartY())
1280
- });
1403
+ const calculateDragDistance = (endX, endY) => {
1404
+ const endPageX = endX + window.scrollX;
1405
+ const endPageY = endY + window.scrollY;
1406
+ return {
1407
+ x: Math.abs(endPageX - dragStartX()),
1408
+ y: Math.abs(endPageY - dragStartY())
1409
+ };
1410
+ };
1281
1411
  const isDraggingBeyondThreshold = solidJs.createMemo(() => {
1282
1412
  if (!isDragging()) return false;
1283
1413
  const dragDistance = calculateDragDistance(mouseX(), mouseY());
1284
1414
  return dragDistance.x > DRAG_THRESHOLD_PX || dragDistance.y > DRAG_THRESHOLD_PX;
1285
1415
  });
1286
1416
  const calculateDragRectangle = (endX, endY) => {
1287
- const dragX = Math.min(dragStartX(), endX);
1288
- const dragY = Math.min(dragStartY(), endY);
1289
- const dragWidth = Math.abs(endX - dragStartX());
1290
- const dragHeight = Math.abs(endY - dragStartY());
1417
+ const endPageX = endX + window.scrollX;
1418
+ const endPageY = endY + window.scrollY;
1419
+ const dragPageX = Math.min(dragStartX(), endPageX);
1420
+ const dragPageY = Math.min(dragStartY(), endPageY);
1421
+ const dragWidth = Math.abs(endPageX - dragStartX());
1422
+ const dragHeight = Math.abs(endPageY - dragStartY());
1291
1423
  return {
1292
- x: dragX,
1293
- y: dragY,
1424
+ x: dragPageX - window.scrollX,
1425
+ y: dragPageY - window.scrollY,
1294
1426
  width: dragWidth,
1295
1427
  height: dragHeight
1296
1428
  };
@@ -1330,6 +1462,15 @@ ${formatStack(await getStack(element))}`));
1330
1462
  setLastGrabbedElement(null);
1331
1463
  }
1332
1464
  }));
1465
+ solidJs.createEffect(solidJs.on(() => viewportVersion(), () => {
1466
+ const currentBoxes = grabbedBoxes();
1467
+ if (currentBoxes.length === 0) return;
1468
+ const updatedBoxes = currentBoxes.map((box) => ({
1469
+ ...box,
1470
+ bounds: createElementBounds(box.element)
1471
+ }));
1472
+ setGrabbedBoxes(updatedBoxes);
1473
+ }));
1333
1474
  const startProgressAnimation = () => {
1334
1475
  const startTime = Date.now();
1335
1476
  setProgressStartTime(startTime);
@@ -1366,6 +1507,31 @@ ${formatStack(await getStack(element))}`));
1366
1507
  setProgress(1);
1367
1508
  setShowProgressIndicator(false);
1368
1509
  };
1510
+ const startAutoScroll = () => {
1511
+ const scroll = () => {
1512
+ if (!isDragging()) {
1513
+ stopAutoScroll();
1514
+ return;
1515
+ }
1516
+ const direction = getAutoScrollDirection(mouseX(), mouseY());
1517
+ if (direction.top) window.scrollBy(0, -AUTO_SCROLL_SPEED_PX);
1518
+ if (direction.bottom) window.scrollBy(0, AUTO_SCROLL_SPEED_PX);
1519
+ if (direction.left) window.scrollBy(-AUTO_SCROLL_SPEED_PX, 0);
1520
+ if (direction.right) window.scrollBy(AUTO_SCROLL_SPEED_PX, 0);
1521
+ if (direction.top || direction.bottom || direction.left || direction.right) {
1522
+ autoScrollAnimationId = requestAnimationFrame(scroll);
1523
+ } else {
1524
+ autoScrollAnimationId = null;
1525
+ }
1526
+ };
1527
+ scroll();
1528
+ };
1529
+ const stopAutoScroll = () => {
1530
+ if (autoScrollAnimationId !== null) {
1531
+ cancelAnimationFrame(autoScrollAnimationId);
1532
+ autoScrollAnimationId = null;
1533
+ }
1534
+ };
1369
1535
  const activateRenderer = () => {
1370
1536
  stopProgressAnimation();
1371
1537
  setIsActivated(true);
@@ -1376,6 +1542,8 @@ ${formatStack(await getStack(element))}`));
1376
1542
  setIsToggleMode(false);
1377
1543
  setIsHoldingKeys(false);
1378
1544
  setIsActivated(false);
1545
+ setIsInputMode(false);
1546
+ setInputText("");
1379
1547
  document.body.style.cursor = "";
1380
1548
  if (isDragging()) {
1381
1549
  setIsDragging(false);
@@ -1388,17 +1556,44 @@ ${formatStack(await getStack(element))}`));
1388
1556
  mouseSettleTimerId = null;
1389
1557
  }
1390
1558
  setMouseHasSettled(false);
1559
+ stopAutoScroll();
1391
1560
  stopProgressAnimation();
1392
1561
  options.onDeactivate?.();
1393
1562
  };
1563
+ const handleInputChange = (value) => {
1564
+ setInputText(value);
1565
+ };
1566
+ const handleInputSubmit = () => {
1567
+ if (!isInputMode()) return;
1568
+ const element = targetElement();
1569
+ const prompt = inputText().trim();
1570
+ const currentX = mouseX();
1571
+ const currentY = mouseY();
1572
+ setIsInputMode(false);
1573
+ setInputText("");
1574
+ if (element) {
1575
+ void executeCopyOperation(currentX, currentY, () => copySingleElementToClipboard(element, prompt || void 0)).then(() => {
1576
+ deactivateRenderer();
1577
+ });
1578
+ } else {
1579
+ deactivateRenderer();
1580
+ }
1581
+ };
1582
+ const handleInputCancel = () => {
1583
+ if (!isInputMode()) return;
1584
+ deactivateRenderer();
1585
+ };
1394
1586
  const abortController = new AbortController();
1395
1587
  const eventListenerSignal = abortController.signal;
1396
1588
  window.addEventListener("keydown", (event) => {
1397
1589
  if (event.key === "Escape" && isHoldingKeys()) {
1590
+ if (isInputMode()) {
1591
+ return;
1592
+ }
1398
1593
  deactivateRenderer();
1399
1594
  return;
1400
1595
  }
1401
- if (event.key === "Enter" && isHoldingKeys()) {
1596
+ if (event.key === "Enter" && isHoldingKeys() && !isInputMode()) {
1402
1597
  setIsToggleMode(true);
1403
1598
  if (keydownSpamTimerId !== null) {
1404
1599
  window.clearTimeout(keydownSpamTimerId);
@@ -1408,6 +1603,7 @@ ${formatStack(await getStack(element))}`));
1408
1603
  if (holdTimerId) window.clearTimeout(holdTimerId);
1409
1604
  activateRenderer();
1410
1605
  }
1606
+ setIsInputMode(true);
1411
1607
  return;
1412
1608
  }
1413
1609
  if (!options.allowActivationInsideInput && isKeyboardEventTriggeredByInput(event)) {
@@ -1461,15 +1657,32 @@ ${formatStack(await getStack(element))}`));
1461
1657
  setMouseHasSettled(true);
1462
1658
  mouseSettleTimerId = null;
1463
1659
  }, 300);
1660
+ if (isDragging()) {
1661
+ const direction = getAutoScrollDirection(event.clientX, event.clientY);
1662
+ const isNearEdge = direction.top || direction.bottom || direction.left || direction.right;
1663
+ if (isNearEdge && autoScrollAnimationId === null) {
1664
+ startAutoScroll();
1665
+ } else if (!isNearEdge && autoScrollAnimationId !== null) {
1666
+ stopAutoScroll();
1667
+ }
1668
+ }
1464
1669
  }, {
1465
1670
  signal: eventListenerSignal
1466
1671
  });
1467
1672
  window.addEventListener("mousedown", (event) => {
1673
+ if (isInputMode()) {
1674
+ const target = event.target;
1675
+ const isClickingInput = target.closest("[data-react-grab-input]");
1676
+ if (!isClickingInput) {
1677
+ handleInputCancel();
1678
+ }
1679
+ return;
1680
+ }
1468
1681
  if (!isRendererActive() || isCopying()) return;
1469
1682
  event.preventDefault();
1470
1683
  setIsDragging(true);
1471
- setDragStartX(event.clientX);
1472
- setDragStartY(event.clientY);
1684
+ setDragStartX(event.clientX + window.scrollX);
1685
+ setDragStartY(event.clientY + window.scrollY);
1473
1686
  document.body.style.userSelect = "none";
1474
1687
  }, {
1475
1688
  signal: eventListenerSignal
@@ -1479,6 +1692,7 @@ ${formatStack(await getStack(element))}`));
1479
1692
  const dragDistance = calculateDragDistance(event.clientX, event.clientY);
1480
1693
  const wasDragGesture = dragDistance.x > DRAG_THRESHOLD_PX || dragDistance.y > DRAG_THRESHOLD_PX;
1481
1694
  setIsDragging(false);
1695
+ stopAutoScroll();
1482
1696
  document.body.style.userSelect = "";
1483
1697
  if (wasDragGesture) {
1484
1698
  setDidJustDrag(true);
@@ -1528,11 +1742,23 @@ ${formatStack(await getStack(element))}`));
1528
1742
  }, {
1529
1743
  signal: eventListenerSignal
1530
1744
  });
1745
+ window.addEventListener("scroll", () => {
1746
+ setViewportVersion((version) => version + 1);
1747
+ }, {
1748
+ signal: eventListenerSignal,
1749
+ capture: true
1750
+ });
1751
+ window.addEventListener("resize", () => {
1752
+ setViewportVersion((version) => version + 1);
1753
+ }, {
1754
+ signal: eventListenerSignal
1755
+ });
1531
1756
  solidJs.onCleanup(() => {
1532
1757
  abortController.abort();
1533
1758
  if (holdTimerId) window.clearTimeout(holdTimerId);
1534
1759
  if (keydownSpamTimerId) window.clearTimeout(keydownSpamTimerId);
1535
1760
  if (mouseSettleTimerId) window.clearTimeout(mouseSettleTimerId);
1761
+ stopAutoScroll();
1536
1762
  stopProgressAnimation();
1537
1763
  document.body.style.userSelect = "";
1538
1764
  document.body.style.cursor = "";
@@ -1542,12 +1768,14 @@ ${formatStack(await getStack(element))}`));
1542
1768
  const dragVisible = solidJs.createMemo(() => isRendererActive() && isDraggingBeyondThreshold());
1543
1769
  const labelVariant = solidJs.createMemo(() => isCopying() ? "processing" : "hover");
1544
1770
  const labelVisible = solidJs.createMemo(() => {
1771
+ if (isInputMode()) return false;
1545
1772
  if (isCopying()) return true;
1546
1773
  if (successLabels().length > 0) return false;
1547
1774
  return isRendererActive() && !isDragging() && Boolean(targetElement());
1548
1775
  });
1549
1776
  const progressVisible = solidJs.createMemo(() => isCopying() && showProgressIndicator() && hasValidMousePosition());
1550
1777
  const crosshairVisible = solidJs.createMemo(() => isRendererActive() && !isDragging());
1778
+ const inputVisible = solidJs.createMemo(() => isInputMode());
1551
1779
  web.render(() => web.createComponent(ReactGrabRenderer, {
1552
1780
  get selectionVisible() {
1553
1781
  return selectionVisible();
@@ -1600,7 +1828,22 @@ ${formatStack(await getStack(element))}`));
1600
1828
  },
1601
1829
  get crosshairVisible() {
1602
1830
  return crosshairVisible();
1603
- }
1831
+ },
1832
+ get inputVisible() {
1833
+ return inputVisible();
1834
+ },
1835
+ get inputX() {
1836
+ return mouseX();
1837
+ },
1838
+ get inputY() {
1839
+ return mouseY();
1840
+ },
1841
+ get inputValue() {
1842
+ return inputText();
1843
+ },
1844
+ onInputChange: handleInputChange,
1845
+ onInputSubmit: handleInputSubmit,
1846
+ onInputCancel: handleInputCancel
1604
1847
  }), rendererRoot);
1605
1848
  return {
1606
1849
  activate: () => {
package/dist/index.d.cts CHANGED
@@ -47,6 +47,13 @@ interface ReactGrabRendererProps {
47
47
  mouseX?: number;
48
48
  mouseY?: number;
49
49
  crosshairVisible?: boolean;
50
+ inputVisible?: boolean;
51
+ inputX?: number;
52
+ inputY?: number;
53
+ inputValue?: string;
54
+ onInputChange?: (value: string) => void;
55
+ onInputSubmit?: () => void;
56
+ onInputCancel?: () => void;
50
57
  }
51
58
 
52
59
  declare const init: (rawOptions?: Options) => ReactGrabAPI;
package/dist/index.d.ts CHANGED
@@ -47,6 +47,13 @@ interface ReactGrabRendererProps {
47
47
  mouseX?: number;
48
48
  mouseY?: number;
49
49
  crosshairVisible?: boolean;
50
+ inputVisible?: boolean;
51
+ inputX?: number;
52
+ inputY?: number;
53
+ inputValue?: string;
54
+ onInputChange?: (value: string) => void;
55
+ onInputSubmit?: () => void;
56
+ onInputCancel?: () => void;
50
57
  }
51
58
 
52
59
  declare const init: (rawOptions?: Options) => ReactGrabAPI;