@githumbi/grabby 0.5.1 → 0.6.0
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/CHANGELOG.md +13 -0
- package/dist/angular/index.d.ts +22 -1
- package/dist/angular/index.js +542 -46
- package/dist/angular/index.js.map +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/core/index.cjs +658 -162
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +542 -46
- package/dist/core/index.js.map +1 -1
- package/dist/export/index.cjs +19 -1
- package/dist/export/index.cjs.map +1 -1
- package/dist/export/index.d.cts +23 -2
- package/dist/export/index.d.ts +23 -2
- package/dist/export/index.js +19 -1
- package/dist/export/index.js.map +1 -1
- package/dist/grabby.global.js +146 -120
- package/dist/live/index.d.cts +1 -1
- package/dist/live/index.d.ts +1 -1
- package/dist/react/index.d.ts +22 -1
- package/dist/react/index.js +542 -46
- package/dist/react/index.js.map +1 -1
- package/dist/{types-BQDEG-Gl.d.cts → types-DOAcZ0U6.d.cts} +23 -2
- package/dist/{types-BQDEG-Gl.d.ts → types-DOAcZ0U6.d.ts} +23 -2
- package/package.json +1 -1
package/dist/angular/index.js
CHANGED
|
@@ -595,6 +595,20 @@ function describeTarget(target) {
|
|
|
595
595
|
const name = facts.label || facts.heading || facts.text || facts.alt || "";
|
|
596
596
|
return quoted(noun, name);
|
|
597
597
|
}
|
|
598
|
+
var GROUP_NAMED = 3;
|
|
599
|
+
function describeGroup(labels) {
|
|
600
|
+
const named = labels.slice(0, GROUP_NAMED).join(", ");
|
|
601
|
+
const more = labels.length > GROUP_NAMED ? ` and ${labels.length - GROUP_NAMED} more` : "";
|
|
602
|
+
return `${labels.length} elements: ${named}${more}`;
|
|
603
|
+
}
|
|
604
|
+
function describeArea(around) {
|
|
605
|
+
return `Area in ${around}`;
|
|
606
|
+
}
|
|
607
|
+
function describeComment(c) {
|
|
608
|
+
if (c.members?.length) return describeGroup(c.members.map((m) => m.label));
|
|
609
|
+
if (c.area) return describeArea(describeTarget(c.target));
|
|
610
|
+
return describeTarget(c.target);
|
|
611
|
+
}
|
|
598
612
|
|
|
599
613
|
// src/core/overlay/overlay-renderer.ts
|
|
600
614
|
var OVERLAY_ID = "__grabby-overlay__";
|
|
@@ -1245,11 +1259,114 @@ function buildUniqueSelector(el) {
|
|
|
1245
1259
|
return steps.join(" > ");
|
|
1246
1260
|
}
|
|
1247
1261
|
|
|
1262
|
+
// src/core/picker/region.ts
|
|
1263
|
+
var MAX_MEMBERS = 20;
|
|
1264
|
+
var INSIDE_RATIO = 0.85;
|
|
1265
|
+
var MIN_SIDE = 4;
|
|
1266
|
+
var MAX_VISITS = 4e3;
|
|
1267
|
+
var SKIP_TAGS = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT", "HEAD", "META", "LINK", "BR", "WBR"]);
|
|
1268
|
+
function boxFromPoints(a, b) {
|
|
1269
|
+
return { left: Math.min(a.x, b.x), top: Math.min(a.y, b.y), right: Math.max(a.x, b.x), bottom: Math.max(a.y, b.y) };
|
|
1270
|
+
}
|
|
1271
|
+
function overlapArea(r, box) {
|
|
1272
|
+
const w = Math.min(r.right, box.right) - Math.max(r.left, box.left);
|
|
1273
|
+
const h2 = Math.min(r.bottom, box.bottom) - Math.max(r.top, box.top);
|
|
1274
|
+
return w > 0 && h2 > 0 ? w * h2 : 0;
|
|
1275
|
+
}
|
|
1276
|
+
function contains(r, box) {
|
|
1277
|
+
return r.left <= box.left && r.top <= box.top && r.right >= box.right && r.bottom >= box.bottom;
|
|
1278
|
+
}
|
|
1279
|
+
function isHidden(el) {
|
|
1280
|
+
const style = getComputedStyle(el);
|
|
1281
|
+
return style.visibility === "hidden" || style.opacity === "0";
|
|
1282
|
+
}
|
|
1283
|
+
function elementsInBox(box, isUiNode2, root2 = document.body) {
|
|
1284
|
+
const found = [];
|
|
1285
|
+
let visits = 0;
|
|
1286
|
+
const visit = (el) => {
|
|
1287
|
+
if (found.length >= MAX_MEMBERS || ++visits > MAX_VISITS) return;
|
|
1288
|
+
if (SKIP_TAGS.has(el.tagName) || isUiNode2(el) || el.hasAttribute(IGNORE_ATTR)) return;
|
|
1289
|
+
const r = el.getBoundingClientRect();
|
|
1290
|
+
const boxless = r.width === 0 && r.height === 0;
|
|
1291
|
+
if (!boxless && overlapArea(r, box) === 0) return;
|
|
1292
|
+
if (!boxless && r.width >= MIN_SIDE && r.height >= MIN_SIDE) {
|
|
1293
|
+
const inside = overlapArea(r, box) / (r.width * r.height);
|
|
1294
|
+
if (inside >= INSIDE_RATIO && detectKind(el) !== "section" && !isHidden(el)) {
|
|
1295
|
+
found.push(el);
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
for (const child of Array.from(el.children)) visit(child);
|
|
1300
|
+
};
|
|
1301
|
+
for (const child of Array.from(root2.children)) visit(child);
|
|
1302
|
+
return found;
|
|
1303
|
+
}
|
|
1304
|
+
function commonContainer(elements) {
|
|
1305
|
+
if (elements.length === 0) return document.body;
|
|
1306
|
+
let candidate = elements[0].parentElement ?? document.body;
|
|
1307
|
+
while (candidate && !elements.every((el) => candidate.contains(el))) candidate = candidate.parentElement;
|
|
1308
|
+
return candidate ?? document.body;
|
|
1309
|
+
}
|
|
1310
|
+
function containerForBox(box, isUiNode2) {
|
|
1311
|
+
const cx = (box.left + box.right) / 2;
|
|
1312
|
+
const cy = (box.top + box.bottom) / 2;
|
|
1313
|
+
const stack = typeof document.elementsFromPoint === "function" ? document.elementsFromPoint(cx, cy) : [];
|
|
1314
|
+
for (const el of stack) {
|
|
1315
|
+
if (isUiNode2(el) || el.closest(`[${IGNORE_ATTR}]`)) continue;
|
|
1316
|
+
for (let cur = el; cur; cur = cur.parentElement) {
|
|
1317
|
+
if (contains(cur.getBoundingClientRect(), box)) return cur;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
return document.body;
|
|
1321
|
+
}
|
|
1322
|
+
var frac = (v) => Math.round(Math.min(1, Math.max(0, v)) * 1e3) / 1e3;
|
|
1323
|
+
function areaWithin(el, box) {
|
|
1324
|
+
const r = el.getBoundingClientRect();
|
|
1325
|
+
const w = r.width || 1;
|
|
1326
|
+
const h2 = r.height || 1;
|
|
1327
|
+
return {
|
|
1328
|
+
x: frac((box.left - r.left) / w),
|
|
1329
|
+
y: frac((box.top - r.top) / h2),
|
|
1330
|
+
w: frac((box.right - box.left) / w),
|
|
1331
|
+
h: frac((box.bottom - box.top) / h2)
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
function areaToBox(el, area) {
|
|
1335
|
+
const r = el.getBoundingClientRect();
|
|
1336
|
+
return {
|
|
1337
|
+
left: r.left + area.x * r.width,
|
|
1338
|
+
top: r.top + area.y * r.height,
|
|
1339
|
+
right: r.left + (area.x + area.w) * r.width,
|
|
1340
|
+
bottom: r.top + (area.y + area.h) * r.height
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
function unionBox(elements) {
|
|
1344
|
+
let out = null;
|
|
1345
|
+
for (const el of elements) {
|
|
1346
|
+
const r = el.getBoundingClientRect();
|
|
1347
|
+
if (r.width === 0 && r.height === 0) continue;
|
|
1348
|
+
out = out ? { left: Math.min(out.left, r.left), top: Math.min(out.top, r.top), right: Math.max(out.right, r.right), bottom: Math.max(out.bottom, r.bottom) } : { left: r.left, top: r.top, right: r.right, bottom: r.bottom };
|
|
1349
|
+
}
|
|
1350
|
+
return out;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1248
1353
|
// src/core/picker/element-picker.ts
|
|
1354
|
+
var DRAG_PX = 6;
|
|
1355
|
+
var IS_MAC = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
1356
|
+
var PRESS_EVENTS = ["pointerdown", "mousedown", "pointerup", "mouseup", "touchstart"];
|
|
1357
|
+
function addKey(e) {
|
|
1358
|
+
return IS_MAC ? e.metaKey : e.ctrlKey;
|
|
1359
|
+
}
|
|
1249
1360
|
function createElementPicker(deps) {
|
|
1250
1361
|
let hoveredElement = null;
|
|
1251
1362
|
let heldElement = null;
|
|
1252
1363
|
let listening = false;
|
|
1364
|
+
let press = null;
|
|
1365
|
+
let dragBox = null;
|
|
1366
|
+
let dragFrame = null;
|
|
1367
|
+
let lastPoint = { x: 0, y: 0 };
|
|
1368
|
+
let swallowNextClick = false;
|
|
1369
|
+
let collected = [];
|
|
1253
1370
|
function resolveComponentName(el) {
|
|
1254
1371
|
const resolver = deps.getComponentResolver();
|
|
1255
1372
|
if (!resolver) return null;
|
|
@@ -1279,14 +1396,93 @@ function createElementPicker(deps) {
|
|
|
1279
1396
|
if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
|
|
1280
1397
|
return exact ? raw : promoteTarget(raw);
|
|
1281
1398
|
}
|
|
1399
|
+
function isOurs(el) {
|
|
1400
|
+
return !!deps.isToolbarElement?.(el) || deps.overlay.isOverlayElement(el) || deps.crosshair.isCrosshairElement(el);
|
|
1401
|
+
}
|
|
1282
1402
|
function showOverlay(target) {
|
|
1283
1403
|
const componentName = resolveComponentName(target);
|
|
1284
1404
|
const sourcePath = resolveSourcePath(target);
|
|
1285
1405
|
const cssClasses = filterAngularClasses(target.classList);
|
|
1286
1406
|
deps.overlay.show(target, componentName, sourcePath, cssClasses);
|
|
1287
1407
|
}
|
|
1408
|
+
const countLabel = (n) => `${n} element${n === 1 ? "" : "s"}`;
|
|
1409
|
+
function showCollected() {
|
|
1410
|
+
if (collected.length) {
|
|
1411
|
+
deps.groupOutline.show({ elements: collected }, `${countLabel(collected.length)} \xB7 release ${IS_MAC ? "\u2318" : "Ctrl"} to comment`);
|
|
1412
|
+
} else {
|
|
1413
|
+
deps.groupOutline.hide();
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
function clearCollected() {
|
|
1417
|
+
if (!collected.length) return;
|
|
1418
|
+
collected = [];
|
|
1419
|
+
deps.groupOutline.hide();
|
|
1420
|
+
}
|
|
1421
|
+
function previewDrag() {
|
|
1422
|
+
dragFrame = null;
|
|
1423
|
+
if (!dragBox) return;
|
|
1424
|
+
deps.groupOutline.marquee(dragBox);
|
|
1425
|
+
const found = elementsInBox(dragBox, isOurs);
|
|
1426
|
+
if (found.length) deps.groupOutline.show({ elements: found }, countLabel(found.length));
|
|
1427
|
+
else deps.groupOutline.hide();
|
|
1428
|
+
}
|
|
1429
|
+
function endDrag() {
|
|
1430
|
+
dragBox = null;
|
|
1431
|
+
if (dragFrame !== null) cancelAnimationFrame(dragFrame);
|
|
1432
|
+
dragFrame = null;
|
|
1433
|
+
deps.groupOutline.marquee(null);
|
|
1434
|
+
deps.groupOutline.hide();
|
|
1435
|
+
}
|
|
1436
|
+
function finishDrag(point) {
|
|
1437
|
+
const box = dragBox;
|
|
1438
|
+
endDrag();
|
|
1439
|
+
const found = elementsInBox(box, isOurs);
|
|
1440
|
+
if (found.length === 1) {
|
|
1441
|
+
hoveredElement = found[0];
|
|
1442
|
+
deps.onSelect(found[0], point);
|
|
1443
|
+
} else if (found.length > 1) {
|
|
1444
|
+
deps.onSelectGroup(found, point);
|
|
1445
|
+
} else {
|
|
1446
|
+
const container = containerForBox(box, isOurs);
|
|
1447
|
+
deps.onSelectArea(container, areaWithin(container, box), point);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
function handlePress(e) {
|
|
1451
|
+
const origin = eventTarget(e);
|
|
1452
|
+
if (origin && deps.isToolbarElement?.(origin)) return;
|
|
1453
|
+
e.stopPropagation();
|
|
1454
|
+
if (e.type === "mousedown" || e.type === "touchstart") e.preventDefault();
|
|
1455
|
+
if (heldElement) return;
|
|
1456
|
+
const m = e;
|
|
1457
|
+
const down = e.type === "pointerdown" || e.type === "mousedown";
|
|
1458
|
+
if (down && m.button === 0 && !press) {
|
|
1459
|
+
press = { x: m.clientX, y: m.clientY };
|
|
1460
|
+
swallowNextClick = false;
|
|
1461
|
+
} else if (!down && e.type !== "touchstart" && press) {
|
|
1462
|
+
const point = { x: m.clientX, y: m.clientY };
|
|
1463
|
+
const start = press;
|
|
1464
|
+
press = null;
|
|
1465
|
+
if (dragBox) {
|
|
1466
|
+
dragBox = boxFromPoints(start, point);
|
|
1467
|
+
swallowNextClick = true;
|
|
1468
|
+
finishDrag(point);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1288
1472
|
function handleMouseMove(e) {
|
|
1289
1473
|
if (heldElement) return;
|
|
1474
|
+
lastPoint = { x: e.clientX, y: e.clientY };
|
|
1475
|
+
if (press) {
|
|
1476
|
+
if (!dragBox && Math.hypot(e.clientX - press.x, e.clientY - press.y) < DRAG_PX) return;
|
|
1477
|
+
if (!dragBox) {
|
|
1478
|
+
clearCollected();
|
|
1479
|
+
deps.overlay.hide();
|
|
1480
|
+
hoveredElement = null;
|
|
1481
|
+
}
|
|
1482
|
+
dragBox = boxFromPoints(press, lastPoint);
|
|
1483
|
+
if (dragFrame === null) dragFrame = requestAnimationFrame(previewDrag);
|
|
1484
|
+
return;
|
|
1485
|
+
}
|
|
1290
1486
|
const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
|
|
1291
1487
|
if (!target || deps.overlay.isOverlayElement(target)) return;
|
|
1292
1488
|
if (deps.crosshair.isCrosshairElement(target)) return;
|
|
@@ -1304,8 +1500,32 @@ function createElementPicker(deps) {
|
|
|
1304
1500
|
e.preventDefault();
|
|
1305
1501
|
e.stopPropagation();
|
|
1306
1502
|
if (heldElement) return;
|
|
1307
|
-
if (
|
|
1308
|
-
|
|
1503
|
+
if (swallowNextClick) {
|
|
1504
|
+
swallowNextClick = false;
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
if (!hoveredElement) return;
|
|
1508
|
+
lastPoint = { x: e.clientX, y: e.clientY };
|
|
1509
|
+
if (addKey(e)) {
|
|
1510
|
+
const at = collected.indexOf(hoveredElement);
|
|
1511
|
+
if (at >= 0) collected.splice(at, 1);
|
|
1512
|
+
else if (collected.length < MAX_MEMBERS) collected.push(hoveredElement);
|
|
1513
|
+
showCollected();
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
clearCollected();
|
|
1517
|
+
deps.onSelect(hoveredElement, lastPoint);
|
|
1518
|
+
}
|
|
1519
|
+
function handleKeyUp(e) {
|
|
1520
|
+
if (e.key !== (IS_MAC ? "Meta" : "Control") || !collected.length || heldElement) return;
|
|
1521
|
+
const elements = collected;
|
|
1522
|
+
collected = [];
|
|
1523
|
+
deps.groupOutline.hide();
|
|
1524
|
+
if (elements.length === 1) {
|
|
1525
|
+
hoveredElement = elements[0];
|
|
1526
|
+
deps.onSelect(elements[0], lastPoint);
|
|
1527
|
+
} else {
|
|
1528
|
+
deps.onSelectGroup(elements, lastPoint);
|
|
1309
1529
|
}
|
|
1310
1530
|
}
|
|
1311
1531
|
return {
|
|
@@ -1313,31 +1533,46 @@ function createElementPicker(deps) {
|
|
|
1313
1533
|
if (listening) return;
|
|
1314
1534
|
listening = true;
|
|
1315
1535
|
deps.crosshair.activate();
|
|
1536
|
+
for (const type of PRESS_EVENTS) window.addEventListener(type, handlePress, { capture: true, passive: false });
|
|
1316
1537
|
document.addEventListener("mousemove", handleMouseMove, true);
|
|
1317
1538
|
document.addEventListener("click", handleClick, true);
|
|
1539
|
+
window.addEventListener("keyup", handleKeyUp, true);
|
|
1318
1540
|
},
|
|
1319
1541
|
deactivate() {
|
|
1320
1542
|
if (!listening) return;
|
|
1321
1543
|
listening = false;
|
|
1322
1544
|
hoveredElement = null;
|
|
1323
1545
|
heldElement = null;
|
|
1546
|
+
press = null;
|
|
1547
|
+
swallowNextClick = false;
|
|
1548
|
+
collected = [];
|
|
1549
|
+
endDrag();
|
|
1324
1550
|
deps.crosshair.hold(false);
|
|
1325
1551
|
deps.crosshair.deactivate();
|
|
1552
|
+
for (const type of PRESS_EVENTS) window.removeEventListener(type, handlePress, true);
|
|
1326
1553
|
document.removeEventListener("mousemove", handleMouseMove, true);
|
|
1327
1554
|
document.removeEventListener("click", handleClick, true);
|
|
1555
|
+
window.removeEventListener("keyup", handleKeyUp, true);
|
|
1328
1556
|
deps.overlay.hide();
|
|
1329
1557
|
deps.onHover(null);
|
|
1330
1558
|
},
|
|
1331
|
-
hold(element) {
|
|
1559
|
+
hold(element, group) {
|
|
1332
1560
|
if (!listening) return;
|
|
1333
1561
|
heldElement = element;
|
|
1334
1562
|
hoveredElement = element;
|
|
1563
|
+
press = null;
|
|
1335
1564
|
deps.crosshair.hold(true);
|
|
1336
|
-
|
|
1565
|
+
if (group) {
|
|
1566
|
+
deps.overlay.hide();
|
|
1567
|
+
deps.groupOutline.show(group.spec, group.label);
|
|
1568
|
+
} else {
|
|
1569
|
+
showOverlay(element);
|
|
1570
|
+
}
|
|
1337
1571
|
},
|
|
1338
1572
|
release() {
|
|
1339
1573
|
if (!heldElement) return;
|
|
1340
1574
|
heldElement = null;
|
|
1575
|
+
deps.groupOutline.hide();
|
|
1341
1576
|
deps.crosshair.hold(false);
|
|
1342
1577
|
},
|
|
1343
1578
|
isHolding() {
|
|
@@ -2088,10 +2323,15 @@ function header(comments, env, ctx) {
|
|
|
2088
2323
|
}
|
|
2089
2324
|
return lines;
|
|
2090
2325
|
}
|
|
2326
|
+
var pct = (v) => `${Math.round(v * 100)}%`;
|
|
2327
|
+
function memberRefs(c, full) {
|
|
2328
|
+
return (c.members ?? []).map((m) => m.source ? location2(m.source.file, m.source.line, full) : m.selector).join(", ");
|
|
2329
|
+
}
|
|
2091
2330
|
function compactLine(c, i, ctx) {
|
|
2092
2331
|
const t = c.target;
|
|
2093
2332
|
const where = t.source ? location2(t.source.file, t.source.line, true) : t.selector;
|
|
2094
|
-
const
|
|
2333
|
+
const own = [where, t.component, `<${t.tag}>`].filter(Boolean).join(" ");
|
|
2334
|
+
const parts = c.members?.length ? `[${c.members.length} elements] ${memberRefs(c, true)}` : c.area ? `[area] in ${own}` : own;
|
|
2095
2335
|
const who = ctx.showAuthors ? ` (${authorLabel(c.author)})` : "";
|
|
2096
2336
|
const route = ctx.showRoutes ? ` [${c.page.route}]` : "";
|
|
2097
2337
|
const id = ctx.showIds ? ` [id ${c.id}]` : "";
|
|
@@ -2108,7 +2348,20 @@ function detailBlock(c, i, ctx, groupHasSource, headedComponent) {
|
|
|
2108
2348
|
} else if (t.source?.line != null && groupHasSource) {
|
|
2109
2349
|
where.push(`line ${t.source.line}`);
|
|
2110
2350
|
}
|
|
2351
|
+
if (c.members?.length) where.unshift("in");
|
|
2352
|
+
if (c.area) where.unshift("area in");
|
|
2111
2353
|
b(where.join(" "));
|
|
2354
|
+
if (c.area) {
|
|
2355
|
+
const a = c.area;
|
|
2356
|
+
b(`region: ${pct(a.x)} from left, ${pct(a.y)} from top, ${pct(a.w)} wide, ${pct(a.h)} tall`);
|
|
2357
|
+
}
|
|
2358
|
+
if (c.members?.length) {
|
|
2359
|
+
b(`${c.members.length} elements:`);
|
|
2360
|
+
for (const m of c.members) {
|
|
2361
|
+
const at = m.source ? location2(m.source.file, m.source.line, full) : `selector \`${m.selector}\``;
|
|
2362
|
+
lines.push(` - \`${m.preview}\` (${m.kind})${m.component && m.component !== t.component ? ` ${m.component}` : ""} ${at}`);
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2112
2365
|
if (!t.source || full) b(`selector: \`${t.selector}\``);
|
|
2113
2366
|
const plain = Object.entries(t.facts).filter(([k, v]) => !STYLE_FACTS.has(k) && !(PREVIEW_FACTS.has(k) && !full && inPreview(t.preview, v)));
|
|
2114
2367
|
if (plain.length) b(plain.map(([k, v]) => `${k}: ${v}`).join(" \xB7 "));
|
|
@@ -2370,7 +2623,8 @@ function createCommentsPanel(callbacks, options = {}) {
|
|
|
2370
2623
|
}
|
|
2371
2624
|
function row2(comment, showAuthors) {
|
|
2372
2625
|
const t = comment.target;
|
|
2373
|
-
const
|
|
2626
|
+
const group = comment.members?.length ? `${comment.members.length} elements` : comment.area ? "area" : null;
|
|
2627
|
+
const meta = live ? [document.createTextNode(`${describeComment(comment)} `)] : [h("span", { class: "grabby-kind" }, group ?? t.kind)];
|
|
2374
2628
|
if (!live) {
|
|
2375
2629
|
if (t.component) meta.push(document.createTextNode(`${t.component} `));
|
|
2376
2630
|
if (t.source) {
|
|
@@ -2600,6 +2854,13 @@ function createCommentPopover(callbacks) {
|
|
|
2600
2854
|
font: 500 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding: 8px 4px; border: none;
|
|
2601
2855
|
background: transparent; color: var(--grabby-text-muted, #64748b); cursor: pointer; text-decoration: underline;
|
|
2602
2856
|
}
|
|
2857
|
+
#${POPOVER_ID} .grabby-cp-heading {
|
|
2858
|
+
font: 600 12px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
2859
|
+
color: #15803d;
|
|
2860
|
+
overflow: hidden;
|
|
2861
|
+
text-overflow: ellipsis;
|
|
2862
|
+
white-space: nowrap;
|
|
2863
|
+
}
|
|
2603
2864
|
#${POPOVER_ID} .grabby-cp-edit-actions { display: flex; align-items: center; gap: 6px; }
|
|
2604
2865
|
#${POPOVER_ID} .grabby-cp-edit-actions .grabby-cp-spacer { flex: 1; }
|
|
2605
2866
|
#${POPOVER_ID} .grabby-cp-delete {
|
|
@@ -2638,18 +2899,18 @@ function createCommentPopover(callbacks) {
|
|
|
2638
2899
|
getUiRoot().appendChild(popover);
|
|
2639
2900
|
return popover;
|
|
2640
2901
|
}
|
|
2641
|
-
function position(el, anchor) {
|
|
2902
|
+
function position(el, anchor, box) {
|
|
2642
2903
|
const vw = window.innerWidth;
|
|
2643
2904
|
const vh = window.innerHeight;
|
|
2644
2905
|
const fW = 300;
|
|
2645
2906
|
const fH = 120;
|
|
2646
|
-
if (!anchor) {
|
|
2907
|
+
if (!anchor && !box) {
|
|
2647
2908
|
el.style.left = "50%";
|
|
2648
2909
|
el.style.top = "24px";
|
|
2649
2910
|
el.style.transform = "translateX(-50%)";
|
|
2650
2911
|
return;
|
|
2651
2912
|
}
|
|
2652
|
-
const rect = anchor.getBoundingClientRect();
|
|
2913
|
+
const rect = box ? { ...box, width: box.right - box.left, height: box.bottom - box.top } : anchor.getBoundingClientRect();
|
|
2653
2914
|
let left;
|
|
2654
2915
|
let top;
|
|
2655
2916
|
if (rect.right + 16 + fW <= vw) {
|
|
@@ -2803,8 +3064,12 @@ function createCommentPopover(callbacks) {
|
|
|
2803
3064
|
currentCtx = { mode: opts.mode, entryId: opts.entryId };
|
|
2804
3065
|
askIdentity = opts.askIdentity === true && opts.mode === "new";
|
|
2805
3066
|
visible = true;
|
|
3067
|
+
textarea.placeholder = opts.placeholder ?? "What should change here?";
|
|
3068
|
+
if (opts.heading) {
|
|
3069
|
+
el.prepend(h("div", { class: "grabby-cp-heading", title: opts.heading }, opts.heading));
|
|
3070
|
+
}
|
|
2806
3071
|
if (opts.mode === "edit") el.appendChild(editActions());
|
|
2807
|
-
position(el, opts.anchor);
|
|
3072
|
+
position(el, opts.anchor, opts.anchorBox);
|
|
2808
3073
|
attachKey();
|
|
2809
3074
|
textarea?.focus();
|
|
2810
3075
|
requestAnimationFrame(() => textarea?.focus());
|
|
@@ -3766,6 +4031,8 @@ function createMarkers(deps) {
|
|
|
3766
4031
|
transition: transform 0.12s ease, box-shadow 0.15s ease;
|
|
3767
4032
|
}
|
|
3768
4033
|
.grabby-markers-layer .grabby-marker[hidden] { display: none; }
|
|
4034
|
+
/* Several elements or an area: a green square, like the outline it shows. */
|
|
4035
|
+
.grabby-markers-layer .grabby-marker.grabby-marker-group { border-radius: 6px; background: #16a34a; }
|
|
3769
4036
|
.grabby-markers-layer .grabby-marker:hover,
|
|
3770
4037
|
.grabby-markers-layer .grabby-marker:focus-visible {
|
|
3771
4038
|
z-index: 1;
|
|
@@ -3930,6 +4197,7 @@ function createMarkers(deps) {
|
|
|
3930
4197
|
host2.appendChild(entry.button);
|
|
3931
4198
|
}
|
|
3932
4199
|
entry.comment = comment;
|
|
4200
|
+
entry.button.classList.toggle("grabby-marker-group", !!(comment.members?.length || comment.area));
|
|
3933
4201
|
const n = String(i + 1);
|
|
3934
4202
|
entry.number.textContent = n;
|
|
3935
4203
|
entry.button.setAttribute("aria-label", `Comment ${n}: ${preview(comment.comment)}. Click to edit.`);
|
|
@@ -4039,11 +4307,141 @@ function createMarkers(deps) {
|
|
|
4039
4307
|
};
|
|
4040
4308
|
}
|
|
4041
4309
|
|
|
4310
|
+
// src/core/overlay/group-outline.ts
|
|
4311
|
+
var LAYER_ID2 = "__grabby-group__";
|
|
4312
|
+
var STYLE_ID10 = "__grabby-group-styles__";
|
|
4313
|
+
var GREEN = "#16a34a";
|
|
4314
|
+
function createGroupOutline() {
|
|
4315
|
+
let layer = null;
|
|
4316
|
+
let marqueeEl = null;
|
|
4317
|
+
let labelEl = null;
|
|
4318
|
+
let boxes = [];
|
|
4319
|
+
let spec = null;
|
|
4320
|
+
let rafId = null;
|
|
4321
|
+
function ensureLayer() {
|
|
4322
|
+
if (layer) return layer;
|
|
4323
|
+
if (!hasStyles(STYLE_ID10)) {
|
|
4324
|
+
addStyles(STYLE_ID10, `
|
|
4325
|
+
#${LAYER_ID2} { position: fixed; inset: 0; pointer-events: none; z-index: ${Z_INDEX_OVERLAY}; }
|
|
4326
|
+
#${LAYER_ID2} .grabby-group-box {
|
|
4327
|
+
position: absolute; left: 0; top: 0; box-sizing: border-box;
|
|
4328
|
+
border: 2px dashed ${GREEN}; border-radius: 4px; background: rgba(22, 163, 74, 0.08);
|
|
4329
|
+
}
|
|
4330
|
+
#${LAYER_ID2} .grabby-group-marquee {
|
|
4331
|
+
position: absolute; left: 0; top: 0; box-sizing: border-box;
|
|
4332
|
+
border: 1px solid var(--grabby-accent, #2563eb); border-radius: 2px;
|
|
4333
|
+
background: color-mix(in srgb, var(--grabby-accent, #2563eb) 8%, transparent);
|
|
4334
|
+
}
|
|
4335
|
+
#${LAYER_ID2} .grabby-group-label {
|
|
4336
|
+
position: absolute; left: 0; top: 0; padding: 2px 6px; border-radius: 3px;
|
|
4337
|
+
background: ${GREEN}; color: #fff; white-space: nowrap;
|
|
4338
|
+
font: 600 11px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
4339
|
+
}
|
|
4340
|
+
#${LAYER_ID2} [hidden] { display: none; }
|
|
4341
|
+
`);
|
|
4342
|
+
}
|
|
4343
|
+
layer = document.createElement("div");
|
|
4344
|
+
layer.id = LAYER_ID2;
|
|
4345
|
+
getUiRoot().appendChild(layer);
|
|
4346
|
+
return layer;
|
|
4347
|
+
}
|
|
4348
|
+
function place(el, b) {
|
|
4349
|
+
el.style.transform = `translate(${Math.round(b.left)}px, ${Math.round(b.top)}px)`;
|
|
4350
|
+
el.style.width = `${Math.max(0, Math.round(b.right - b.left))}px`;
|
|
4351
|
+
el.style.height = `${Math.max(0, Math.round(b.bottom - b.top))}px`;
|
|
4352
|
+
}
|
|
4353
|
+
function currentBoxes() {
|
|
4354
|
+
if (!spec) return [];
|
|
4355
|
+
if ("area" in spec) return spec.element.isConnected ? [areaToBox(spec.element, spec.area)] : [];
|
|
4356
|
+
return spec.elements.flatMap((el) => {
|
|
4357
|
+
if (!el.isConnected) return [];
|
|
4358
|
+
const r = el.getBoundingClientRect();
|
|
4359
|
+
return r.width === 0 && r.height === 0 ? [] : [{ left: r.left, top: r.top, right: r.right, bottom: r.bottom }];
|
|
4360
|
+
});
|
|
4361
|
+
}
|
|
4362
|
+
function render() {
|
|
4363
|
+
const host2 = ensureLayer();
|
|
4364
|
+
const list = currentBoxes();
|
|
4365
|
+
while (boxes.length < list.length) {
|
|
4366
|
+
const b = document.createElement("div");
|
|
4367
|
+
b.className = "grabby-group-box";
|
|
4368
|
+
host2.insertBefore(b, labelEl);
|
|
4369
|
+
boxes.push(b);
|
|
4370
|
+
}
|
|
4371
|
+
boxes.forEach((b, i) => {
|
|
4372
|
+
b.hidden = i >= list.length;
|
|
4373
|
+
if (i < list.length) place(b, list[i]);
|
|
4374
|
+
});
|
|
4375
|
+
if (labelEl && !labelEl.hidden) {
|
|
4376
|
+
const u = spec && "elements" in spec ? unionBox(spec.elements) : list[0] ?? null;
|
|
4377
|
+
if (u) labelEl.style.transform = `translate(${Math.round(u.left)}px, ${Math.round(Math.max(0, u.top - 20))}px)`;
|
|
4378
|
+
}
|
|
4379
|
+
}
|
|
4380
|
+
function track() {
|
|
4381
|
+
rafId = null;
|
|
4382
|
+
if (!spec) return;
|
|
4383
|
+
render();
|
|
4384
|
+
rafId = requestAnimationFrame(track);
|
|
4385
|
+
}
|
|
4386
|
+
function stop() {
|
|
4387
|
+
if (rafId !== null) cancelAnimationFrame(rafId);
|
|
4388
|
+
rafId = null;
|
|
4389
|
+
}
|
|
4390
|
+
return {
|
|
4391
|
+
marquee(box) {
|
|
4392
|
+
if (!box) {
|
|
4393
|
+
if (marqueeEl) marqueeEl.hidden = true;
|
|
4394
|
+
return;
|
|
4395
|
+
}
|
|
4396
|
+
const host2 = ensureLayer();
|
|
4397
|
+
if (!marqueeEl) {
|
|
4398
|
+
marqueeEl = document.createElement("div");
|
|
4399
|
+
marqueeEl.className = "grabby-group-marquee";
|
|
4400
|
+
host2.appendChild(marqueeEl);
|
|
4401
|
+
}
|
|
4402
|
+
marqueeEl.hidden = false;
|
|
4403
|
+
place(marqueeEl, box);
|
|
4404
|
+
},
|
|
4405
|
+
show(next, label) {
|
|
4406
|
+
spec = next;
|
|
4407
|
+
const host2 = ensureLayer();
|
|
4408
|
+
if (!labelEl) {
|
|
4409
|
+
labelEl = document.createElement("div");
|
|
4410
|
+
labelEl.className = "grabby-group-label";
|
|
4411
|
+
host2.appendChild(labelEl);
|
|
4412
|
+
}
|
|
4413
|
+
labelEl.hidden = !label;
|
|
4414
|
+
labelEl.textContent = label ?? "";
|
|
4415
|
+
stop();
|
|
4416
|
+
track();
|
|
4417
|
+
},
|
|
4418
|
+
hide() {
|
|
4419
|
+
spec = null;
|
|
4420
|
+
stop();
|
|
4421
|
+
for (const b of boxes) b.hidden = true;
|
|
4422
|
+
if (labelEl) labelEl.hidden = true;
|
|
4423
|
+
},
|
|
4424
|
+
isVisible() {
|
|
4425
|
+
return spec !== null;
|
|
4426
|
+
},
|
|
4427
|
+
dispose() {
|
|
4428
|
+
stop();
|
|
4429
|
+
layer?.remove();
|
|
4430
|
+
layer = null;
|
|
4431
|
+
marqueeEl = null;
|
|
4432
|
+
labelEl = null;
|
|
4433
|
+
boxes = [];
|
|
4434
|
+
spec = null;
|
|
4435
|
+
removeStyles(STYLE_ID10);
|
|
4436
|
+
}
|
|
4437
|
+
};
|
|
4438
|
+
}
|
|
4439
|
+
|
|
4042
4440
|
// src/core/overlay/select-feedback.ts
|
|
4043
|
-
var
|
|
4441
|
+
var STYLE_ID11 = "__grabby-feedback-styles__";
|
|
4044
4442
|
function injectStyles() {
|
|
4045
|
-
if (hasStyles(
|
|
4046
|
-
addStyles(
|
|
4443
|
+
if (hasStyles(STYLE_ID11)) return;
|
|
4444
|
+
addStyles(STYLE_ID11, `
|
|
4047
4445
|
@keyframes grabby-flash {
|
|
4048
4446
|
0% { opacity: 1; }
|
|
4049
4447
|
100% { opacity: 0; transform: scale(1.02); }
|
|
@@ -4122,7 +4520,7 @@ function showSelectFeedback(element, label = "Selected") {
|
|
|
4122
4520
|
setTimeout(cleanup, 1200);
|
|
4123
4521
|
}
|
|
4124
4522
|
function disposeFeedbackStyles() {
|
|
4125
|
-
removeStyles(
|
|
4523
|
+
removeStyles(STYLE_ID11);
|
|
4126
4524
|
}
|
|
4127
4525
|
|
|
4128
4526
|
// src/core/storage/history-persistence.ts
|
|
@@ -4545,6 +4943,21 @@ function captureTarget(el, deps) {
|
|
|
4545
4943
|
extra
|
|
4546
4944
|
};
|
|
4547
4945
|
}
|
|
4946
|
+
var MEMBER_PREVIEW = 120;
|
|
4947
|
+
function captureMember(el, deps) {
|
|
4948
|
+
const cleanClasses = deps.cleanClasses ?? ((list) => list.filter((c) => !isNoiseClass(c)));
|
|
4949
|
+
const kind = detectKind(el);
|
|
4950
|
+
const { component, frames } = resolveStack(el, deps);
|
|
4951
|
+
return {
|
|
4952
|
+
kind,
|
|
4953
|
+
tag: el.tagName.toLowerCase(),
|
|
4954
|
+
component,
|
|
4955
|
+
source: resolveSource2(el, deps, frames),
|
|
4956
|
+
selector: buildUniqueSelector(el),
|
|
4957
|
+
preview: kind === "section" ? `<${el.tagName.toLowerCase()}>` : truncate(buildPreview(el, cleanClasses), MEMBER_PREVIEW),
|
|
4958
|
+
label: describeElement(el)
|
|
4959
|
+
};
|
|
4960
|
+
}
|
|
4548
4961
|
|
|
4549
4962
|
// src/core/capture/screenshot.ts
|
|
4550
4963
|
var MAX_SIDE = 1200;
|
|
@@ -4618,16 +5031,28 @@ function withTimeout(promise, ms) {
|
|
|
4618
5031
|
);
|
|
4619
5032
|
});
|
|
4620
5033
|
}
|
|
4621
|
-
|
|
5034
|
+
var MAX_CLIP_DEPTH = 4e3;
|
|
5035
|
+
var clamp = (v, max) => Math.min(Math.max(v, 0), max);
|
|
5036
|
+
async function captureScreenshot(el, clip) {
|
|
4622
5037
|
if (typeof window === "undefined" || !el.isConnected) return null;
|
|
4623
5038
|
const rect = el.getBoundingClientRect();
|
|
4624
5039
|
if (rect.width < 1 || rect.height < 1) return null;
|
|
4625
|
-
const
|
|
4626
|
-
const
|
|
5040
|
+
const fullWidth = Math.min(rect.width, document.documentElement.scrollWidth || rect.width);
|
|
5041
|
+
const region = clip ? {
|
|
5042
|
+
x: clamp(clip.left - rect.left, fullWidth),
|
|
5043
|
+
y: clamp(clip.top - rect.top, rect.height),
|
|
5044
|
+
right: clamp(clip.right - rect.left, fullWidth),
|
|
5045
|
+
bottom: clamp(clip.bottom - rect.top, rect.height)
|
|
5046
|
+
} : null;
|
|
5047
|
+
if (region && (region.right - region.x < 1 || region.bottom - region.y < 1 || region.bottom > MAX_CLIP_DEPTH)) return null;
|
|
5048
|
+
const cssWidth = fullWidth;
|
|
5049
|
+
const cssHeight = region ? region.bottom : Math.min(rect.height, MAX_CSS_HEIGHT);
|
|
5050
|
+
const outWidth = region ? region.right - region.x : cssWidth;
|
|
5051
|
+
const outHeight = region ? Math.min(region.bottom - region.y, MAX_CSS_HEIGHT) : cssHeight;
|
|
4627
5052
|
const dpr = window.devicePixelRatio || 1;
|
|
4628
|
-
const scale = Math.min(dpr, MAX_SIDE / Math.max(
|
|
5053
|
+
const scale = Math.min(dpr, MAX_SIDE / Math.max(outWidth, outHeight));
|
|
4629
5054
|
const render = async () => {
|
|
4630
|
-
const { createContext, destroyContext, domToBlob } = await import("modern-screenshot");
|
|
5055
|
+
const { createContext, destroyContext, domToBlob, domToCanvas } = await import("modern-screenshot");
|
|
4631
5056
|
const context = await createContext(el, {
|
|
4632
5057
|
width: cssWidth,
|
|
4633
5058
|
height: cssHeight,
|
|
@@ -4644,13 +5069,22 @@ async function captureScreenshot(el) {
|
|
|
4644
5069
|
context.sandbox = await getSandbox();
|
|
4645
5070
|
let blob;
|
|
4646
5071
|
try {
|
|
4647
|
-
|
|
5072
|
+
if (region) {
|
|
5073
|
+
const full = await domToCanvas(context);
|
|
5074
|
+
const crop = document.createElement("canvas");
|
|
5075
|
+
crop.width = Math.max(1, Math.round(outWidth * scale));
|
|
5076
|
+
crop.height = Math.max(1, Math.round(outHeight * scale));
|
|
5077
|
+
crop.getContext("2d")?.drawImage(full, region.x * scale, region.y * scale, outWidth * scale, outHeight * scale, 0, 0, crop.width, crop.height);
|
|
5078
|
+
blob = await new Promise((resolve) => crop.toBlob(resolve, "image/webp", 0.8));
|
|
5079
|
+
} else {
|
|
5080
|
+
blob = await domToBlob(context);
|
|
5081
|
+
}
|
|
4648
5082
|
} finally {
|
|
4649
5083
|
context.sandbox = void 0;
|
|
4650
5084
|
destroyContext(context);
|
|
4651
5085
|
}
|
|
4652
5086
|
if (!blob) return null;
|
|
4653
|
-
return { blob, width: Math.round(
|
|
5087
|
+
return { blob, width: Math.round(outWidth * scale), height: Math.round(outHeight * scale) };
|
|
4654
5088
|
};
|
|
4655
5089
|
return withTimeout(render(), TIMEOUT_MS + 1e3);
|
|
4656
5090
|
}
|
|
@@ -5205,6 +5639,7 @@ function createGrabInstance(options) {
|
|
|
5205
5639
|
}
|
|
5206
5640
|
}
|
|
5207
5641
|
const overlay = createOverlayRenderer({ plainLabels: live });
|
|
5642
|
+
const groupOutline = createGroupOutline();
|
|
5208
5643
|
const crosshair = createCrosshair();
|
|
5209
5644
|
const freezeOverlay = createFreezeOverlay();
|
|
5210
5645
|
const pluginRegistry = createPluginRegistry();
|
|
@@ -5217,6 +5652,9 @@ function createGrabInstance(options) {
|
|
|
5217
5652
|
const cleanClasses = (list) => adapters.cleanClasses(list.filter((c) => !isNoiseClass(c)));
|
|
5218
5653
|
let selectedElement = null;
|
|
5219
5654
|
let selectedPin;
|
|
5655
|
+
let selectedMembers = null;
|
|
5656
|
+
let selectedArea = null;
|
|
5657
|
+
const commentedMembers = /* @__PURE__ */ new Map();
|
|
5220
5658
|
let pendingShot = null;
|
|
5221
5659
|
const commentedElements = /* @__PURE__ */ new Map();
|
|
5222
5660
|
let editingFromMarker = false;
|
|
@@ -5278,7 +5716,9 @@ function createGrabInstance(options) {
|
|
|
5278
5716
|
column: c.target.source?.column ?? null
|
|
5279
5717
|
};
|
|
5280
5718
|
}
|
|
5281
|
-
function saveComment(element, text, shot,
|
|
5719
|
+
function saveComment(element, text, shot, extras = {}) {
|
|
5720
|
+
const { pin, members, area } = extras;
|
|
5721
|
+
const deps = { componentResolver, sourceResolver, cleanClasses };
|
|
5282
5722
|
const now = Date.now();
|
|
5283
5723
|
const comment = {
|
|
5284
5724
|
id: randomId(),
|
|
@@ -5292,13 +5732,16 @@ function createGrabInstance(options) {
|
|
|
5292
5732
|
title: document.title,
|
|
5293
5733
|
viewport: [window.innerWidth, window.innerHeight]
|
|
5294
5734
|
},
|
|
5295
|
-
target: captureTarget(element,
|
|
5735
|
+
target: captureTarget(element, deps),
|
|
5296
5736
|
screenshot: null,
|
|
5297
5737
|
framework: adapters.frameworkFor(element),
|
|
5298
5738
|
...outbox ? { sync: "pending" } : {},
|
|
5299
|
-
...pin ? { pin } : {}
|
|
5739
|
+
...pin ? { pin } : {},
|
|
5740
|
+
...members?.length ? { members: members.map((el) => captureMember(el, deps)) } : {},
|
|
5741
|
+
...area ? { area } : {}
|
|
5300
5742
|
};
|
|
5301
5743
|
commentedElements.set(comment.id, element);
|
|
5744
|
+
if (members?.length) commentedMembers.set(comment.id, members);
|
|
5302
5745
|
setComments([comment, ...comments()].slice(0, MAX_COMMENTS));
|
|
5303
5746
|
pluginRegistry.callHook("onComment", comment, element);
|
|
5304
5747
|
outbox?.send(comment.id);
|
|
@@ -5343,7 +5786,10 @@ function createGrabInstance(options) {
|
|
|
5343
5786
|
const idSet = new Set(ids);
|
|
5344
5787
|
const before = comments();
|
|
5345
5788
|
const removed = before.filter((c) => idSet.has(c.id));
|
|
5346
|
-
for (const id of ids)
|
|
5789
|
+
for (const id of ids) {
|
|
5790
|
+
commentedElements.delete(id);
|
|
5791
|
+
commentedMembers.delete(id);
|
|
5792
|
+
}
|
|
5347
5793
|
setComments(before.filter((c) => !idSet.has(c.id)));
|
|
5348
5794
|
const withdrawn = withdraw && outbox ? removed.filter((c) => c.sync !== void 0) : [];
|
|
5349
5795
|
const hadQueued = new Set(withdrawn.filter((c) => outbox.isQueued(c.id)).map((c) => c.id));
|
|
@@ -5402,16 +5848,52 @@ function createGrabInstance(options) {
|
|
|
5402
5848
|
commentPopover.hide();
|
|
5403
5849
|
endMarkerEdit();
|
|
5404
5850
|
if (picker.isHolding()) {
|
|
5405
|
-
|
|
5406
|
-
selectedPin = void 0;
|
|
5407
|
-
pendingShot = null;
|
|
5851
|
+
clearSelection();
|
|
5408
5852
|
picker.release();
|
|
5409
5853
|
}
|
|
5410
5854
|
}
|
|
5855
|
+
function clearSelection() {
|
|
5856
|
+
selectedElement = null;
|
|
5857
|
+
selectedPin = void 0;
|
|
5858
|
+
selectedMembers = null;
|
|
5859
|
+
selectedArea = null;
|
|
5860
|
+
pendingShot = null;
|
|
5861
|
+
}
|
|
5411
5862
|
function endMarkerEdit() {
|
|
5412
5863
|
if (!editingFromMarker) return;
|
|
5413
5864
|
editingFromMarker = false;
|
|
5414
5865
|
overlay.hide();
|
|
5866
|
+
groupOutline.hide();
|
|
5867
|
+
}
|
|
5868
|
+
function pinIn(el, point) {
|
|
5869
|
+
const rect = el.getBoundingClientRect();
|
|
5870
|
+
const frac2 = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
|
|
5871
|
+
return {
|
|
5872
|
+
x: Math.round(frac2(point.x, rect.left, rect.width) * 1e3) / 1e3,
|
|
5873
|
+
y: Math.round(frac2(point.y, rect.top, rect.height) * 1e3) / 1e3
|
|
5874
|
+
};
|
|
5875
|
+
}
|
|
5876
|
+
function groupSpecFor(comment, element) {
|
|
5877
|
+
if (comment.area && element) return { spec: { element, area: comment.area }, label: "Area" };
|
|
5878
|
+
if (!comment.members?.length) return null;
|
|
5879
|
+
const known = commentedMembers.get(comment.id)?.filter((el) => el.isConnected);
|
|
5880
|
+
const elements = known?.length ? known : comment.members.flatMap((m) => safeQuery(m.selector) ?? []);
|
|
5881
|
+
return elements.length ? { spec: { elements }, label: `${comment.members.length} elements` } : null;
|
|
5882
|
+
}
|
|
5883
|
+
function beginGroupComment(container, point, spec, heading, label, clip) {
|
|
5884
|
+
selectedElement = container;
|
|
5885
|
+
selectedPin = pinIn(container, point);
|
|
5886
|
+
pendingShot = store.state.options.screenshots ? captureScreenshot(container, clip ?? void 0) : null;
|
|
5887
|
+
coachMark.dismiss();
|
|
5888
|
+
picker.hold(container, { spec, label });
|
|
5889
|
+
commentPopover.show({
|
|
5890
|
+
anchor: container,
|
|
5891
|
+
anchorBox: clip,
|
|
5892
|
+
mode: "new",
|
|
5893
|
+
askIdentity: shouldAskIdentity(),
|
|
5894
|
+
heading,
|
|
5895
|
+
placeholder: "What should change here?"
|
|
5896
|
+
});
|
|
5415
5897
|
}
|
|
5416
5898
|
function closeAllPopovers() {
|
|
5417
5899
|
commentsPanel.hide();
|
|
@@ -5439,6 +5921,7 @@ function createGrabInstance(options) {
|
|
|
5439
5921
|
const picker = createElementPicker({
|
|
5440
5922
|
overlay,
|
|
5441
5923
|
crosshair,
|
|
5924
|
+
groupOutline,
|
|
5442
5925
|
getComponentResolver: () => componentResolver,
|
|
5443
5926
|
getSourceResolver: () => sourceResolver,
|
|
5444
5927
|
isToolbarElement: isAnyToolbarElement,
|
|
@@ -5451,18 +5934,24 @@ function createGrabInstance(options) {
|
|
|
5451
5934
|
},
|
|
5452
5935
|
onSelect(element, point) {
|
|
5453
5936
|
selectedElement = element;
|
|
5454
|
-
|
|
5455
|
-
const frac = (v, start, size2) => size2 > 0 ? Math.min(1, Math.max(0, (v - start) / size2)) : 0.5;
|
|
5456
|
-
selectedPin = {
|
|
5457
|
-
x: Math.round(frac(point.x, rect.left, rect.width) * 1e3) / 1e3,
|
|
5458
|
-
y: Math.round(frac(point.y, rect.top, rect.height) * 1e3) / 1e3
|
|
5459
|
-
};
|
|
5937
|
+
selectedPin = pinIn(element, point);
|
|
5460
5938
|
pendingShot = store.state.options.screenshots ? captureScreenshot(element) : null;
|
|
5461
5939
|
pluginRegistry.callHook("onElementSelect", element);
|
|
5462
5940
|
coachMark.dismiss();
|
|
5463
5941
|
showSelectFeedback(element);
|
|
5464
5942
|
picker.hold(element);
|
|
5465
5943
|
commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
|
|
5944
|
+
},
|
|
5945
|
+
onSelectGroup(elements, point) {
|
|
5946
|
+
selectedMembers = elements;
|
|
5947
|
+
const heading = describeGroup(elements.map(describeElement));
|
|
5948
|
+
for (const el of elements) pluginRegistry.callHook("onElementSelect", el);
|
|
5949
|
+
beginGroupComment(commonContainer(elements), point, { elements }, heading, `${elements.length} elements`, unionBox(elements));
|
|
5950
|
+
},
|
|
5951
|
+
onSelectArea(container, area, point) {
|
|
5952
|
+
selectedArea = area;
|
|
5953
|
+
pluginRegistry.callHook("onElementSelect", container);
|
|
5954
|
+
beginGroupComment(container, point, { element: container, area }, describeArea(describeElement(container)), "Area", areaToBox(container, area));
|
|
5466
5955
|
}
|
|
5467
5956
|
});
|
|
5468
5957
|
const markers = createMarkers({
|
|
@@ -5475,20 +5964,30 @@ function createGrabInstance(options) {
|
|
|
5475
5964
|
},
|
|
5476
5965
|
onHover(comment, element) {
|
|
5477
5966
|
if (picker.isHolding() || editingFromMarker || commentPopover.isVisible()) return;
|
|
5478
|
-
|
|
5479
|
-
|
|
5967
|
+
const group = comment ? groupSpecFor(comment, element) : null;
|
|
5968
|
+
if (group) groupOutline.show(group.spec, group.label);
|
|
5969
|
+
else if (comment && element) overlay.show(element, comment.target.component, null, []);
|
|
5970
|
+
else {
|
|
5971
|
+
overlay.hide();
|
|
5972
|
+
groupOutline.hide();
|
|
5973
|
+
}
|
|
5480
5974
|
},
|
|
5481
5975
|
onOpen(comment, element, marker) {
|
|
5482
5976
|
if (picker.isHolding()) return;
|
|
5483
5977
|
closeAllPopovers();
|
|
5484
5978
|
doDeactivate(true);
|
|
5485
5979
|
editingFromMarker = true;
|
|
5486
|
-
|
|
5980
|
+
const group = groupSpecFor(comment, element);
|
|
5981
|
+
if (group) groupOutline.show(group.spec, group.label);
|
|
5982
|
+
else if (element) overlay.show(element, comment.target.component, null, []);
|
|
5983
|
+
const spec = group?.spec;
|
|
5487
5984
|
commentPopover.show({
|
|
5488
5985
|
anchor: element ?? marker,
|
|
5986
|
+
anchorBox: spec ? "area" in spec ? areaToBox(spec.element, spec.area) : unionBox(spec.elements) : null,
|
|
5489
5987
|
initialValue: comment.comment,
|
|
5490
5988
|
mode: "edit",
|
|
5491
|
-
entryId: comment.id
|
|
5989
|
+
entryId: comment.id,
|
|
5990
|
+
heading: comment.members?.length || comment.area ? describeComment(comment) : void 0
|
|
5492
5991
|
});
|
|
5493
5992
|
}
|
|
5494
5993
|
});
|
|
@@ -5663,12 +6162,10 @@ function createGrabInstance(options) {
|
|
|
5663
6162
|
if (identity) saveIdentity({ name: identity.name, anonymous: !identity.name });
|
|
5664
6163
|
if (ctx.mode === "new") {
|
|
5665
6164
|
const element = selectedElement;
|
|
6165
|
+
const extras = { pin: selectedPin, members: selectedMembers, area: selectedArea };
|
|
5666
6166
|
const shot = pendingShot;
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
selectedPin = void 0;
|
|
5670
|
-
pendingShot = null;
|
|
5671
|
-
if (element) saveComment(element, value, shot, pin);
|
|
6167
|
+
clearSelection();
|
|
6168
|
+
if (element) saveComment(element, value, shot, extras);
|
|
5672
6169
|
doDeactivate(true);
|
|
5673
6170
|
return;
|
|
5674
6171
|
}
|
|
@@ -5684,9 +6181,7 @@ function createGrabInstance(options) {
|
|
|
5684
6181
|
},
|
|
5685
6182
|
onCancel(ctx) {
|
|
5686
6183
|
if (ctx.mode === "new") {
|
|
5687
|
-
|
|
5688
|
-
selectedPin = void 0;
|
|
5689
|
-
pendingShot = null;
|
|
6184
|
+
clearSelection();
|
|
5690
6185
|
doDeactivate(true);
|
|
5691
6186
|
return;
|
|
5692
6187
|
}
|
|
@@ -5852,6 +6347,7 @@ function createGrabInstance(options) {
|
|
|
5852
6347
|
crosshair.dispose();
|
|
5853
6348
|
freezeOverlay.dispose();
|
|
5854
6349
|
markers.dispose();
|
|
6350
|
+
groupOutline.dispose();
|
|
5855
6351
|
disposeToast();
|
|
5856
6352
|
disposeFeedbackStyles();
|
|
5857
6353
|
pluginRegistry.dispose();
|