@fluid-topics/ft-infinite-scroll 1.1.79 → 1.1.81

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.
@@ -74,9 +74,11 @@ class FtInfiniteScroll extends FtLitElement {
74
74
  this.lastScrollTop = currentScrollTop;
75
75
  if (this.scrolledToTarget) {
76
76
  this.restoreScrollIfNeeded(ignoreThisScrollEvent ? 0 : scrollDiff);
77
- const scrollRestorationElement = this.searchFirstVisibleItem(currentScrollTop, this.itemsContainer.children);
78
- this.scrollRestorationItem = scrollRestorationElement ? +scrollRestorationElement.getAttribute("data-item-index") : undefined;
79
- this.scrollRestorationOffset = currentScrollTop - this.getOffset(scrollRestorationElement);
77
+ if (!ignoreThisScrollEvent || this.scrollRestorationItem == null) {
78
+ const newScrollRestorationElement = this.searchFirstVisibleItem(currentScrollTop, this.itemsContainer.children);
79
+ this.scrollRestorationItem = newScrollRestorationElement ? +newScrollRestorationElement.getAttribute("data-item-index") : undefined;
80
+ this.scrollRestorationOffset = currentScrollTop - this.getOffset(newScrollRestorationElement);
81
+ }
80
82
  }
81
83
  };
82
84
  this.restoreScrollIfNeeded = (scrollCorrection = 0) => {
@@ -28,7 +28,7 @@
28
28
  display: flow-root;
29
29
  min-height: ${I.itemContainerMinHeight};
30
30
  }
31
- `;var h=function(r,e,t,s){var i=arguments.length,l=i<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")l=Reflect.decorate(r,e,t,s);else for(var d=r.length-1;d>=0;d--)(o=r[d])&&(l=(i<3?o(l):i>3?o(e,t,l):o(e,t))||l);return i>3&&l&&Object.defineProperty(e,t,l),l},T=class extends CustomEvent{constructor(e,t){super("visible-items-change",{detail:{visibleIndexes:e,visibleItems:t}})}},S=class extends Event{constructor(){super("scrolled-to-target")}},G=r=>(r??[])[(r??[]).length-1],n=class extends c.FtLitElement{constructor(){super(...arguments),this.items=[],this.renderItem=()=>m.html``,this.getItemKey=(e,t)=>`${t} - ${JSON.stringify(e)}`,this.internalScroll=!1,this.renderBeforeFirst=1,this.renderAfterLast=1,this.ensureScrollToTarget=!1,this.visibleItems=[],this.scrolledToTarget=!1,this.scrolling=!1,this.renderApprovalTimeouts=[],this.renderedIndexes=new Set,this.scrollDebouncer=new c.Debouncer(5),this.scrollDoneDebouncer=new c.Debouncer(10),this.onVisibilityChange=e=>{let t=new Set(this.visibleItems),s=new Set;for(let i of e){let l=+i.target.getAttribute("data-item-index");i.intersectionRect.height>0?(t.add(l),s.add(l)):s.has(l)||t.delete(l)}this.visibleItems=[...t].sort((i,l)=>i-l)},this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange),this.scrollingDebouncer=new c.Debouncer(50),this.ignoreNextScrollEvent=!1,this.scrollListener=()=>{var e;let t=this.ignoreNextScrollEvent;this.ignoreNextScrollEvent=!1,t||(this.scrolling=!0,this.scrollingDebouncer.run(()=>this.scrolling=!1));let s=this.scrollable.scrollTop,i=s-((e=this.lastScrollTop)!==null&&e!==void 0?e:0);if(this.lastScrollTop=s,this.scrolledToTarget){this.restoreScrollIfNeeded(t?0:i);let l=this.searchFirstVisibleItem(s,this.itemsContainer.children);this.scrollRestorationItem=l?+l.getAttribute("data-item-index"):void 0,this.scrollRestorationOffset=s-this.getOffset(l)}},this.restoreScrollIfNeeded=(e=0)=>{var t;let s=this.scrollable.scrollHeight,i=s-((t=this.lastScrollHeight)!==null&&t!==void 0?t:s);if(this.lastScrollHeight=s,i!==0&&this.scrollRestorationItem!=null&&this.scrollRestorationOffset!=null&&this.scrolledToTarget){let l=this.getItem(this.scrollRestorationItem),o=this.getOffset(l),d=(0,c.minmax)(this.scrollRestorationItem===0?-o:1,this.scrollRestorationOffset,l.clientHeight-1),b=o+d+e-this.scrollable.scrollTop;(Math.abs(i-b)<4||Math.abs(b)>5)&&(this.ignoreNextScrollEvent=!0,this.scrollable.scrollTop+=b)}},this._shouldRestoreScroll=!1,this.scrollAdjustment=()=>{this.restoreScrollIfNeeded(),this.shouldRestoreScroll&&requestAnimationFrame(this.scrollAdjustment)},this.onMutation=()=>{for(let e of this.itemsContainer.children)this.intersectionObserver.observe(e)},this.mutationObserver=new MutationObserver(this.onMutation),this.resetVisibleItemsDebouncer=new c.Debouncer(10)}get scrollable(){var e;return(e=this._scrollable)!==null&&e!==void 0?e:document.body}set scrollable(e){var t,s,i,l;this._scrollable!==e&&((t=this._scrollable)===null||t===void 0||t.removeEventListener("scroll",this.scrollListener),this._scrollable&&this.initialOverflowAnchorValue&&(this.scrollable.style.overflowAnchor=this.initialOverflowAnchorValue),this._scrollable=e,(s=this._scrollable)===null||s===void 0||s.addEventListener("scroll",this.scrollListener),this.lastScrollTop=(i=this._scrollable)===null||i===void 0?void 0:i.scrollTop,this.lastScrollHeight=(l=this._scrollable)===null||l===void 0?void 0:l.scrollHeight,this._scrollable&&(this.initialOverflowAnchorValue=getComputedStyle(this._scrollable).overflowAnchor,this._scrollable.style.overflowAnchor="none"))}render(){return m.html`
31
+ `;var h=function(r,e,t,s){var i=arguments.length,l=i<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")l=Reflect.decorate(r,e,t,s);else for(var d=r.length-1;d>=0;d--)(o=r[d])&&(l=(i<3?o(l):i>3?o(e,t,l):o(e,t))||l);return i>3&&l&&Object.defineProperty(e,t,l),l},T=class extends CustomEvent{constructor(e,t){super("visible-items-change",{detail:{visibleIndexes:e,visibleItems:t}})}},S=class extends Event{constructor(){super("scrolled-to-target")}},G=r=>(r??[])[(r??[]).length-1],n=class extends c.FtLitElement{constructor(){super(...arguments),this.items=[],this.renderItem=()=>m.html``,this.getItemKey=(e,t)=>`${t} - ${JSON.stringify(e)}`,this.internalScroll=!1,this.renderBeforeFirst=1,this.renderAfterLast=1,this.ensureScrollToTarget=!1,this.visibleItems=[],this.scrolledToTarget=!1,this.scrolling=!1,this.renderApprovalTimeouts=[],this.renderedIndexes=new Set,this.scrollDebouncer=new c.Debouncer(5),this.scrollDoneDebouncer=new c.Debouncer(10),this.onVisibilityChange=e=>{let t=new Set(this.visibleItems),s=new Set;for(let i of e){let l=+i.target.getAttribute("data-item-index");i.intersectionRect.height>0?(t.add(l),s.add(l)):s.has(l)||t.delete(l)}this.visibleItems=[...t].sort((i,l)=>i-l)},this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange),this.scrollingDebouncer=new c.Debouncer(50),this.ignoreNextScrollEvent=!1,this.scrollListener=()=>{var e;let t=this.ignoreNextScrollEvent;this.ignoreNextScrollEvent=!1,t||(this.scrolling=!0,this.scrollingDebouncer.run(()=>this.scrolling=!1));let s=this.scrollable.scrollTop,i=s-((e=this.lastScrollTop)!==null&&e!==void 0?e:0);if(this.lastScrollTop=s,this.scrolledToTarget&&(this.restoreScrollIfNeeded(t?0:i),!t||this.scrollRestorationItem==null)){let l=this.searchFirstVisibleItem(s,this.itemsContainer.children);this.scrollRestorationItem=l?+l.getAttribute("data-item-index"):void 0,this.scrollRestorationOffset=s-this.getOffset(l)}},this.restoreScrollIfNeeded=(e=0)=>{var t;let s=this.scrollable.scrollHeight,i=s-((t=this.lastScrollHeight)!==null&&t!==void 0?t:s);if(this.lastScrollHeight=s,i!==0&&this.scrollRestorationItem!=null&&this.scrollRestorationOffset!=null&&this.scrolledToTarget){let l=this.getItem(this.scrollRestorationItem),o=this.getOffset(l),d=(0,c.minmax)(this.scrollRestorationItem===0?-o:1,this.scrollRestorationOffset,l.clientHeight-1),b=o+d+e-this.scrollable.scrollTop;(Math.abs(i-b)<4||Math.abs(b)>5)&&(this.ignoreNextScrollEvent=!0,this.scrollable.scrollTop+=b)}},this._shouldRestoreScroll=!1,this.scrollAdjustment=()=>{this.restoreScrollIfNeeded(),this.shouldRestoreScroll&&requestAnimationFrame(this.scrollAdjustment)},this.onMutation=()=>{for(let e of this.itemsContainer.children)this.intersectionObserver.observe(e)},this.mutationObserver=new MutationObserver(this.onMutation),this.resetVisibleItemsDebouncer=new c.Debouncer(10)}get scrollable(){var e;return(e=this._scrollable)!==null&&e!==void 0?e:document.body}set scrollable(e){var t,s,i,l;this._scrollable!==e&&((t=this._scrollable)===null||t===void 0||t.removeEventListener("scroll",this.scrollListener),this._scrollable&&this.initialOverflowAnchorValue&&(this.scrollable.style.overflowAnchor=this.initialOverflowAnchorValue),this._scrollable=e,(s=this._scrollable)===null||s===void 0||s.addEventListener("scroll",this.scrollListener),this.lastScrollTop=(i=this._scrollable)===null||i===void 0?void 0:i.scrollTop,this.lastScrollHeight=(l=this._scrollable)===null||l===void 0?void 0:l.scrollHeight,this._scrollable&&(this.initialOverflowAnchorValue=getComputedStyle(this._scrollable).overflowAnchor,this._scrollable.style.overflowAnchor="none"))}render(){return m.html`
32
32
  <div class="items-container ${this.internalScroll?"scrollable":""}"
33
33
  tabindex="-1"
34
34
  @find-scrollable-parent=${this.findScrollableParent}>