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

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,12 @@
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;
4622
+ this._scrollRAF = null;
4623
+ this._hoverRAF = null;
4618
4624
  }
4619
4625
  enable() {
4620
4626
  if (this.isActive) return;
@@ -4622,6 +4628,7 @@
4622
4628
  this.mouseEvents.forEach(eventType => {
4623
4629
  window.addEventListener(eventType, this._handleEvent, true);
4624
4630
  });
4631
+ window.addEventListener('scroll', this._handleScroll, true);
4625
4632
  this.addCommentModeStyle();
4626
4633
  }
4627
4634
  disable() {
@@ -4630,8 +4637,38 @@
4630
4637
  this.mouseEvents.forEach(eventType => {
4631
4638
  window.removeEventListener(eventType, this._handleEvent, true);
4632
4639
  });
4640
+ window.removeEventListener('scroll', this._handleScroll, true);
4641
+ this.hoverTarget = null;
4642
+ this.selectedTarget = null;
4643
+ if (this._scrollRAF) cancelAnimationFrame(this._scrollRAF);
4644
+ if (this._hoverRAF) cancelAnimationFrame(this._hoverRAF);
4645
+ this._scrollRAF = null;
4646
+ this._hoverRAF = null;
4633
4647
  this.removeCommentStyle();
4634
4648
  }
4649
+ _handleScroll() {
4650
+ if (!this.isActive) return;
4651
+ if (this._scrollRAF) return;
4652
+ this._scrollRAF = requestAnimationFrame(() => {
4653
+ this._scrollRAF = null;
4654
+ if (this.selectedTarget && document.body.contains(this.selectedTarget)) {
4655
+ const data = this.buildElementData(this.selectedTarget);
4656
+ window.parent.postMessage({
4657
+ type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_POSITION_UPDATE,
4658
+ data,
4659
+ targetType: 'selected'
4660
+ }, '*');
4661
+ }
4662
+ if (this.hoverTarget && document.body.contains(this.hoverTarget)) {
4663
+ const data = this.buildElementData(this.hoverTarget);
4664
+ window.parent.postMessage({
4665
+ type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_POSITION_UPDATE,
4666
+ data,
4667
+ targetType: 'hover'
4668
+ }, '*');
4669
+ }
4670
+ });
4671
+ }
4635
4672
  addCommentModeStyle() {
4636
4673
  let style = document.getElementById('ai-comment-cursor-style');
4637
4674
  if (!style) {
@@ -4653,12 +4690,19 @@
4653
4690
  const target = event.target;
4654
4691
  const isBodyOrHtml = target === document.body || target === document.documentElement;
4655
4692
  if (event.type === 'mouseover') {
4656
- const data = isBodyOrHtml ? null : this.buildElementData(target);
4657
- window.parent.postMessage({
4658
- type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_HOVER,
4659
- data
4660
- }, '*');
4693
+ this.hoverTarget = isBodyOrHtml ? null : target;
4694
+ if (this._hoverRAF) return;
4695
+ this._hoverRAF = requestAnimationFrame(() => {
4696
+ this._hoverRAF = null;
4697
+ const currentTarget = this.hoverTarget;
4698
+ const data = currentTarget ? this.buildElementData(currentTarget) : null;
4699
+ window.parent.postMessage({
4700
+ type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_HOVER,
4701
+ data
4702
+ }, '*');
4703
+ });
4661
4704
  } else if (event.type === 'click') {
4705
+ this.selectedTarget = isBodyOrHtml ? null : target;
4662
4706
  const data = isBodyOrHtml ? null : this.buildElementData(target);
4663
4707
  window.parent.postMessage({
4664
4708
  type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_SELECTED,