@fluid-topics/ft-infinite-scroll 0.3.69 → 0.3.71
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PropertyValues, TemplateResult } from "lit";
|
|
2
|
+
import { KeyFn } from "lit/directives/repeat.js";
|
|
2
3
|
import { FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
3
4
|
import { FtInfiniteScrollProperties } from "./ft-infinite-scroll.properties";
|
|
4
5
|
export declare type VisibleItems<T> = {
|
|
@@ -15,6 +16,7 @@ export declare class FtInfiniteScroll<T> extends FtLitElement implements FtInfin
|
|
|
15
16
|
static styles: import("lit").CSSResult;
|
|
16
17
|
items: Array<T>;
|
|
17
18
|
renderItem: (item: T, index: number) => TemplateResult | string;
|
|
19
|
+
getItemKey: KeyFn<T>;
|
|
18
20
|
scrollToItem?: T;
|
|
19
21
|
scrollToIndex?: number;
|
|
20
22
|
internalScroll: boolean;
|
|
@@ -31,6 +31,7 @@ export class FtInfiniteScroll extends FtLitElement {
|
|
|
31
31
|
super(...arguments);
|
|
32
32
|
this.items = [];
|
|
33
33
|
this.renderItem = () => html ``;
|
|
34
|
+
this.getItemKey = (item, index) => `${index} - ${JSON.stringify(item)}`;
|
|
34
35
|
this.internalScroll = false;
|
|
35
36
|
this.renderBeforeFirst = 1;
|
|
36
37
|
this.renderAfterLast = 1;
|
|
@@ -56,19 +57,18 @@ export class FtInfiniteScroll extends FtLitElement {
|
|
|
56
57
|
};
|
|
57
58
|
this.intersectionObserver = new IntersectionObserver(this.onVisibilityChange);
|
|
58
59
|
this.onResize = (resizables) => {
|
|
59
|
-
var _a;
|
|
60
|
+
var _a, _b, _c;
|
|
60
61
|
this.triggerFindScrollableParent();
|
|
61
62
|
resizables = resizables.sort((a, b) => a.contentRect.top - b.contentRect.top);
|
|
63
|
+
const noOverflowAnchor = this.scrollable && ((_a = getComputedStyle(this.scrollable).overflowAnchor) !== null && _a !== void 0 ? _a : "none") === "none";
|
|
62
64
|
for (const resizable of resizables) {
|
|
63
65
|
const index = +resizable.target.parentElement.getAttribute("data-item-index");
|
|
64
66
|
const oldHeight = resizable.target.parentElement.clientHeight;
|
|
65
67
|
const newHeight = resizable.contentRect.height;
|
|
66
|
-
if (this.alreadyRenderedIndexes.has(index)) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.scrollable.scrollTop += Math.ceil(newHeight - oldHeight);
|
|
71
|
-
}
|
|
68
|
+
if (this.alreadyRenderedIndexes.has(index) || resizable.target.classList.contains("rendered")) {
|
|
69
|
+
const isAboveScrollTop = this.getOffset(resizable.target.parentElement) + oldHeight < ((_c = (_b = this.scrollable) === null || _b === void 0 ? void 0 : _b.scrollTop) !== null && _c !== void 0 ? _c : 0);
|
|
70
|
+
if (noOverflowAnchor && isAboveScrollTop) {
|
|
71
|
+
this.scrollable.scrollTop += Math.ceil(newHeight - oldHeight);
|
|
72
72
|
}
|
|
73
73
|
resizable.target.parentElement.style.height = newHeight + "px";
|
|
74
74
|
}
|
|
@@ -91,7 +91,7 @@ export class FtInfiniteScroll extends FtLitElement {
|
|
|
91
91
|
<div class="items-container ${this.internalScroll ? "scrollable" : ""}"
|
|
92
92
|
tabindex="-1"
|
|
93
93
|
@find-scrollable-parent=${this.findScrollableParent}>
|
|
94
|
-
${repeat(this.items, (item, index) => this.renderItemContainer(item, index))}
|
|
94
|
+
${repeat(this.items, (item, index) => this.getItemKey(item, index), (item, index) => this.renderItemContainer(item, index))}
|
|
95
95
|
</div>
|
|
96
96
|
`;
|
|
97
97
|
}
|
|
@@ -258,6 +258,9 @@ __decorate([
|
|
|
258
258
|
__decorate([
|
|
259
259
|
property({ attribute: false })
|
|
260
260
|
], FtInfiniteScroll.prototype, "renderItem", void 0);
|
|
261
|
+
__decorate([
|
|
262
|
+
property({ attribute: false })
|
|
263
|
+
], FtInfiniteScroll.prototype, "getItemKey", void 0);
|
|
261
264
|
__decorate([
|
|
262
265
|
property({ type: Object })
|
|
263
266
|
], FtInfiniteScroll.prototype, "scrollToItem", void 0);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!function(t,e,i,s,l
|
|
1
|
+
!function(t,e,i,s,n,l){const r={padding:e.FtCssVariableFactory.create("--ft-infinite-scroll-padding","SIZE","0"),itemsGap:e.FtCssVariableFactory.create("--ft-infinite-scroll-items-gap","SIZE","4px")},o=i.css`
|
|
2
2
|
.items-container {
|
|
3
3
|
position: relative;
|
|
4
4
|
padding: ${r.padding};
|
|
@@ -29,25 +29,25 @@
|
|
|
29
29
|
width: 0;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
.resizable
|
|
32
|
+
.item-container, .resizable.rendered {
|
|
33
33
|
min-height: .1px;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
.rendered {
|
|
37
37
|
display: flow-root;
|
|
38
38
|
}
|
|
39
|
-
`;var h=function(t,e,i,s){for(var l
|
|
39
|
+
`;var h=function(t,e,i,s){for(var n,l=arguments.length,r=l<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,o=t.length-1;o>=0;o--)(n=t[o])&&(r=(l<3?n(r):l>3?n(e,i,r):n(e,i))||r);return l>3&&r&&Object.defineProperty(e,i,r),r};class a extends CustomEvent{constructor(t,e){super("visible-items-change",{detail:{visibleIndexes:t,visibleItems:e}})}}class d extends Event{constructor(){super("scrolled-to-target")}}class c extends e.FtLitElement{constructor(){super(...arguments),this.items=[],this.renderItem=()=>i.html``,this.getItemKey=(t,e)=>`${e} - ${JSON.stringify(t)}`,this.internalScroll=!1,this.renderBeforeFirst=1,this.renderAfterLast=1,this.visibleItems=[],this.scrolledToTarget=!1,this.alreadyRenderedIndexes=new Set,this.scrollDebouncer=new e.Debouncer(5),this.scrollDoneDebouncer=new e.Debouncer(10),this.onVisibilityChange=t=>{let e=new Set(this.visibleItems),i=new Set;for(let s of t){let t=+s.target.attributes.getNamedItem("data-item-index").value;s.intersectionRect.height>0?(e.add(t),i.add(t)):i.has(t)||e.delete(t)}this.visibleItems=[...e].sort(((t,e)=>t-e))},this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange),this.onResize=t=>{var e,i,s;this.triggerFindScrollableParent(),t=t.sort(((t,e)=>t.contentRect.top-e.contentRect.top));const n=this.scrollable&&"none"===(null!==(e=getComputedStyle(this.scrollable).overflowAnchor)&&void 0!==e?e:"none");for(const e of t){const t=+e.target.parentElement.getAttribute("data-item-index"),l=e.target.parentElement.clientHeight,r=e.contentRect.height;if(this.alreadyRenderedIndexes.has(t)||e.target.classList.contains("rendered")){const t=this.getOffset(e.target.parentElement)+l<(null!==(s=null===(i=this.scrollable)||void 0===i?void 0:i.scrollTop)&&void 0!==s?s:0);n&&t&&(this.scrollable.scrollTop+=Math.ceil(r-l)),e.target.parentElement.style.height=r+"px"}}},this.resizeObserver=new ResizeObserver(this.onResize),this.onMutation=()=>{[...this.itemsContainer.children].forEach((t=>{this.intersectionObserver.observe(t),this.resizeObserver.observe(t.children.item(0))}))},this.mutationObserver=new MutationObserver(this.onMutation)}get scrollable(){return this.internalScroll?this.internalScrollable:this.firstScrollableParent}render(){return i.html`
|
|
40
40
|
<div class="items-container ${this.internalScroll?"scrollable":""}"
|
|
41
41
|
tabindex="-1"
|
|
42
42
|
@find-scrollable-parent=${this.findScrollableParent}>
|
|
43
|
-
${
|
|
43
|
+
${n.repeat(this.items,((t,e)=>this.getItemKey(t,e)),((t,e)=>this.renderItemContainer(t,e)))}
|
|
44
44
|
</div>
|
|
45
|
-
`}renderItemContainer(t,e){const s=this.scrolledToTarget&&this.visibleItems.includes(e),
|
|
45
|
+
`}renderItemContainer(t,e){const s=this.scrolledToTarget&&this.visibleItems.includes(e),n=this.alreadyRenderedIndexes.has(e)||this.scrolledToTarget&&e>=this.visibleItems[0]-this.renderBeforeFirst&&e<=(null!=(r=this.visibleItems)?r:[])[(null!=r?r:[]).length-1]+this.renderAfterLast;var r;n&&this.alreadyRenderedIndexes.add(e);return i.html`
|
|
46
46
|
<div id="item-${e}"
|
|
47
47
|
class="item-container"
|
|
48
48
|
data-item-index="${e}">
|
|
49
|
-
<div class="resizable ${s?"visible":""} ${
|
|
50
|
-
${
|
|
49
|
+
<div class="resizable ${s?"visible":""} ${n?"rendered":""}">
|
|
50
|
+
${n?(()=>{const s=this.renderItem(t,e);return"string"==typeof s?i.html`${l.unsafeHTML(s)}`:s})():null}
|
|
51
51
|
</div>
|
|
52
52
|
</div>
|
|
53
|
-
`}resetScroll(){this.triggerFindScrollableParent(),this.intersectionObserver.disconnect(),this.resizeObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.scrollDebouncer.run((()=>{var t;let e=null!==(t=this.scrollToIndex)&&void 0!==t?t:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;e>=this.items.length&&(e=-1);let i=this.getItem(e);this.scrollToTarget(i),this.onMutation(),this.scrollDoneDebouncer.run((()=>{this.scrolledToTarget=!0}))}))}getItem(t){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(`#item-${t}`)}scrollToTarget(t){var e;if(t){let i=+(null!==(e=t.getAttribute("data-item-index"))&&void 0!==e?e:"0");this.scrollable&&0===i?this.scrollable.scrollTop=0:t.scrollIntoView({block:"start"})}}getOffset(t){var e;let i=0,s=t;for(;s&&s.offsetParent!==this.scrollable.offsetParent;)i+=s.offsetTop,s=s.offsetParent;return i+(null!==(e=null==s?void 0:s.offsetTop)&&void 0!==e?e:0)-this.scrollable.offsetTop}appendItems(...t){this.items=[...this.items,...t]}prependItems(...t){this.items=[...t,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout((()=>{this.triggerFindScrollableParent(),this.initIntersectionObserver(),this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0})}),0)}initIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]})}triggerFindScrollableParent(){var t;null===(t=this.itemsContainer)||void 0===t||t.dispatchEvent(new Event("find-scrollable-parent",{composed:!0}))}findScrollableParent(t){let e,i;t.stopPropagation();for(let s of t.composedPath()){const t=s,
|
|
53
|
+
`}resetScroll(){this.triggerFindScrollableParent(),this.intersectionObserver.disconnect(),this.resizeObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.scrollDebouncer.run((()=>{var t;let e=null!==(t=this.scrollToIndex)&&void 0!==t?t:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;e>=this.items.length&&(e=-1);let i=this.getItem(e);this.scrollToTarget(i),this.onMutation(),this.scrollDoneDebouncer.run((()=>{this.scrolledToTarget=!0}))}))}getItem(t){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(`#item-${t}`)}scrollToTarget(t){var e;if(t){let i=+(null!==(e=t.getAttribute("data-item-index"))&&void 0!==e?e:"0");this.scrollable&&0===i?this.scrollable.scrollTop=0:t.scrollIntoView({block:"start"})}}getOffset(t){var e;let i=0,s=t;for(;s&&s.offsetParent!==this.scrollable.offsetParent;)i+=s.offsetTop,s=s.offsetParent;return i+(null!==(e=null==s?void 0:s.offsetTop)&&void 0!==e?e:0)-this.scrollable.offsetTop}appendItems(...t){this.items=[...this.items,...t]}prependItems(...t){this.items=[...t,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout((()=>{this.triggerFindScrollableParent(),this.initIntersectionObserver(),this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0})}),0)}initIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]})}triggerFindScrollableParent(){var t;null===(t=this.itemsContainer)||void 0===t||t.dispatchEvent(new Event("find-scrollable-parent",{composed:!0}))}findScrollableParent(t){let e,i;t.stopPropagation();for(let s of t.composedPath()){const t=s,n=this.elementCanScroll(t);if(t.clientHeight&&t.clientHeight<t.scrollHeight&&n){e=t;break}n&&(i=t)}let s=e||i;s!==this.firstScrollableParent&&(this.firstScrollableParent=s,this.initIntersectionObserver(),this.resetScroll())}elementCanScroll(t){try{return["auto","scroll"].includes(getComputedStyle(t).overflowY)}catch(t){return!1}}disconnectedCallback(){super.disconnectedCallback(),this.intersectionObserver.disconnect(),this.resizeObserver.disconnect(),this.mutationObserver.disconnect()}firstUpdated(t){super.firstUpdated(t),this.resetScroll()}update(t){super.update(t),t.has("items")&&(this.alreadyRenderedIndexes=new Set),(t.has("scrollToItem")||t.has("scrollToIndex")&&(null!=this.scrollToItem||null!=this.scrollToIndex))&&this.resetScroll()}updated(t){super.updated(t),(t.has("visibleItems")||t.has("items"))&&this.dispatchEvent(new a(this.visibleItems,this.visibleItems.map((t=>this.items[t])))),t.has("scrolledToTarget")&&this.scrolledToTarget&&(null!=this.scrollToItem||null!=this.scrollToIndex)&&this.dispatchEvent(new d)}}c.styles=o,h([s.property({type:Array})],c.prototype,"items",void 0),h([s.property({attribute:!1})],c.prototype,"renderItem",void 0),h([s.property({attribute:!1})],c.prototype,"getItemKey",void 0),h([s.property({type:Object})],c.prototype,"scrollToItem",void 0),h([s.property({type:Number})],c.prototype,"scrollToIndex",void 0),h([s.property({type:Boolean})],c.prototype,"internalScroll",void 0),h([s.property({type:Number})],c.prototype,"renderBeforeFirst",void 0),h([s.property({type:Number})],c.prototype,"renderAfterLast",void 0),h([s.state({hasChanged:(t,e)=>null!=t&&null==e||t.length!==e.length||t[0]!==e[0]})],c.prototype,"visibleItems",void 0),h([s.query(".scrollable")],c.prototype,"internalScrollable",void 0),h([s.query(".items-container")],c.prototype,"itemsContainer",void 0),h([s.state()],c.prototype,"scrolledToTarget",void 0),e.customElement("ft-infinite-scroll")(c),t.FtInfiniteScroll=c,t.FtInfiniteScrollCssVariables=r,t.ScrolledToTargetEvent=d,t.VisibleItemsChangeEvent=a,t.styles=o,Object.defineProperty(t,"t",{value:!0})}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators,ftGlobals.litRepeat,ftGlobals.litUnsafeHTML);
|
|
@@ -57,7 +57,7 @@ const a=window,h=a.ShadowRoot&&(void 0===a.ShadyCSS||a.ShadyCSS.nativeShadow)&&"
|
|
|
57
57
|
* Copyright 2017 Google LLC
|
|
58
58
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
59
59
|
*/
|
|
60
|
-
var
|
|
60
|
+
var $;E.finalized=!0,E.elementProperties=new Map,E.elementStyles=[],E.shadowRootOptions={mode:"open"},null==g||g({ReactiveElement:E}),(null!==(m=x.reactiveElementVersions)&&void 0!==m?m:x.reactiveElementVersions=[]).push("1.4.1");const S=window,R=S.trustedTypes,M=R?R.createPolicy("lit-html",{createHTML:t=>t}):void 0,k=`lit$${(Math.random()+"").slice(9)}$`,U="?"+k,A=`<${U}>`,F=document,j=(t="")=>F.createComment(t),L=t=>null===t||"object"!=typeof t&&"function"!=typeof t,T=Array.isArray,I=t=>T(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),_=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,B=/-->/g,W=/>/g,K=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),z=/'/g,D=/"/g,P=/^(?:script|style|textarea|title)$/i,H=(t=>(e,...i)=>({_$litType$:t,strings:e,values:i}))(1),Z=Symbol.for("lit-noChange"),J=Symbol.for("lit-nothing"),V=new WeakMap,q=F.createTreeWalker(F,129,null,!1),G=(t,e)=>{const i=t.length-1,s=[];let n,r=2===e?"<svg>":"",o=_;for(let e=0;e<i;e++){const i=t[e];let l,a,h=-1,c=0;for(;c<i.length&&(o.lastIndex=c,a=o.exec(i),null!==a);)c=o.lastIndex,o===_?"!--"===a[1]?o=B:void 0!==a[1]?o=W:void 0!==a[2]?(P.test(a[2])&&(n=RegExp("</"+a[2],"g")),o=K):void 0!==a[3]&&(o=K):o===K?">"===a[0]?(o=null!=n?n:_,h=-1):void 0===a[1]?h=-2:(h=o.lastIndex-a[2].length,l=a[1],o=void 0===a[3]?K:'"'===a[3]?D:z):o===D||o===z?o=K:o===B||o===W?o=_:(o=K,n=void 0);const u=o===K&&t[e+1].startsWith("/>")?" ":"";r+=o===_?i+A:h>=0?(s.push(l),i.slice(0,h)+"$lit$"+i.slice(h)+k+u):i+k+(-2===h?(s.push(void 0),e):u)}const l=r+(t[i]||"<?>")+(2===e?"</svg>":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==M?M.createHTML(l):l,s]};class X{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let n=0,r=0;const o=t.length-1,l=this.parts,[a,h]=G(t,e);if(this.el=X.createElement(a,i),q.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(s=q.nextNode())&&l.length<o;){if(1===s.nodeType){if(s.hasAttributes()){const t=[];for(const e of s.getAttributeNames())if(e.endsWith("$lit$")||e.startsWith(k)){const i=h[r++];if(t.push(e),void 0!==i){const t=s.getAttribute(i.toLowerCase()+"$lit$").split(k),e=/([.?@])?(.*)/.exec(i);l.push({type:1,index:n,name:e[2],strings:t,ctor:"."===e[1]?it:"?"===e[1]?nt:"@"===e[1]?rt:et})}else l.push({type:6,index:n})}for(const e of t)s.removeAttribute(e)}if(P.test(s.tagName)){const t=s.textContent.split(k),e=t.length-1;if(e>0){s.textContent=R?R.emptyScript:"";for(let i=0;i<e;i++)s.append(t[i],j()),q.nextNode(),l.push({type:2,index:++n});s.append(t[e],j())}}}else if(8===s.nodeType)if(s.data===U)l.push({type:2,index:n});else{let t=-1;for(;-1!==(t=s.data.indexOf(k,t+1));)l.push({type:7,index:n}),t+=k.length-1}n++}}static createElement(t,e){const i=F.createElement("template");return i.innerHTML=t,i}}function Q(t,e,i=t,s){var n,r,o,l;if(e===Z)return e;let a=void 0!==s?null===(n=i._$Co)||void 0===n?void 0:n[s]:i._$Cl;const h=L(e)?void 0:e._$litDirective$;return(null==a?void 0:a.constructor)!==h&&(null===(r=null==a?void 0:a._$AO)||void 0===r||r.call(a,!1),void 0===h?a=void 0:(a=new h(t),a._$AT(t,i,s)),void 0!==s?(null!==(o=(l=i)._$Co)&&void 0!==o?o:l._$Co=[])[s]=a:i._$Cl=a),void 0!==a&&(e=Q(t,a._$AS(t,e.values),a,s)),e}class Y{constructor(t,e){this.u=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}v(t){var e;const{el:{content:i},parts:s}=this._$AD,n=(null!==(e=null==t?void 0:t.creationScope)&&void 0!==e?e:F).importNode(i,!0);q.currentNode=n;let r=q.nextNode(),o=0,l=0,a=s[0];for(;void 0!==a;){if(o===a.index){let e;2===a.type?e=new tt(r,r.nextSibling,this,t):1===a.type?e=new a.ctor(r,a.name,a.strings,this,t):6===a.type&&(e=new ot(r,this,t)),this.u.push(e),a=s[++l]}o!==(null==a?void 0:a.index)&&(r=q.nextNode(),o++)}return n}p(t){let e=0;for(const i of this.u)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class tt{constructor(t,e,i,s){var n;this.type=2,this._$AH=J,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=s,this._$Cm=null===(n=null==s?void 0:s.isConnected)||void 0===n||n}get _$AU(){var t,e;return null!==(e=null===(t=this._$AM)||void 0===t?void 0:t._$AU)&&void 0!==e?e:this._$Cm}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=Q(this,t,e),L(t)?t===J||null==t||""===t?(this._$AH!==J&&this._$AR(),this._$AH=J):t!==this._$AH&&t!==Z&&this.g(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):I(t)?this.k(t):this.g(t)}O(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}g(t){this._$AH!==J&&L(this._$AH)?this._$AA.nextSibling.data=t:this.T(F.createTextNode(t)),this._$AH=t}$(t){var e;const{values:i,_$litType$:s}=t,n="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=X.createElement(s.h,this.options)),s);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===n)this._$AH.p(i);else{const t=new Y(n,this),e=t.v(this.options);t.p(i),this.T(e),this._$AH=t}}_$AC(t){let e=V.get(t.strings);return void 0===e&&V.set(t.strings,e=new X(t)),e}k(t){T(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const n of t)s===e.length?e.push(i=new tt(this.O(j()),this.O(j()),this,this.options)):i=e[s],i._$AI(n),s++;s<e.length&&(this._$AR(i&&i._$AB.nextSibling,s),e.length=s)}_$AR(t=this._$AA.nextSibling,e){var i;for(null===(i=this._$AP)||void 0===i||i.call(this,!1,!0,e);t&&t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){var e;void 0===this._$AM&&(this._$Cm=t,null===(e=this._$AP)||void 0===e||e.call(this,t))}}class et{constructor(t,e,i,s,n){this.type=1,this._$AH=J,this._$AN=void 0,this.element=t,this.name=e,this._$AM=s,this.options=n,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=J}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,s){const n=this.strings;let r=!1;if(void 0===n)t=Q(this,t,e,0),r=!L(t)||t!==this._$AH&&t!==Z,r&&(this._$AH=t);else{const s=t;let o,l;for(t=n[0],o=0;o<n.length-1;o++)l=Q(this,s[i+o],e,o),l===Z&&(l=this._$AH[o]),r||(r=!L(l)||l!==this._$AH[o]),l===J?t=J:t!==J&&(t+=(null!=l?l:"")+n[o+1]),this._$AH[o]=l}r&&!s&&this.j(t)}j(t){t===J?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,null!=t?t:"")}}class it extends et{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===J?void 0:t}}const st=R?R.emptyScript:"";class nt extends et{constructor(){super(...arguments),this.type=4}j(t){t&&t!==J?this.element.setAttribute(this.name,st):this.element.removeAttribute(this.name)}}class rt extends et{constructor(t,e,i,s,n){super(t,e,i,s,n),this.type=5}_$AI(t,e=this){var i;if((t=null!==(i=Q(this,t,e,0))&&void 0!==i?i:J)===Z)return;const s=this._$AH,n=t===J&&s!==J||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,r=t!==J&&(s===J||n);n&&this.element.removeEventListener(this.name,this,s),r&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var e,i;"function"==typeof this._$AH?this._$AH.call(null!==(i=null===(e=this.options)||void 0===e?void 0:e.host)&&void 0!==i?i:this.element,t):this._$AH.handleEvent(t)}}class ot{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){Q(this,t)}}const lt={P:"$lit$",A:k,M:U,C:1,L:G,R:Y,D:I,V:Q,I:tt,H:et,N:nt,U:rt,B:it,F:ot},at=S.litHtmlPolyfillSupport;null==at||at(X,tt),(null!==($=S.litHtmlVersions)&&void 0!==$?$:S.litHtmlVersions=[]).push("2.4.0");
|
|
61
61
|
/**
|
|
62
62
|
* @license
|
|
63
63
|
* Copyright 2017 Google LLC
|
|
@@ -117,7 +117,7 @@ const xt=2,yt=t=>(...e)=>({_$litDirective$:t,values:e});class wt{constructor(t){
|
|
|
117
117
|
* @license
|
|
118
118
|
* Copyright 2020 Google LLC
|
|
119
119
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
120
|
-
*/const{I:gt}=lt,Ot=()=>document.createComment(""),Nt=(t,e,i)=>{var s;const n=t._$AA.parentNode,r=void 0===e?t._$AB:e._$AA;if(void 0===i){const e=n.insertBefore(Ot(),r),s=n.insertBefore(Ot(),r);i=new gt(e,s,t,t.options)}else{const e=i._$AB.nextSibling,o=i._$AM,l=o!==t;if(l){let e;null===(s=i._$AQ)||void 0===s||s.call(i,t),i._$AM=t,void 0!==i._$AP&&(e=t._$AU)!==o._$AU&&i._$AP(e)}if(e!==r||l){let t=i._$AA;for(;t!==e;){const e=t.nextSibling;n.insertBefore(t,r),t=e}}}return i},Ct=(t,e,i=t)=>(t._$AI(e,i),t),Et={}
|
|
120
|
+
*/const{I:gt}=lt,Ot=()=>document.createComment(""),Nt=(t,e,i)=>{var s;const n=t._$AA.parentNode,r=void 0===e?t._$AB:e._$AA;if(void 0===i){const e=n.insertBefore(Ot(),r),s=n.insertBefore(Ot(),r);i=new gt(e,s,t,t.options)}else{const e=i._$AB.nextSibling,o=i._$AM,l=o!==t;if(l){let e;null===(s=i._$AQ)||void 0===s||s.call(i,t),i._$AM=t,void 0!==i._$AP&&(e=t._$AU)!==o._$AU&&i._$AP(e)}if(e!==r||l){let t=i._$AA;for(;t!==e;){const e=t.nextSibling;n.insertBefore(t,r),t=e}}}return i},Ct=(t,e,i=t)=>(t._$AI(e,i),t),Et={},$t=t=>{var e;null===(e=t._$AP)||void 0===e||e.call(t,!1,!0);let i=t._$AA;const s=t._$AB.nextSibling;for(;i!==s;){const t=i.nextSibling;i.remove(),i=t}},St=(t,e,i)=>{const s=new Map;for(let n=e;n<=i;n++)s.set(t[n],n);return s},Rt=yt(class extends wt{constructor(t){if(super(t),t.type!==xt)throw Error("repeat() can only be used in text expressions")}ht(t,e,i){let s;void 0===i?i=e:void 0!==e&&(s=e);const n=[],r=[];let o=0;for(const e of t)n[o]=s?s(e,o):o,r[o]=i(e,o),o++;return{values:r,keys:n}}render(t,e,i){return this.ht(t,e,i).values}update(t,[e,i,s]){var n;const r=(t=>t._$AH)(t),{values:o,keys:l}=this.ht(e,i,s);if(!Array.isArray(r))return this.ut=l,o;const a=null!==(n=this.ut)&&void 0!==n?n:this.ut=[],h=[];let c,u,d=0,p=r.length-1,f=0,v=o.length-1;for(;d<=p&&f<=v;)if(null===r[d])d++;else if(null===r[p])p--;else if(a[d]===l[f])h[f]=Ct(r[d],o[f]),d++,f++;else if(a[p]===l[v])h[v]=Ct(r[p],o[v]),p--,v--;else if(a[d]===l[v])h[v]=Ct(r[d],o[v]),Nt(t,h[v+1],r[d]),d++,v--;else if(a[p]===l[f])h[f]=Ct(r[p],o[f]),Nt(t,r[d],r[p]),p--,f++;else if(void 0===c&&(c=St(l,f,v),u=St(a,d,p)),c.has(a[d]))if(c.has(a[p])){const e=u.get(l[f]),i=void 0!==e?r[e]:null;if(null===i){const e=Nt(t,r[d]);Ct(e,o[f]),h[f]=e}else h[f]=Ct(i,o[f]),Nt(t,r[d],i),r[e]=null;f++}else $t(r[p]),p--;else $t(r[d]),d++;for(;f<=v;){const e=Nt(t,h[v+1]);Ct(e,o[f]),h[f++]=e}for(;d<=p;){const t=r[d++];null!==t&&$t(t)}return this.ut=l,((t,e=Et)=>{t._$AH=e})(t,h),Z}});
|
|
121
121
|
/**
|
|
122
122
|
* @license
|
|
123
123
|
* Copyright 2017 Google LLC
|
|
@@ -159,18 +159,18 @@ class Mt extends wt{constructor(t){if(super(t),this.it=J,t.type!==xt)throw Error
|
|
|
159
159
|
width: 0;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
.resizable
|
|
162
|
+
.item-container, .resizable.rendered {
|
|
163
163
|
min-height: .1px;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
.rendered {
|
|
167
167
|
display: flow-root;
|
|
168
168
|
}
|
|
169
|
-
`;var Ft=function(t,e,i,s){for(var n,r=arguments.length,o=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,l=t.length-1;l>=0;l--)(n=t[l])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class jt extends CustomEvent{constructor(t,e){super("visible-items-change",{detail:{visibleIndexes:t,visibleItems:e}})}}class Lt extends Event{constructor(){super("scrolled-to-target")}}class Tt extends mt{constructor(){super(...arguments),this.items=[],this.renderItem=()=>H``,this.internalScroll=!1,this.renderBeforeFirst=1,this.renderAfterLast=1,this.visibleItems=[],this.scrolledToTarget=!1,this.alreadyRenderedIndexes=new Set,this.scrollDebouncer=new e(5),this.scrollDoneDebouncer=new e(10),this.onVisibilityChange=t=>{let e=new Set(this.visibleItems),i=new Set;for(let s of t){let t=+s.target.attributes.getNamedItem("data-item-index").value;s.intersectionRect.height>0?(e.add(t),i.add(t)):i.has(t)||e.delete(t)}this.visibleItems=[...e].sort(((t,e)=>t-e))},this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange),this.onResize=t=>{var e;this.triggerFindScrollableParent(),t=t.sort(((t,e)=>t.contentRect.top-e.contentRect.top));for(const
|
|
169
|
+
`;var Ft=function(t,e,i,s){for(var n,r=arguments.length,o=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,l=t.length-1;l>=0;l--)(n=t[l])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};class jt extends CustomEvent{constructor(t,e){super("visible-items-change",{detail:{visibleIndexes:t,visibleItems:e}})}}class Lt extends Event{constructor(){super("scrolled-to-target")}}class Tt extends mt{constructor(){super(...arguments),this.items=[],this.renderItem=()=>H``,this.getItemKey=(t,e)=>`${e} - ${JSON.stringify(t)}`,this.internalScroll=!1,this.renderBeforeFirst=1,this.renderAfterLast=1,this.visibleItems=[],this.scrolledToTarget=!1,this.alreadyRenderedIndexes=new Set,this.scrollDebouncer=new e(5),this.scrollDoneDebouncer=new e(10),this.onVisibilityChange=t=>{let e=new Set(this.visibleItems),i=new Set;for(let s of t){let t=+s.target.attributes.getNamedItem("data-item-index").value;s.intersectionRect.height>0?(e.add(t),i.add(t)):i.has(t)||e.delete(t)}this.visibleItems=[...e].sort(((t,e)=>t-e))},this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange),this.onResize=t=>{var e,i,s;this.triggerFindScrollableParent(),t=t.sort(((t,e)=>t.contentRect.top-e.contentRect.top));const n=this.scrollable&&"none"===(null!==(e=getComputedStyle(this.scrollable).overflowAnchor)&&void 0!==e?e:"none");for(const e of t){const t=+e.target.parentElement.getAttribute("data-item-index"),r=e.target.parentElement.clientHeight,o=e.contentRect.height;if(this.alreadyRenderedIndexes.has(t)||e.target.classList.contains("rendered")){const t=this.getOffset(e.target.parentElement)+r<(null!==(s=null===(i=this.scrollable)||void 0===i?void 0:i.scrollTop)&&void 0!==s?s:0);n&&t&&(this.scrollable.scrollTop+=Math.ceil(o-r)),e.target.parentElement.style.height=o+"px"}}},this.resizeObserver=new ResizeObserver(this.onResize),this.onMutation=()=>{[...this.itemsContainer.children].forEach((t=>{this.intersectionObserver.observe(t),this.resizeObserver.observe(t.children.item(0))}))},this.mutationObserver=new MutationObserver(this.onMutation)}get scrollable(){return this.internalScroll?this.internalScrollable:this.firstScrollableParent}render(){return H`
|
|
170
170
|
<div class="items-container ${this.internalScroll?"scrollable":""}"
|
|
171
171
|
tabindex="-1"
|
|
172
172
|
@find-scrollable-parent=${this.findScrollableParent}>
|
|
173
|
-
${Rt(this.items,((t,e)=>this.renderItemContainer(t,e)))}
|
|
173
|
+
${Rt(this.items,((t,e)=>this.getItemKey(t,e)),((t,e)=>this.renderItemContainer(t,e)))}
|
|
174
174
|
</div>
|
|
175
175
|
`}renderItemContainer(t,e){const i=this.scrolledToTarget&&this.visibleItems.includes(e),s=this.alreadyRenderedIndexes.has(e)||this.scrolledToTarget&&e>=this.visibleItems[0]-this.renderBeforeFirst&&e<=(null!=(n=this.visibleItems)?n:[])[(null!=n?n:[]).length-1]+this.renderAfterLast;var n;s&&this.alreadyRenderedIndexes.add(e);return H`
|
|
176
176
|
<div id="item-${e}"
|
|
@@ -180,4 +180,4 @@ class Mt extends wt{constructor(t){if(super(t),this.it=J,t.type!==xt)throw Error
|
|
|
180
180
|
${s?(()=>{const i=this.renderItem(t,e);return"string"==typeof i?H`${kt(i)}`:i})():null}
|
|
181
181
|
</div>
|
|
182
182
|
</div>
|
|
183
|
-
`}resetScroll(){this.triggerFindScrollableParent(),this.intersectionObserver.disconnect(),this.resizeObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.scrollDebouncer.run((()=>{var t;let e=null!==(t=this.scrollToIndex)&&void 0!==t?t:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;e>=this.items.length&&(e=-1);let i=this.getItem(e);this.scrollToTarget(i),this.onMutation(),this.scrollDoneDebouncer.run((()=>{this.scrolledToTarget=!0}))}))}getItem(t){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(`#item-${t}`)}scrollToTarget(t){var e;if(t){let i=+(null!==(e=t.getAttribute("data-item-index"))&&void 0!==e?e:"0");this.scrollable&&0===i?this.scrollable.scrollTop=0:t.scrollIntoView({block:"start"})}}getOffset(t){var e;let i=0,s=t;for(;s&&s.offsetParent!==this.scrollable.offsetParent;)i+=s.offsetTop,s=s.offsetParent;return i+(null!==(e=null==s?void 0:s.offsetTop)&&void 0!==e?e:0)-this.scrollable.offsetTop}appendItems(...t){this.items=[...this.items,...t]}prependItems(...t){this.items=[...t,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout((()=>{this.triggerFindScrollableParent(),this.initIntersectionObserver(),this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0})}),0)}initIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]})}triggerFindScrollableParent(){var t;null===(t=this.itemsContainer)||void 0===t||t.dispatchEvent(new Event("find-scrollable-parent",{composed:!0}))}findScrollableParent(t){let e,i;t.stopPropagation();for(let s of t.composedPath()){const t=s,n=this.elementCanScroll(t);if(t.clientHeight&&t.clientHeight<t.scrollHeight&&n){e=t;break}n&&(i=t)}let s=e||i;s!==this.firstScrollableParent&&(this.firstScrollableParent=s,this.initIntersectionObserver(),this.resetScroll())}elementCanScroll(t){try{return["auto","scroll"].includes(getComputedStyle(t).overflowY)}catch(t){return!1}}disconnectedCallback(){super.disconnectedCallback(),this.intersectionObserver.disconnect(),this.resizeObserver.disconnect(),this.mutationObserver.disconnect()}firstUpdated(t){super.firstUpdated(t),this.resetScroll()}update(t){super.update(t),t.has("items")&&(this.alreadyRenderedIndexes=new Set),(t.has("scrollToItem")||t.has("scrollToIndex")&&(null!=this.scrollToItem||null!=this.scrollToIndex))&&this.resetScroll()}updated(t){super.updated(t),(t.has("visibleItems")||t.has("items"))&&this.dispatchEvent(new jt(this.visibleItems,this.visibleItems.map((t=>this.items[t])))),t.has("scrolledToTarget")&&this.scrolledToTarget&&(null!=this.scrollToItem||null!=this.scrollToIndex)&&this.dispatchEvent(new Lt)}}var
|
|
183
|
+
`}resetScroll(){this.triggerFindScrollableParent(),this.intersectionObserver.disconnect(),this.resizeObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.scrollDebouncer.run((()=>{var t;let e=null!==(t=this.scrollToIndex)&&void 0!==t?t:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;e>=this.items.length&&(e=-1);let i=this.getItem(e);this.scrollToTarget(i),this.onMutation(),this.scrollDoneDebouncer.run((()=>{this.scrolledToTarget=!0}))}))}getItem(t){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(`#item-${t}`)}scrollToTarget(t){var e;if(t){let i=+(null!==(e=t.getAttribute("data-item-index"))&&void 0!==e?e:"0");this.scrollable&&0===i?this.scrollable.scrollTop=0:t.scrollIntoView({block:"start"})}}getOffset(t){var e;let i=0,s=t;for(;s&&s.offsetParent!==this.scrollable.offsetParent;)i+=s.offsetTop,s=s.offsetParent;return i+(null!==(e=null==s?void 0:s.offsetTop)&&void 0!==e?e:0)-this.scrollable.offsetTop}appendItems(...t){this.items=[...this.items,...t]}prependItems(...t){this.items=[...t,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout((()=>{this.triggerFindScrollableParent(),this.initIntersectionObserver(),this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0})}),0)}initIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]})}triggerFindScrollableParent(){var t;null===(t=this.itemsContainer)||void 0===t||t.dispatchEvent(new Event("find-scrollable-parent",{composed:!0}))}findScrollableParent(t){let e,i;t.stopPropagation();for(let s of t.composedPath()){const t=s,n=this.elementCanScroll(t);if(t.clientHeight&&t.clientHeight<t.scrollHeight&&n){e=t;break}n&&(i=t)}let s=e||i;s!==this.firstScrollableParent&&(this.firstScrollableParent=s,this.initIntersectionObserver(),this.resetScroll())}elementCanScroll(t){try{return["auto","scroll"].includes(getComputedStyle(t).overflowY)}catch(t){return!1}}disconnectedCallback(){super.disconnectedCallback(),this.intersectionObserver.disconnect(),this.resizeObserver.disconnect(),this.mutationObserver.disconnect()}firstUpdated(t){super.firstUpdated(t),this.resetScroll()}update(t){super.update(t),t.has("items")&&(this.alreadyRenderedIndexes=new Set),(t.has("scrollToItem")||t.has("scrollToIndex")&&(null!=this.scrollToItem||null!=this.scrollToIndex))&&this.resetScroll()}updated(t){super.updated(t),(t.has("visibleItems")||t.has("items"))&&this.dispatchEvent(new jt(this.visibleItems,this.visibleItems.map((t=>this.items[t])))),t.has("scrolledToTarget")&&this.scrolledToTarget&&(null!=this.scrollToItem||null!=this.scrollToIndex)&&this.dispatchEvent(new Lt)}}var It;Tt.styles=At,Ft([s({type:Array})],Tt.prototype,"items",void 0),Ft([s({attribute:!1})],Tt.prototype,"renderItem",void 0),Ft([s({attribute:!1})],Tt.prototype,"getItemKey",void 0),Ft([s({type:Object})],Tt.prototype,"scrollToItem",void 0),Ft([s({type:Number})],Tt.prototype,"scrollToIndex",void 0),Ft([s({type:Boolean})],Tt.prototype,"internalScroll",void 0),Ft([s({type:Number})],Tt.prototype,"renderBeforeFirst",void 0),Ft([s({type:Number})],Tt.prototype,"renderAfterLast",void 0),Ft([n({hasChanged:(t,e)=>null!=t&&null==e||t.length!==e.length||t[0]!==e[0]})],Tt.prototype,"visibleItems",void 0),Ft([r(".scrollable")],Tt.prototype,"internalScrollable",void 0),Ft([r(".items-container")],Tt.prototype,"itemsContainer",void 0),Ft([n()],Tt.prototype,"scrolledToTarget",void 0),(It="ft-infinite-scroll",t=>{window.customElements.get(It)||window.customElements.define(It,t)})(Tt),t.FtInfiniteScroll=Tt,t.FtInfiniteScrollCssVariables=Ut,t.ScrolledToTargetEvent=Lt,t.VisibleItemsChangeEvent=jt,t.styles=At,Object.defineProperty(t,"i",{value:!0})}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-infinite-scroll",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.71",
|
|
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": "0.3.
|
|
22
|
+
"@fluid-topics/ft-wc-utils": "0.3.71",
|
|
23
23
|
"lit": "2.2.8"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "aeaa883cc0e3596e6cc75d282aa99de3c603f6a2"
|
|
26
26
|
}
|