@tanstack/lit-virtual 3.15.1 → 3.15.2
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/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +13 -0
package/dist/cjs/index.cjs
CHANGED
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nclass VirtualizerControllerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> implements ReactiveController {\n host: ReactiveControllerHost\n\n private readonly virtualizer: Virtualizer<TScrollElement, TItemElement>\n\n private options: VirtualizerOptions<TScrollElement, TItemElement>\n\n private cleanup: () => void = () => {}\n\n constructor(\n host: ReactiveControllerHost,\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n ) {\n this.host = host\n this.options = { ...options }\n this.virtualizer = new Virtualizer(this.resolveOptions(this.options))\n this.host.addController(this)\n }\n\n public getVirtualizer() {\n return this.virtualizer\n }\n\n /**\n * Merge a partial options update into the options this controller already\n * holds, push them to the virtualizer, and request a host update. Lit folds\n * a request made from `willUpdate` into the update already in progress.\n *\n * Keys set to `undefined` are ignored, matching core `setOptions`, so a\n * partial update cannot wipe an option stored earlier. Defaults supplied by\n * `VirtualizerController` / `WindowVirtualizerController` stay in place\n * unless a later call replaces them.\n */\n public setOptions(\n options: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,\n ) {\n if (!this.applyOptions(options)) return\n\n this.virtualizer.setOptions(this.resolveOptions(this.options))\n this.virtualizer._willUpdate()\n this.host.requestUpdate()\n }\n\n hostConnected() {\n this.cleanup = this.virtualizer._didMount()\n }\n\n hostUpdated() {\n this.virtualizer._willUpdate()\n }\n\n hostDisconnected() {\n this.cleanup()\n }\n\n private applyOptions(\n partial: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,\n ): boolean {\n const next: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...this.options,\n }\n let changed = false\n\n for (const key in partial) {\n if (!Object.prototype.hasOwnProperty.call(partial, key)) continue\n\n const value = partial[key as keyof typeof partial]\n if (value === undefined) continue\n\n if (!Object.is(next[key as keyof typeof next], value)) {\n changed = true\n Object.assign(next, { [key]: value })\n }\n }\n\n if (changed) this.options = next\n return changed\n }\n\n private resolveOptions(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n ): VirtualizerOptions<TScrollElement, TItemElement> {\n return {\n ...options,\n onChange: (instance, sync) => {\n this.host.updateComplete.then(() => this.host.requestUpdate())\n options.onChange?.(instance, sync)\n },\n }\n }\n}\n\nexport class VirtualizerController<\n TScrollElement extends Element,\n TItemElement extends Element,\n> extends VirtualizerControllerBase<TScrollElement, TItemElement> {\n constructor(\n host: ReactiveControllerHost,\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n ) {\n super(host, {\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n }\n}\n\nexport class WindowVirtualizerController<\n TItemElement extends Element,\n> extends VirtualizerControllerBase<Window, TItemElement> {\n constructor(\n host: ReactiveControllerHost,\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n ) {\n super(host, {\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () =>\n typeof document !== 'undefined' ? window.scrollY : 0,\n ...options,\n })\n }\n}\n"],"names":["Virtualizer","observeElementRect","observeElementOffset","elementScroll","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;AAcA,MAAM,0BAG0B;AAAA,EAS9B,YACE,MACA,SACA;AALF,SAAQ,UAAsB,MAAM;AAAA,IAAC;AAMnC,SAAK,OAAO;AACZ,SAAK,UAAU,EAAE,GAAG,QAAA;AACpB,SAAK,cAAc,IAAIA,YAAAA,YAAY,KAAK,eAAe,KAAK,OAAO,CAAC;AACpE,SAAK,KAAK,cAAc,IAAI;AAAA,EAC9B;AAAA,EAEO,iBAAiB;AACtB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYO,WACL,SACA;AACA,QAAI,CAAC,KAAK,aAAa,OAAO,EAAG;AAEjC,SAAK,YAAY,WAAW,KAAK,eAAe,KAAK,OAAO,CAAC;AAC7D,SAAK,YAAY,YAAA;AACjB,SAAK,KAAK,cAAA;AAAA,EACZ;AAAA,EAEA,gBAAgB;AACd,SAAK,UAAU,KAAK,YAAY,UAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nclass VirtualizerControllerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> implements ReactiveController {\n host: ReactiveControllerHost\n\n private readonly virtualizer: Virtualizer<TScrollElement, TItemElement>\n\n private options: VirtualizerOptions<TScrollElement, TItemElement>\n\n private cleanup: () => void = () => {}\n\n constructor(\n host: ReactiveControllerHost,\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n ) {\n this.host = host\n this.options = { ...options }\n this.virtualizer = new Virtualizer(this.resolveOptions(this.options))\n this.host.addController(this)\n }\n\n public getVirtualizer() {\n return this.virtualizer\n }\n\n /**\n * Merge a partial options update into the options this controller already\n * holds, push them to the virtualizer, and request a host update. Lit folds\n * a request made from `willUpdate` into the update already in progress.\n *\n * Keys set to `undefined` are ignored, matching core `setOptions`, so a\n * partial update cannot wipe an option stored earlier. Defaults supplied by\n * `VirtualizerController` / `WindowVirtualizerController` stay in place\n * unless a later call replaces them.\n */\n public setOptions(\n options: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,\n ) {\n if (!this.applyOptions(options)) return\n\n this.virtualizer.setOptions(this.resolveOptions(this.options))\n this.virtualizer._willUpdate()\n this.host.requestUpdate()\n }\n\n hostConnected() {\n this.cleanup = this.virtualizer._didMount()\n // `hostDisconnected` runs the cleanup returned by `_didMount`, which\n // drops `scrollElement` and its observers. Lit calls `hostUpdated` only\n // when an update runs, and reconnecting a host with no pending update\n // does not schedule one, so scrolling would stop changing the rendered\n // range until a reactive property changed.\n //\n // Scroll elements that are already readable (the window, or a\n // `getScrollElement` that does not use Lit's `ref`) can be observed\n // immediately. `ref` clears its value on disconnect and restores it only\n // after this callback returns, so also request an update: the following\n // `hostUpdated` runs `_willUpdate` once that ref is populated again.\n this.virtualizer._willUpdate()\n this.host.requestUpdate()\n }\n\n hostUpdated() {\n this.virtualizer._willUpdate()\n }\n\n hostDisconnected() {\n this.cleanup()\n }\n\n private applyOptions(\n partial: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,\n ): boolean {\n const next: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...this.options,\n }\n let changed = false\n\n for (const key in partial) {\n if (!Object.prototype.hasOwnProperty.call(partial, key)) continue\n\n const value = partial[key as keyof typeof partial]\n if (value === undefined) continue\n\n if (!Object.is(next[key as keyof typeof next], value)) {\n changed = true\n Object.assign(next, { [key]: value })\n }\n }\n\n if (changed) this.options = next\n return changed\n }\n\n private resolveOptions(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n ): VirtualizerOptions<TScrollElement, TItemElement> {\n return {\n ...options,\n onChange: (instance, sync) => {\n this.host.updateComplete.then(() => this.host.requestUpdate())\n options.onChange?.(instance, sync)\n },\n }\n }\n}\n\nexport class VirtualizerController<\n TScrollElement extends Element,\n TItemElement extends Element,\n> extends VirtualizerControllerBase<TScrollElement, TItemElement> {\n constructor(\n host: ReactiveControllerHost,\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n ) {\n super(host, {\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n }\n}\n\nexport class WindowVirtualizerController<\n TItemElement extends Element,\n> extends VirtualizerControllerBase<Window, TItemElement> {\n constructor(\n host: ReactiveControllerHost,\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n ) {\n super(host, {\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () =>\n typeof document !== 'undefined' ? window.scrollY : 0,\n ...options,\n })\n }\n}\n"],"names":["Virtualizer","observeElementRect","observeElementOffset","elementScroll","observeWindowRect","observeWindowOffset","windowScroll"],"mappings":";;;AAcA,MAAM,0BAG0B;AAAA,EAS9B,YACE,MACA,SACA;AALF,SAAQ,UAAsB,MAAM;AAAA,IAAC;AAMnC,SAAK,OAAO;AACZ,SAAK,UAAU,EAAE,GAAG,QAAA;AACpB,SAAK,cAAc,IAAIA,YAAAA,YAAY,KAAK,eAAe,KAAK,OAAO,CAAC;AACpE,SAAK,KAAK,cAAc,IAAI;AAA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AIA;AACA,UAAM,MAAM;AAAA,MAAA,oBACVC,YAAAA;AAAAA,MAAA,sBACAC,YAAAA;AAAAA,MACA,YAAYC,YAAAA;AAAAA,MACZ,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AACF;AAEO,MAAM,oCAEH,0BAAgD;AAAA,EACxD,YACE,MACA,SAOA;AACA,UAAM,MAAM;AAAA,MACV,kBAAkB,MAAO,OAAO,aAAa,cAAc,SAAS;AAAA,MACpE,oBAAoBC,YAAAA;AAAAA,MACpB,sBAAsBC,YAAAA;AAAAA,MACtB,YAAYC,YAAAA;AAAAA,MACZ,eAAe,MACb,OAAO,aAAa,cAAc,OAAO,UAAU;AAAA,MACrD,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AACF;;;;;;;;;"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nclass VirtualizerControllerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> implements ReactiveController {\n host: ReactiveControllerHost\n\n private readonly virtualizer: Virtualizer<TScrollElement, TItemElement>\n\n private options: VirtualizerOptions<TScrollElement, TItemElement>\n\n private cleanup: () => void = () => {}\n\n constructor(\n host: ReactiveControllerHost,\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n ) {\n this.host = host\n this.options = { ...options }\n this.virtualizer = new Virtualizer(this.resolveOptions(this.options))\n this.host.addController(this)\n }\n\n public getVirtualizer() {\n return this.virtualizer\n }\n\n /**\n * Merge a partial options update into the options this controller already\n * holds, push them to the virtualizer, and request a host update. Lit folds\n * a request made from `willUpdate` into the update already in progress.\n *\n * Keys set to `undefined` are ignored, matching core `setOptions`, so a\n * partial update cannot wipe an option stored earlier. Defaults supplied by\n * `VirtualizerController` / `WindowVirtualizerController` stay in place\n * unless a later call replaces them.\n */\n public setOptions(\n options: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,\n ) {\n if (!this.applyOptions(options)) return\n\n this.virtualizer.setOptions(this.resolveOptions(this.options))\n this.virtualizer._willUpdate()\n this.host.requestUpdate()\n }\n\n hostConnected() {\n this.cleanup = this.virtualizer._didMount()\n }\n\n hostUpdated() {\n this.virtualizer._willUpdate()\n }\n\n hostDisconnected() {\n this.cleanup()\n }\n\n private applyOptions(\n partial: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,\n ): boolean {\n const next: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...this.options,\n }\n let changed = false\n\n for (const key in partial) {\n if (!Object.prototype.hasOwnProperty.call(partial, key)) continue\n\n const value = partial[key as keyof typeof partial]\n if (value === undefined) continue\n\n if (!Object.is(next[key as keyof typeof next], value)) {\n changed = true\n Object.assign(next, { [key]: value })\n }\n }\n\n if (changed) this.options = next\n return changed\n }\n\n private resolveOptions(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n ): VirtualizerOptions<TScrollElement, TItemElement> {\n return {\n ...options,\n onChange: (instance, sync) => {\n this.host.updateComplete.then(() => this.host.requestUpdate())\n options.onChange?.(instance, sync)\n },\n }\n }\n}\n\nexport class VirtualizerController<\n TScrollElement extends Element,\n TItemElement extends Element,\n> extends VirtualizerControllerBase<TScrollElement, TItemElement> {\n constructor(\n host: ReactiveControllerHost,\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n ) {\n super(host, {\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n }\n}\n\nexport class WindowVirtualizerController<\n TItemElement extends Element,\n> extends VirtualizerControllerBase<Window, TItemElement> {\n constructor(\n host: ReactiveControllerHost,\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n ) {\n super(host, {\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () =>\n typeof document !== 'undefined' ? window.scrollY : 0,\n ...options,\n })\n }\n}\n"],"names":[],"mappings":";;AAcA,MAAM,0BAG0B;AAAA,EAS9B,YACE,MACA,SACA;AALF,SAAQ,UAAsB,MAAM;AAAA,IAAC;AAMnC,SAAK,OAAO;AACZ,SAAK,UAAU,EAAE,GAAG,QAAA;AACpB,SAAK,cAAc,IAAI,YAAY,KAAK,eAAe,KAAK,OAAO,CAAC;AACpE,SAAK,KAAK,cAAc,IAAI;AAAA,EAC9B;AAAA,EAEO,iBAAiB;AACtB,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYO,WACL,SACA;AACA,QAAI,CAAC,KAAK,aAAa,OAAO,EAAG;AAEjC,SAAK,YAAY,WAAW,KAAK,eAAe,KAAK,OAAO,CAAC;AAC7D,SAAK,YAAY,YAAA;AACjB,SAAK,KAAK,cAAA;AAAA,EACZ;AAAA,EAEA,gBAAgB;AACd,SAAK,UAAU,KAAK,YAAY,UAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import {\n Virtualizer,\n elementScroll,\n observeElementOffset,\n observeElementRect,\n observeWindowOffset,\n observeWindowRect,\n windowScroll,\n} from '@tanstack/virtual-core'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { PartialKeys, VirtualizerOptions } from '@tanstack/virtual-core'\n\nexport * from '@tanstack/virtual-core'\n\nclass VirtualizerControllerBase<\n TScrollElement extends Element | Window,\n TItemElement extends Element,\n> implements ReactiveController {\n host: ReactiveControllerHost\n\n private readonly virtualizer: Virtualizer<TScrollElement, TItemElement>\n\n private options: VirtualizerOptions<TScrollElement, TItemElement>\n\n private cleanup: () => void = () => {}\n\n constructor(\n host: ReactiveControllerHost,\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n ) {\n this.host = host\n this.options = { ...options }\n this.virtualizer = new Virtualizer(this.resolveOptions(this.options))\n this.host.addController(this)\n }\n\n public getVirtualizer() {\n return this.virtualizer\n }\n\n /**\n * Merge a partial options update into the options this controller already\n * holds, push them to the virtualizer, and request a host update. Lit folds\n * a request made from `willUpdate` into the update already in progress.\n *\n * Keys set to `undefined` are ignored, matching core `setOptions`, so a\n * partial update cannot wipe an option stored earlier. Defaults supplied by\n * `VirtualizerController` / `WindowVirtualizerController` stay in place\n * unless a later call replaces them.\n */\n public setOptions(\n options: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,\n ) {\n if (!this.applyOptions(options)) return\n\n this.virtualizer.setOptions(this.resolveOptions(this.options))\n this.virtualizer._willUpdate()\n this.host.requestUpdate()\n }\n\n hostConnected() {\n this.cleanup = this.virtualizer._didMount()\n // `hostDisconnected` runs the cleanup returned by `_didMount`, which\n // drops `scrollElement` and its observers. Lit calls `hostUpdated` only\n // when an update runs, and reconnecting a host with no pending update\n // does not schedule one, so scrolling would stop changing the rendered\n // range until a reactive property changed.\n //\n // Scroll elements that are already readable (the window, or a\n // `getScrollElement` that does not use Lit's `ref`) can be observed\n // immediately. `ref` clears its value on disconnect and restores it only\n // after this callback returns, so also request an update: the following\n // `hostUpdated` runs `_willUpdate` once that ref is populated again.\n this.virtualizer._willUpdate()\n this.host.requestUpdate()\n }\n\n hostUpdated() {\n this.virtualizer._willUpdate()\n }\n\n hostDisconnected() {\n this.cleanup()\n }\n\n private applyOptions(\n partial: Partial<VirtualizerOptions<TScrollElement, TItemElement>>,\n ): boolean {\n const next: VirtualizerOptions<TScrollElement, TItemElement> = {\n ...this.options,\n }\n let changed = false\n\n for (const key in partial) {\n if (!Object.prototype.hasOwnProperty.call(partial, key)) continue\n\n const value = partial[key as keyof typeof partial]\n if (value === undefined) continue\n\n if (!Object.is(next[key as keyof typeof next], value)) {\n changed = true\n Object.assign(next, { [key]: value })\n }\n }\n\n if (changed) this.options = next\n return changed\n }\n\n private resolveOptions(\n options: VirtualizerOptions<TScrollElement, TItemElement>,\n ): VirtualizerOptions<TScrollElement, TItemElement> {\n return {\n ...options,\n onChange: (instance, sync) => {\n this.host.updateComplete.then(() => this.host.requestUpdate())\n options.onChange?.(instance, sync)\n },\n }\n }\n}\n\nexport class VirtualizerController<\n TScrollElement extends Element,\n TItemElement extends Element,\n> extends VirtualizerControllerBase<TScrollElement, TItemElement> {\n constructor(\n host: ReactiveControllerHost,\n options: PartialKeys<\n VirtualizerOptions<TScrollElement, TItemElement>,\n 'observeElementRect' | 'observeElementOffset' | 'scrollToFn'\n >,\n ) {\n super(host, {\n observeElementRect: observeElementRect,\n observeElementOffset: observeElementOffset,\n scrollToFn: elementScroll,\n ...options,\n })\n }\n}\n\nexport class WindowVirtualizerController<\n TItemElement extends Element,\n> extends VirtualizerControllerBase<Window, TItemElement> {\n constructor(\n host: ReactiveControllerHost,\n options: PartialKeys<\n VirtualizerOptions<Window, TItemElement>,\n | 'getScrollElement'\n | 'observeElementRect'\n | 'observeElementOffset'\n | 'scrollToFn'\n >,\n ) {\n super(host, {\n getScrollElement: () => (typeof document !== 'undefined' ? window : null),\n observeElementRect: observeWindowRect,\n observeElementOffset: observeWindowOffset,\n scrollToFn: windowScroll,\n initialOffset: () =>\n typeof document !== 'undefined' ? window.scrollY : 0,\n ...options,\n })\n }\n}\n"],"names":[],"mappings":";;AAcA,MAAM,0BAG0B;AAAA,EAS9B,YACE,MACA,SACA;AALF,SAAQ,UAAsB,MAAM;AAAA,IAAC;AAMnC,SAAK,OAAO;AACZ,SAAK,UAAU,EAAE,GAAG,QAAA;AACpB,SAA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/B;AAAA,IAAA;AAAA,EAEJ;AACF;AAEO,MAAM,8BAGH,0BAAwD;AAAA,EAChE,YACE,MACA,SAIA;AACA,UAAM,MAAM;AAAA,MACV;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AACF;AAEO,MAAM,oCAEH,0BAAgD;AAAA,EACxD,YACE,MACA,SAOA;AACA,UAAM,MAAM;AAAA,MACV,kBAAkB,MAAO,OAAO,aAAa,cAAc,SAAS;AAAA,MACpE,oBAAoB;AAAA,MACpB,sBAAsB;AAAA,MACtB,YAAY;AAAA,MACZ,eAAe,MACb,OAAO,aAAa,cAAc,OAAO,UAAU;AAAA,MACrD,GAAG;AAAA,IAAA,CACJ;AAAA,EACH;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/lit-virtual",
|
|
3
|
-
"version": "3.15.
|
|
3
|
+
"version": "3.15.2",
|
|
4
4
|
"description": "Headless UI for virtualizing scrollable elements in Lit",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"src"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@tanstack/virtual-core": "3.19.
|
|
46
|
+
"@tanstack/virtual-core": "3.19.10"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@open-wc/testing": "^4.0.0",
|
package/src/index.ts
CHANGED
|
@@ -60,6 +60,19 @@ class VirtualizerControllerBase<
|
|
|
60
60
|
|
|
61
61
|
hostConnected() {
|
|
62
62
|
this.cleanup = this.virtualizer._didMount()
|
|
63
|
+
// `hostDisconnected` runs the cleanup returned by `_didMount`, which
|
|
64
|
+
// drops `scrollElement` and its observers. Lit calls `hostUpdated` only
|
|
65
|
+
// when an update runs, and reconnecting a host with no pending update
|
|
66
|
+
// does not schedule one, so scrolling would stop changing the rendered
|
|
67
|
+
// range until a reactive property changed.
|
|
68
|
+
//
|
|
69
|
+
// Scroll elements that are already readable (the window, or a
|
|
70
|
+
// `getScrollElement` that does not use Lit's `ref`) can be observed
|
|
71
|
+
// immediately. `ref` clears its value on disconnect and restores it only
|
|
72
|
+
// after this callback returns, so also request an update: the following
|
|
73
|
+
// `hostUpdated` runs `_willUpdate` once that ref is populated again.
|
|
74
|
+
this.virtualizer._willUpdate()
|
|
75
|
+
this.host.requestUpdate()
|
|
63
76
|
}
|
|
64
77
|
|
|
65
78
|
hostUpdated() {
|