@fluid-topics/ft-infinite-scroll 1.2.8 → 1.2.9

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.
@@ -95,7 +95,7 @@ class FtInfiniteScroll extends FtLitElement {
95
95
  const offset = minmax(this.scrollRestorationItem === 0 ? -scrollTarget : 1, this.scrollRestorationOffset, scrollRestorationElement.clientHeight - 1);
96
96
  const scrollDiff = scrollTarget + offset + scrollCorrection - this.scrollable.scrollTop;
97
97
  if (Math.abs(heightDiff - scrollDiff) < 4 || Math.abs(scrollDiff) > 5) {
98
- this.ignoreNextScrollEvent = true;
98
+ this.ignoreNextScrollEvent = true; // Next line automatically trigger a scroll event we need to ignore
99
99
  this.scrollable.scrollTop += scrollDiff;
100
100
  }
101
101
  }
@@ -242,6 +242,7 @@ class FtInfiniteScroll extends FtLitElement {
242
242
  .find((elt) => typeof elt.matches == "function" && elt.matches(".item-container"))) === null || _a === void 0 ? void 0 : _a.getAttribute("data-item-index");
243
243
  this.scrollRestorationItem = itemContainerIndex == null ? this.scrollRestorationItem : +itemContainerIndex;
244
244
  this.scrollRestorationOffset = targetOffset - this.getOffset(this.scrollRestorationItem);
245
+ this.ignoreNextScrollEvent = true; // Next line automatically trigger a scroll event we need to ignore
245
246
  this.scrollable.scrollTop = targetOffset;
246
247
  }
247
248
  getOffset(target) {
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var H=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var b=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports);var q=(l,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of L(e))!k.call(l,i)&&i!==t&&y(l,i,{get:()=>e[i],enumerable:!(s=M(e,i))||s.enumerable});return l};var m=(l,e,t)=>(t=l!=null?H(j(l)):{},q(e||!l||!l.__esModule?y(t,"default",{value:l,enumerable:!0}):t,l));var u=b((U,O)=>{O.exports=ftGlobals.wcUtils});var g=b((P,R)=>{R.exports=ftGlobals.lit});var w=b((K,x)=>{x.exports=ftGlobals.litDecorators});var A=b((Z,_)=>{_.exports=ftGlobals.litRepeat});var V=b((W,C)=>{C.exports=ftGlobals.litUnsafeHTML});var $=m(u());var f=m(g()),h=m(w()),N=m(A()),o=m(u()),F=m(V());var E=m(g()),p=m(u()),I={padding:p.FtCssVariableFactory.create("--ft-infinite-scroll-padding","","SIZE","0"),itemsGap:p.FtCssVariableFactory.create("--ft-infinite-scroll-items-gap","","SIZE","4px"),itemContainerMinHeight:p.FtCssVariableFactory.create("--ft-infinite-scroll-item-container-min-height","","SIZE",".1px")},D=E.css`
1
+ "use strict";(()=>{var H=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var b=(l,e)=>()=>(e||l((e={exports:{}}).exports,e),e.exports);var q=(l,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of L(e))!k.call(l,i)&&i!==t&&y(l,i,{get:()=>e[i],enumerable:!(s=M(e,i))||s.enumerable});return l};var m=(l,e,t)=>(t=l!=null?H(j(l)):{},q(e||!l||!l.__esModule?y(t,"default",{value:l,enumerable:!0}):t,l));var u=b((U,O)=>{O.exports=ftGlobals.wcUtils});var g=b((P,R)=>{R.exports=ftGlobals.lit});var w=b((K,x)=>{x.exports=ftGlobals.litDecorators});var A=b((Z,_)=>{_.exports=ftGlobals.litRepeat});var E=b((W,C)=>{C.exports=ftGlobals.litUnsafeHTML});var $=m(u());var f=m(g()),h=m(w()),N=m(A()),o=m(u()),F=m(E());var V=m(g()),p=m(u()),I={padding:p.FtCssVariableFactory.create("--ft-infinite-scroll-padding","","SIZE","0"),itemsGap:p.FtCssVariableFactory.create("--ft-infinite-scroll-items-gap","","SIZE","4px"),itemContainerMinHeight:p.FtCssVariableFactory.create("--ft-infinite-scroll-item-container-min-height","","SIZE",".1px")},D=V.css`
2
2
  .items-container {
3
3
  padding: ${I.padding};
4
4
  outline: none;
@@ -38,4 +38,4 @@
38
38
  data-item-index="${t}">
39
39
  ${i?(()=>{let c=this.renderItem(e,t);return typeof c=="string"?(0,F.unsafeHTML)(c):c})():f.nothing}
40
40
  </div>
41
- `}prepareRenderIfNeeded(e){let t=this.renderApprovalTimeouts[e]!=null;this.inRenderRange(e)&&!t&&(this.renderApprovalTimeouts[e]=setTimeout(()=>{this.inRenderRange(e)?this.renderedIndexes.add(e):this.renderApprovalTimeouts[e]=void 0,this.requestUpdate()},300))}inRenderRange(e){return e>=this.visibleItems[0]-this.renderBeforeFirst&&e<=G(this.visibleItems)+this.renderAfterLast}isRendered(e){return this.renderedIndexes.has(this.items.indexOf(e))}resetScroll(e=!0){this.shouldRestoreScroll=!1,this.intersectionObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.internalScroll&&this.scrollable!==this.internalScrollable?this.scrollable=this.internalScrollable:!this.internalScroll&&e&&(this.scrollable=o.scrollHelper.findFirstScrollableParent(this.itemsContainer));let t=this.resolveScrollToIndex();this.renderedIndexes.add(t),this.scrollToTarget(t),this.scrollDoneDebouncer.run(()=>{this.ensureScrollToTarget&&t>=0&&this.scrollDebouncer.run(()=>{Math.abs(this.scrollable.scrollTop-this.getOffset(t))>5&&this.scrollToTarget(t)},500),this.scrollToTarget(t),this.scrolledToTarget=!0,this.shouldRestoreScroll=!0,this.resetIntersectionObserver()})}resolveScrollToIndex(){var e;let t=(e=this.scrollToIndex)!==null&&e!==void 0?e:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;return t>=this.items.length?-1:t}getItem(e){var t,s,i;return(s=(t=this.shadowRoot)===null||t===void 0?void 0:t.querySelector(`#item-${e}`))!==null&&s!==void 0?s:(i=this.shadowRoot)===null||i===void 0?void 0:i.querySelector("#item-0")}scrollToTarget(e){e<=0?(this.scrollable.scrollTop=0,this.scrollRestorationOffset=-this.getOffset(e)):(this.scrollable.scrollTop=this.getOffset(e),this.scrollRestorationOffset=0),this.scrollRestorationItem=e>=0?e:void 0}onScrollIntoView(e){var t;this.scrollDebouncer.cancel();let s=e.composedPath()[0],i=this.getOffset(s),r=(t=e.composedPath().find(c=>typeof c.matches=="function"&&c.matches(".item-container")))===null||t===void 0?void 0:t.getAttribute("data-item-index");this.scrollRestorationItem=r==null?this.scrollRestorationItem:+r,this.scrollRestorationOffset=i-this.getOffset(this.scrollRestorationItem),this.scrollable.scrollTop=i}getOffset(e){let t=typeof e=="number"?this.getItem(e):e;return t?o.scrollHelper.getAbsoluteScrollOffset(this.scrollable,t):0}appendItems(...e){this.items=[...this.items,...e]}prependItems(...e){this.items=[...e,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0}),this.resetScroll()},0)}disconnectedCallback(){super.disconnectedCallback(),this.scrollable=void 0,this.intersectionObserver.disconnect(),this.mutationObserver.disconnect(),this.shouldRestoreScroll=!1}resetIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]}),this.onMutation()}searchFirstVisibleItem(e,t,s,i){if(s=s??0,i=i??t.length-1,i<=s)return t[s];let r=Math.floor((i-s)/2)+s,c=t[r],d=this.getOffset(c);return d>e?this.searchFirstVisibleItem(e,t,s,r-1):d+c.clientHeight<e?this.searchFirstVisibleItem(e,t,r+1,i):c}get shouldRestoreScroll(){return this._shouldRestoreScroll}set shouldRestoreScroll(e){let t=e&&!this._shouldRestoreScroll;this._shouldRestoreScroll=e,t&&requestAnimationFrame(this.scrollAdjustment)}update(e){super.update(e),e.has("items")&&(this.renderedIndexes=new Set,this.renderApprovalTimeouts=[]),((e.has("scrollToItem")||e.has("scrollToIndex"))&&(this.scrollToItem!=null||this.scrollToIndex!=null)||e.has("internalScroll"))&&this.resetScroll()}updated(e){super.updated(e),(e.has("visibleItems")||e.has("items"))&&this.onVisibleItemsChange(),e.has("scrolledToTarget")&&this.scrolledToTarget&&(this.scrollToItem!=null||this.scrollToIndex!=null)&&this.dispatchEvent(new S)}onVisibleItemsChange(){this.visibleItems.every((t,s)=>this.visibleItems[s+1]==null||t+1===this.visibleItems[s+1])||(0,o.deepEqual)(this.visibleItems,this.lastNotOkVisibleItems)?(this.resetVisibleItemsDebouncer.cancel(),this.dispatchVisibleItemsEvent()):this.resetVisibleItemsDebouncer.run(()=>{this.lastNotOkVisibleItems=[...this.visibleItems],this.visibleItems=[],this.resetIntersectionObserver()})}dispatchVisibleItemsEvent(){var e;(e=this.cancelableDispatchEvent)===null||e===void 0||e.cancel(),this.cancelableDispatchEvent=(0,o.cancelable)((0,o.waitUntil)(()=>!this.scrolling)),this.cancelableDispatchEvent.then(()=>this.dispatchEvent(new T(this.visibleItems,this.visibleItems.map(t=>this.items[t])))).catch(()=>null)}};n.styles=D;a([(0,h.property)({type:Array})],n.prototype,"items",void 0);a([(0,h.property)({attribute:!1})],n.prototype,"renderItem",void 0);a([(0,h.property)({attribute:!1})],n.prototype,"getItemKey",void 0);a([(0,h.property)({type:Object})],n.prototype,"scrollToItem",void 0);a([(0,h.property)({type:Number})],n.prototype,"scrollToIndex",void 0);a([(0,h.property)({type:Boolean})],n.prototype,"internalScroll",void 0);a([(0,h.property)({type:Number})],n.prototype,"renderBeforeFirst",void 0);a([(0,h.property)({type:Number})],n.prototype,"renderAfterLast",void 0);a([(0,h.property)({type:Boolean})],n.prototype,"ensureScrollToTarget",void 0);a([(0,h.state)({hasChanged(l,e){return l!=null&&e==null||l.length!==e.length||l[0]!==e[0]}})],n.prototype,"visibleItems",void 0);a([(0,h.query)(".scrollable")],n.prototype,"internalScrollable",void 0);a([(0,h.query)(".items-container")],n.prototype,"itemsContainer",void 0);a([(0,h.state)()],n.prototype,"scrolledToTarget",void 0);a([(0,h.state)()],n.prototype,"scrolling",void 0);a([(0,h.state)({hasChanged:o.hasChanged})],n.prototype,"renderedIndexes",void 0);(0,$.customElement)("ft-infinite-scroll")(n);})();
41
+ `}prepareRenderIfNeeded(e){let t=this.renderApprovalTimeouts[e]!=null;this.inRenderRange(e)&&!t&&(this.renderApprovalTimeouts[e]=setTimeout(()=>{this.inRenderRange(e)?this.renderedIndexes.add(e):this.renderApprovalTimeouts[e]=void 0,this.requestUpdate()},300))}inRenderRange(e){return e>=this.visibleItems[0]-this.renderBeforeFirst&&e<=G(this.visibleItems)+this.renderAfterLast}isRendered(e){return this.renderedIndexes.has(this.items.indexOf(e))}resetScroll(e=!0){this.shouldRestoreScroll=!1,this.intersectionObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.internalScroll&&this.scrollable!==this.internalScrollable?this.scrollable=this.internalScrollable:!this.internalScroll&&e&&(this.scrollable=o.scrollHelper.findFirstScrollableParent(this.itemsContainer));let t=this.resolveScrollToIndex();this.renderedIndexes.add(t),this.scrollToTarget(t),this.scrollDoneDebouncer.run(()=>{this.ensureScrollToTarget&&t>=0&&this.scrollDebouncer.run(()=>{Math.abs(this.scrollable.scrollTop-this.getOffset(t))>5&&this.scrollToTarget(t)},500),this.scrollToTarget(t),this.scrolledToTarget=!0,this.shouldRestoreScroll=!0,this.resetIntersectionObserver()})}resolveScrollToIndex(){var e;let t=(e=this.scrollToIndex)!==null&&e!==void 0?e:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;return t>=this.items.length?-1:t}getItem(e){var t,s,i;return(s=(t=this.shadowRoot)===null||t===void 0?void 0:t.querySelector(`#item-${e}`))!==null&&s!==void 0?s:(i=this.shadowRoot)===null||i===void 0?void 0:i.querySelector("#item-0")}scrollToTarget(e){e<=0?(this.scrollable.scrollTop=0,this.scrollRestorationOffset=-this.getOffset(e)):(this.scrollable.scrollTop=this.getOffset(e),this.scrollRestorationOffset=0),this.scrollRestorationItem=e>=0?e:void 0}onScrollIntoView(e){var t;this.scrollDebouncer.cancel();let s=e.composedPath()[0],i=this.getOffset(s),r=(t=e.composedPath().find(c=>typeof c.matches=="function"&&c.matches(".item-container")))===null||t===void 0?void 0:t.getAttribute("data-item-index");this.scrollRestorationItem=r==null?this.scrollRestorationItem:+r,this.scrollRestorationOffset=i-this.getOffset(this.scrollRestorationItem),this.ignoreNextScrollEvent=!0,this.scrollable.scrollTop=i}getOffset(e){let t=typeof e=="number"?this.getItem(e):e;return t?o.scrollHelper.getAbsoluteScrollOffset(this.scrollable,t):0}appendItems(...e){this.items=[...this.items,...e]}prependItems(...e){this.items=[...e,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0}),this.resetScroll()},0)}disconnectedCallback(){super.disconnectedCallback(),this.scrollable=void 0,this.intersectionObserver.disconnect(),this.mutationObserver.disconnect(),this.shouldRestoreScroll=!1}resetIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]}),this.onMutation()}searchFirstVisibleItem(e,t,s,i){if(s=s??0,i=i??t.length-1,i<=s)return t[s];let r=Math.floor((i-s)/2)+s,c=t[r],d=this.getOffset(c);return d>e?this.searchFirstVisibleItem(e,t,s,r-1):d+c.clientHeight<e?this.searchFirstVisibleItem(e,t,r+1,i):c}get shouldRestoreScroll(){return this._shouldRestoreScroll}set shouldRestoreScroll(e){let t=e&&!this._shouldRestoreScroll;this._shouldRestoreScroll=e,t&&requestAnimationFrame(this.scrollAdjustment)}update(e){super.update(e),e.has("items")&&(this.renderedIndexes=new Set,this.renderApprovalTimeouts=[]),((e.has("scrollToItem")||e.has("scrollToIndex"))&&(this.scrollToItem!=null||this.scrollToIndex!=null)||e.has("internalScroll"))&&this.resetScroll()}updated(e){super.updated(e),(e.has("visibleItems")||e.has("items"))&&this.onVisibleItemsChange(),e.has("scrolledToTarget")&&this.scrolledToTarget&&(this.scrollToItem!=null||this.scrollToIndex!=null)&&this.dispatchEvent(new S)}onVisibleItemsChange(){this.visibleItems.every((t,s)=>this.visibleItems[s+1]==null||t+1===this.visibleItems[s+1])||(0,o.deepEqual)(this.visibleItems,this.lastNotOkVisibleItems)?(this.resetVisibleItemsDebouncer.cancel(),this.dispatchVisibleItemsEvent()):this.resetVisibleItemsDebouncer.run(()=>{this.lastNotOkVisibleItems=[...this.visibleItems],this.visibleItems=[],this.resetIntersectionObserver()})}dispatchVisibleItemsEvent(){var e;(e=this.cancelableDispatchEvent)===null||e===void 0||e.cancel(),this.cancelableDispatchEvent=(0,o.cancelable)((0,o.waitUntil)(()=>!this.scrolling)),this.cancelableDispatchEvent.then(()=>this.dispatchEvent(new T(this.visibleItems,this.visibleItems.map(t=>this.items[t])))).catch(()=>null)}};n.styles=D;a([(0,h.property)({type:Array})],n.prototype,"items",void 0);a([(0,h.property)({attribute:!1})],n.prototype,"renderItem",void 0);a([(0,h.property)({attribute:!1})],n.prototype,"getItemKey",void 0);a([(0,h.property)({type:Object})],n.prototype,"scrollToItem",void 0);a([(0,h.property)({type:Number})],n.prototype,"scrollToIndex",void 0);a([(0,h.property)({type:Boolean})],n.prototype,"internalScroll",void 0);a([(0,h.property)({type:Number})],n.prototype,"renderBeforeFirst",void 0);a([(0,h.property)({type:Number})],n.prototype,"renderAfterLast",void 0);a([(0,h.property)({type:Boolean})],n.prototype,"ensureScrollToTarget",void 0);a([(0,h.state)({hasChanged(l,e){return l!=null&&e==null||l.length!==e.length||l[0]!==e[0]}})],n.prototype,"visibleItems",void 0);a([(0,h.query)(".scrollable")],n.prototype,"internalScrollable",void 0);a([(0,h.query)(".items-container")],n.prototype,"itemsContainer",void 0);a([(0,h.state)()],n.prototype,"scrolledToTarget",void 0);a([(0,h.state)()],n.prototype,"scrolling",void 0);a([(0,h.state)({hasChanged:o.hasChanged})],n.prototype,"renderedIndexes",void 0);(0,$.customElement)("ft-infinite-scroll")(n);})();
@@ -87,7 +87,7 @@ Also for action icons.`,c.colorGray200),contentGlobalSubtle:t.extend("--ft-conte
87
87
  data-item-index="${r}">
88
88
  ${a?(()=>{let s=this.renderItem(e,r);return typeof s=="string"?co(s):s})():W}
89
89
  </div>
90
- `}prepareRenderIfNeeded(e){let r=this.renderApprovalTimeouts[e]!=null;this.inRenderRange(e)&&!r&&(this.renderApprovalTimeouts[e]=setTimeout(()=>{this.inRenderRange(e)?this.renderedIndexes.add(e):this.renderApprovalTimeouts[e]=void 0,this.requestUpdate()},300))}inRenderRange(e){return e>=this.visibleItems[0]-this.renderBeforeFirst&&e<=Bd(this.visibleItems)+this.renderAfterLast}isRendered(e){return this.renderedIndexes.has(this.items.indexOf(e))}resetScroll(e=!0){this.shouldRestoreScroll=!1,this.intersectionObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.internalScroll&&this.scrollable!==this.internalScrollable?this.scrollable=this.internalScrollable:!this.internalScroll&&e&&(this.scrollable=yt.findFirstScrollableParent(this.itemsContainer));let r=this.resolveScrollToIndex();this.renderedIndexes.add(r),this.scrollToTarget(r),this.scrollDoneDebouncer.run(()=>{this.ensureScrollToTarget&&r>=0&&this.scrollDebouncer.run(()=>{Math.abs(this.scrollable.scrollTop-this.getOffset(r))>5&&this.scrollToTarget(r)},500),this.scrollToTarget(r),this.scrolledToTarget=!0,this.shouldRestoreScroll=!0,this.resetIntersectionObserver()})}resolveScrollToIndex(){var e;let r=(e=this.scrollToIndex)!==null&&e!==void 0?e:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;return r>=this.items.length?-1:r}getItem(e){var r,n,a;return(n=(r=this.shadowRoot)===null||r===void 0?void 0:r.querySelector(`#item-${e}`))!==null&&n!==void 0?n:(a=this.shadowRoot)===null||a===void 0?void 0:a.querySelector("#item-0")}scrollToTarget(e){e<=0?(this.scrollable.scrollTop=0,this.scrollRestorationOffset=-this.getOffset(e)):(this.scrollable.scrollTop=this.getOffset(e),this.scrollRestorationOffset=0),this.scrollRestorationItem=e>=0?e:void 0}onScrollIntoView(e){var r;this.scrollDebouncer.cancel();let n=e.composedPath()[0],a=this.getOffset(n),i=(r=e.composedPath().find(s=>typeof s.matches=="function"&&s.matches(".item-container")))===null||r===void 0?void 0:r.getAttribute("data-item-index");this.scrollRestorationItem=i==null?this.scrollRestorationItem:+i,this.scrollRestorationOffset=a-this.getOffset(this.scrollRestorationItem),this.scrollable.scrollTop=a}getOffset(e){let r=typeof e=="number"?this.getItem(e):e;return r?yt.getAbsoluteScrollOffset(this.scrollable,r):0}appendItems(...e){this.items=[...this.items,...e]}prependItems(...e){this.items=[...e,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0}),this.resetScroll()},0)}disconnectedCallback(){super.disconnectedCallback(),this.scrollable=void 0,this.intersectionObserver.disconnect(),this.mutationObserver.disconnect(),this.shouldRestoreScroll=!1}resetIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]}),this.onMutation()}searchFirstVisibleItem(e,r,n,a){if(n=n??0,a=a??r.length-1,a<=n)return r[n];let i=Math.floor((a-n)/2)+n,s=r[i],d=this.getOffset(s);return d>e?this.searchFirstVisibleItem(e,r,n,i-1):d+s.clientHeight<e?this.searchFirstVisibleItem(e,r,i+1,a):s}get shouldRestoreScroll(){return this._shouldRestoreScroll}set shouldRestoreScroll(e){let r=e&&!this._shouldRestoreScroll;this._shouldRestoreScroll=e,r&&requestAnimationFrame(this.scrollAdjustment)}update(e){super.update(e),e.has("items")&&(this.renderedIndexes=new Set,this.renderApprovalTimeouts=[]),((e.has("scrollToItem")||e.has("scrollToIndex"))&&(this.scrollToItem!=null||this.scrollToIndex!=null)||e.has("internalScroll"))&&this.resetScroll()}updated(e){super.updated(e),(e.has("visibleItems")||e.has("items"))&&this.onVisibleItemsChange(),e.has("scrolledToTarget")&&this.scrolledToTarget&&(this.scrollToItem!=null||this.scrollToIndex!=null)&&this.dispatchEvent(new Wn)}onVisibleItemsChange(){this.visibleItems.every((r,n)=>this.visibleItems[n+1]==null||r+1===this.visibleItems[n+1])||Ve(this.visibleItems,this.lastNotOkVisibleItems)?(this.resetVisibleItemsDebouncer.cancel(),this.dispatchVisibleItemsEvent()):this.resetVisibleItemsDebouncer.run(()=>{this.lastNotOkVisibleItems=[...this.visibleItems],this.visibleItems=[],this.resetIntersectionObserver()})}dispatchVisibleItemsEvent(){var e;(e=this.cancelableDispatchEvent)===null||e===void 0||e.cancel(),this.cancelableDispatchEvent=kt(So(()=>!this.scrolling)),this.cancelableDispatchEvent.then(()=>this.dispatchEvent(new Bn(this.visibleItems,this.visibleItems.map(r=>this.items[r])))).catch(()=>null)}};H.styles=Bs;K([M({type:Array})],H.prototype,"items",void 0);K([M({attribute:!1})],H.prototype,"renderItem",void 0);K([M({attribute:!1})],H.prototype,"getItemKey",void 0);K([M({type:Object})],H.prototype,"scrollToItem",void 0);K([M({type:Number})],H.prototype,"scrollToIndex",void 0);K([M({type:Boolean})],H.prototype,"internalScroll",void 0);K([M({type:Number})],H.prototype,"renderBeforeFirst",void 0);K([M({type:Number})],H.prototype,"renderAfterLast",void 0);K([M({type:Boolean})],H.prototype,"ensureScrollToTarget",void 0);K([ve({hasChanged(o,e){return o!=null&&e==null||o.length!==e.length||o[0]!==e[0]}})],H.prototype,"visibleItems",void 0);K([Or(".scrollable")],H.prototype,"internalScrollable",void 0);K([Or(".items-container")],H.prototype,"itemsContainer",void 0);K([ve()],H.prototype,"scrolledToTarget",void 0);K([ve()],H.prototype,"scrolling",void 0);K([ve({hasChanged:Ge})],H.prototype,"renderedIndexes",void 0);Eo("ft-infinite-scroll")(H);})();
90
+ `}prepareRenderIfNeeded(e){let r=this.renderApprovalTimeouts[e]!=null;this.inRenderRange(e)&&!r&&(this.renderApprovalTimeouts[e]=setTimeout(()=>{this.inRenderRange(e)?this.renderedIndexes.add(e):this.renderApprovalTimeouts[e]=void 0,this.requestUpdate()},300))}inRenderRange(e){return e>=this.visibleItems[0]-this.renderBeforeFirst&&e<=Bd(this.visibleItems)+this.renderAfterLast}isRendered(e){return this.renderedIndexes.has(this.items.indexOf(e))}resetScroll(e=!0){this.shouldRestoreScroll=!1,this.intersectionObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.internalScroll&&this.scrollable!==this.internalScrollable?this.scrollable=this.internalScrollable:!this.internalScroll&&e&&(this.scrollable=yt.findFirstScrollableParent(this.itemsContainer));let r=this.resolveScrollToIndex();this.renderedIndexes.add(r),this.scrollToTarget(r),this.scrollDoneDebouncer.run(()=>{this.ensureScrollToTarget&&r>=0&&this.scrollDebouncer.run(()=>{Math.abs(this.scrollable.scrollTop-this.getOffset(r))>5&&this.scrollToTarget(r)},500),this.scrollToTarget(r),this.scrolledToTarget=!0,this.shouldRestoreScroll=!0,this.resetIntersectionObserver()})}resolveScrollToIndex(){var e;let r=(e=this.scrollToIndex)!==null&&e!==void 0?e:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;return r>=this.items.length?-1:r}getItem(e){var r,n,a;return(n=(r=this.shadowRoot)===null||r===void 0?void 0:r.querySelector(`#item-${e}`))!==null&&n!==void 0?n:(a=this.shadowRoot)===null||a===void 0?void 0:a.querySelector("#item-0")}scrollToTarget(e){e<=0?(this.scrollable.scrollTop=0,this.scrollRestorationOffset=-this.getOffset(e)):(this.scrollable.scrollTop=this.getOffset(e),this.scrollRestorationOffset=0),this.scrollRestorationItem=e>=0?e:void 0}onScrollIntoView(e){var r;this.scrollDebouncer.cancel();let n=e.composedPath()[0],a=this.getOffset(n),i=(r=e.composedPath().find(s=>typeof s.matches=="function"&&s.matches(".item-container")))===null||r===void 0?void 0:r.getAttribute("data-item-index");this.scrollRestorationItem=i==null?this.scrollRestorationItem:+i,this.scrollRestorationOffset=a-this.getOffset(this.scrollRestorationItem),this.ignoreNextScrollEvent=!0,this.scrollable.scrollTop=a}getOffset(e){let r=typeof e=="number"?this.getItem(e):e;return r?yt.getAbsoluteScrollOffset(this.scrollable,r):0}appendItems(...e){this.items=[...this.items,...e]}prependItems(...e){this.items=[...e,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0}),this.resetScroll()},0)}disconnectedCallback(){super.disconnectedCallback(),this.scrollable=void 0,this.intersectionObserver.disconnect(),this.mutationObserver.disconnect(),this.shouldRestoreScroll=!1}resetIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]}),this.onMutation()}searchFirstVisibleItem(e,r,n,a){if(n=n??0,a=a??r.length-1,a<=n)return r[n];let i=Math.floor((a-n)/2)+n,s=r[i],d=this.getOffset(s);return d>e?this.searchFirstVisibleItem(e,r,n,i-1):d+s.clientHeight<e?this.searchFirstVisibleItem(e,r,i+1,a):s}get shouldRestoreScroll(){return this._shouldRestoreScroll}set shouldRestoreScroll(e){let r=e&&!this._shouldRestoreScroll;this._shouldRestoreScroll=e,r&&requestAnimationFrame(this.scrollAdjustment)}update(e){super.update(e),e.has("items")&&(this.renderedIndexes=new Set,this.renderApprovalTimeouts=[]),((e.has("scrollToItem")||e.has("scrollToIndex"))&&(this.scrollToItem!=null||this.scrollToIndex!=null)||e.has("internalScroll"))&&this.resetScroll()}updated(e){super.updated(e),(e.has("visibleItems")||e.has("items"))&&this.onVisibleItemsChange(),e.has("scrolledToTarget")&&this.scrolledToTarget&&(this.scrollToItem!=null||this.scrollToIndex!=null)&&this.dispatchEvent(new Wn)}onVisibleItemsChange(){this.visibleItems.every((r,n)=>this.visibleItems[n+1]==null||r+1===this.visibleItems[n+1])||Ve(this.visibleItems,this.lastNotOkVisibleItems)?(this.resetVisibleItemsDebouncer.cancel(),this.dispatchVisibleItemsEvent()):this.resetVisibleItemsDebouncer.run(()=>{this.lastNotOkVisibleItems=[...this.visibleItems],this.visibleItems=[],this.resetIntersectionObserver()})}dispatchVisibleItemsEvent(){var e;(e=this.cancelableDispatchEvent)===null||e===void 0||e.cancel(),this.cancelableDispatchEvent=kt(So(()=>!this.scrolling)),this.cancelableDispatchEvent.then(()=>this.dispatchEvent(new Bn(this.visibleItems,this.visibleItems.map(r=>this.items[r])))).catch(()=>null)}};H.styles=Bs;K([M({type:Array})],H.prototype,"items",void 0);K([M({attribute:!1})],H.prototype,"renderItem",void 0);K([M({attribute:!1})],H.prototype,"getItemKey",void 0);K([M({type:Object})],H.prototype,"scrollToItem",void 0);K([M({type:Number})],H.prototype,"scrollToIndex",void 0);K([M({type:Boolean})],H.prototype,"internalScroll",void 0);K([M({type:Number})],H.prototype,"renderBeforeFirst",void 0);K([M({type:Number})],H.prototype,"renderAfterLast",void 0);K([M({type:Boolean})],H.prototype,"ensureScrollToTarget",void 0);K([ve({hasChanged(o,e){return o!=null&&e==null||o.length!==e.length||o[0]!==e[0]}})],H.prototype,"visibleItems",void 0);K([Or(".scrollable")],H.prototype,"internalScrollable",void 0);K([Or(".items-container")],H.prototype,"itemsContainer",void 0);K([ve()],H.prototype,"scrolledToTarget",void 0);K([ve()],H.prototype,"scrolling",void 0);K([ve({hasChanged:Ge})],H.prototype,"renderedIndexes",void 0);Eo("ft-infinite-scroll")(H);})();
91
91
  /*! Bundled license information:
92
92
 
93
93
  @webcomponents/scoped-custom-element-registry/src/scoped-custom-element-registry.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-infinite-scroll",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
4
4
  "description": "An infinite scroller.",
5
5
  "keywords": [
6
6
  "Lit"
@@ -19,8 +19,8 @@
19
19
  "url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
20
20
  },
21
21
  "dependencies": {
22
- "@fluid-topics/ft-wc-utils": "1.2.8",
22
+ "@fluid-topics/ft-wc-utils": "1.2.9",
23
23
  "lit": "3.1.0"
24
24
  },
25
- "gitHead": "26d2cbd5aba536de63759b72e1c171449519d74e"
25
+ "gitHead": "d845852f5b176916a556b5a23d38be9472fa1fc6"
26
26
  }