@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.
@@ -673,6 +673,7 @@ function createCrosshair() {
673
673
  let hLine = null;
674
674
  let vLine = null;
675
675
  let listening = false;
676
+ let held = false;
676
677
  function injectStyles2() {
677
678
  if (hasStyles(CROSSHAIR_STYLE_ID)) return;
678
679
  addStyles(CROSSHAIR_STYLE_ID, `
@@ -695,7 +696,7 @@ function createCrosshair() {
695
696
  width: 1px;
696
697
  }
697
698
  `);
698
- addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active { cursor: crosshair !important; }", "document");
699
+ addStyles(CURSOR_STYLE_ID, "body.grabby-crosshair-active:not(.grabby-crosshair-held) { cursor: crosshair !important; }", "document");
699
700
  }
700
701
  function ensureElements() {
701
702
  if (!hLine) {
@@ -712,7 +713,12 @@ function createCrosshair() {
712
713
  getUiRoot().appendChild(vLine);
713
714
  }
714
715
  }
716
+ function hideLines() {
717
+ if (hLine) hLine.style.top = "-10px";
718
+ if (vLine) vLine.style.left = "-10px";
719
+ }
715
720
  function handleMouseMove(e) {
721
+ if (held) return;
716
722
  if (hLine) {
717
723
  hLine.style.top = `${e.clientY}px`;
718
724
  }
@@ -733,13 +739,19 @@ function createCrosshair() {
733
739
  listening = false;
734
740
  document.body.classList.remove("grabby-crosshair-active");
735
741
  document.removeEventListener("mousemove", handleMouseMove, true);
736
- if (hLine) hLine.style.top = "-10px";
737
- if (vLine) vLine.style.left = "-10px";
742
+ hideLines();
743
+ },
744
+ hold(on) {
745
+ if (held === on) return;
746
+ held = on;
747
+ document.body.classList.toggle("grabby-crosshair-held", on);
748
+ if (on) hideLines();
738
749
  },
739
750
  isCrosshairElement(el) {
740
751
  return el === hLine || el === vLine || el.id === H_LINE_ID || el.id === V_LINE_ID;
741
752
  },
742
753
  dispose() {
754
+ this.hold(false);
743
755
  this.deactivate();
744
756
  hLine?.remove();
745
757
  vLine?.remove();
@@ -1142,6 +1154,7 @@ function buildUniqueSelector(el) {
1142
1154
  // src/core/picker/element-picker.ts
1143
1155
  function createElementPicker(deps) {
1144
1156
  let hoveredElement = null;
1157
+ let heldElement = null;
1145
1158
  let listening = false;
1146
1159
  function resolveComponentName(el) {
1147
1160
  const resolver = deps.getComponentResolver();
@@ -1172,17 +1185,21 @@ function createElementPicker(deps) {
1172
1185
  if (!raw || raw.closest(`[${IGNORE_ATTR}]`)) return raw && deps.isToolbarElement?.(raw) ? raw : null;
1173
1186
  return exact ? raw : promoteTarget(raw);
1174
1187
  }
1188
+ function showOverlay(target) {
1189
+ const componentName = resolveComponentName(target);
1190
+ const sourcePath = resolveSourcePath(target);
1191
+ const cssClasses = filterAngularClasses(target.classList);
1192
+ deps.overlay.show(target, componentName, sourcePath, cssClasses);
1193
+ }
1175
1194
  function handleMouseMove(e) {
1195
+ if (heldElement) return;
1176
1196
  const target = elementAtPoint(e.clientX, e.clientY, e.shiftKey);
1177
1197
  if (!target || deps.overlay.isOverlayElement(target)) return;
1178
1198
  if (deps.crosshair.isCrosshairElement(target)) return;
1179
1199
  if (deps.isToolbarElement?.(target)) return;
1180
1200
  if (target === hoveredElement) return;
1181
1201
  hoveredElement = target;
1182
- const componentName = resolveComponentName(target);
1183
- const sourcePath = resolveSourcePath(target);
1184
- const cssClasses = filterAngularClasses(target.classList);
1185
- deps.overlay.show(target, componentName, sourcePath, cssClasses);
1202
+ showOverlay(target);
1186
1203
  deps.onHover(target);
1187
1204
  }
1188
1205
  function handleClick(e) {
@@ -1192,6 +1209,7 @@ function createElementPicker(deps) {
1192
1209
  if (target && (deps.isToolbarElement?.(target) || deps.crosshair.isCrosshairElement(target))) return;
1193
1210
  e.preventDefault();
1194
1211
  e.stopPropagation();
1212
+ if (heldElement) return;
1195
1213
  if (hoveredElement) {
1196
1214
  deps.onSelect(hoveredElement);
1197
1215
  }
@@ -1208,12 +1226,29 @@ function createElementPicker(deps) {
1208
1226
  if (!listening) return;
1209
1227
  listening = false;
1210
1228
  hoveredElement = null;
1229
+ heldElement = null;
1230
+ deps.crosshair.hold(false);
1211
1231
  deps.crosshair.deactivate();
1212
1232
  document.removeEventListener("mousemove", handleMouseMove, true);
1213
1233
  document.removeEventListener("click", handleClick, true);
1214
1234
  deps.overlay.hide();
1215
1235
  deps.onHover(null);
1216
1236
  },
1237
+ hold(element) {
1238
+ if (!listening) return;
1239
+ heldElement = element;
1240
+ hoveredElement = element;
1241
+ deps.crosshair.hold(true);
1242
+ showOverlay(element);
1243
+ },
1244
+ release() {
1245
+ if (!heldElement) return;
1246
+ heldElement = null;
1247
+ deps.crosshair.hold(false);
1248
+ },
1249
+ isHolding() {
1250
+ return heldElement !== null;
1251
+ },
1217
1252
  getHoveredElement() {
1218
1253
  return hoveredElement;
1219
1254
  },
@@ -1546,6 +1581,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1546
1581
  let allElements = /* @__PURE__ */ new Set();
1547
1582
  let badge = null;
1548
1583
  let status = null;
1584
+ let expandBadge = null;
1585
+ let collapsed = false;
1549
1586
  function injectStyles2() {
1550
1587
  if (hasStyles(STYLE_ID3)) return;
1551
1588
  addStyles(STYLE_ID3, `
@@ -1661,6 +1698,24 @@ function createToolbarRenderer(callbacks, options = {}) {
1661
1698
  background: var(--grabby-accent-hover, #1d4ed8);
1662
1699
  color: #fff;
1663
1700
  }
1701
+ #${TOOLBAR_ID} button.grabby-btn-expand { display: none; }
1702
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed {
1703
+ left: auto;
1704
+ right: 20px;
1705
+ transform: none;
1706
+ padding: 4px;
1707
+ }
1708
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed.grabby-toolbar-hidden {
1709
+ transform: translateY(20px);
1710
+ }
1711
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > * { display: none !important; }
1712
+ #${TOOLBAR_ID}.grabby-toolbar-collapsed > button.grabby-btn-expand {
1713
+ display: flex !important;
1714
+ width: 40px;
1715
+ height: 40px;
1716
+ border-radius: 50%;
1717
+ color: var(--grabby-accent, #2563eb);
1718
+ }
1664
1719
  #${TOOLBAR_ID} .grabby-toolbar-left.grabby-toolbar-left-hidden {
1665
1720
  max-width: 0;
1666
1721
  opacity: 0;
@@ -1701,6 +1756,12 @@ function createToolbarRenderer(callbacks, options = {}) {
1701
1756
  buttons.history.appendChild(badge);
1702
1757
  buttons.enable = createButton("enable", ICON_POWER, "Enable/Disable", callbacks.onEnableToggle);
1703
1758
  buttons.dismiss = createButton("dismiss", ICON_DISMISS, options.dismissLabel ?? "Dismiss toolbar", callbacks.onDismiss);
1759
+ buttons.expand = createButton("expand", ICON_GRAB, options.expandLabel ?? "Open Grabby toolbar", () => callbacks.onExpand?.());
1760
+ buttons.expand.classList.add("grabby-btn-expand");
1761
+ expandBadge = document.createElement("span");
1762
+ expandBadge.className = "grabby-badge";
1763
+ expandBadge.hidden = true;
1764
+ buttons.expand.appendChild(expandBadge);
1704
1765
  const divider = document.createElement("span");
1705
1766
  divider.className = "grabby-toolbar-divider";
1706
1767
  leftGroup = document.createElement("div");
@@ -1731,6 +1792,8 @@ function createToolbarRenderer(callbacks, options = {}) {
1731
1792
  }
1732
1793
  if (!options.hideEnable) container.appendChild(buttons.enable);
1733
1794
  container.appendChild(buttons.dismiss);
1795
+ container.appendChild(buttons.expand);
1796
+ container.classList.toggle("grabby-toolbar-collapsed", collapsed);
1734
1797
  getUiRoot().appendChild(container);
1735
1798
  allElements.clear();
1736
1799
  allElements.add(container);
@@ -1758,9 +1821,10 @@ function createToolbarRenderer(callbacks, options = {}) {
1758
1821
  buttons.selection.classList.remove("grabby-btn-active");
1759
1822
  }
1760
1823
  const count = state.toolbar.comments.length;
1761
- if (badge) {
1762
- badge.hidden = count === 0;
1763
- badge.textContent = count > 99 ? "99+" : String(count);
1824
+ for (const b of [badge, expandBadge]) {
1825
+ if (!b) continue;
1826
+ b.hidden = count === 0;
1827
+ b.textContent = count > 99 ? "99+" : String(count);
1764
1828
  }
1765
1829
  buttons.history.setAttribute("aria-label", count ? `Comments (${count})` : "Comments");
1766
1830
  if (status && buttons.finish) {
@@ -1778,6 +1842,17 @@ function createToolbarRenderer(callbacks, options = {}) {
1778
1842
  leftGroup?.classList.add("grabby-toolbar-left-hidden");
1779
1843
  }
1780
1844
  },
1845
+ collapse() {
1846
+ collapsed = true;
1847
+ container?.classList.add("grabby-toolbar-collapsed");
1848
+ },
1849
+ expand() {
1850
+ collapsed = false;
1851
+ container?.classList.remove("grabby-toolbar-collapsed");
1852
+ },
1853
+ isCollapsed() {
1854
+ return collapsed;
1855
+ },
1781
1856
  isToolbarElement(el) {
1782
1857
  if (allElements.has(el)) return true;
1783
1858
  let current = el;
@@ -1795,6 +1870,7 @@ function createToolbarRenderer(callbacks, options = {}) {
1795
1870
  leftGroup = null;
1796
1871
  buttons = {};
1797
1872
  badge = null;
1873
+ expandBadge = null;
1798
1874
  status = null;
1799
1875
  allElements.clear();
1800
1876
  }
@@ -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") {