@internetarchive/collection-browser 4.3.2-alpha-webdev7939.12 → 4.3.2-rc-webdev-8334.0

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.
Files changed (38) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +27 -27
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +1 -1
  7. package/.prettierignore +1 -1
  8. package/LICENSE +661 -661
  9. package/README.md +83 -83
  10. package/dist/src/app-root.js +0 -4
  11. package/dist/src/app-root.js.map +1 -1
  12. package/dist/src/collection-browser.d.ts +0 -41
  13. package/dist/src/collection-browser.js +36 -128
  14. package/dist/src/collection-browser.js.map +1 -1
  15. package/dist/src/tiles/item-image.d.ts +1 -9
  16. package/dist/src/tiles/item-image.js +2 -22
  17. package/dist/src/tiles/item-image.js.map +1 -1
  18. package/dist/src/tiles/tile-display-value-provider.js +2 -1
  19. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  20. package/dist/test/tiles/grid/item-tile.test.js +2 -2
  21. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  22. package/dist/test/tiles/list/tile-list.test.js +2 -2
  23. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  24. package/eslint.config.mjs +53 -53
  25. package/index.html +24 -24
  26. package/local.archive.org.cert +86 -86
  27. package/local.archive.org.key +27 -27
  28. package/package.json +120 -120
  29. package/renovate.json +6 -6
  30. package/src/app-root.ts +0 -3
  31. package/src/collection-browser.ts +35 -146
  32. package/src/tiles/item-image.ts +1 -28
  33. package/src/tiles/tile-display-value-provider.ts +2 -3
  34. package/test/tiles/grid/item-tile.test.ts +2 -2
  35. package/test/tiles/list/tile-list.test.ts +2 -2
  36. package/tsconfig.json +25 -25
  37. package/web-dev-server.config.mjs +30 -30
  38. package/web-test-runner.config.mjs +52 -52
@@ -1,4 +1,3 @@
1
- var CollectionBrowser_1;
2
1
  import { __decorate } from "tslib";
3
2
  import { html, css, LitElement, nothing, } from 'lit';
4
3
  import { customElement, property, query, state } from 'lit/decorators.js';
@@ -25,7 +24,6 @@ import './collection-facets';
25
24
  import './circular-activity-indicator';
26
25
  import './collection-facets/smart-facets/smart-facet-bar';
27
26
  let CollectionBrowser = class CollectionBrowser extends LitElement {
28
- static { CollectionBrowser_1 = this; }
29
27
  constructor() {
30
28
  super();
31
29
  this.baseImageUrl = 'https://archive.org';
@@ -190,7 +188,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
190
188
  */
191
189
  this.dataSourceInstallInProgress = false;
192
190
  this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
193
- this.deferredFetchTimer = 0;
194
191
  /**
195
192
  * Updates the height of the left column according to its position on the page.
196
193
  * Arrow function ensures proper `this` binding.
@@ -228,7 +225,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
228
225
  const model = this.dataSource.getTileModelAt(index);
229
226
  /**
230
227
  * If we encounter a model we don't have yet and we're not in the middle of an
231
- * automated scroll, schedule a fetch for the missing page and return undefined.
228
+ * automated scroll, fetch the page and just return undefined.
232
229
  * The datasource will be updated once the page is loaded and the cell will be rendered.
233
230
  *
234
231
  * We disable it during the automated scroll since we don't want to fetch pages for intervening cells the
@@ -236,51 +233,9 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
236
233
  */
237
234
  if (!model && !this.isScrollingToCell && this.dataSource.queryInitialized) {
238
235
  const pageNumber = Math.floor(index / this.pageSize) + 1;
239
- this.scheduleDeferredPageFetch(pageNumber);
240
- }
241
- return model;
242
- }
243
- /**
244
- * Debounce delay for page fetches initiated by new cells becoming visible.
245
- * Tuned so quick scrolling through unloaded regions doesn't send rapid-fire
246
- * search requests for every page we pass through, but to still feel responsive
247
- * when the scroll ends.
248
- */
249
- static { this.DEFERRED_FETCH_DELAY_MS = 150; }
250
- /**
251
- * Schedules a fetch for the given page, debounced to ensure we don't
252
- * rapid-fire fetches while scrolling through pages quickly.
253
- *
254
- * If there's no pending fetch timer yet, it will fire a fetch immediately.
255
- * Otherwise, it will reset any existing timer. In either case, a deferred
256
- * fetch for the visible pages is scheduled after a brief delay to account
257
- * for whatever pages we land on after scrolling.
258
- */
259
- scheduleDeferredPageFetch(pageNumber) {
260
- if (!this.deferredFetchTimer) {
261
236
  this.dataSource.fetchPage(pageNumber);
262
237
  }
263
- else {
264
- window.clearTimeout(this.deferredFetchTimer);
265
- }
266
- this.deferredFetchTimer = window.setTimeout(() => {
267
- this.deferredFetchTimer = 0;
268
- this.fetchVisiblePages();
269
- }, CollectionBrowser_1.DEFERRED_FETCH_DELAY_MS);
270
- }
271
- /**
272
- * Fetch each currently-visible page whose first cell still has no
273
- * loaded model.
274
- */
275
- fetchVisiblePages() {
276
- const visibleIndices = this.infiniteScroller?.getVisibleCellIndices() ?? [];
277
- const visiblePages = new Set(visibleIndices.map(i => Math.floor(i / this.pageSize) + 1));
278
- for (const page of visiblePages) {
279
- const firstCellOfPage = (page - 1) * this.pageSize;
280
- if (!this.dataSource.getTileModelAt(firstCellOfPage)) {
281
- this.dataSource.fetchPage(page);
282
- }
283
- }
238
+ return model;
284
239
  }
285
240
  // this is the total number of tiles we expect if
286
241
  // the data returned is a full page worth
@@ -658,7 +613,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
658
613
  class=${this.infiniteScrollerClasses}
659
614
  itemCount=${this.placeholderType ? 0 : nothing}
660
615
  ariaLandmarkLabel="Search results"
661
- .estimatedCellHeight=${this.estimatedTileHeight}
662
616
  .cellProvider=${this}
663
617
  .placeholderCellTemplate=${this.placeholderCellTemplate}
664
618
  @scrollThresholdReached=${this.scrollThresholdReached}
@@ -678,24 +632,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
678
632
  hidden: !!this.placeholderType,
679
633
  });
680
634
  }
681
- /**
682
- * Best-effort hint of how tall a single rendered tile is, by display mode.
683
- * The scroller uses this to better estimate the size its initial scroll
684
- * spacer and buffer position before real cell heights are measured.
685
- * Should roughly match the placeholder heights since the initial render
686
- * of a new page generally shows placeholders only anyway.
687
- */
688
- get estimatedTileHeight() {
689
- switch (this.displayMode) {
690
- case 'list-detail':
691
- return 80;
692
- case 'list-compact':
693
- return 45;
694
- case 'grid':
695
- default:
696
- return 225;
697
- }
698
- }
699
635
  /**
700
636
  * Template for the sort & filtering bar that appears atop the search results.
701
637
  */
@@ -879,7 +815,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
879
815
  if ((this.currentPage ?? 1) > 1) {
880
816
  this.goToPage(1);
881
817
  }
882
- this.setCurrentPage(1);
818
+ this.currentPage = 1;
883
819
  }
884
820
  /**
885
821
  * Fires an analytics event for sorting changes.
@@ -1521,10 +1457,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1521
1457
  if (this.boundNavigationHandler) {
1522
1458
  window.removeEventListener('popstate', this.boundNavigationHandler);
1523
1459
  }
1524
- if (this.deferredFetchTimer) {
1525
- window.clearTimeout(this.deferredFetchTimer);
1526
- this.deferredFetchTimer = 0;
1527
- }
1528
1460
  this.leftColIntersectionObserver?.disconnect();
1529
1461
  this.facetsIntersectionObserver?.disconnect();
1530
1462
  window.removeEventListener('resize', this.updateLeftColumnHeight);
@@ -1696,39 +1628,26 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1696
1628
  * @returns
1697
1629
  */
1698
1630
  visibleCellsChanged(e) {
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
1631
  if (this.isScrollingToCell)
1707
1632
  return;
1633
+ const { visibleCellIndices } = e.detail;
1708
1634
  if (visibleCellIndices.length === 0)
1709
1635
  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);
1713
1636
  // For page determination, do not count more than a single page of visible cells,
1714
1637
  // since otherwise patrons using very tall screens will be treated as one page
1715
1638
  // further than they actually are.
1716
- const lastIndexWithinCurrentPage = Math.min(this.pageSize, sorted.length) - 1;
1717
- const lastVisibleCellIndex = sorted[lastIndexWithinCurrentPage];
1639
+ const lastIndexWithinCurrentPage = Math.min(this.pageSize, visibleCellIndices.length) - 1;
1640
+ const lastVisibleCellIndex = visibleCellIndices[lastIndexWithinCurrentPage];
1718
1641
  const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
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
- }));
1642
+ if (this.currentPage !== lastVisibleCellPage) {
1643
+ this.currentPage = lastVisibleCellPage;
1644
+ }
1645
+ const event = new CustomEvent('visiblePageChanged', {
1646
+ detail: {
1647
+ pageNumber: lastVisibleCellPage,
1648
+ },
1649
+ });
1650
+ this.dispatchEvent(event);
1732
1651
  }
1733
1652
  /**
1734
1653
  * A Promise which, after each query change, resolves once the fetches for the initial
@@ -1804,10 +1723,10 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1804
1723
  this.selectedFacets = restorationState.selectedFacets;
1805
1724
  if (!this.suppressURLQuery)
1806
1725
  this.baseQuery = restorationState.baseQuery;
1807
- this.setCurrentPage(restorationState.currentPage ?? 1);
1726
+ this.currentPage = restorationState.currentPage ?? 1;
1808
1727
  this.minSelectedDate = restorationState.minSelectedDate;
1809
1728
  this.maxSelectedDate = restorationState.maxSelectedDate;
1810
- if (this.currentPage && this.currentPage > 1) {
1729
+ if (this.currentPage > 1) {
1811
1730
  this.goToPage(this.currentPage);
1812
1731
  }
1813
1732
  }
@@ -1875,36 +1794,25 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1875
1794
  label: facetType,
1876
1795
  });
1877
1796
  }
1878
- async scrollToPage(pageNumber) {
1879
- const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1880
- // Wait for the infinite scroller be rendered before proceeding
1881
- let waitAttempts = 0;
1882
- while (!this.infiniteScroller && waitAttempts < 20) {
1883
- await this.updateComplete;
1884
- waitAttempts++;
1885
- }
1886
- if (!this.infiniteScroller)
1887
- return;
1888
- // The scroller have its default `itemCount=0`, so propagate our estimated
1889
- // tile count before jumping to the desired page.
1890
- if (this.infiniteScroller.itemCount < this.estimatedTileCount) {
1891
- this.infiniteScroller.itemCount = this.estimatedTileCount;
1892
- await this.updateComplete;
1893
- }
1894
- // Without this setTimeout(0), Safari just pauses until the `fetchPage`
1895
- // is complete then scrolls to the cell.
1896
- await new Promise(resolve => {
1897
- setTimeout(resolve, 0);
1797
+ scrollToPage(pageNumber) {
1798
+ return new Promise(resolve => {
1799
+ const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1800
+ // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1801
+ // then scrolls to the cell
1802
+ setTimeout(() => {
1803
+ this.isScrollingToCell = true;
1804
+ this.infiniteScroller?.scrollToCell(cellIndexToScrollTo, true);
1805
+ // This timeout is to give the scroll animation time to finish
1806
+ // then updating the infinite scroller once we're done scrolling
1807
+ // There's no scroll animation completion callback so we're
1808
+ // giving it 0.5s to finish.
1809
+ setTimeout(() => {
1810
+ this.isScrollingToCell = false;
1811
+ this.infiniteScroller?.refreshAllVisibleCells();
1812
+ resolve();
1813
+ }, 500);
1814
+ }, 0);
1898
1815
  });
1899
- this.isScrollingToCell = true;
1900
- const scrolled = await this.infiniteScroller.scrollToCell(cellIndexToScrollTo, true);
1901
- this.isScrollingToCell = false;
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
- }
1908
1816
  }
1909
1817
  /**
1910
1818
  * Whether sorting by relevance makes sense for the current state.
@@ -2809,7 +2717,7 @@ __decorate([
2809
2717
  __decorate([
2810
2718
  query('infinite-scroller')
2811
2719
  ], CollectionBrowser.prototype, "infiniteScroller", void 0);
2812
- CollectionBrowser = CollectionBrowser_1 = __decorate([
2720
+ CollectionBrowser = __decorate([
2813
2721
  customElement('collection-browser')
2814
2722
  ], CollectionBrowser);
2815
2723
  export { CollectionBrowser };