seatable-html-page-sdk 0.0.13-beta.5 → 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
@@ -4619,6 +4619,8 @@
4619
4619
  this.mouseEvents = ['click', 'dblclick', 'mousedown', 'mouseup', 'mousemove', 'mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'contextmenu'];
4620
4620
  this.hoverTarget = null;
4621
4621
  this.selectedTarget = null;
4622
+ this._scrollRAF = null;
4623
+ this._hoverRAF = null;
4622
4624
  }
4623
4625
  enable() {
4624
4626
  if (this.isActive) return;
@@ -4638,26 +4640,34 @@
4638
4640
  window.removeEventListener('scroll', this._handleScroll, true);
4639
4641
  this.hoverTarget = null;
4640
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;
4641
4647
  this.removeCommentStyle();
4642
4648
  }
4643
4649
  _handleScroll() {
4644
4650
  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
- }
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
+ });
4661
4671
  }
4662
4672
  addCommentModeStyle() {
4663
4673
  let style = document.getElementById('ai-comment-cursor-style');
@@ -4681,11 +4691,16 @@
4681
4691
  const isBodyOrHtml = target === document.body || target === document.documentElement;
4682
4692
  if (event.type === 'mouseover') {
4683
4693
  this.hoverTarget = isBodyOrHtml ? null : target;
4684
- const data = isBodyOrHtml ? null : this.buildElementData(target);
4685
- window.parent.postMessage({
4686
- type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_HOVER,
4687
- data
4688
- }, '*');
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
+ });
4689
4704
  } else if (event.type === 'click') {
4690
4705
  this.selectedTarget = isBodyOrHtml ? null : target;
4691
4706
  const data = isBodyOrHtml ? null : this.buildElementData(target);