@khanglvm/relay 0.16.1 → 0.17.1

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/src/ui/kit.js CHANGED
@@ -401,6 +401,7 @@
401
401
  let started = false;
402
402
  let hot = null; // currently outlined element
403
403
  let pin = null; // floating pin button
404
+ let hoverEnabled = true;
404
405
  let hideTimer = 0;
405
406
  let lastCounts = {};
406
407
  let overlayBadges = []; // [{el, badge}] for replaced elements
@@ -453,18 +454,25 @@
453
454
  function ensurePin() {
454
455
  if (pin || !document.body) return pin;
455
456
  pin = document.createElement('button');
457
+ pin.className = 'relay-ann-pin';
456
458
  pin.type = 'button';
457
459
  pin.setAttribute('aria-label', 'Add a comment');
458
460
  pin.title = 'Add a comment';
459
461
  pin.style.cssText = [
460
- 'position:fixed', 'z-index:2147483647', 'display:none', 'width:22px', 'height:22px',
462
+ 'all:initial', 'position:fixed', 'z-index:2147483647', 'display:none', 'width:22px', 'height:22px',
463
+ 'box-sizing:border-box', 'margin:0',
461
464
  'padding:0', 'border:none', 'border-radius:50%', 'cursor:pointer', 'background:' + accent(),
462
465
  'color:#fff', 'align-items:center', 'justify-content:center', 'line-height:0',
463
466
  'box-shadow:0 1px 4px rgba(0,0,0,.3)',
464
- ].join(';');
467
+ ].map((rule) => rule + ' !important').join(';');
465
468
  pin.innerHTML =
466
469
  '<svg viewBox="0 0 16 16" width="11" height="11" aria-hidden="true">' +
467
470
  '<path d="M3 2.5h10A1.5 1.5 0 0 1 14.5 4v5a1.5 1.5 0 0 1-1.5 1.5H8.4L5 13.4v-2.9H3A1.5 1.5 0 0 1 1.5 9V4A1.5 1.5 0 0 1 3 2.5Z" fill="currentColor"/></svg>';
471
+ pin.querySelector('svg').style.cssText =
472
+ 'all:initial !important;display:block !important;width:11px !important;height:11px !important;fill:currentColor !important;color:inherit !important;';
473
+ pin.querySelector('path').style.setProperty('fill', 'currentColor', 'important');
474
+ pin.addEventListener('focus', () => pin.style.setProperty('outline', '2px solid ' + accent(), 'important'));
475
+ pin.addEventListener('blur', () => pin.style.removeProperty('outline'));
468
476
  pin.addEventListener('mouseenter', () => clearTimeout(hideTimer));
469
477
  pin.addEventListener('mouseleave', scheduleHide);
470
478
  pin.addEventListener('click', (e) => {
@@ -478,16 +486,16 @@
478
486
  }
479
487
 
480
488
  function showPinFor(el) {
481
- if (!ensurePin()) return;
489
+ if (!hoverEnabled || !ensurePin()) return;
482
490
  clearTimeout(hideTimer);
483
491
  if (hot && hot !== el) hot.classList.remove('relay-ann-hot');
484
492
  hot = el;
485
493
  el.classList.add('relay-ann-hot');
486
494
  const r = el.getBoundingClientRect();
487
495
  const w = 22;
488
- pin.style.display = 'flex';
489
- pin.style.left = Math.max(2, Math.min(r.right - w / 2, window.innerWidth - w - 2)) + 'px';
490
- pin.style.top = Math.max(2, Math.min(r.top - w / 2, window.innerHeight - w - 2)) + 'px';
496
+ pin.style.setProperty('display', 'flex', 'important');
497
+ pin.style.setProperty('left', Math.max(2, Math.min(r.right - w / 2, window.innerWidth - w - 2)) + 'px', 'important');
498
+ pin.style.setProperty('top', Math.max(2, Math.min(r.top - w / 2, window.innerHeight - w - 2)) + 'px', 'important');
491
499
  }
492
500
 
493
501
  function scheduleHide() {
@@ -499,7 +507,7 @@
499
507
  clearTimeout(hideTimer);
500
508
  if (hot) hot.classList.remove('relay-ann-hot');
501
509
  hot = null;
502
- if (pin) pin.style.display = 'none';
510
+ if (pin) pin.style.setProperty('display', 'none', 'important');
503
511
  }
504
512
 
505
513
  // Ask the parent to open its annotation popover for this element.
@@ -631,8 +639,13 @@
631
639
  }, true);
632
640
  window.addEventListener('resize', () => { hidePin(); repositionOverlays(); });
633
641
  window.addEventListener('message', (e) => {
642
+ if (e.source !== parent) return;
634
643
  const m = e.data;
635
644
  if (m && typeof m === 'object' && m.relay === 'annotate-counts') renderBadges(m.counts || {});
645
+ if (m && typeof m === 'object' && m.relay === 'annotate-hover' && typeof m.enabled === 'boolean') {
646
+ hoverEnabled = m.enabled;
647
+ if (!hoverEnabled) hidePin();
648
+ }
636
649
  });
637
650
  // Re-pick up DOM that author JS builds after load. We observe childList
638
651
  // only (not attributes, so our own hover-class toggles don't fire it) and