@internetarchive/collection-browser 1.14.17-alpha.6 → 1.14.17-alpha.60

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 (86) hide show
  1. package/dist/index.d.ts +3 -2
  2. package/dist/index.js +3 -2
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/collection-browser.d.ts +13 -30
  5. package/dist/src/collection-browser.js +79 -72
  6. package/dist/src/collection-browser.js.map +1 -1
  7. package/dist/src/collection-facets.js +7 -4
  8. package/dist/src/collection-facets.js.map +1 -1
  9. package/dist/src/data-source/collection-browser-data-source-interface.d.ts +213 -0
  10. package/dist/src/data-source/collection-browser-data-source-interface.js +2 -0
  11. package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -0
  12. package/dist/src/data-source/collection-browser-data-source.d.ts +75 -175
  13. package/dist/src/data-source/collection-browser-data-source.js +226 -81
  14. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  15. package/dist/src/data-source/collection-browser-query-state.d.ts +43 -0
  16. package/dist/src/data-source/collection-browser-query-state.js +2 -0
  17. package/dist/src/data-source/collection-browser-query-state.js.map +1 -0
  18. package/dist/src/data-source/models.d.ts +1 -39
  19. package/dist/src/data-source/models.js.map +1 -1
  20. package/dist/src/models.d.ts +2 -1
  21. package/dist/src/models.js +9 -3
  22. package/dist/src/models.js.map +1 -1
  23. package/dist/src/sort-filter-bar/sort-filter-bar.js +1 -1
  24. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  25. package/dist/src/tiles/grid/item-tile.d.ts +1 -2
  26. package/dist/src/tiles/grid/item-tile.js +28 -25
  27. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  28. package/dist/src/tiles/grid/tile-stats.js +13 -8
  29. package/dist/src/tiles/grid/tile-stats.js.map +1 -1
  30. package/dist/src/tiles/item-image.d.ts +3 -0
  31. package/dist/src/tiles/item-image.js +30 -2
  32. package/dist/src/tiles/item-image.js.map +1 -1
  33. package/dist/src/tiles/list/tile-list.d.ts +1 -0
  34. package/dist/src/tiles/list/tile-list.js +30 -1
  35. package/dist/src/tiles/list/tile-list.js.map +1 -1
  36. package/dist/src/tiles/tile-dispatcher.js +3 -2
  37. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  38. package/dist/src/tiles/tile-display-value-provider.d.ts +5 -1
  39. package/dist/src/tiles/tile-display-value-provider.js +15 -1
  40. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  41. package/dist/src/utils/log.d.ts +7 -0
  42. package/dist/src/utils/log.js +16 -0
  43. package/dist/src/utils/log.js.map +1 -0
  44. package/dist/test/collection-browser.test.js +54 -6
  45. package/dist/test/collection-browser.test.js.map +1 -1
  46. package/dist/test/data-source/collection-browser-data-source.test.d.ts +1 -0
  47. package/dist/test/data-source/collection-browser-data-source.test.js +67 -0
  48. package/dist/test/data-source/collection-browser-data-source.test.js.map +1 -0
  49. package/dist/test/mocks/mock-search-responses.d.ts +1 -0
  50. package/dist/test/mocks/mock-search-responses.js +31 -1
  51. package/dist/test/mocks/mock-search-responses.js.map +1 -1
  52. package/dist/test/mocks/mock-search-service.js +3 -1
  53. package/dist/test/mocks/mock-search-service.js.map +1 -1
  54. package/dist/test/tile-stats.test.js +62 -0
  55. package/dist/test/tile-stats.test.js.map +1 -1
  56. package/dist/test/tiles/grid/item-tile.test.js +44 -0
  57. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  58. package/dist/test/tiles/list/tile-list.test.js +44 -0
  59. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  60. package/dist/test/tiles/tile-dispatcher.test.js +12 -0
  61. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  62. package/index.ts +3 -5
  63. package/package.json +3 -4
  64. package/src/collection-browser.ts +98 -104
  65. package/src/collection-facets.ts +6 -4
  66. package/src/data-source/collection-browser-data-source-interface.ts +267 -0
  67. package/src/data-source/collection-browser-data-source.ts +257 -306
  68. package/src/data-source/collection-browser-query-state.ts +54 -0
  69. package/src/data-source/models.ts +0 -47
  70. package/src/models.ts +12 -2
  71. package/src/sort-filter-bar/sort-filter-bar.ts +1 -1
  72. package/src/tiles/grid/item-tile.ts +36 -30
  73. package/src/tiles/grid/tile-stats.ts +12 -7
  74. package/src/tiles/item-image.ts +28 -0
  75. package/src/tiles/list/tile-list.ts +37 -1
  76. package/src/tiles/tile-dispatcher.ts +2 -1
  77. package/src/tiles/tile-display-value-provider.ts +19 -1
  78. package/src/utils/log.ts +16 -0
  79. package/test/collection-browser.test.ts +69 -8
  80. package/test/data-source/collection-browser-data-source.test.ts +86 -0
  81. package/test/mocks/mock-search-responses.ts +35 -1
  82. package/test/mocks/mock-search-service.ts +4 -0
  83. package/test/tile-stats.test.ts +104 -0
  84. package/test/tiles/grid/item-tile.test.ts +55 -0
  85. package/test/tiles/list/tile-list.test.ts +55 -0
  86. package/test/tiles/tile-dispatcher.test.ts +13 -0
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { CollectionBrowser } from './src/collection-browser';
2
- export { CollectionBrowserDataSource, CollectionBrowserDataSourceInterface, } from './src/data-source/collection-browser-data-source';
3
- export { CollectionBrowserQueryState } from './src/data-source/models';
2
+ export { CollectionBrowserDataSource } from './src/data-source/collection-browser-data-source';
3
+ export { CollectionBrowserDataSourceInterface } from './src/data-source/collection-browser-data-source-interface';
4
+ export { CollectionBrowserQueryState } from './src/data-source/collection-browser-query-state';
4
5
  export { SortFilterBar } from './src/sort-filter-bar/sort-filter-bar';
5
6
  export { CollectionDisplayMode, SortField, TileModel } from './src/models';
6
7
  export { CollectionBrowserLoadingTile } from './src/tiles/collection-browser-loading-tile';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { CollectionBrowser } from './src/collection-browser';
2
- export { CollectionBrowserDataSource, } from './src/data-source/collection-browser-data-source';
3
- export {} from './src/data-source/models';
2
+ export { CollectionBrowserDataSource } from './src/data-source/collection-browser-data-source';
3
+ export {} from './src/data-source/collection-browser-data-source-interface';
4
+ export {} from './src/data-source/collection-browser-query-state';
4
5
  export { SortFilterBar } from './src/sort-filter-bar/sort-filter-bar';
5
6
  export { SortField, TileModel } from './src/models';
6
7
  export { CollectionBrowserLoadingTile } from './src/tiles/collection-browser-loading-tile';
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,EACL,2BAA2B,GAE5B,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EAA+B,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAyB,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3E,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","sourcesContent":["export { CollectionBrowser } from './src/collection-browser';\nexport {\n CollectionBrowserDataSource,\n CollectionBrowserDataSourceInterface,\n} from './src/data-source/collection-browser-data-source';\nexport { CollectionBrowserQueryState } from './src/data-source/models';\nexport { SortFilterBar } from './src/sort-filter-bar/sort-filter-bar';\nexport { CollectionDisplayMode, SortField, TileModel } 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';\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;AAC/F,OAAO,EAAwC,MAAM,4DAA4D,CAAC;AAClH,OAAO,EAA+B,MAAM,kDAAkD,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAyB,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3E,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","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 { CollectionDisplayMode, SortField, TileModel } 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';\n"]}
@@ -6,17 +6,17 @@ import '@internetarchive/infinite-scroller';
6
6
  import type { ModalManagerInterface } from '@internetarchive/modal-manager';
7
7
  import type { FeatureFeedbackServiceInterface } from '@internetarchive/feature-feedback';
8
8
  import type { RecaptchaManagerInterface } from '@internetarchive/recaptcha-manager';
9
+ import { SelectedFacets, SortField, CollectionBrowserContext, TileModel, CollectionDisplayMode, FacetEventDetails } from './models';
10
+ import { RestorationStateHandlerInterface } from './restoration-state-handler';
11
+ import type { CollectionBrowserQueryState, CollectionBrowserSearchInterface } from './data-source/collection-browser-query-state';
12
+ import type { CollectionBrowserDataSourceInterface } from './data-source/collection-browser-data-source-interface';
13
+ import './empty-placeholder';
9
14
  import './tiles/tile-dispatcher';
10
15
  import './tiles/collection-browser-loading-tile';
11
16
  import './sort-filter-bar/sort-filter-bar';
12
17
  import './manage/manage-bar';
13
18
  import './collection-facets';
14
19
  import './circular-activity-indicator';
15
- import { SelectedFacets, SortField, CollectionBrowserContext, TileModel, CollectionDisplayMode, FacetEventDetails } from './models';
16
- import { RestorationStateHandlerInterface } from './restoration-state-handler';
17
- import { CollectionBrowserDataSourceInterface } from './data-source/collection-browser-data-source';
18
- import type { CollectionBrowserSearchInterface } from './data-source/models';
19
- import './empty-placeholder';
20
20
  export declare class CollectionBrowser extends LitElement implements InfiniteScrollerCellProviderInterface, SharedResizeObserverResizeHandlerInterface, CollectionBrowserSearchInterface {
21
21
  baseNavigationUrl?: string;
22
22
  baseImageUrl: string;
@@ -42,6 +42,7 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
42
42
  suppressResultCount: boolean;
43
43
  suppressURLQuery: boolean;
44
44
  suppressFacets: boolean;
45
+ suppressSortBar: boolean;
45
46
  clearResultsOnEmptyQuery: boolean;
46
47
  collectionPagePath: string;
47
48
  /** describes where this component is being used */
@@ -59,7 +60,6 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
59
60
  */
60
61
  isManageView: boolean;
61
62
  isLoansTab: boolean;
62
- queryErrorMessage?: string;
63
63
  /**
64
64
  * The results per page so we can paginate.
65
65
  *
@@ -91,7 +91,6 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
91
91
  private defaultSortField;
92
92
  private defaultSortDirection;
93
93
  private placeholderType;
94
- private prefixFilterCountMap;
95
94
  private contentContainer;
96
95
  private leftColumn?;
97
96
  private collectionFacets?;
@@ -109,6 +108,7 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
109
108
  private leftColIntersectionObserver?;
110
109
  private facetsIntersectionObserver?;
111
110
  private placeholderCellTemplate;
111
+ constructor();
112
112
  private tileModelAtCellIndex;
113
113
  private get estimatedTileCount();
114
114
  /**
@@ -277,6 +277,7 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
277
277
  * Emits an event indicating a change in whether the manage mode is shown.
278
278
  */
279
279
  private emitManageModeChangedEvent;
280
+ installDataSourceAndQueryState(dataSource: CollectionBrowserDataSourceInterface, queryState: CollectionBrowserQueryState): Promise<void>;
280
281
  firstUpdated(): void;
281
282
  updated(changed: PropertyValues): void;
282
283
  disconnectedCallback(): void;
@@ -304,7 +305,7 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
304
305
  private updateFacetFadeOut;
305
306
  private emitBaseQueryChanged;
306
307
  private emitSearchTypeChanged;
307
- private emitQueryStateChanged;
308
+ emitQueryStateChanged(): void;
308
309
  emitEmptyResults(): void;
309
310
  private disconnectResizeObserver;
310
311
  private setupResizeObserver;
@@ -319,15 +320,6 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
319
320
  private initialQueryChangeHappened;
320
321
  private historyPopOccurred;
321
322
  private previousQueryKey?;
322
- /**
323
- * Internal property to store the `resolve` function for the most recent
324
- * `initialSearchComplete` promise, allowing us to resolve it at the appropriate time.
325
- */
326
- private _initialSearchCompleteResolver;
327
- /**
328
- * Internal property to store the private value backing the `initialSearchComplete` getter.
329
- */
330
- private _initialSearchCompletePromise;
331
323
  /**
332
324
  * A Promise which, after each query change, resolves once the fetches for the initial
333
325
  * search have completed. Waits for *both* the hits and aggregations fetches to finish.
@@ -363,6 +355,10 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
363
355
  * - Weekly views for all other collections
364
356
  */
365
357
  applyDefaultCollectionSort(collectionInfo?: CollectionExtraInfo): void;
358
+ /**
359
+ * Applies the default sort option for the current profile element
360
+ */
361
+ applyDefaultProfileSort(): void;
366
362
  /**
367
363
  * This is useful for determining whether we need to reload the scroller.
368
364
  *
@@ -374,19 +370,6 @@ export declare class CollectionBrowser extends LitElement implements InfiniteScr
374
370
  * Refreshes all visible result cells in the infinite scroller.
375
371
  */
376
372
  refreshVisibleResults(): void;
377
- /**
378
- * Fetches and caches the prefix filter counts for the current sort type,
379
- * provided it is one that permits prefix filtering. (If not, this does nothing).
380
- */
381
- private updatePrefixFiltersForCurrentSort;
382
- /**
383
- * Clears the cached letter counts for both title and creator, and
384
- * fetches a new set of counts for whichever of them is the currently
385
- * selected sort option (which may be neither).
386
- *
387
- * Call this whenever the counts are invalidated (e.g., by a query change).
388
- */
389
- private refreshLetterCounts;
390
373
  /**
391
374
  * Callback when a result is selected
392
375
  */
@@ -6,24 +6,25 @@ import { classMap } from 'lit/directives/class-map.js';
6
6
  import { msg } from '@lit/localize';
7
7
  import { SearchType, } from '@internetarchive/search-service';
8
8
  import '@internetarchive/infinite-scroller';
9
+ import { SortField, getDefaultSelectedFacets, sortOptionFromAPIString, SORT_OPTIONS, defaultProfileElementSorts, } from './models';
10
+ import { RestorationStateHandler, } from './restoration-state-handler';
11
+ import { CollectionBrowserDataSource } from './data-source/collection-browser-data-source';
12
+ import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
13
+ import chevronIcon from './assets/img/icons/chevron';
14
+ import { srOnlyStyle } from './styles/sr-only';
15
+ import { sha1 } from './utils/sha1';
16
+ import { formatDate } from './utils/format-date';
17
+ import { log } from './utils/log';
18
+ import './empty-placeholder';
9
19
  import './tiles/tile-dispatcher';
10
20
  import './tiles/collection-browser-loading-tile';
11
21
  import './sort-filter-bar/sort-filter-bar';
12
22
  import './manage/manage-bar';
13
23
  import './collection-facets';
14
24
  import './circular-activity-indicator';
15
- import { SortField, getDefaultSelectedFacets, sortOptionFromAPIString, SORT_OPTIONS, } from './models';
16
- import { RestorationStateHandler, } from './restoration-state-handler';
17
- import { CollectionBrowserDataSource, } from './data-source/collection-browser-data-source';
18
- import chevronIcon from './assets/img/icons/chevron';
19
- import './empty-placeholder';
20
- import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
21
- import { srOnlyStyle } from './styles/sr-only';
22
- import { sha1 } from './utils/sha1';
23
- import { formatDate } from './utils/format-date';
24
25
  let CollectionBrowser = class CollectionBrowser extends LitElement {
25
26
  constructor() {
26
- super(...arguments);
27
+ super();
27
28
  this.baseImageUrl = 'https://archive.org';
28
29
  this.searchType = SearchType.METADATA;
29
30
  this.defaultSortParam = null;
@@ -37,6 +38,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
37
38
  this.suppressResultCount = false;
38
39
  this.suppressURLQuery = false;
39
40
  this.suppressFacets = false;
41
+ this.suppressSortBar = false;
40
42
  this.clearResultsOnEmptyQuery = false;
41
43
  this.collectionPagePath = '/details/';
42
44
  /** describes where this component is being used */
@@ -82,7 +84,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
82
84
  this.defaultSortField = SortField.relevance;
83
85
  this.defaultSortDirection = null;
84
86
  this.placeholderType = null;
85
- this.prefixFilterCountMap = {};
86
87
  /**
87
88
  * When we're animated scrolling to the page, we don't want to fetch
88
89
  * all of the pages as it scrolls so this lets us know if we're scrolling
@@ -126,16 +127,10 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
126
127
  // so this keeps track of whether we've already set the initial query
127
128
  this.initialQueryChangeHappened = false;
128
129
  this.historyPopOccurred = false;
129
- /**
130
- * Internal property to store the private value backing the `initialSearchComplete` getter.
131
- */
132
- this._initialSearchCompletePromise = new Promise(res => {
133
- this._initialSearchCompleteResolver = res;
134
- });
130
+ this.addController(this.dataSource);
135
131
  }
136
132
  tileModelAtCellIndex(index) {
137
- const offsetIndex = index + this.tileModelOffset;
138
- const model = this.dataSource.getTileModelAt(offsetIndex);
133
+ const model = this.dataSource.getTileModelAt(index);
139
134
  /**
140
135
  * If we encounter a model we don't have yet and we're not in the middle of an
141
136
  * automated scroll, fetch the page and just return undefined.
@@ -144,8 +139,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
144
139
  * We disable it during the automated scroll since we don't want to fetch pages for intervening cells the
145
140
  * user may never see.
146
141
  */
147
- if (!model && !this.isScrollingToCell) {
148
- const pageNumber = Math.floor(offsetIndex / this.pageSize) + 1;
142
+ if (!model && !this.isScrollingToCell && this.dataSource.queryInitialized) {
143
+ const pageNumber = Math.floor(index / this.pageSize) + 1;
149
144
  this.dataSource.fetchPage(pageNumber);
150
145
  }
151
146
  return model;
@@ -299,7 +294,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
299
294
  this.placeholderType =
300
295
  !hasQuery && isCollection ? 'empty-collection' : 'no-results';
301
296
  }
302
- if (this.queryErrorMessage) {
297
+ if (this.dataSource.queryErrorMessage) {
303
298
  this.placeholderType =
304
299
  !hasQuery && isCollection ? 'collection-error' : 'query-error';
305
300
  }
@@ -311,7 +306,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
311
306
  .placeholderType=${this.placeholderType}
312
307
  ?isMobileView=${this.mobileView}
313
308
  ?isCollection=${!!this.withinCollection}
314
- .detailMessage=${(_a = this.queryErrorMessage) !== null && _a !== void 0 ? _a : ''}
309
+ .detailMessage=${(_a = this.dataSource.queryErrorMessage) !== null && _a !== void 0 ? _a : ''}
315
310
  .baseNavigationUrl=${this.baseNavigationUrl}
316
311
  ></empty-placeholder>
317
312
  ${this.infiniteScrollerTemplate}
@@ -446,6 +441,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
446
441
  }
447
442
  get sortFilterBarTemplate() {
448
443
  var _a;
444
+ if (this.suppressSortBar)
445
+ return nothing;
449
446
  return html `
450
447
  <sort-filter-bar
451
448
  .defaultSortField=${this.defaultSortField}
@@ -533,7 +530,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
533
530
  }
534
531
  selectedSortChanged() {
535
532
  // Lazy-load the alphabet counts for title/creator sort bar as needed
536
- this.updatePrefixFiltersForCurrentSort();
533
+ this.dataSource.updatePrefixFiltersForCurrentSort();
537
534
  }
538
535
  get sortParam() {
539
536
  var _a;
@@ -773,6 +770,32 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
773
770
  detail: this.isManageView,
774
771
  }));
775
772
  }
773
+ async installDataSourceAndQueryState(dataSource, queryState) {
774
+ var _a, _b;
775
+ log('Installing data source & query state in CB:', dataSource, queryState);
776
+ if (this.dataSource)
777
+ this.removeController(this.dataSource);
778
+ this.dataSource = dataSource;
779
+ this.addController(this.dataSource);
780
+ this.baseQuery = queryState.baseQuery;
781
+ this.profileElement = queryState.profileElement;
782
+ this.searchType = queryState.searchType;
783
+ this.selectedFacets =
784
+ (_a = queryState.selectedFacets) !== null && _a !== void 0 ? _a : getDefaultSelectedFacets();
785
+ this.minSelectedDate = queryState.minSelectedDate;
786
+ this.maxSelectedDate = queryState.maxSelectedDate;
787
+ this.selectedSort = (_b = queryState.selectedSort) !== null && _b !== void 0 ? _b : SortField.default;
788
+ this.sortDirection = queryState.sortDirection;
789
+ this.selectedTitleFilter = queryState.selectedTitleFilter;
790
+ this.selectedCreatorFilter = queryState.selectedCreatorFilter;
791
+ this.requestUpdate();
792
+ await this.updateComplete;
793
+ if (!this.searchResultsLoading) {
794
+ this.setTotalResultCount(this.dataSource.totalResults);
795
+ this.setTileCount(this.dataSource.size);
796
+ }
797
+ this.refreshVisibleResults();
798
+ }
776
799
  firstUpdated() {
777
800
  this.setupStateRestorationObserver();
778
801
  this.restoreState();
@@ -818,6 +841,9 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
818
841
  });
819
842
  }
820
843
  }
844
+ if (changed.has('profileElement')) {
845
+ this.applyDefaultProfileSort();
846
+ }
821
847
  if (changed.has('baseQuery')) {
822
848
  this.emitBaseQueryChanged();
823
849
  }
@@ -832,8 +858,10 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
832
858
  changed.has('maxSelectedDate') ||
833
859
  changed.has('selectedFacets') ||
834
860
  changed.has('searchService') ||
835
- changed.has('withinCollection')) {
836
- this.refreshLetterCounts();
861
+ changed.has('withinCollection') ||
862
+ changed.has('withinProfile') ||
863
+ changed.has('profileElement')) {
864
+ this.dataSource.refreshLetterCounts();
837
865
  }
838
866
  if (changed.has('selectedSort') || changed.has('sortDirection')) {
839
867
  const prevSortDirection = changed.get('sortDirection');
@@ -1027,11 +1055,10 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1027
1055
  * one, to ensure you do not await an obsolete promise from the previous update.
1028
1056
  */
1029
1057
  get initialSearchComplete() {
1030
- return this._initialSearchCompletePromise;
1058
+ return this.dataSource.initialSearchComplete;
1031
1059
  }
1032
1060
  async handleQueryChange() {
1033
1061
  var _a;
1034
- console.log('CB: handling query change', this.previousQueryKey, this.dataSource.pageFetchQueryKey, this.dataSource.canPerformSearch);
1035
1062
  // only reset if the query has actually changed
1036
1063
  if (!this.searchService ||
1037
1064
  this.dataSource.pageFetchQueryKey === this.previousQueryKey)
@@ -1040,16 +1067,14 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1040
1067
  if (!this.dataSource.canPerformSearch &&
1041
1068
  !(this.clearResultsOnEmptyQuery && this.baseQuery === ''))
1042
1069
  return;
1043
- console.log('CB will reset', this.baseQuery, JSON.stringify(this.selectedFacets));
1044
1070
  this.previousQueryKey = this.dataSource.pageFetchQueryKey;
1045
- this.emitQueryStateChanged();
1071
+ // this.emitQueryStateChanged();
1046
1072
  this.tileModelOffset = 0;
1047
1073
  this.totalResults = undefined;
1048
1074
  this.pagesToRender =
1049
1075
  this.initialPageNumber === 1
1050
1076
  ? 2 // First two pages are batched into one request when starting from page 1
1051
1077
  : this.initialPageNumber;
1052
- this.queryErrorMessage = undefined;
1053
1078
  // Reset the infinite scroller's item count, so that it
1054
1079
  // shows tile placeholders until the new query's results load in
1055
1080
  if (this.infiniteScroller) {
@@ -1070,14 +1095,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1070
1095
  this.persistState();
1071
1096
  }
1072
1097
  this.historyPopOccurred = false;
1073
- // Reset the `initialSearchComplete` promise with a new value for the imminent search
1074
- this._initialSearchCompletePromise = new Promise(res => {
1075
- this._initialSearchCompleteResolver = res;
1076
- });
1077
1098
  // Fire the initial page and facets requests
1078
- await this.dataSource.handleQueryChange();
1079
- // Resolve the `initialSearchComplete` promise for this search
1080
- this._initialSearchCompleteResolver(true);
1099
+ // await this.dataSource.handleQueryChange();
1081
1100
  }
1082
1101
  setupStateRestorationObserver() {
1083
1102
  if (this.boundNavigationHandler)
@@ -1194,7 +1213,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1194
1213
  * Sets the total number of tiles displayed in the infinite scroller.
1195
1214
  */
1196
1215
  setTileCount(count) {
1197
- console.log('Setting scroller tile count to', count);
1198
1216
  if (this.infiniteScroller) {
1199
1217
  this.infiniteScroller.itemCount = count;
1200
1218
  }
@@ -1244,6 +1262,23 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1244
1262
  };
1245
1263
  }
1246
1264
  }
1265
+ /**
1266
+ * Applies the default sort option for the current profile element
1267
+ */
1268
+ applyDefaultProfileSort() {
1269
+ if (this.profileElement) {
1270
+ const defaultSortField = defaultProfileElementSorts[this.profileElement];
1271
+ this.defaultSortField = defaultSortField !== null && defaultSortField !== void 0 ? defaultSortField : SortField.weeklyview;
1272
+ }
1273
+ else {
1274
+ this.defaultSortField = SortField.weeklyview;
1275
+ }
1276
+ this.defaultSortDirection = 'desc';
1277
+ this.defaultSortParam = {
1278
+ field: this.defaultSortField,
1279
+ direction: this.defaultSortDirection,
1280
+ };
1281
+ }
1247
1282
  /**
1248
1283
  * This is useful for determining whether we need to reload the scroller.
1249
1284
  *
@@ -1267,31 +1302,6 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1267
1302
  var _a;
1268
1303
  (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1269
1304
  }
1270
- /**
1271
- * Fetches and caches the prefix filter counts for the current sort type,
1272
- * provided it is one that permits prefix filtering. (If not, this does nothing).
1273
- */
1274
- async updatePrefixFiltersForCurrentSort() {
1275
- if (['title', 'creator'].includes(this.selectedSort)) {
1276
- const filterType = this.selectedSort;
1277
- if (!this.prefixFilterCountMap[filterType]) {
1278
- this.dataSource.updatePrefixFilterCounts(filterType);
1279
- }
1280
- }
1281
- }
1282
- /**
1283
- * Clears the cached letter counts for both title and creator, and
1284
- * fetches a new set of counts for whichever of them is the currently
1285
- * selected sort option (which may be neither).
1286
- *
1287
- * Call this whenever the counts are invalidated (e.g., by a query change).
1288
- */
1289
- refreshLetterCounts() {
1290
- if (Object.keys(this.prefixFilterCountMap).length > 0) {
1291
- this.prefixFilterCountMap = {};
1292
- }
1293
- this.updatePrefixFiltersForCurrentSort();
1294
- }
1295
1305
  /**
1296
1306
  * Callback when a result is selected
1297
1307
  */
@@ -1302,7 +1312,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1302
1312
  // this.mapDataSource(model => ({ ...model }));
1303
1313
  const cellIndex = this.dataSource.indexOf(event.detail);
1304
1314
  if (cellIndex >= 0)
1305
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshCell(cellIndex - this.tileModelOffset);
1315
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshCell(cellIndex);
1306
1316
  }
1307
1317
  (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1308
1318
  category: this.searchContext,
@@ -1345,7 +1355,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1345
1355
  * increase the number of pages to render and start fetching data for the new page
1346
1356
  */
1347
1357
  scrollThresholdReached() {
1348
- if (!this.dataSource.endOfDataReached) {
1358
+ if (!this.dataSource.endOfDataReached && this.dataSource.queryInitialized) {
1349
1359
  this.pagesToRender += 1;
1350
1360
  this.dataSource.fetchPage(this.pagesToRender);
1351
1361
  }
@@ -1803,6 +1813,9 @@ __decorate([
1803
1813
  __decorate([
1804
1814
  property({ type: Boolean })
1805
1815
  ], CollectionBrowser.prototype, "suppressFacets", void 0);
1816
+ __decorate([
1817
+ property({ type: Boolean })
1818
+ ], CollectionBrowser.prototype, "suppressSortBar", void 0);
1806
1819
  __decorate([
1807
1820
  property({ type: Boolean })
1808
1821
  ], CollectionBrowser.prototype, "clearResultsOnEmptyQuery", void 0);
@@ -1842,9 +1855,6 @@ __decorate([
1842
1855
  __decorate([
1843
1856
  property({ type: Boolean })
1844
1857
  ], CollectionBrowser.prototype, "isLoansTab", void 0);
1845
- __decorate([
1846
- property({ type: String })
1847
- ], CollectionBrowser.prototype, "queryErrorMessage", void 0);
1848
1858
  __decorate([
1849
1859
  property({ type: Object })
1850
1860
  ], CollectionBrowser.prototype, "dataSource", void 0);
@@ -1878,9 +1888,6 @@ __decorate([
1878
1888
  __decorate([
1879
1889
  state()
1880
1890
  ], CollectionBrowser.prototype, "placeholderType", void 0);
1881
- __decorate([
1882
- state()
1883
- ], CollectionBrowser.prototype, "prefixFilterCountMap", void 0);
1884
1891
  __decorate([
1885
1892
  query('#content-container')
1886
1893
  ], CollectionBrowser.prototype, "contentContainer", void 0);