@githumbi/grabby 0.3.0 → 0.4.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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # @githumbi/grabby
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1beb9ae: The toolbar's close button now collapses it into a round button in the bottom-right corner, with the comment count on it, instead of removing it. One click (or Alt+G) opens the toolbar again. It stays collapsed when the reviewer moves to another page in the same tab, and comments keep sending while it is collapsed. Finish review is unchanged, and `hideToolbar()` / `hide()` still remove the toolbar completely.
8
+
9
+ ### Patch Changes
10
+
11
+ - 1beb9ae: The element you clicked stays selected while you write its comment. Moving the mouse used to move the highlight onto whatever was underneath, so it was unclear which element the comment would go to (and a click elsewhere quietly switched it). Now the highlight stays on the chosen element, the crosshair lines hide and the normal cursor returns until you save or cancel, and clicks on the page are ignored. Pages that guard their own pointer handlers with `body.grabby-crosshair-active` stay guarded: the class remains, and `body.grabby-crosshair-held` is added while a comment is open.
12
+
3
13
  ## 0.3.0
4
14
 
5
15
  ### Minor Changes
@@ -767,6 +767,7 @@ function createCrosshair() {
767
767
  let hLine = null;
768
768
  let vLine = null;
769
769
  let listening = false;
770
+ let held = false;
770
771
  function injectStyles2() {
771
772
  if (hasStyles(CROSSHAIR_STYLE_ID)) return;
772
773
  addStyles(CROSSHAIR_STYLE_ID, `
@@ -789,7 +790,7 @@ function createCrosshair() {
789
790
  width: 1px;
790
791
  }
791
792
  `);
792
- addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active { cursor: crosshair !important; }", "document");
793
+ addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active:not(.grabby-crosshair-held) { cursor: crosshair !important; }", "document");
793
794
  }
794
795
  function ensureElements() {
795
796
  if (!hLine) {
@@ -806,7 +807,12 @@ function createCrosshair() {
806
807
  getUiRoot().appendChild(vLine);
807
808
  }
808
809
  }
810
+ function hideLines() {
811
+ if (hLine) hLine.style.top = "-10px";
812
+ if (vLine) vLine.style.left = "-10px";
813
+ }
809
814
  function handleMouseMove(e) {
815
+ if (held) return;
810
816
  if (hLine) {
811
817
  hLine.style.top = `${e.clientY}px`;
812
818
  }
@@ -827,13 +833,19 @@ function createCrosshair() {
827
833
  listening = false;
828
834
  document.body.classList.remove("grabby-crosshair-active");
829
835
  document.removeEventListener("mousemove", handleMouseMove, true);
830
- if (hLine) hLine.style.top = "-10px";
831
- if (vLine) vLine.style.left = "-10px";
836
+ hideLines();
837
+ },
838
+ hold(on) {
839
+ if (held === on) return;
840
+ held = on;
841
+ document.body.classList.toggle("grabby-crosshair-held", on);
842
+ if (on) hideLines();
832
843
  },
833
844
  isCrosshairElement(el) {
834
845
  return el === hLine || el === vLine || el.id === H_LINE_ID || el.id === V_LINE_ID;
835
846
  },
836
847
  dispose() {
848
+ this.hold(false);
837
849
  this.deactivate();
838
850
  hLine?.remove();
839
851
  vLine?.remove();
@@ -1236,6 +1248,7 @@ function buildUniqueSelector(el) {
1236
1248
  // src/core/picker/element-picker.ts
1237
1249
  function createElementPicker(deps) {
1238
1250
  let hoveredElement = null;
1251
+ let heldElement = null;
1239
1252
  let listening = false;
1240
1253
  function resolveComponentName(el) {
1241
1254
  const resolver = deps.getComponentResolver();
@@ -1266,17 +1279,21 @@ function createElementPicker(deps) {
1266
1279
  if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
1267
1280
  return exact ? raw : promoteTarget(raw);
1268
1281
  }
1282
+ function showOverlay(target) {
1283
+ const componentName = resolveComponentName(target);
1284
+ const sourcePath = resolveSourcePath(target);
1285
+ const cssClasses = filterAngularClasses(target.classList);
1286
+ deps.overlay.show(target, componentName, sourcePath, cssClasses);
1287
+ }
1269
1288
  function handleMouseMove(e) {
1289
+ if (heldElement) return;
1270
1290
  const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
1271
1291
  if (!target || deps.overlay.isOverlayElement(target)) return;
1272
1292
  if (deps.crosshair.isCrosshairElement(target)) return;
1273
1293
  if (deps.isToolbarElement?.(target)) return;
1274
1294
  if (target === hoveredElement) return;
1275
1295
  hoveredElement = target;
1276
- const componentName = resolveComponentName(target);
1277
- const sourcePath = resolveSourcePath(target);
1278
- const cssClasses = filterAngularClasses(target.classList);
1279
- deps.overlay.show(target, componentName, sourcePath, cssClasses);
1296
+ showOverlay(target);
1280
1297
  deps.onHover(target);
1281
1298
  }
1282
1299
  function handleClick(e) {
@@ -1286,6 +1303,7 @@ function createElementPicker(deps) {
1286
1303
  if (target && (deps.isToolbarElement?.(target) || deps.crosshair.isCrosshairElement(target))) return;
1287
1304
  e.preventDefault();
1288
1305
  e.stopPropagation();
1306
+ if (heldElement) return;
1289
1307
  if (hoveredElement) {
1290
1308
  deps.onSelect(hoveredElement);
1291
1309
  }
@@ -1302,12 +1320,29 @@ function createElementPicker(deps) {
1302
1320
  if (!listening) return;
1303
1321
  listening = false;
1304
1322
  hoveredElement = null;
1323
+ heldElement = null;
1324
+ deps.crosshair.hold(false);
1305
1325
  deps.crosshair.deactivate();
1306
1326
  document.removeEventListener("mousemove", handleMouseMove, true);
1307
1327
  document.removeEventListener("click", handleClick, true);
1308
1328
  deps.overlay.hide();
1309
1329
  deps.onHover(null);
1310
1330
  },
1331
+ hold(element) {
1332
+ if (!listening) return;
1333
+ heldElement = element;
1334
+ hoveredElement = element;
1335
+ deps.crosshair.hold(true);
1336
+ showOverlay(element);
1337
+ },
1338
+ release() {
1339
+ if (!heldElement) return;
1340
+ heldElement = null;
1341
+ deps.crosshair.hold(false);
1342
+ },
1343
+ isHolding() {
1344
+ return heldElement !== null;
1345
+ },
1311
1346
  getHoveredElement() {
1312
1347
  return hoveredElement;
1313
1348
  },
@@ -1640,6 +1675,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1640
1675
  let allElements = /* @__PURE__ */ new Set();
1641
1676
  let badge = null;
1642
1677
  let status = null;
1678
+ let expandBadge = null;
1679
+ let collapsed = false;
1643
1680
  function injectStyles2() {
1644
1681
  if (hasStyles(STYLE_ID3)) return;
1645
1682
  addStyles(STYLE_ID3, `
@@ -1755,6 +1792,24 @@ function createToolbarRenderer(callbacks, options = {}) {
1755
1792
  background: var(--grabby-accent-hover, #1d4ed8);
1756
1793
  color: #fff;
1757
1794
  }
1795
+ #${TOOLBAR_ID} button.grabby-btn-expand { display: none; }
1796
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed {
1797
+ left: auto;
1798
+ right: 20px;
1799
+ transform: none;
1800
+ padding: 4px;
1801
+ }
1802
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed.grabby-toolbar-hidden {
1803
+ transform: translateY(20px);
1804
+ }
1805
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > * { display: none !important; }
1806
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > button.grabby-btn-expand {
1807
+ display: flex !important;
1808
+ width: 40px;
1809
+ height: 40px;
1810
+ border-radius: 50%;
1811
+ color: var(--grabby-accent, #2563eb);
1812
+ }
1758
1813
  #${TOOLBAR_ID} .grabby-toolbar-left.grabby-toolbar-left-hidden {
1759
1814
  max-width: 0;
1760
1815
  opacity: 0;
@@ -1795,6 +1850,12 @@ function createToolbarRenderer(callbacks, options = {}) {
1795
1850
  buttons.history.appendChild(badge);
1796
1851
  buttons.enable = createButton("enable", ICON_POWER, "Enable/Disable", callbacks.onEnableToggle);
1797
1852
  buttons.dismiss = createButton("dismiss", ICON_DISMISS, options.dismissLabel ?? "Dismiss toolbar", callbacks.onDismiss);
1853
+ buttons.expand = createButton("expand", ICON_GRAB, options.expandLabel ?? "Open Grabby toolbar", () => callbacks.onExpand?.());
1854
+ buttons.expand.classList.add("grabby-btn-expand");
1855
+ expandBadge = document.createElement("span");
1856
+ expandBadge.className = "grabby-badge";
1857
+ expandBadge.hidden = true;
1858
+ buttons.expand.appendChild(expandBadge);
1798
1859
  const divider = document.createElement("span");
1799
1860
  divider.className = "grabby-toolbar-divider";
1800
1861
  leftGroup = document.createElement("div");
@@ -1825,6 +1886,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1825
1886
  }
1826
1887
  if (!options.hideEnable) container.appendChild(buttons.enable);
1827
1888
  container.appendChild(buttons.dismiss);
1889
+ container.appendChild(buttons.expand);
1890
+ container.classList.toggle("grabby-toolbar-collapsed", collapsed);
1828
1891
  getUiRoot().appendChild(container);
1829
1892
  allElements.clear();
1830
1893
  allElements.add(container);
@@ -1852,9 +1915,10 @@ function createToolbarRenderer(callbacks, options = {}) {
1852
1915
  buttons.selection.classList.remove("grabby-btn-active");
1853
1916
  }
1854
1917
  const count = state.toolbar.comments.length;
1855
- if (badge) {
1856
- badge.hidden = count === 0;
1857
- badge.textContent = count > 99 ? "99+" : String(count);
1918
+ for (const b of [badge, expandBadge]) {
1919
+ if (!b) continue;
1920
+ b.hidden = count === 0;
1921
+ b.textContent = count > 99 ? "99+" : String(count);
1858
1922
  }
1859
1923
  buttons.history.setAttribute("aria-label", count ? `Comments (${count})` : "Comments");
1860
1924
  if (status && buttons.finish) {
@@ -1872,6 +1936,17 @@ function createToolbarRenderer(callbacks, options = {}) {
1872
1936
  leftGroup?.classList.add("grabby-toolbar-left-hidden");
1873
1937
  }
1874
1938
  },
1939
+ collapse() {
1940
+ collapsed = true;
1941
+ container?.classList.add("grabby-toolbar-collapsed");
1942
+ },
1943
+ expand() {
1944
+ collapsed = false;
1945
+ container?.classList.remove("grabby-toolbar-collapsed");
1946
+ },
1947
+ isCollapsed() {
1948
+ return collapsed;
1949
+ },
1875
1950
  isToolbarElement(el) {
1876
1951
  if (allElements.has(el)) return true;
1877
1952
  let current = el;
@@ -1889,6 +1964,7 @@ function createToolbarRenderer(callbacks, options = {}) {
1889
1964
  leftGroup = null;
1890
1965
  buttons = {};
1891
1966
  badge = null;
1967
+ expandBadge = null;
1892
1968
  status = null;
1893
1969
  allElements.clear();
1894
1970
  }
@@ -4583,6 +4659,21 @@ function flushLeftovers(options) {
4583
4659
  }
4584
4660
  });
4585
4661
  }
4662
+ var COLLAPSED_KEY = "grabby:v1:collapsed";
4663
+ function loadCollapsed() {
4664
+ try {
4665
+ return sessionStorage.getItem(COLLAPSED_KEY) === "1";
4666
+ } catch {
4667
+ return false;
4668
+ }
4669
+ }
4670
+ function saveCollapsed(on) {
4671
+ try {
4672
+ if (on) sessionStorage.setItem(COLLAPSED_KEY, "1");
4673
+ else sessionStorage.removeItem(COLLAPSED_KEY);
4674
+ } catch {
4675
+ }
4676
+ }
4586
4677
  function isDevMode() {
4587
4678
  try {
4588
4679
  if (typeof ngDevMode !== "undefined" && ngDevMode === false) return false;
@@ -4665,6 +4756,7 @@ function createGrabInstance(options) {
4665
4756
  let selectedElement = null;
4666
4757
  let pendingShot = null;
4667
4758
  let level = loadLevel(merged.detailLevel);
4759
+ let collapsed = loadCollapsed();
4668
4760
  const pendingShotDeletes = /* @__PURE__ */ new Map();
4669
4761
  themeManager.apply(store.state.toolbar.themeMode);
4670
4762
  updateToastOffset();
@@ -4838,9 +4930,17 @@ function createGrabInstance(options) {
4838
4930
  function isAnyToolbarElement(el) {
4839
4931
  return isUiNode(el) || freezeOverlay.isFreezeElement(el);
4840
4932
  }
4933
+ function hideCommentPopover() {
4934
+ commentPopover.hide();
4935
+ if (picker.isHolding()) {
4936
+ selectedElement = null;
4937
+ pendingShot = null;
4938
+ picker.release();
4939
+ }
4940
+ }
4841
4941
  function closeAllPopovers() {
4842
4942
  commentsPanel.hide();
4843
- commentPopover.hide();
4943
+ hideCommentPopover();
4844
4944
  copySheet.close();
4845
4945
  finishSheet.close();
4846
4946
  }
@@ -4880,6 +4980,7 @@ function createGrabInstance(options) {
4880
4980
  pluginRegistry.callHook("onElementSelect", element);
4881
4981
  coachMark.dismiss();
4882
4982
  showSelectFeedback(element);
4983
+ picker.hold(element);
4883
4984
  commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
4884
4985
  }
4885
4986
  });
@@ -4890,6 +4991,7 @@ function createGrabInstance(options) {
4890
4991
  store.state.toolbar = { ...store.state.toolbar, visible: true };
4891
4992
  toolbar.show();
4892
4993
  }
4994
+ if (collapsed) expandToolbar();
4893
4995
  closeAllPopovers();
4894
4996
  store.state.active = true;
4895
4997
  picker.activate();
@@ -4924,7 +5026,7 @@ function createGrabInstance(options) {
4924
5026
  }
4925
5027
  },
4926
5028
  onHistory() {
4927
- commentPopover.hide();
5029
+ hideCommentPopover();
4928
5030
  copySheet.close();
4929
5031
  if (commentsPanel.isVisible()) {
4930
5032
  commentsPanel.hide();
@@ -4941,16 +5043,28 @@ function createGrabInstance(options) {
4941
5043
  }
4942
5044
  toolbar.update(store.state);
4943
5045
  },
4944
- onDismiss() {
4945
- const { pending, failed } = reviewCounts();
4946
- if (live && outbox && (pending || failed)) {
4947
- openFinishSheet();
4948
- return;
4949
- }
4950
- exitFeedbackMode();
4951
- },
5046
+ // Close collapses the toolbar into a round button in the bottom-right
5047
+ // corner instead of removing it, so nothing is lost and it's one click
5048
+ // back. Comments keep sending while it's collapsed.
5049
+ onDismiss: collapseToolbar,
5050
+ onExpand: expandToolbar,
4952
5051
  onFinish: openFinishSheet
4953
- }, live ? { label: "Comment", dismissLabel: "Exit feedback mode", hideEnable: true, review: !!merged.server } : {});
5052
+ }, live ? { label: "Comment", dismissLabel: "Hide toolbar", expandLabel: "Leave feedback", hideEnable: true, review: !!merged.server } : { dismissLabel: "Hide toolbar", expandLabel: "Open Grabby toolbar" });
5053
+ function collapseToolbar() {
5054
+ closeAllPopovers();
5055
+ coachMark.dismiss();
5056
+ doDeactivate(true);
5057
+ collapsed = true;
5058
+ toolbar.collapse();
5059
+ saveCollapsed(true);
5060
+ updateToastOffset();
5061
+ }
5062
+ function expandToolbar() {
5063
+ collapsed = false;
5064
+ toolbar.expand();
5065
+ saveCollapsed(false);
5066
+ updateToastOffset();
5067
+ }
4954
5068
  const commentsPanel = createCommentsPanel({
4955
5069
  onHover(comment) {
4956
5070
  const el = comment ? safeQuery(comment.target.selector) : null;
@@ -5087,7 +5201,7 @@ function createGrabInstance(options) {
5087
5201
  }
5088
5202
  window.addEventListener("beforeunload", handleBeforeUnload);
5089
5203
  function updateToastOffset() {
5090
- if (store.state.toolbar.visible) {
5204
+ if (store.state.toolbar.visible && !collapsed) {
5091
5205
  document.documentElement.style.setProperty("--grabby-toast-bottom", TOOLBAR_TOAST_OFFSET);
5092
5206
  } else {
5093
5207
  document.documentElement.style.removeProperty("--grabby-toast-bottom");
@@ -5237,9 +5351,10 @@ function createGrabInstance(options) {
5237
5351
  keyboard.start();
5238
5352
  }
5239
5353
  store.state.toolbar = { ...store.state.toolbar, visible: false };
5354
+ if (collapsed) toolbar.collapse();
5240
5355
  if (live && merged.showToolbar) {
5241
5356
  api.showToolbar();
5242
- coachMark.maybeShow();
5357
+ if (!collapsed) coachMark.maybeShow();
5243
5358
  }
5244
5359
  store.subscribe((state, key) => {
5245
5360
  if (key === "options") {