@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.
- package/.editorconfig +29 -29
- package/.github/workflows/ci.yml +27 -27
- package/.github/workflows/gh-pages-main.yml +39 -39
- package/.github/workflows/npm-publish.yml +39 -39
- package/.github/workflows/pr-preview.yml +38 -38
- package/.husky/pre-commit +1 -1
- package/.prettierignore +1 -1
- package/LICENSE +661 -661
- package/README.md +83 -83
- package/dist/src/app-root.js +0 -4
- package/dist/src/app-root.js.map +1 -1
- package/dist/src/collection-browser.d.ts +0 -41
- package/dist/src/collection-browser.js +36 -128
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/tiles/item-image.d.ts +1 -9
- package/dist/src/tiles/item-image.js +2 -22
- package/dist/src/tiles/item-image.js.map +1 -1
- package/dist/src/tiles/tile-display-value-provider.js +2 -1
- package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
- package/dist/test/tiles/grid/item-tile.test.js +2 -2
- package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list.test.js +2 -2
- package/dist/test/tiles/list/tile-list.test.js.map +1 -1
- package/eslint.config.mjs +53 -53
- package/index.html +24 -24
- package/local.archive.org.cert +86 -86
- package/local.archive.org.key +27 -27
- package/package.json +120 -120
- package/renovate.json +6 -6
- package/src/app-root.ts +0 -3
- package/src/collection-browser.ts +35 -146
- package/src/tiles/item-image.ts +1 -28
- package/src/tiles/tile-display-value-provider.ts +2 -3
- package/test/tiles/grid/item-tile.test.ts +2 -2
- package/test/tiles/list/tile-list.test.ts +2 -2
- package/tsconfig.json +25 -25
- package/web-dev-server.config.mjs +30 -30
- 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,
|
|
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
|
-
|
|
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.
|
|
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,
|
|
1717
|
-
const lastVisibleCellIndex =
|
|
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.
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
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.
|
|
1726
|
+
this.currentPage = restorationState.currentPage ?? 1;
|
|
1808
1727
|
this.minSelectedDate = restorationState.minSelectedDate;
|
|
1809
1728
|
this.maxSelectedDate = restorationState.maxSelectedDate;
|
|
1810
|
-
if (this.currentPage
|
|
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
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
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 =
|
|
2720
|
+
CollectionBrowser = __decorate([
|
|
2813
2721
|
customElement('collection-browser')
|
|
2814
2722
|
], CollectionBrowser);
|
|
2815
2723
|
export { CollectionBrowser };
|