seatable-html-page-sdk 0.0.13-beta.3 → 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,8 @@
4622
4626
  this.mouseEvents.forEach(eventType => {
4623
4627
  window.addEventListener(eventType, this._handleEvent, true);
4624
4628
  });
4629
+ window.addEventListener('scroll', this._handleScroll, true);
4630
+ this.addCommentModeStyle();
4625
4631
  }
4626
4632
  disable() {
4627
4633
  if (!this.isActive) return;
@@ -4629,6 +4635,42 @@
4629
4635
  this.mouseEvents.forEach(eventType => {
4630
4636
  window.removeEventListener(eventType, this._handleEvent, true);
4631
4637
  });
4638
+ window.removeEventListener('scroll', this._handleScroll, true);
4639
+ this.hoverTarget = null;
4640
+ this.selectedTarget = null;
4641
+ this.removeCommentStyle();
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
+ }
4662
+ addCommentModeStyle() {
4663
+ let style = document.getElementById('ai-comment-cursor-style');
4664
+ if (!style) {
4665
+ style = document.createElement('style');
4666
+ style.id = 'ai-comment-cursor-style';
4667
+ style.innerHTML = '* { cursor: crosshair !important; }';
4668
+ document.head.appendChild(style);
4669
+ }
4670
+ }
4671
+ removeCommentStyle() {
4672
+ const style = document.getElementById('ai-comment-cursor-style');
4673
+ if (style) style.remove();
4632
4674
  }
4633
4675
  _handleEvent(event) {
4634
4676
  if (!this.isActive) return;
@@ -4638,12 +4680,14 @@
4638
4680
  const target = event.target;
4639
4681
  const isBodyOrHtml = target === document.body || target === document.documentElement;
4640
4682
  if (event.type === 'mouseover') {
4683
+ this.hoverTarget = isBodyOrHtml ? null : target;
4641
4684
  const data = isBodyOrHtml ? null : this.buildElementData(target);
4642
4685
  window.parent.postMessage({
4643
4686
  type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_HOVER,
4644
4687
  data
4645
4688
  }, '*');
4646
4689
  } else if (event.type === 'click') {
4690
+ this.selectedTarget = isBodyOrHtml ? null : target;
4647
4691
  const data = isBodyOrHtml ? null : this.buildElementData(target);
4648
4692
  window.parent.postMessage({
4649
4693
  type: POST_MESSAGE_TYPE.HTML_PAGE_COMMENT_MODE_ELEMENT_SELECTED,
@@ -4891,12 +4935,10 @@
4891
4935
  this.emitEvent(eventType, payload);
4892
4936
  } else if (type === POST_MESSAGE_TYPE.HTML_PAGE_ENABLE_COMMENT_MODE) {
4893
4937
  this.isCommentMode = true;
4894
- document.body.style.cursor = 'crosshair';
4895
4938
  this.unbindInteractiveEvents();
4896
4939
  if (this.commentModeAdapter) this.commentModeAdapter.enable();
4897
4940
  } else if (type === POST_MESSAGE_TYPE.HTML_PAGE_DISABLE_COMMENT_MODE) {
4898
4941
  this.isCommentMode = false;
4899
- document.body.style.cursor = '';
4900
4942
  if (this.commentModeAdapter) this.commentModeAdapter.disable();
4901
4943
  this.bindInteractiveEvents();
4902
4944
  } else if (type === POST_MESSAGE_TYPE.WINDOW_EVENT) {