@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.
@@ -679,6 +679,7 @@ function createCrosshair() {
679
679
  let hLine = null;
680
680
  let vLine = null;
681
681
  let listening = false;
682
+ let held = false;
682
683
  function injectStyles2() {
683
684
  if (hasStyles(CROSSHAIR_STYLE_ID)) return;
684
685
  addStyles(CROSSHAIR_STYLE_ID, `
@@ -701,7 +702,7 @@ function createCrosshair() {
701
702
  width: 1px;
702
703
  }
703
704
  `);
704
- addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active { cursor: crosshair !important; }", "document");
705
+ addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active:not(.grabby-crosshair-held) { cursor: crosshair !important; }", "document");
705
706
  }
706
707
  function ensureElements() {
707
708
  if (!hLine) {
@@ -718,7 +719,12 @@ function createCrosshair() {
718
719
  getUiRoot().appendChild(vLine);
719
720
  }
720
721
  }
722
+ function hideLines() {
723
+ if (hLine) hLine.style.top = "-10px";
724
+ if (vLine) vLine.style.left = "-10px";
725
+ }
721
726
  function handleMouseMove(e) {
727
+ if (held) return;
722
728
  if (hLine) {
723
729
  hLine.style.top = `${e.clientY}px`;
724
730
  }
@@ -739,13 +745,19 @@ function createCrosshair() {
739
745
  listening = false;
740
746
  document.body.classList.remove("grabby-crosshair-active");
741
747
  document.removeEventListener("mousemove", handleMouseMove, true);
742
- if (hLine) hLine.style.top = "-10px";
743
- if (vLine) vLine.style.left = "-10px";
748
+ hideLines();
749
+ },
750
+ hold(on) {
751
+ if (held === on) return;
752
+ held = on;
753
+ document.body.classList.toggle("grabby-crosshair-held", on);
754
+ if (on) hideLines();
744
755
  },
745
756
  isCrosshairElement(el) {
746
757
  return el === hLine || el === vLine || el.id === H_LINE_ID || el.id === V_LINE_ID;
747
758
  },
748
759
  dispose() {
760
+ this.hold(false);
749
761
  this.deactivate();
750
762
  hLine?.remove();
751
763
  vLine?.remove();
@@ -1148,6 +1160,7 @@ function buildUniqueSelector(el) {
1148
1160
  // src/core/picker/element-picker.ts
1149
1161
  function createElementPicker(deps) {
1150
1162
  let hoveredElement = null;
1163
+ let heldElement = null;
1151
1164
  let listening = false;
1152
1165
  function resolveComponentName(el) {
1153
1166
  const resolver = deps.getComponentResolver();
@@ -1178,17 +1191,21 @@ function createElementPicker(deps) {
1178
1191
  if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
1179
1192
  return exact ? raw : promoteTarget(raw);
1180
1193
  }
1194
+ function showOverlay(target) {
1195
+ const componentName = resolveComponentName(target);
1196
+ const sourcePath = resolveSourcePath(target);
1197
+ const cssClasses = filterAngularClasses(target.classList);
1198
+ deps.overlay.show(target, componentName, sourcePath, cssClasses);
1199
+ }
1181
1200
  function handleMouseMove(e) {
1201
+ if (heldElement) return;
1182
1202
  const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
1183
1203
  if (!target || deps.overlay.isOverlayElement(target)) return;
1184
1204
  if (deps.crosshair.isCrosshairElement(target)) return;
1185
1205
  if (deps.isToolbarElement?.(target)) return;
1186
1206
  if (target === hoveredElement) return;
1187
1207
  hoveredElement = target;
1188
- const componentName = resolveComponentName(target);
1189
- const sourcePath = resolveSourcePath(target);
1190
- const cssClasses = filterAngularClasses(target.classList);
1191
- deps.overlay.show(target, componentName, sourcePath, cssClasses);
1208
+ showOverlay(target);
1192
1209
  deps.onHover(target);
1193
1210
  }
1194
1211
  function handleClick(e) {
@@ -1198,6 +1215,7 @@ function createElementPicker(deps) {
1198
1215
  if (target && (deps.isToolbarElement?.(target) || deps.crosshair.isCrosshairElement(target))) return;
1199
1216
  e.preventDefault();
1200
1217
  e.stopPropagation();
1218
+ if (heldElement) return;
1201
1219
  if (hoveredElement) {
1202
1220
  deps.onSelect(hoveredElement);
1203
1221
  }
@@ -1214,12 +1232,29 @@ function createElementPicker(deps) {
1214
1232
  if (!listening) return;
1215
1233
  listening = false;
1216
1234
  hoveredElement = null;
1235
+ heldElement = null;
1236
+ deps.crosshair.hold(false);
1217
1237
  deps.crosshair.deactivate();
1218
1238
  document.removeEventListener("mousemove", handleMouseMove, true);
1219
1239
  document.removeEventListener("click", handleClick, true);
1220
1240
  deps.overlay.hide();
1221
1241
  deps.onHover(null);
1222
1242
  },
1243
+ hold(element) {
1244
+ if (!listening) return;
1245
+ heldElement = element;
1246
+ hoveredElement = element;
1247
+ deps.crosshair.hold(true);
1248
+ showOverlay(element);
1249
+ },
1250
+ release() {
1251
+ if (!heldElement) return;
1252
+ heldElement = null;
1253
+ deps.crosshair.hold(false);
1254
+ },
1255
+ isHolding() {
1256
+ return heldElement !== null;
1257
+ },
1223
1258
  getHoveredElement() {
1224
1259
  return hoveredElement;
1225
1260
  },
@@ -1552,6 +1587,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1552
1587
  let allElements = /* @__PURE__ */ new Set();
1553
1588
  let badge = null;
1554
1589
  let status = null;
1590
+ let expandBadge = null;
1591
+ let collapsed = false;
1555
1592
  function injectStyles2() {
1556
1593
  if (hasStyles(STYLE_ID3)) return;
1557
1594
  addStyles(STYLE_ID3, `
@@ -1667,6 +1704,24 @@ function createToolbarRenderer(callbacks, options = {}) {
1667
1704
  background: var(--grabby-accent-hover, #1d4ed8);
1668
1705
  color: #fff;
1669
1706
  }
1707
+ #${TOOLBAR_ID} button.grabby-btn-expand { display: none; }
1708
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed {
1709
+ left: auto;
1710
+ right: 20px;
1711
+ transform: none;
1712
+ padding: 4px;
1713
+ }
1714
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed.grabby-toolbar-hidden {
1715
+ transform: translateY(20px);
1716
+ }
1717
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > * { display: none !important; }
1718
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > button.grabby-btn-expand {
1719
+ display: flex !important;
1720
+ width: 40px;
1721
+ height: 40px;
1722
+ border-radius: 50%;
1723
+ color: var(--grabby-accent, #2563eb);
1724
+ }
1670
1725
  #${TOOLBAR_ID} .grabby-toolbar-left.grabby-toolbar-left-hidden {
1671
1726
  max-width: 0;
1672
1727
  opacity: 0;
@@ -1707,6 +1762,12 @@ function createToolbarRenderer(callbacks, options = {}) {
1707
1762
  buttons.history.appendChild(badge);
1708
1763
  buttons.enable = createButton("enable", ICON_POWER, "Enable/Disable", callbacks.onEnableToggle);
1709
1764
  buttons.dismiss = createButton("dismiss", ICON_DISMISS, options.dismissLabel ?? "Dismiss toolbar", callbacks.onDismiss);
1765
+ buttons.expand = createButton("expand", ICON_GRAB, options.expandLabel ?? "Open Grabby toolbar", () => callbacks.onExpand?.());
1766
+ buttons.expand.classList.add("grabby-btn-expand");
1767
+ expandBadge = document.createElement("span");
1768
+ expandBadge.className = "grabby-badge";
1769
+ expandBadge.hidden = true;
1770
+ buttons.expand.appendChild(expandBadge);
1710
1771
  const divider = document.createElement("span");
1711
1772
  divider.className = "grabby-toolbar-divider";
1712
1773
  leftGroup = document.createElement("div");
@@ -1737,6 +1798,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1737
1798
  }
1738
1799
  if (!options.hideEnable) container.appendChild(buttons.enable);
1739
1800
  container.appendChild(buttons.dismiss);
1801
+ container.appendChild(buttons.expand);
1802
+ container.classList.toggle("grabby-toolbar-collapsed", collapsed);
1740
1803
  getUiRoot().appendChild(container);
1741
1804
  allElements.clear();
1742
1805
  allElements.add(container);
@@ -1764,9 +1827,10 @@ function createToolbarRenderer(callbacks, options = {}) {
1764
1827
  buttons.selection.classList.remove("grabby-btn-active");
1765
1828
  }
1766
1829
  const count = state.toolbar.comments.length;
1767
- if (badge) {
1768
- badge.hidden = count === 0;
1769
- badge.textContent = count > 99 ? "99+" : String(count);
1830
+ for (const b of [badge, expandBadge]) {
1831
+ if (!b) continue;
1832
+ b.hidden = count === 0;
1833
+ b.textContent = count > 99 ? "99+" : String(count);
1770
1834
  }
1771
1835
  buttons.history.setAttribute("aria-label", count ? `Comments (${count})` : "Comments");
1772
1836
  if (status && buttons.finish) {
@@ -1784,6 +1848,17 @@ function createToolbarRenderer(callbacks, options = {}) {
1784
1848
  leftGroup?.classList.add("grabby-toolbar-left-hidden");
1785
1849
  }
1786
1850
  },
1851
+ collapse() {
1852
+ collapsed = true;
1853
+ container?.classList.add("grabby-toolbar-collapsed");
1854
+ },
1855
+ expand() {
1856
+ collapsed = false;
1857
+ container?.classList.remove("grabby-toolbar-collapsed");
1858
+ },
1859
+ isCollapsed() {
1860
+ return collapsed;
1861
+ },
1787
1862
  isToolbarElement(el) {
1788
1863
  if (allElements.has(el)) return true;
1789
1864
  let current = el;
@@ -1801,6 +1876,7 @@ function createToolbarRenderer(callbacks, options = {}) {
1801
1876
  leftGroup = null;
1802
1877
  buttons = {};
1803
1878
  badge = null;
1879
+ expandBadge = null;
1804
1880
  status = null;
1805
1881
  allElements.clear();
1806
1882
  }
@@ -4550,6 +4626,21 @@ function flushLeftovers(options) {
4550
4626
  }
4551
4627
  });
4552
4628
  }
4629
+ var COLLAPSED_KEY = "grabby:v1:collapsed";
4630
+ function loadCollapsed() {
4631
+ try {
4632
+ return sessionStorage.getItem(COLLAPSED_KEY) === "1";
4633
+ } catch {
4634
+ return false;
4635
+ }
4636
+ }
4637
+ function saveCollapsed(on) {
4638
+ try {
4639
+ if (on) sessionStorage.setItem(COLLAPSED_KEY, "1");
4640
+ else sessionStorage.removeItem(COLLAPSED_KEY);
4641
+ } catch {
4642
+ }
4643
+ }
4553
4644
  function isDevMode() {
4554
4645
  try {
4555
4646
  if (typeof ngDevMode !== "undefined" && ngDevMode === false) return false;
@@ -4632,6 +4723,7 @@ function createGrabInstance(options) {
4632
4723
  let selectedElement = null;
4633
4724
  let pendingShot = null;
4634
4725
  let level = loadLevel(merged.detailLevel);
4726
+ let collapsed = loadCollapsed();
4635
4727
  const pendingShotDeletes = /* @__PURE__ */ new Map();
4636
4728
  themeManager.apply(store.state.toolbar.themeMode);
4637
4729
  updateToastOffset();
@@ -4805,9 +4897,17 @@ function createGrabInstance(options) {
4805
4897
  function isAnyToolbarElement(el) {
4806
4898
  return isUiNode(el) || freezeOverlay.isFreezeElement(el);
4807
4899
  }
4900
+ function hideCommentPopover() {
4901
+ commentPopover.hide();
4902
+ if (picker.isHolding()) {
4903
+ selectedElement = null;
4904
+ pendingShot = null;
4905
+ picker.release();
4906
+ }
4907
+ }
4808
4908
  function closeAllPopovers() {
4809
4909
  commentsPanel.hide();
4810
- commentPopover.hide();
4910
+ hideCommentPopover();
4811
4911
  copySheet.close();
4812
4912
  finishSheet.close();
4813
4913
  }
@@ -4847,6 +4947,7 @@ function createGrabInstance(options) {
4847
4947
  pluginRegistry.callHook("onElementSelect", element);
4848
4948
  coachMark.dismiss();
4849
4949
  showSelectFeedback(element);
4950
+ picker.hold(element);
4850
4951
  commentPopover.show({ anchor: element, mode: "new", askIdentity: shouldAskIdentity() });
4851
4952
  }
4852
4953
  });
@@ -4857,6 +4958,7 @@ function createGrabInstance(options) {
4857
4958
  store.state.toolbar = { ...store.state.toolbar, visible: true };
4858
4959
  toolbar.show();
4859
4960
  }
4961
+ if (collapsed) expandToolbar();
4860
4962
  closeAllPopovers();
4861
4963
  store.state.active = true;
4862
4964
  picker.activate();
@@ -4891,7 +4993,7 @@ function createGrabInstance(options) {
4891
4993
  }
4892
4994
  },
4893
4995
  onHistory() {
4894
- commentPopover.hide();
4996
+ hideCommentPopover();
4895
4997
  copySheet.close();
4896
4998
  if (commentsPanel.isVisible()) {
4897
4999
  commentsPanel.hide();
@@ -4908,16 +5010,28 @@ function createGrabInstance(options) {
4908
5010
  }
4909
5011
  toolbar.update(store.state);
4910
5012
  },
4911
- onDismiss() {
4912
- const { pending, failed } = reviewCounts();
4913
- if (live && outbox && (pending || failed)) {
4914
- openFinishSheet();
4915
- return;
4916
- }
4917
- exitFeedbackMode();
4918
- },
5013
+ // Close collapses the toolbar into a round button in the bottom-right
5014
+ // corner instead of removing it, so nothing is lost and it's one click
5015
+ // back. Comments keep sending while it's collapsed.
5016
+ onDismiss: collapseToolbar,
5017
+ onExpand: expandToolbar,
4919
5018
  onFinish: openFinishSheet
4920
- }, live ? { label: "Comment", dismissLabel: "Exit feedback mode", hideEnable: true, review: !!merged.server } : {});
5019
+ }, live ? { label: "Comment", dismissLabel: "Hide toolbar", expandLabel: "Leave feedback", hideEnable: true, review: !!merged.server } : { dismissLabel: "Hide toolbar", expandLabel: "Open Grabby toolbar" });
5020
+ function collapseToolbar() {
5021
+ closeAllPopovers();
5022
+ coachMark.dismiss();
5023
+ doDeactivate(true);
5024
+ collapsed = true;
5025
+ toolbar.collapse();
5026
+ saveCollapsed(true);
5027
+ updateToastOffset();
5028
+ }
5029
+ function expandToolbar() {
5030
+ collapsed = false;
5031
+ toolbar.expand();
5032
+ saveCollapsed(false);
5033
+ updateToastOffset();
5034
+ }
4921
5035
  const commentsPanel = createCommentsPanel({
4922
5036
  onHover(comment) {
4923
5037
  const el = comment ? safeQuery(comment.target.selector) : null;
@@ -5054,7 +5168,7 @@ function createGrabInstance(options) {
5054
5168
  }
5055
5169
  window.addEventListener("beforeunload", handleBeforeUnload);
5056
5170
  function updateToastOffset() {
5057
- if (store.state.toolbar.visible) {
5171
+ if (store.state.toolbar.visible && !collapsed) {
5058
5172
  document.documentElement.style.setProperty("--grabby-toast-bottom", TOOLBAR_TOAST_OFFSET);
5059
5173
  } else {
5060
5174
  document.documentElement.style.removeProperty("--grabby-toast-bottom");
@@ -5204,9 +5318,10 @@ function createGrabInstance(options) {
5204
5318
  keyboard.start();
5205
5319
  }
5206
5320
  store.state.toolbar = { ...store.state.toolbar, visible: false };
5321
+ if (collapsed) toolbar.collapse();
5207
5322
  if (live && merged.showToolbar) {
5208
5323
  api.showToolbar();
5209
- coachMark.maybeShow();
5324
+ if (!collapsed) coachMark.maybeShow();
5210
5325
  }
5211
5326
  store.subscribe((state, key) => {
5212
5327
  if (key === "options") {