seatable-html-page-sdk 0.0.13-beta.4 → 0.0.13-beta.5

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/dist/index.js CHANGED
@@ -4547,6 +4547,7 @@
4547
4547
  HTML_PAGE_DISABLE_COMMENT_MODE: 'HTML_PAGE_DISABLE_COMMENT_MODE',
4548
4548
  HTML_PAGE_COMMENT_MODE_ELEMENT_HOVER: 'HTML_PAGE_COMMENT_MODE_ELEMENT_HOVER',
4549
4549
  HTML_PAGE_COMMENT_MODE_ELEMENT_SELECTED: 'HTML_PAGE_COMMENT_MODE_ELEMENT_SELECTED',
4550
+ HTML_PAGE_COMMENT_MODE_ELEMENT_POSITION_UPDATE: 'HTML_PAGE_COMMENT_MODE_ELEMENT_POSITION_UPDATE',
4550
4551
  WINDOW_EVENT: 'WINDOW_EVENT'
4551
4552
  };
4552
4553
 
@@ -4614,7 +4615,10 @@
4614
4615
  constructor() {
4615
4616
  this.isActive = false;
4616
4617
  this._handleEvent = this._handleEvent.bind(this);
4618
+ this._handleScroll = this._handleScroll.bind(this);
4617
4619
  this.mouseEvents = ['click', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'contextmenu'];
4620
+ this.hoverTarget = null;
4621
+ this.selectedTarget = null;
4618
4622
  }
4619
4623
  enable() {
4620
4624
  if (this.isActive) return;
@@ -4622,6 +4626,7 @@
4622
4626
  this.mouseEvents.forEach(eventType => {
4623
4627
  window.addEventListener(eventType, this._handleEvent, true);
4624
4628
  });
4629
+ window.addEventListener('scroll', this._handleScroll, true);
4625
4630
  this.addCommentModeStyle();
4626
4631
  }
4627
4632
  disable() {
@@ -4630,8 +4635,30 @@
4630
4635
  this.mouseEvents.forEach(eventType => {
4631
4636
  window.removeEventListener(eventType, this._handleEvent, true);
4632
4637
  });
4638
+ window.removeEventListener('scroll', this._handleScroll, true);
4639
+ this.hoverTarget = null;
4640
+ this.selectedTarget = null;
4633
4641
  this.removeCommentStyle();
4634
4642
  }
4643
+ _handleScroll() {
4644
+ if (!this.isActive) return;
4645
+ if (this.selectedTarget && document.body.contains(this.selectedTarget)) {
4646
+ const data = this.buildElementData(this.selectedTarget);
4647
+ window.parent.postMessage({
4648
+ type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_POSITION_UPDATE,
4649
+ data,
4650
+ targetType: 'selected'
4651
+ }, '*');
4652
+ }
4653
+ if (this.hoverTarget && document.body.contains(this.hoverTarget)) {
4654
+ const data = this.buildElementData(this.hoverTarget);
4655
+ window.parent.postMessage({
4656
+ type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_POSITION_UPDATE,
4657
+ data,
4658
+ targetType: 'hover'
4659
+ }, '*');
4660
+ }
4661
+ }
4635
4662
  addCommentModeStyle() {
4636
4663
  let style = document.getElementById('ai-comment-cursor-style');
4637
4664
  if (!style) {
@@ -4653,12 +4680,14 @@
4653
4680
  const target = event.target;
4654
4681
  const isBodyOrHtml = target === document.body || target === document.documentElement;
4655
4682
  if (event.type === 'mouseover') {
4683
+ this.hoverTarget = isBodyOrHtml ? null : target;
4656
4684
  const data = isBodyOrHtml ? null : this.buildElementData(target);
4657
4685
  window.parent.postMessage({
4658
4686
  type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_HOVER,
4659
4687
  data
4660
4688
  }, '*');
4661
4689
  } else if (event.type === 'click') {
4690
+ this.selectedTarget = isBodyOrHtml ? null : target;
4662
4691
  const data = isBodyOrHtml ? null : this.buildElementData(target);
4663
4692
  window.parent.postMessage({
4664
4693
  type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_SELECTED,