react-grab 0.0.38 → 0.0.40
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 +194 -55
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.global.js +80 -18
- package/dist/index.js +189 -56
- package/package.json +5 -3
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,11 @@ var solidJs = require('solid-js');
|
|
|
5
5
|
var bippy = require('bippy');
|
|
6
6
|
var source = require('bippy/dist/source');
|
|
7
7
|
var finder = require('@medv/finder');
|
|
8
|
+
var TurndownService = require('turndown');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var TurndownService__default = /*#__PURE__*/_interopDefault(TurndownService);
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
* @license MIT
|
|
@@ -178,7 +183,7 @@ var SelectionBox = (props) => {
|
|
|
178
183
|
position: "fixed",
|
|
179
184
|
"box-sizing": "border-box",
|
|
180
185
|
"pointer-events": props.variant === "drag" ? "none" : "auto",
|
|
181
|
-
"z-index": "2147483646"
|
|
186
|
+
"z-index": props.variant === "grabbed" ? "2147483645" : "2147483646"
|
|
182
187
|
};
|
|
183
188
|
const variantStyle = () => {
|
|
184
189
|
if (props.variant === "drag") {
|
|
@@ -190,10 +195,16 @@ var SelectionBox = (props) => {
|
|
|
190
195
|
cursor: "crosshair"
|
|
191
196
|
};
|
|
192
197
|
}
|
|
198
|
+
if (props.variant === "selection") {
|
|
199
|
+
return {
|
|
200
|
+
border: "1px dashed rgba(210, 57, 192, 0.5)",
|
|
201
|
+
"background-color": "rgba(210, 57, 192, 0.08)"
|
|
202
|
+
};
|
|
203
|
+
}
|
|
193
204
|
return {
|
|
194
205
|
border: "1px solid rgb(210, 57, 192)",
|
|
195
|
-
"background-color": "rgba(210, 57, 192, 0.
|
|
196
|
-
transition:
|
|
206
|
+
"background-color": "rgba(210, 57, 192, 0.08)",
|
|
207
|
+
transition: "opacity 0.3s ease-out"
|
|
197
208
|
};
|
|
198
209
|
};
|
|
199
210
|
return web.createComponent(solidJs.Show, {
|
|
@@ -680,10 +691,10 @@ var ReactGrabRenderer = (props) => {
|
|
|
680
691
|
return label.text;
|
|
681
692
|
},
|
|
682
693
|
get x() {
|
|
683
|
-
return
|
|
694
|
+
return props.mouseX ?? 0;
|
|
684
695
|
},
|
|
685
696
|
get y() {
|
|
686
|
-
return
|
|
697
|
+
return props.mouseY ?? 0;
|
|
687
698
|
}
|
|
688
699
|
})
|
|
689
700
|
}), web.createComponent(solidJs.Show, {
|
|
@@ -748,7 +759,7 @@ var generateCSSSelector = (element) => {
|
|
|
748
759
|
return finder.finder(element);
|
|
749
760
|
};
|
|
750
761
|
var truncateString = (string, maxLength) => string.length > maxLength ? `${string.substring(0, maxLength)}...` : string;
|
|
751
|
-
var isInternalComponent = (name) => !isCapitalized(name) || name.startsWith("_") || name.includes("Provider") && name.includes("Context");
|
|
762
|
+
var isInternalComponent = (name) => !isCapitalized(name) || name.startsWith("_") || name.startsWith("Primitive.") || name.includes("Provider") && name.includes("Context");
|
|
752
763
|
var getNearestComponentDisplayName = (element) => {
|
|
753
764
|
const fiber = bippy.getFiberFromHostInstance(element);
|
|
754
765
|
if (!fiber) return null;
|
|
@@ -773,8 +784,16 @@ var formatComponentSourceLocation = async (el) => {
|
|
|
773
784
|
const source$1 = await source.getSourceFromHostInstance(el);
|
|
774
785
|
if (!source$1) return null;
|
|
775
786
|
const fileName = source.normalizeFileName(source$1.fileName);
|
|
776
|
-
if (
|
|
777
|
-
|
|
787
|
+
if (source.isSourceFile(fileName)) {
|
|
788
|
+
return `${fileName}:${source$1.lineNumber}:${source$1.columnNumber}`;
|
|
789
|
+
}
|
|
790
|
+
if (fileName && (fileName.includes(".tsx") || fileName.includes(".ts") || fileName.includes(".jsx") || fileName.includes(".js"))) {
|
|
791
|
+
const cleanedFileName = fileName.replace(/^webpack:\/\/_N_E\//, "").replace(/^webpack:\/\/\//, "").replace(/^webpack:\/\//, "").replace(/^\.\//, "");
|
|
792
|
+
if (cleanedFileName && !cleanedFileName.startsWith("node_modules") && !cleanedFileName.includes(".next") && !cleanedFileName.startsWith("webpack")) {
|
|
793
|
+
return `${cleanedFileName}:${source$1.lineNumber}:${source$1.columnNumber}`;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return null;
|
|
778
797
|
};
|
|
779
798
|
var getHTMLSnippet = async (element) => {
|
|
780
799
|
const semanticTags = /* @__PURE__ */ new Set([
|
|
@@ -872,14 +891,26 @@ var getHTMLSnippet = async (element) => {
|
|
|
872
891
|
ancestors.map((ancestor) => formatComponentSourceLocation(ancestor))
|
|
873
892
|
);
|
|
874
893
|
const elementSource = await formatComponentSourceLocation(element);
|
|
894
|
+
const ancestorElementIndents = [];
|
|
895
|
+
const ancestorComponentIndents = [];
|
|
896
|
+
let currentIndentLevel = 0;
|
|
897
|
+
const getIndent = (level) => " ".repeat(level);
|
|
875
898
|
for (let i = 0; i < ancestors.length; i++) {
|
|
876
|
-
const indent2 = " ".repeat(i);
|
|
877
899
|
const componentName = ancestorComponents[i];
|
|
878
900
|
const source = ancestorSources[i];
|
|
879
|
-
|
|
880
|
-
|
|
901
|
+
const isNewComponent = componentName && source && (i === 0 || ancestorComponents[i - 1] !== componentName);
|
|
902
|
+
if (isNewComponent) {
|
|
903
|
+
ancestorComponentIndents[i] = currentIndentLevel;
|
|
904
|
+
lines.push(
|
|
905
|
+
`${getIndent(currentIndentLevel)}<${componentName} used-at="${source}">`
|
|
906
|
+
);
|
|
907
|
+
currentIndentLevel++;
|
|
881
908
|
}
|
|
882
|
-
|
|
909
|
+
ancestorElementIndents[i] = currentIndentLevel;
|
|
910
|
+
lines.push(
|
|
911
|
+
`${getIndent(currentIndentLevel)}${formatElementOpeningTag(ancestors[i], true)}`
|
|
912
|
+
);
|
|
913
|
+
currentIndentLevel++;
|
|
883
914
|
}
|
|
884
915
|
const parent = element.parentElement;
|
|
885
916
|
let targetIndex = -1;
|
|
@@ -887,30 +918,37 @@ var getHTMLSnippet = async (element) => {
|
|
|
887
918
|
const siblings = Array.from(parent.children);
|
|
888
919
|
targetIndex = siblings.indexOf(element);
|
|
889
920
|
if (targetIndex > 0) {
|
|
890
|
-
const
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
921
|
+
const indent = getIndent(currentIndentLevel);
|
|
922
|
+
if (targetIndex <= 2) {
|
|
923
|
+
for (let i = 0; i < targetIndex; i++) {
|
|
924
|
+
const sibling = siblings[i];
|
|
925
|
+
const siblingId = extractSiblingIdentifier(sibling);
|
|
926
|
+
if (siblingId) {
|
|
927
|
+
lines.push(`${indent}${formatElementOpeningTag(sibling, true)}`);
|
|
928
|
+
lines.push(`${indent}</${sibling.tagName.toLowerCase()}>`);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
} else {
|
|
898
932
|
lines.push(
|
|
899
|
-
`${
|
|
933
|
+
`${indent}... (${targetIndex} element${targetIndex === 1 ? "" : "s"})`
|
|
900
934
|
);
|
|
901
935
|
}
|
|
902
936
|
}
|
|
903
937
|
}
|
|
904
|
-
const indent = " ".repeat(ancestors.length);
|
|
905
938
|
const lastAncestorComponent = ancestors.length > 0 ? ancestorComponents[ancestorComponents.length - 1] : null;
|
|
906
939
|
const showElementComponent = elementComponent && elementSource && elementComponent !== lastAncestorComponent;
|
|
940
|
+
let elementIndentLevel = currentIndentLevel;
|
|
941
|
+
const elementComponentIndentLevel = currentIndentLevel;
|
|
907
942
|
if (showElementComponent) {
|
|
908
|
-
lines.push(
|
|
943
|
+
lines.push(
|
|
944
|
+
`${getIndent(elementIndentLevel)}<${elementComponent} used-at="${elementSource}">`
|
|
945
|
+
);
|
|
946
|
+
elementIndentLevel++;
|
|
909
947
|
}
|
|
910
|
-
|
|
948
|
+
const elementIndent = getIndent(elementIndentLevel);
|
|
949
|
+
lines.push(`${elementIndent}<!-- IMPORTANT: selected element -->`);
|
|
911
950
|
const textContent = extractTruncatedTextContent(element);
|
|
912
951
|
const childrenCount = element.children.length;
|
|
913
|
-
const elementIndent = `${indent}${showElementComponent ? " " : " "}`;
|
|
914
952
|
if (textContent && childrenCount === 0 && textContent.length < 40) {
|
|
915
953
|
lines.push(
|
|
916
954
|
`${elementIndent}${formatElementOpeningTag(element)}${textContent}${formatElementClosingTag(
|
|
@@ -930,31 +968,37 @@ var getHTMLSnippet = async (element) => {
|
|
|
930
968
|
lines.push(`${elementIndent}${formatElementClosingTag(element)}`);
|
|
931
969
|
}
|
|
932
970
|
if (showElementComponent) {
|
|
933
|
-
lines.push(
|
|
971
|
+
lines.push(
|
|
972
|
+
`${getIndent(elementComponentIndentLevel)}</${elementComponent}>`
|
|
973
|
+
);
|
|
934
974
|
}
|
|
935
975
|
if (parent && targetIndex >= 0) {
|
|
936
976
|
const siblings = Array.from(parent.children);
|
|
937
977
|
const siblingsAfter = siblings.length - targetIndex - 1;
|
|
938
978
|
if (siblingsAfter > 0) {
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
979
|
+
const indent = getIndent(currentIndentLevel);
|
|
980
|
+
if (siblingsAfter <= 2) {
|
|
981
|
+
for (let i = targetIndex + 1; i < siblings.length; i++) {
|
|
982
|
+
const sibling = siblings[i];
|
|
983
|
+
const siblingId = extractSiblingIdentifier(sibling);
|
|
984
|
+
if (siblingId) {
|
|
985
|
+
lines.push(`${indent}${formatElementOpeningTag(sibling, true)}`);
|
|
986
|
+
lines.push(`${indent}</${sibling.tagName.toLowerCase()}>`);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
944
989
|
} else {
|
|
945
990
|
lines.push(
|
|
946
|
-
`${indent}
|
|
991
|
+
`${indent}... (${siblingsAfter} element${siblingsAfter === 1 ? "" : "s"})`
|
|
947
992
|
);
|
|
948
993
|
}
|
|
949
994
|
}
|
|
950
995
|
}
|
|
951
996
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
952
|
-
const
|
|
953
|
-
lines.push(`${
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
lines.push(`${indent2}</${componentName}>`);
|
|
997
|
+
const elementIndent2 = getIndent(ancestorElementIndents[i]);
|
|
998
|
+
lines.push(`${elementIndent2}${formatElementClosingTag(ancestors[i])}`);
|
|
999
|
+
if (ancestorComponentIndents[i] !== void 0) {
|
|
1000
|
+
const compIndent = getIndent(ancestorComponentIndents[i]);
|
|
1001
|
+
lines.push(`${compIndent}</${ancestorComponents[i]}>`);
|
|
958
1002
|
}
|
|
959
1003
|
}
|
|
960
1004
|
lines.push("```");
|
|
@@ -1212,6 +1256,62 @@ var isLocalhost = () => {
|
|
|
1212
1256
|
const hostname = window.location.hostname;
|
|
1213
1257
|
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
1214
1258
|
};
|
|
1259
|
+
var turndownService = null;
|
|
1260
|
+
var getTurndownService = () => {
|
|
1261
|
+
if (!turndownService) {
|
|
1262
|
+
turndownService = new TurndownService__default.default({
|
|
1263
|
+
headingStyle: "atx",
|
|
1264
|
+
codeBlockStyle: "fenced",
|
|
1265
|
+
emDelimiter: "_",
|
|
1266
|
+
bulletListMarker: "-",
|
|
1267
|
+
linkStyle: "inlined",
|
|
1268
|
+
linkReferenceStyle: "full"
|
|
1269
|
+
});
|
|
1270
|
+
turndownService.addRule("strikethrough", {
|
|
1271
|
+
filter: ["del", "s"],
|
|
1272
|
+
replacement: (content) => `~~${content}~~`
|
|
1273
|
+
});
|
|
1274
|
+
turndownService.addRule("removeHidden", {
|
|
1275
|
+
filter: (node) => {
|
|
1276
|
+
if (node instanceof HTMLElement) {
|
|
1277
|
+
const style = window.getComputedStyle(node);
|
|
1278
|
+
return style.display === "none" || style.visibility === "hidden" || style.opacity === "0";
|
|
1279
|
+
}
|
|
1280
|
+
return false;
|
|
1281
|
+
},
|
|
1282
|
+
replacement: () => ""
|
|
1283
|
+
});
|
|
1284
|
+
turndownService.addRule("preserveButtons", {
|
|
1285
|
+
filter: ["button"],
|
|
1286
|
+
replacement: (content) => content ? `[${content}]` : ""
|
|
1287
|
+
});
|
|
1288
|
+
turndownService.addRule("preserveInputs", {
|
|
1289
|
+
filter: (node) => {
|
|
1290
|
+
if (node.nodeName === "INPUT" && node instanceof HTMLInputElement) {
|
|
1291
|
+
return true;
|
|
1292
|
+
}
|
|
1293
|
+
return false;
|
|
1294
|
+
},
|
|
1295
|
+
replacement: (_, node) => {
|
|
1296
|
+
if (node instanceof HTMLInputElement) {
|
|
1297
|
+
const value = node.value || node.placeholder;
|
|
1298
|
+
return value ? `[${value}]` : "";
|
|
1299
|
+
}
|
|
1300
|
+
return "";
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
return turndownService;
|
|
1305
|
+
};
|
|
1306
|
+
var htmlToMarkdown = (html) => {
|
|
1307
|
+
const service = getTurndownService();
|
|
1308
|
+
return service.turndown(html).trim();
|
|
1309
|
+
};
|
|
1310
|
+
var elementToMarkdown = (element) => {
|
|
1311
|
+
const clonedElement = element.cloneNode(true);
|
|
1312
|
+
const service = getTurndownService();
|
|
1313
|
+
return service.turndown(clonedElement).trim();
|
|
1314
|
+
};
|
|
1215
1315
|
|
|
1216
1316
|
// src/core.tsx
|
|
1217
1317
|
var PROGRESS_INDICATOR_DELAY_MS = 150;
|
|
@@ -1251,6 +1351,7 @@ var init = (rawOptions) => {
|
|
|
1251
1351
|
const [grabbedBoxes, setGrabbedBoxes] = solidJs.createSignal([]);
|
|
1252
1352
|
const [successLabels, setSuccessLabels] = solidJs.createSignal([]);
|
|
1253
1353
|
const [isActivated, setIsActivated] = solidJs.createSignal(false);
|
|
1354
|
+
const [isToggleMode, setIsToggleMode] = solidJs.createSignal(false);
|
|
1254
1355
|
const [showProgressIndicator, setShowProgressIndicator] = solidJs.createSignal(false);
|
|
1255
1356
|
const [didJustDrag, setDidJustDrag] = solidJs.createSignal(false);
|
|
1256
1357
|
const [copyStartX, setCopyStartX] = solidJs.createSignal(OFFSCREEN_POSITION);
|
|
@@ -1280,13 +1381,11 @@ var init = (rawOptions) => {
|
|
|
1280
1381
|
setGrabbedBoxes((previousBoxes) => previousBoxes.filter((box) => box.id !== boxId));
|
|
1281
1382
|
}, SUCCESS_LABEL_DURATION_MS);
|
|
1282
1383
|
};
|
|
1283
|
-
const showTemporarySuccessLabel = (text
|
|
1384
|
+
const showTemporarySuccessLabel = (text) => {
|
|
1284
1385
|
const labelId = `success-${Date.now()}-${Math.random()}`;
|
|
1285
1386
|
setSuccessLabels((previousLabels) => [...previousLabels, {
|
|
1286
1387
|
id: labelId,
|
|
1287
|
-
text
|
|
1288
|
-
x: positionX,
|
|
1289
|
-
y: positionY
|
|
1388
|
+
text
|
|
1290
1389
|
}]);
|
|
1291
1390
|
setTimeout(() => {
|
|
1292
1391
|
setSuccessLabels((previousLabels) => previousLabels.filter((label) => label.id !== labelId));
|
|
@@ -1332,7 +1431,7 @@ ${context}
|
|
|
1332
1431
|
bippy.traverseFiber(fiber, (currentFiber) => {
|
|
1333
1432
|
if (bippy.isCompositeFiber(currentFiber)) {
|
|
1334
1433
|
const displayName = bippy.getDisplayName(currentFiber);
|
|
1335
|
-
if (displayName && isCapitalized(displayName) && !displayName.startsWith("_")) {
|
|
1434
|
+
if (displayName && isCapitalized(displayName) && !displayName.startsWith("_") && !displayName.startsWith("Primitive.")) {
|
|
1336
1435
|
componentName = displayName;
|
|
1337
1436
|
return true;
|
|
1338
1437
|
}
|
|
@@ -1375,6 +1474,13 @@ ${context}
|
|
|
1375
1474
|
await operation().finally(() => {
|
|
1376
1475
|
setIsCopying(false);
|
|
1377
1476
|
stopProgressAnimation();
|
|
1477
|
+
if (isToggleMode()) {
|
|
1478
|
+
if (!isHoldingKeys()) {
|
|
1479
|
+
deactivateRenderer();
|
|
1480
|
+
} else {
|
|
1481
|
+
setIsToggleMode(false);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1378
1484
|
});
|
|
1379
1485
|
};
|
|
1380
1486
|
const hasInnerText = (element) => "innerText" in element;
|
|
@@ -1385,15 +1491,16 @@ ${context}
|
|
|
1385
1491
|
return element.textContent ?? "";
|
|
1386
1492
|
};
|
|
1387
1493
|
const createCombinedTextContent = (elements) => elements.map((element) => extractElementTextContent(element).trim()).filter((textContent) => textContent.length > 0).join("\n\n");
|
|
1494
|
+
const createCombinedMarkdownContent = (elements) => elements.map((element) => elementToMarkdown(element).trim()).filter((markdownContent) => markdownContent.length > 0).join("\n\n");
|
|
1388
1495
|
const copySingleElementToClipboard = async (targetElement2) => {
|
|
1389
1496
|
showTemporaryGrabbedBox(createElementBounds(targetElement2));
|
|
1390
1497
|
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
1391
1498
|
let didCopy = false;
|
|
1392
1499
|
try {
|
|
1393
1500
|
if (isExtensionTextOnlyMode()) {
|
|
1394
|
-
const
|
|
1395
|
-
if (
|
|
1396
|
-
didCopy = await copyContent(
|
|
1501
|
+
const markdownContent = createCombinedMarkdownContent([targetElement2]);
|
|
1502
|
+
if (markdownContent.length > 0) {
|
|
1503
|
+
didCopy = await copyContent(markdownContent, options.playCopySound ? playCopySound : void 0);
|
|
1397
1504
|
}
|
|
1398
1505
|
} else {
|
|
1399
1506
|
const content = await getHTMLSnippet(targetElement2);
|
|
@@ -1418,7 +1525,7 @@ ${context}
|
|
|
1418
1525
|
}
|
|
1419
1526
|
}
|
|
1420
1527
|
if (didCopy) {
|
|
1421
|
-
showTemporarySuccessLabel(extractElementLabelText(targetElement2)
|
|
1528
|
+
showTemporarySuccessLabel(extractElementLabelText(targetElement2));
|
|
1422
1529
|
}
|
|
1423
1530
|
notifyElementsSelected([targetElement2]);
|
|
1424
1531
|
};
|
|
@@ -1431,9 +1538,9 @@ ${context}
|
|
|
1431
1538
|
let didCopy = false;
|
|
1432
1539
|
try {
|
|
1433
1540
|
if (isExtensionTextOnlyMode()) {
|
|
1434
|
-
const
|
|
1435
|
-
if (
|
|
1436
|
-
didCopy = await copyContent(
|
|
1541
|
+
const markdownContent = createCombinedMarkdownContent(targetElements);
|
|
1542
|
+
if (markdownContent.length > 0) {
|
|
1543
|
+
didCopy = await copyContent(markdownContent, options.playCopySound ? playCopySound : void 0);
|
|
1437
1544
|
}
|
|
1438
1545
|
} else {
|
|
1439
1546
|
const elementSnippetResults = await Promise.allSettled(targetElements.map((element) => getHTMLSnippet(element)));
|
|
@@ -1463,7 +1570,7 @@ ${context}
|
|
|
1463
1570
|
} catch {
|
|
1464
1571
|
}
|
|
1465
1572
|
if (didCopy) {
|
|
1466
|
-
showTemporarySuccessLabel(`${targetElements.length} elements
|
|
1573
|
+
showTemporarySuccessLabel(`${targetElements.length} elements`);
|
|
1467
1574
|
}
|
|
1468
1575
|
notifyElementsSelected(targetElements);
|
|
1469
1576
|
};
|
|
@@ -1591,6 +1698,7 @@ ${context}
|
|
|
1591
1698
|
document.body.style.cursor = "crosshair";
|
|
1592
1699
|
};
|
|
1593
1700
|
const deactivateRenderer = () => {
|
|
1701
|
+
setIsToggleMode(false);
|
|
1594
1702
|
setIsHoldingKeys(false);
|
|
1595
1703
|
setIsActivated(false);
|
|
1596
1704
|
document.body.style.cursor = "";
|
|
@@ -1616,11 +1724,25 @@ ${context}
|
|
|
1616
1724
|
deactivateRenderer();
|
|
1617
1725
|
return;
|
|
1618
1726
|
}
|
|
1727
|
+
if (event.key === "Enter" && isHoldingKeys()) {
|
|
1728
|
+
setIsToggleMode(true);
|
|
1729
|
+
if (keydownSpamTimerId !== null) {
|
|
1730
|
+
window.clearTimeout(keydownSpamTimerId);
|
|
1731
|
+
keydownSpamTimerId = null;
|
|
1732
|
+
}
|
|
1733
|
+
if (!isActivated()) {
|
|
1734
|
+
if (holdTimerId) window.clearTimeout(holdTimerId);
|
|
1735
|
+
activateRenderer();
|
|
1736
|
+
options.onActivate?.();
|
|
1737
|
+
}
|
|
1738
|
+
return;
|
|
1739
|
+
}
|
|
1619
1740
|
if (!options.allowActivationInsideInput && isKeyboardEventTriggeredByInput(event)) {
|
|
1620
1741
|
return;
|
|
1621
1742
|
}
|
|
1622
1743
|
if (!isTargetKeyCombination(event)) return;
|
|
1623
1744
|
if (isActivated()) {
|
|
1745
|
+
if (isToggleMode()) return;
|
|
1624
1746
|
if (keydownSpamTimerId !== null) {
|
|
1625
1747
|
window.clearTimeout(keydownSpamTimerId);
|
|
1626
1748
|
}
|
|
@@ -1641,13 +1763,15 @@ ${context}
|
|
|
1641
1763
|
options.onActivate?.();
|
|
1642
1764
|
}, options.keyHoldDuration);
|
|
1643
1765
|
}, {
|
|
1644
|
-
signal: eventListenerSignal
|
|
1766
|
+
signal: eventListenerSignal,
|
|
1767
|
+
capture: true
|
|
1645
1768
|
});
|
|
1646
1769
|
window.addEventListener("keyup", (event) => {
|
|
1647
1770
|
if (!isHoldingKeys() && !isActivated()) return;
|
|
1648
1771
|
const isReleasingModifier = !event.metaKey && !event.ctrlKey;
|
|
1649
1772
|
const isReleasingC = event.key.toLowerCase() === "c";
|
|
1650
1773
|
if (isReleasingC || isReleasingModifier) {
|
|
1774
|
+
if (isToggleMode()) return;
|
|
1651
1775
|
deactivateRenderer();
|
|
1652
1776
|
}
|
|
1653
1777
|
}, {
|
|
@@ -1729,9 +1853,17 @@ ${context}
|
|
|
1729
1853
|
if (isRendererActive() || isCopying() || didJustDrag()) {
|
|
1730
1854
|
event.preventDefault();
|
|
1731
1855
|
event.stopPropagation();
|
|
1732
|
-
|
|
1856
|
+
const hadDrag = didJustDrag();
|
|
1857
|
+
if (hadDrag) {
|
|
1733
1858
|
setDidJustDrag(false);
|
|
1734
1859
|
}
|
|
1860
|
+
if (isToggleMode() && !isCopying()) {
|
|
1861
|
+
if (!isHoldingKeys()) {
|
|
1862
|
+
deactivateRenderer();
|
|
1863
|
+
} else {
|
|
1864
|
+
setIsToggleMode(false);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1735
1867
|
}
|
|
1736
1868
|
}, {
|
|
1737
1869
|
signal: eventListenerSignal,
|
|
@@ -1754,10 +1886,14 @@ ${context}
|
|
|
1754
1886
|
document.body.style.cursor = "";
|
|
1755
1887
|
});
|
|
1756
1888
|
const rendererRoot = mountRoot();
|
|
1757
|
-
const selectionVisible = solidJs.createMemo(() =>
|
|
1889
|
+
const selectionVisible = solidJs.createMemo(() => isRendererActive() && !isDragging() && Boolean(targetElement()));
|
|
1758
1890
|
const dragVisible = solidJs.createMemo(() => isRendererActive() && isDraggingBeyondThreshold());
|
|
1759
1891
|
const labelVariant = solidJs.createMemo(() => isCopying() ? "processing" : "hover");
|
|
1760
|
-
const labelVisible = solidJs.createMemo(() =>
|
|
1892
|
+
const labelVisible = solidJs.createMemo(() => {
|
|
1893
|
+
if (isCopying()) return true;
|
|
1894
|
+
if (successLabels().length > 0) return false;
|
|
1895
|
+
return isRendererActive() && !isDragging() && mouseHasSettled() && (Boolean(targetElement()) && !isSameAsLast() || !targetElement());
|
|
1896
|
+
});
|
|
1761
1897
|
const progressVisible = solidJs.createMemo(() => isCopying() && showProgressIndicator() && hasValidMousePosition());
|
|
1762
1898
|
const crosshairVisible = solidJs.createMemo(() => isRendererActive() && !isDragging());
|
|
1763
1899
|
web.render(() => web.createComponent(ReactGrabRenderer, {
|
|
@@ -1794,6 +1930,7 @@ ${context}
|
|
|
1794
1930
|
get labelVisible() {
|
|
1795
1931
|
return labelVisible();
|
|
1796
1932
|
},
|
|
1933
|
+
labelZIndex: 2147483646,
|
|
1797
1934
|
get progressVisible() {
|
|
1798
1935
|
return progressVisible();
|
|
1799
1936
|
},
|
|
@@ -1844,6 +1981,8 @@ if (!window[EXTENSION_MARKER]) {
|
|
|
1844
1981
|
globalApi = init();
|
|
1845
1982
|
}
|
|
1846
1983
|
|
|
1984
|
+
exports.elementToMarkdown = elementToMarkdown;
|
|
1847
1985
|
exports.getGlobalApi = getGlobalApi;
|
|
1986
|
+
exports.htmlToMarkdown = htmlToMarkdown;
|
|
1848
1987
|
exports.init = init;
|
|
1849
1988
|
exports.playCopySound = playCopySound;
|
package/dist/index.d.cts
CHANGED
|
@@ -34,8 +34,6 @@ interface ReactGrabRendererProps {
|
|
|
34
34
|
successLabels?: Array<{
|
|
35
35
|
id: string;
|
|
36
36
|
text: string;
|
|
37
|
-
x: number;
|
|
38
|
-
y: number;
|
|
39
37
|
}>;
|
|
40
38
|
labelVariant?: "hover" | "processing" | "success";
|
|
41
39
|
labelText?: string;
|
|
@@ -59,6 +57,9 @@ declare const init: (rawOptions?: Options) => ReactGrabAPI;
|
|
|
59
57
|
|
|
60
58
|
declare const playCopySound: () => void;
|
|
61
59
|
|
|
60
|
+
declare const htmlToMarkdown: (html: string) => string;
|
|
61
|
+
declare const elementToMarkdown: (element: Element) => string;
|
|
62
|
+
|
|
62
63
|
declare global {
|
|
63
64
|
interface Window {
|
|
64
65
|
__REACT_GRAB_EXTENSION_ACTIVE__?: boolean;
|
|
@@ -66,4 +67,4 @@ declare global {
|
|
|
66
67
|
}
|
|
67
68
|
declare const getGlobalApi: () => ReactGrabAPI | null;
|
|
68
69
|
|
|
69
|
-
export { type Options, type OverlayBounds, type ReactGrabAPI, type ReactGrabRendererProps, getGlobalApi, init, playCopySound };
|
|
70
|
+
export { type Options, type OverlayBounds, type ReactGrabAPI, type ReactGrabRendererProps, elementToMarkdown, getGlobalApi, htmlToMarkdown, init, playCopySound };
|
package/dist/index.d.ts
CHANGED
|
@@ -34,8 +34,6 @@ interface ReactGrabRendererProps {
|
|
|
34
34
|
successLabels?: Array<{
|
|
35
35
|
id: string;
|
|
36
36
|
text: string;
|
|
37
|
-
x: number;
|
|
38
|
-
y: number;
|
|
39
37
|
}>;
|
|
40
38
|
labelVariant?: "hover" | "processing" | "success";
|
|
41
39
|
labelText?: string;
|
|
@@ -59,6 +57,9 @@ declare const init: (rawOptions?: Options) => ReactGrabAPI;
|
|
|
59
57
|
|
|
60
58
|
declare const playCopySound: () => void;
|
|
61
59
|
|
|
60
|
+
declare const htmlToMarkdown: (html: string) => string;
|
|
61
|
+
declare const elementToMarkdown: (element: Element) => string;
|
|
62
|
+
|
|
62
63
|
declare global {
|
|
63
64
|
interface Window {
|
|
64
65
|
__REACT_GRAB_EXTENSION_ACTIVE__?: boolean;
|
|
@@ -66,4 +67,4 @@ declare global {
|
|
|
66
67
|
}
|
|
67
68
|
declare const getGlobalApi: () => ReactGrabAPI | null;
|
|
68
69
|
|
|
69
|
-
export { type Options, type OverlayBounds, type ReactGrabAPI, type ReactGrabRendererProps, getGlobalApi, init, playCopySound };
|
|
70
|
+
export { type Options, type OverlayBounds, type ReactGrabAPI, type ReactGrabRendererProps, elementToMarkdown, getGlobalApi, htmlToMarkdown, init, playCopySound };
|