@internetarchive/collection-browser 4.3.2-alpha-webdev7939.2 → 4.3.2-alpha-webdev7939.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC;AAG/F,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAEL,SAAS,EACT,SAAS,EAGT,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAO7D,cAAc,uDAAuD,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6DAA6D,CAAC","sourcesContent":["export { CollectionBrowser } from './src/collection-browser';\r\nexport { CollectionBrowserDataSource } from './src/data-source/collection-browser-data-source';\r\nexport { CollectionBrowserDataSourceInterface } from './src/data-source/collection-browser-data-source-interface';\r\nexport { CollectionBrowserQueryState } from './src/data-source/collection-browser-query-state';\r\nexport { SortFilterBar } from './src/sort-filter-bar/sort-filter-bar';\r\nexport {\r\n CollectionDisplayMode,\r\n SortField,\r\n TileModel,\r\n FacetOption,\r\n SelectedFacets,\r\n getDefaultSelectedFacets,\r\n} from './src/models';\r\nexport { CollectionBrowserLoadingTile } from './src/tiles/collection-browser-loading-tile';\r\nexport { CollectionTile } from './src/tiles/grid/collection-tile';\r\nexport { AccountTile } from './src/tiles/grid/account-tile';\r\nexport { ItemTile } from './src/tiles/grid/item-tile';\r\nexport { TileList } from './src/tiles/list/tile-list';\r\nexport { TileListCompact } from './src/tiles/list/tile-list-compact';\r\nexport { TileDispatcher } from './src/tiles/tile-dispatcher';\r\nexport { LayoutType } from './src/tiles/models';\r\nexport {\r\n SmartQueryHeuristic,\r\n KeywordFacetMap,\r\n SmartFacet,\r\n} from './src/collection-facets/smart-facets/models';\r\nexport * from './src/collection-facets/smart-facets/heuristics/index';\r\nexport { SmartQueryHeuristicGroup } from './src/collection-facets/smart-facets/smart-facet-heuristics';\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC;AAG/F,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAEL,SAAS,EACT,SAAS,EAGT,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAO7D,cAAc,uDAAuD,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6DAA6D,CAAC","sourcesContent":["export { CollectionBrowser } from './src/collection-browser';\nexport { CollectionBrowserDataSource } from './src/data-source/collection-browser-data-source';\nexport { CollectionBrowserDataSourceInterface } from './src/data-source/collection-browser-data-source-interface';\nexport { CollectionBrowserQueryState } from './src/data-source/collection-browser-query-state';\nexport { SortFilterBar } from './src/sort-filter-bar/sort-filter-bar';\nexport {\n CollectionDisplayMode,\n SortField,\n TileModel,\n FacetOption,\n SelectedFacets,\n getDefaultSelectedFacets,\n} from './src/models';\nexport { CollectionBrowserLoadingTile } from './src/tiles/collection-browser-loading-tile';\nexport { CollectionTile } from './src/tiles/grid/collection-tile';\nexport { AccountTile } from './src/tiles/grid/account-tile';\nexport { ItemTile } from './src/tiles/grid/item-tile';\nexport { TileList } from './src/tiles/list/tile-list';\nexport { TileListCompact } from './src/tiles/list/tile-list-compact';\nexport { TileDispatcher } from './src/tiles/tile-dispatcher';\nexport { LayoutType } from './src/tiles/models';\nexport {\n SmartQueryHeuristic,\n KeywordFacetMap,\n SmartFacet,\n} from './src/collection-facets/smart-facets/models';\nexport * from './src/collection-facets/smart-facets/heuristics/index';\nexport { SmartQueryHeuristicGroup } from './src/collection-facets/smart-facets/smart-facet-heuristics';\n"]}
@@ -634,6 +634,16 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
634
634
  * @returns
635
635
  */
636
636
  private visibleCellsChanged;
637
+ /**
638
+ * Recomputes the current page from the given set of visible cell indices
639
+ * and emits `visiblePageChanged` if the page actually changed.
640
+ */
641
+ private updateVisiblePage;
642
+ /**
643
+ * Sets the current page number and emits a `visiblePageChanged`
644
+ * event if the new page differs from the previous one.
645
+ */
646
+ private setCurrentPage;
637
647
  private initialQueryChangeHappened;
638
648
  private historyPopOccurred;
639
649
  private previousQueryKey?;
@@ -879,7 +879,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
879
879
  if ((this.currentPage ?? 1) > 1) {
880
880
  this.goToPage(1);
881
881
  }
882
- this.currentPage = 1;
882
+ this.setCurrentPage(1);
883
883
  }
884
884
  /**
885
885
  * Fires an analytics event for sorting changes.
@@ -1696,38 +1696,39 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1696
1696
  * @returns
1697
1697
  */
1698
1698
  visibleCellsChanged(e) {
1699
- if (this.isScrollingToCell) {
1700
- // eslint-disable-next-line no-console
1701
- console.log(`[CB visibleCellsChanged] BAIL isScrollingToCell=true visible=[${e.detail.visibleCellIndices.join(',')}]`);
1699
+ this.updateVisiblePage(e.detail.visibleCellIndices);
1700
+ }
1701
+ /**
1702
+ * Recomputes the current page from the given set of visible cell indices
1703
+ * and emits `visiblePageChanged` if the page actually changed.
1704
+ */
1705
+ updateVisiblePage(visibleCellIndices) {
1706
+ if (this.isScrollingToCell)
1702
1707
  return;
1703
- }
1704
- const { visibleCellIndices } = e.detail;
1705
1708
  if (visibleCellIndices.length === 0)
1706
1709
  return;
1710
+ // The indices aren't necessarily sorted, so sort them here to ensure our
1711
+ // calculations below find the right cell/page.
1712
+ const sorted = [...visibleCellIndices].sort((a, b) => a - b);
1707
1713
  // For page determination, do not count more than a single page of visible cells,
1708
1714
  // since otherwise patrons using very tall screens will be treated as one page
1709
1715
  // further than they actually are.
1710
- const lastIndexWithinCurrentPage = Math.min(this.pageSize, visibleCellIndices.length) - 1;
1711
- const lastVisibleCellIndex = visibleCellIndices[lastIndexWithinCurrentPage];
1716
+ const lastIndexWithinCurrentPage = Math.min(this.pageSize, sorted.length) - 1;
1717
+ const lastVisibleCellIndex = sorted[lastIndexWithinCurrentPage];
1712
1718
  const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
1713
- // Detect out-of-order Set: compare the indices we got to a sorted copy.
1714
- const sorted = [...visibleCellIndices].sort((a, b) => a - b);
1715
- const isSorted = sorted.every((v, i) => v === visibleCellIndices[i]);
1716
- const minIdx = sorted[0];
1717
- const maxIdx = sorted[sorted.length - 1];
1718
- const first10 = visibleCellIndices.slice(0, 10).join(',');
1719
- const last10 = visibleCellIndices.slice(-10).join(',');
1720
- // eslint-disable-next-line no-console
1721
- console.log(`[CB visibleCellsChanged] computedPage=${lastVisibleCellPage} lastIdx=${lastVisibleCellIndex} sampledAt=${lastIndexWithinCurrentPage} len=${visibleCellIndices.length} sorted=${isSorted} min=${minIdx} max=${maxIdx} scrollY=${window.scrollY} first10=[${first10}] last10=[${last10}]`);
1722
- if (this.currentPage !== lastVisibleCellPage) {
1723
- this.currentPage = lastVisibleCellPage;
1724
- }
1725
- const event = new CustomEvent('visiblePageChanged', {
1726
- detail: {
1727
- pageNumber: lastVisibleCellPage,
1728
- },
1729
- });
1730
- this.dispatchEvent(event);
1719
+ this.setCurrentPage(lastVisibleCellPage);
1720
+ }
1721
+ /**
1722
+ * Sets the current page number and emits a `visiblePageChanged`
1723
+ * event if the new page differs from the previous one.
1724
+ */
1725
+ setCurrentPage(pageNumber) {
1726
+ if (this.currentPage === pageNumber)
1727
+ return;
1728
+ this.currentPage = pageNumber;
1729
+ this.dispatchEvent(new CustomEvent('visiblePageChanged', {
1730
+ detail: { pageNumber },
1731
+ }));
1731
1732
  }
1732
1733
  /**
1733
1734
  * A Promise which, after each query change, resolves once the fetches for the initial
@@ -1803,10 +1804,10 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1803
1804
  this.selectedFacets = restorationState.selectedFacets;
1804
1805
  if (!this.suppressURLQuery)
1805
1806
  this.baseQuery = restorationState.baseQuery;
1806
- this.currentPage = restorationState.currentPage ?? 1;
1807
+ this.setCurrentPage(restorationState.currentPage ?? 1);
1807
1808
  this.minSelectedDate = restorationState.minSelectedDate;
1808
1809
  this.maxSelectedDate = restorationState.maxSelectedDate;
1809
- if (this.currentPage > 1) {
1810
+ if (this.currentPage && this.currentPage > 1) {
1810
1811
  this.goToPage(this.currentPage);
1811
1812
  }
1812
1813
  }
@@ -1876,19 +1877,14 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1876
1877
  }
1877
1878
  async scrollToPage(pageNumber) {
1878
1879
  const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1879
- // eslint-disable-next-line no-console
1880
- console.log(`[CB scrollToPage] ENTRY page=${pageNumber} targetCell=${cellIndexToScrollTo} pagesToRender=${this.pagesToRender} estimatedTileCount=${this.estimatedTileCount} itemCount=${this.infiniteScroller?.itemCount} scrollY=${window.scrollY}`);
1881
1880
  // Wait for the infinite scroller be rendered before proceeding
1882
1881
  let waitAttempts = 0;
1883
1882
  while (!this.infiniteScroller && waitAttempts < 20) {
1884
1883
  await this.updateComplete;
1885
1884
  waitAttempts++;
1886
1885
  }
1887
- if (!this.infiniteScroller) {
1888
- // eslint-disable-next-line no-console
1889
- console.log(`[CB scrollToPage] NO_SCROLLER after wait waitAttempts=${waitAttempts}`);
1886
+ if (!this.infiniteScroller)
1890
1887
  return;
1891
- }
1892
1888
  // The scroller have its default `itemCount=0`, so propagate our estimated
1893
1889
  // tile count before jumping to the desired page.
1894
1890
  if (this.infiniteScroller.itemCount < this.estimatedTileCount) {
@@ -1903,9 +1899,12 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1903
1899
  this.isScrollingToCell = true;
1904
1900
  const scrolled = await this.infiniteScroller.scrollToCell(cellIndexToScrollTo, true);
1905
1901
  this.isScrollingToCell = false;
1906
- // eslint-disable-next-line no-console
1907
- console.log(`[CB scrollToPage] DONE page=${pageNumber} targetCell=${cellIndexToScrollTo} scrolled=${scrolled} scrollY=${window.scrollY}`);
1908
1902
  this.infiniteScroller.refreshAllVisibleCells();
1903
+ // After we finish scrolling, recompute the visible page from the new state
1904
+ // so that it doesn't fall out of sync.
1905
+ if (scrolled) {
1906
+ this.updateVisiblePage(this.infiniteScroller.getVisibleCellIndices());
1907
+ }
1909
1908
  }
1910
1909
  /**
1911
1910
  * Whether sorting by relevance makes sense for the current state.