@internetarchive/collection-browser 1.8.0 → 1.9.0-alpha2

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 (269) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +26 -26
  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 +4 -4
  7. package/LICENSE +661 -661
  8. package/README.md +83 -83
  9. package/dist/index.d.ts +9 -9
  10. package/dist/index.js +9 -9
  11. package/dist/src/app-root.d.ts +54 -54
  12. package/dist/src/app-root.js +293 -293
  13. package/dist/src/assets/img/icons/arrow-left.d.ts +2 -2
  14. package/dist/src/assets/img/icons/arrow-left.js +2 -2
  15. package/dist/src/assets/img/icons/arrow-right.d.ts +2 -2
  16. package/dist/src/assets/img/icons/arrow-right.js +2 -2
  17. package/dist/src/assets/img/icons/chevron.d.ts +2 -2
  18. package/dist/src/assets/img/icons/chevron.js +2 -2
  19. package/dist/src/assets/img/icons/contract.d.ts +2 -2
  20. package/dist/src/assets/img/icons/contract.js +2 -2
  21. package/dist/src/assets/img/icons/empty-query.d.ts +2 -2
  22. package/dist/src/assets/img/icons/empty-query.js +2 -2
  23. package/dist/src/assets/img/icons/expand.d.ts +2 -2
  24. package/dist/src/assets/img/icons/expand.js +2 -2
  25. package/dist/src/assets/img/icons/eye-closed.d.ts +2 -2
  26. package/dist/src/assets/img/icons/eye-closed.js +2 -2
  27. package/dist/src/assets/img/icons/eye.d.ts +2 -2
  28. package/dist/src/assets/img/icons/eye.js +2 -2
  29. package/dist/src/assets/img/icons/favorite-filled.d.ts +1 -1
  30. package/dist/src/assets/img/icons/favorite-filled.js +2 -2
  31. package/dist/src/assets/img/icons/login-required.d.ts +1 -1
  32. package/dist/src/assets/img/icons/login-required.js +2 -2
  33. package/dist/src/assets/img/icons/mediatype/account.d.ts +1 -1
  34. package/dist/src/assets/img/icons/mediatype/account.js +2 -2
  35. package/dist/src/assets/img/icons/mediatype/audio.d.ts +1 -1
  36. package/dist/src/assets/img/icons/mediatype/audio.js +2 -2
  37. package/dist/src/assets/img/icons/mediatype/collection.d.ts +1 -1
  38. package/dist/src/assets/img/icons/mediatype/collection.js +2 -2
  39. package/dist/src/assets/img/icons/mediatype/data.d.ts +1 -1
  40. package/dist/src/assets/img/icons/mediatype/data.js +2 -2
  41. package/dist/src/assets/img/icons/mediatype/etree.d.ts +1 -1
  42. package/dist/src/assets/img/icons/mediatype/etree.js +2 -2
  43. package/dist/src/assets/img/icons/mediatype/film.d.ts +1 -1
  44. package/dist/src/assets/img/icons/mediatype/film.js +2 -2
  45. package/dist/src/assets/img/icons/mediatype/images.d.ts +1 -1
  46. package/dist/src/assets/img/icons/mediatype/images.js +2 -2
  47. package/dist/src/assets/img/icons/mediatype/radio.d.ts +1 -1
  48. package/dist/src/assets/img/icons/mediatype/radio.js +2 -2
  49. package/dist/src/assets/img/icons/mediatype/software.d.ts +1 -1
  50. package/dist/src/assets/img/icons/mediatype/software.js +2 -2
  51. package/dist/src/assets/img/icons/mediatype/texts.d.ts +1 -1
  52. package/dist/src/assets/img/icons/mediatype/texts.js +2 -2
  53. package/dist/src/assets/img/icons/mediatype/tv.d.ts +1 -1
  54. package/dist/src/assets/img/icons/mediatype/tv.js +2 -2
  55. package/dist/src/assets/img/icons/mediatype/video.d.ts +1 -1
  56. package/dist/src/assets/img/icons/mediatype/video.js +2 -2
  57. package/dist/src/assets/img/icons/mediatype/web.d.ts +1 -1
  58. package/dist/src/assets/img/icons/mediatype/web.js +2 -2
  59. package/dist/src/assets/img/icons/null-result.d.ts +2 -2
  60. package/dist/src/assets/img/icons/null-result.js +2 -2
  61. package/dist/src/assets/img/icons/restricted.d.ts +1 -1
  62. package/dist/src/assets/img/icons/restricted.js +2 -2
  63. package/dist/src/assets/img/icons/reviews.d.ts +1 -1
  64. package/dist/src/assets/img/icons/reviews.js +2 -2
  65. package/dist/src/assets/img/icons/upload.d.ts +1 -1
  66. package/dist/src/assets/img/icons/upload.js +2 -2
  67. package/dist/src/assets/img/icons/views.d.ts +1 -1
  68. package/dist/src/assets/img/icons/views.js +2 -2
  69. package/dist/src/circular-activity-indicator.d.ts +5 -5
  70. package/dist/src/circular-activity-indicator.js +17 -17
  71. package/dist/src/collection-browser.d.ts +469 -469
  72. package/dist/src/collection-browser.js +1677 -1653
  73. package/dist/src/collection-browser.js.map +1 -1
  74. package/dist/src/collection-facets/facet-tombstone-row.d.ts +5 -5
  75. package/dist/src/collection-facets/facet-tombstone-row.js +15 -15
  76. package/dist/src/collection-facets/facets-template.d.ts +20 -20
  77. package/dist/src/collection-facets/facets-template.js +152 -152
  78. package/dist/src/collection-facets/more-facets-content.d.ts +77 -77
  79. package/dist/src/collection-facets/more-facets-content.js +359 -359
  80. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -36
  81. package/dist/src/collection-facets/more-facets-pagination.js +196 -196
  82. package/dist/src/collection-facets/toggle-switch.d.ts +41 -41
  83. package/dist/src/collection-facets/toggle-switch.js +94 -94
  84. package/dist/src/collection-facets.d.ts +99 -99
  85. package/dist/src/collection-facets.js +471 -471
  86. package/dist/src/empty-placeholder.d.ts +21 -21
  87. package/dist/src/empty-placeholder.js +69 -69
  88. package/dist/src/expanded-date-picker.d.ts +43 -43
  89. package/dist/src/expanded-date-picker.js +109 -109
  90. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  91. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  92. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  93. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  94. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  95. package/dist/src/mediatype/mediatype-config.js +85 -85
  96. package/dist/src/models.d.ts +162 -149
  97. package/dist/src/models.js +256 -195
  98. package/dist/src/models.js.map +1 -1
  99. package/dist/src/restoration-state-handler.d.ts +70 -63
  100. package/dist/src/restoration-state-handler.js +355 -326
  101. package/dist/src/restoration-state-handler.js.map +1 -1
  102. package/dist/src/sort-filter-bar/alpha-bar-tooltip.d.ts +6 -6
  103. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js +24 -24
  104. package/dist/src/sort-filter-bar/alpha-bar.d.ts +21 -21
  105. package/dist/src/sort-filter-bar/alpha-bar.js +128 -128
  106. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  107. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  108. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  109. package/dist/src/sort-filter-bar/img/list.js +2 -2
  110. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.d.ts +1 -1
  111. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js +2 -2
  112. package/dist/src/sort-filter-bar/img/sort-toggle-down.d.ts +1 -1
  113. package/dist/src/sort-filter-bar/img/sort-toggle-down.js +2 -2
  114. package/dist/src/sort-filter-bar/img/sort-toggle-up.d.ts +1 -1
  115. package/dist/src/sort-filter-bar/img/sort-toggle-up.js +2 -2
  116. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  117. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  118. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  119. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  120. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +201 -199
  121. package/dist/src/sort-filter-bar/sort-filter-bar.js +622 -617
  122. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  123. package/dist/src/styles/item-image-styles.d.ts +8 -8
  124. package/dist/src/styles/item-image-styles.js +9 -9
  125. package/dist/src/styles/sr-only.d.ts +1 -1
  126. package/dist/src/styles/sr-only.js +2 -2
  127. package/dist/src/tiles/base-tile-component.d.ts +18 -18
  128. package/dist/src/tiles/base-tile-component.js +59 -59
  129. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  130. package/dist/src/tiles/collection-browser-loading-tile.js +15 -15
  131. package/dist/src/tiles/grid/account-tile.d.ts +18 -18
  132. package/dist/src/tiles/grid/account-tile.js +72 -72
  133. package/dist/src/tiles/grid/collection-tile.d.ts +15 -15
  134. package/dist/src/tiles/grid/collection-tile.js +80 -80
  135. package/dist/src/tiles/grid/item-tile.d.ts +27 -27
  136. package/dist/src/tiles/grid/item-tile.js +134 -134
  137. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.d.ts +1 -1
  138. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +8 -8
  139. package/dist/src/tiles/grid/tile-stats.d.ts +11 -11
  140. package/dist/src/tiles/grid/tile-stats.js +48 -48
  141. package/dist/src/tiles/hover/hover-pane-controller.d.ts +219 -219
  142. package/dist/src/tiles/hover/hover-pane-controller.js +352 -352
  143. package/dist/src/tiles/hover/tile-hover-pane.d.ts +15 -15
  144. package/dist/src/tiles/hover/tile-hover-pane.js +38 -38
  145. package/dist/src/tiles/image-block.d.ts +17 -17
  146. package/dist/src/tiles/image-block.js +72 -72
  147. package/dist/src/tiles/item-image.d.ts +35 -35
  148. package/dist/src/tiles/item-image.js +117 -117
  149. package/dist/src/tiles/list/tile-list-compact-header.d.ts +6 -6
  150. package/dist/src/tiles/list/tile-list-compact-header.js +38 -38
  151. package/dist/src/tiles/list/tile-list-compact.d.ts +15 -15
  152. package/dist/src/tiles/list/tile-list-compact.js +114 -114
  153. package/dist/src/tiles/list/tile-list.d.ts +46 -46
  154. package/dist/src/tiles/list/tile-list.js +298 -298
  155. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  156. package/dist/src/tiles/mediatype-icon.js +47 -47
  157. package/dist/src/tiles/overlay/icon-overlay.d.ts +10 -10
  158. package/dist/src/tiles/overlay/icon-overlay.js +40 -40
  159. package/dist/src/tiles/overlay/icon-text-overlay.d.ts +9 -9
  160. package/dist/src/tiles/overlay/icon-text-overlay.js +38 -38
  161. package/dist/src/tiles/overlay/text-overlay.d.ts +10 -10
  162. package/dist/src/tiles/overlay/text-overlay.js +42 -42
  163. package/dist/src/tiles/text-snippet-block.d.ts +27 -27
  164. package/dist/src/tiles/text-snippet-block.js +73 -73
  165. package/dist/src/tiles/tile-dispatcher.d.ts +50 -50
  166. package/dist/src/tiles/tile-dispatcher.js +185 -185
  167. package/dist/src/tiles/tile-display-value-provider.d.ts +43 -43
  168. package/dist/src/tiles/tile-display-value-provider.js +80 -80
  169. package/dist/src/utils/analytics-events.d.ts +24 -24
  170. package/dist/src/utils/analytics-events.js +26 -26
  171. package/dist/src/utils/array-equals.d.ts +4 -4
  172. package/dist/src/utils/array-equals.js +10 -10
  173. package/dist/src/utils/format-count.d.ts +7 -7
  174. package/dist/src/utils/format-count.js +76 -76
  175. package/dist/src/utils/format-date.d.ts +2 -2
  176. package/dist/src/utils/format-date.js +25 -25
  177. package/dist/src/utils/format-unit-size.d.ts +2 -2
  178. package/dist/src/utils/format-unit-size.js +33 -33
  179. package/dist/src/utils/local-date-from-utc.d.ts +9 -9
  180. package/dist/src/utils/local-date-from-utc.js +15 -15
  181. package/dist/src/utils/sha1.d.ts +2 -2
  182. package/dist/src/utils/sha1.js +8 -8
  183. package/dist/test/collection-browser.test.d.ts +1 -1
  184. package/dist/test/collection-browser.test.js +808 -808
  185. package/dist/test/collection-facets/facets-template.test.d.ts +1 -1
  186. package/dist/test/collection-facets/facets-template.test.js +134 -134
  187. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -1
  188. package/dist/test/collection-facets/more-facets-content.test.js +133 -133
  189. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -1
  190. package/dist/test/collection-facets/more-facets-pagination.test.js +117 -117
  191. package/dist/test/collection-facets/toggle-switch.test.d.ts +1 -1
  192. package/dist/test/collection-facets/toggle-switch.test.js +73 -73
  193. package/dist/test/collection-facets.test.d.ts +2 -2
  194. package/dist/test/collection-facets.test.js +645 -645
  195. package/dist/test/empty-placeholder.test.d.ts +1 -1
  196. package/dist/test/empty-placeholder.test.js +56 -56
  197. package/dist/test/expanded-date-picker.test.d.ts +1 -1
  198. package/dist/test/expanded-date-picker.test.js +95 -95
  199. package/dist/test/icon-overlay.test.d.ts +1 -1
  200. package/dist/test/icon-overlay.test.js +24 -24
  201. package/dist/test/image-block.test.d.ts +1 -1
  202. package/dist/test/image-block.test.js +48 -48
  203. package/dist/test/item-image.test.d.ts +1 -1
  204. package/dist/test/item-image.test.js +84 -84
  205. package/dist/test/mediatype-config.test.d.ts +1 -1
  206. package/dist/test/mediatype-config.test.js +16 -16
  207. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  208. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  209. package/dist/test/mocks/mock-collection-name-cache.d.ts +9 -9
  210. package/dist/test/mocks/mock-collection-name-cache.js +17 -17
  211. package/dist/test/mocks/mock-search-responses.d.ts +19 -19
  212. package/dist/test/mocks/mock-search-responses.js +623 -623
  213. package/dist/test/mocks/mock-search-service.d.ts +15 -15
  214. package/dist/test/mocks/mock-search-service.js +48 -48
  215. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  216. package/dist/test/restoration-state-handler.test.js +270 -218
  217. package/dist/test/restoration-state-handler.test.js.map +1 -1
  218. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.d.ts +1 -1
  219. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +12 -12
  220. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +1 -1
  221. package/dist/test/sort-filter-bar/alpha-bar.test.js +73 -73
  222. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -1
  223. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +378 -378
  224. package/dist/test/text-overlay.test.d.ts +1 -1
  225. package/dist/test/text-overlay.test.js +48 -48
  226. package/dist/test/text-snippet-block.test.d.ts +1 -1
  227. package/dist/test/text-snippet-block.test.js +57 -57
  228. package/dist/test/tile-stats.test.d.ts +1 -1
  229. package/dist/test/tile-stats.test.js +33 -33
  230. package/dist/test/tiles/grid/account-tile.test.d.ts +1 -1
  231. package/dist/test/tiles/grid/account-tile.test.js +76 -76
  232. package/dist/test/tiles/grid/collection-tile.test.d.ts +1 -1
  233. package/dist/test/tiles/grid/collection-tile.test.js +73 -73
  234. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -1
  235. package/dist/test/tiles/grid/item-tile.test.js +254 -254
  236. package/dist/test/tiles/hover/hover-pane-controller.test.d.ts +1 -1
  237. package/dist/test/tiles/hover/hover-pane-controller.test.js +257 -257
  238. package/dist/test/tiles/hover/tile-hover-pane.test.d.ts +1 -1
  239. package/dist/test/tiles/hover/tile-hover-pane.test.js +13 -13
  240. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -1
  241. package/dist/test/tiles/list/tile-list-compact.test.js +143 -143
  242. package/dist/test/tiles/list/tile-list.test.d.ts +1 -1
  243. package/dist/test/tiles/list/tile-list.test.js +242 -242
  244. package/dist/test/tiles/tile-dispatcher.test.d.ts +1 -1
  245. package/dist/test/tiles/tile-dispatcher.test.js +67 -67
  246. package/dist/test/tiles/tile-display-value-provider.test.d.ts +1 -1
  247. package/dist/test/tiles/tile-display-value-provider.test.js +141 -141
  248. package/dist/test/utils/array-equals.test.d.ts +1 -1
  249. package/dist/test/utils/array-equals.test.js +26 -26
  250. package/dist/test/utils/format-count.test.d.ts +1 -1
  251. package/dist/test/utils/format-count.test.js +23 -23
  252. package/dist/test/utils/format-date.test.d.ts +1 -1
  253. package/dist/test/utils/format-date.test.js +17 -17
  254. package/dist/test/utils/format-unit-size.test.d.ts +1 -1
  255. package/dist/test/utils/format-unit-size.test.js +17 -17
  256. package/dist/test/utils/local-date-from-utc.test.d.ts +1 -1
  257. package/dist/test/utils/local-date-from-utc.test.js +26 -26
  258. package/local.archive.org.cert +86 -86
  259. package/local.archive.org.key +27 -27
  260. package/package.json +1 -1
  261. package/renovate.json +6 -6
  262. package/src/collection-browser.ts +42 -8
  263. package/src/models.ts +193 -109
  264. package/src/restoration-state-handler.ts +66 -40
  265. package/src/sort-filter-bar/sort-filter-bar.ts +34 -27
  266. package/test/restoration-state-handler.test.ts +68 -1
  267. package/tsconfig.json +21 -21
  268. package/web-dev-server.config.mjs +30 -30
  269. package/web-test-runner.config.mjs +41 -41
@@ -1,289 +1,289 @@
1
- import { __decorate } from "tslib";
2
- /* eslint-disable import/no-duplicates */
3
- import { html, css, LitElement, nothing, } from 'lit';
4
- import { customElement, property, query, state } from 'lit/decorators.js';
5
- import { classMap } from 'lit/directives/class-map.js';
6
- import { FilterConstraint, FilterMapBuilder, SearchType, } from '@internetarchive/search-service';
7
- import '@internetarchive/infinite-scroller';
8
- import './tiles/tile-dispatcher';
9
- import './tiles/collection-browser-loading-tile';
10
- import './sort-filter-bar/sort-filter-bar';
11
- import './collection-facets';
12
- import './circular-activity-indicator';
13
- import './sort-filter-bar/sort-filter-bar';
14
- import { SortField, SortFieldToMetadataField, getDefaultSelectedFacets, prefixFilterAggregationKeys, MetadataFieldToSortField, } from './models';
15
- import { RestorationStateHandler, } from './restoration-state-handler';
16
- import chevronIcon from './assets/img/icons/chevron';
17
- import './empty-placeholder';
18
- import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
19
- import { srOnlyStyle } from './styles/sr-only';
20
- import { sha1 } from './utils/sha1';
21
- let CollectionBrowser = class CollectionBrowser extends LitElement {
22
- constructor() {
23
- super(...arguments);
24
- this.baseImageUrl = 'https://archive.org';
25
- this.searchType = SearchType.METADATA;
26
- this.sortParam = null;
27
- this.selectedSort = SortField.default;
28
- this.selectedTitleFilter = null;
29
- this.selectedCreatorFilter = null;
30
- this.sortDirection = null;
31
- this.pageSize = 50;
32
- this.showHistogramDatePicker = false;
33
- this.collectionPagePath = '/details/';
34
- /** describes where this component is being used */
35
- this.searchContext = analyticsCategories.default;
36
- this.pageContext = 'search';
37
- this.restorationStateHandler = new RestorationStateHandler({
38
- context: this.pageContext,
39
- });
40
- this.mobileBreakpoint = 600;
41
- this.loggedIn = false;
42
- this.modalManager = undefined;
43
- /**
44
- * If item management UI active
45
- */
46
- this.isManageView = false;
47
- /**
48
- * The page that the consumer wants to load.
49
- */
50
- this.initialPageNumber = 1;
51
- /**
52
- * This the the number of pages that we want to show.
53
- *
54
- * The data isn't necessarily loaded for all of the pages, but this lets us
55
- * know how many cells we should render.
56
- */
57
- this.pagesToRender = this.initialPageNumber;
58
- /**
59
- * Whether the initial page fetch for a new query is currently in progress.
60
- */
61
- this.searchResultsLoading = false;
62
- this.facetsLoading = false;
63
- this.fullYearAggregationLoading = false;
64
- this.mobileView = false;
65
- this.mobileFacetsVisible = false;
66
- this.defaultSortField = SortField.relevance;
67
- this.defaultSortDirection = null;
68
- this.placeholderType = null;
69
- this.prefixFilterCountMap = {};
70
- /**
71
- * When we're animated scrolling to the page, we don't want to fetch
72
- * all of the pages as it scrolls so this lets us know if we're scrolling
73
- */
74
- this.isScrollingToCell = false;
75
- /**
76
- * When we've reached the end of the data, stop trying to fetch more
77
- */
78
- this.endOfDataReached = false;
79
- /**
80
- * When page width resizes from desktop to mobile, set true to
81
- * disable expand/collapse transition when loading.
82
- */
83
- this.isResizeToMobile = false;
84
- this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
85
- /**
86
- * The results per page so we can paginate.
87
- *
88
- * This allows us to start in the middle of the search results and
89
- * fetch data before or after the current page. If we don't have a key
90
- * for the previous/next page, we'll fetch the next/previous page to populate it
91
- */
92
- this.dataSource = {};
93
- /**
94
- * Updates the height of the left column according to its position on the page.
95
- * Arrow function ensures proper `this` binding.
96
- */
97
- this.updateLeftColumnHeight = () => {
98
- var _a, _b, _c, _d, _e;
99
- if (this.mobileView) {
100
- (_b = (_a = this.leftColumn) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b.removeProperty('height');
101
- }
102
- else {
103
- const clientTop = (_c = this.leftColumn) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect().top;
104
- (_e = (_d = this.leftColumn) === null || _d === void 0 ? void 0 : _d.style) === null || _e === void 0 ? void 0 : _e.setProperty('height', `${window.innerHeight - (clientTop !== null && clientTop !== void 0 ? clientTop : 0) - 3}px`);
105
- }
106
- };
107
- /**
108
- * Toggles whether the fade-out is visible at the bottom of the facets.
109
- * It should only be visible if the facets are not scrolled to the bottom.
110
- * Arrow function ensures proper `this` binding.
111
- */
112
- this.updateFacetFadeOut = (entries) => {
113
- var _a, _b;
114
- const fadeElmt = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('facets-bottom-fade');
115
- fadeElmt === null || fadeElmt === void 0 ? void 0 : fadeElmt.classList.toggle('hidden', (_b = entries === null || entries === void 0 ? void 0 : entries[0]) === null || _b === void 0 ? void 0 : _b.isIntersecting);
116
- };
117
- // we only want to scroll on the very first query change
118
- // so this keeps track of whether we've already set the initial query
119
- this.initialQueryChangeHappened = false;
120
- this.historyPopOccurred = false;
121
- /**
122
- * Internal property to store the private value backing the `initialSearchComplete` getter.
123
- */
124
- this._initialSearchCompletePromise = new Promise(res => {
125
- this._initialSearchCompleteResolver = res;
126
- });
127
- // this maps the query to the pages being fetched for that query
128
- this.pageFetchesInProgress = {};
129
- }
130
- tileModelAtCellIndex(index) {
131
- var _a;
132
- const pageNumber = Math.floor(index / this.pageSize) + 1;
133
- const itemIndex = index % this.pageSize;
134
- const model = (_a = this.dataSource[pageNumber]) === null || _a === void 0 ? void 0 : _a[itemIndex];
135
- /**
136
- * If we encounter a model we don't have yet and we're not in the middle of an
137
- * automated scroll, fetch the page and just return undefined.
138
- * The datasource will be updated once the page is loaded and the cell will be rendered.
139
- *
140
- * We disable it during the automated scroll since we may fetch pages for cells the
141
- * user may never see.
142
- */
143
- if (!model && !this.isScrollingToCell) {
144
- this.fetchPage(pageNumber);
145
- }
146
- return model;
147
- }
148
- get sortFilterQueries() {
149
- const queries = [this.titleQuery, this.creatorQuery];
150
- return queries.filter(q => q).join(' AND ');
151
- }
152
- // this is the total number of tiles we expect if
153
- // the data returned is a full page worth
154
- // this is useful for putting in placeholders for the expected number of tiles
155
- get estimatedTileCount() {
156
- return this.pagesToRender * this.pageSize;
157
- }
158
- /**
159
- * Returns a promise resolving to a unique string that persists for the current browser session.
160
- * Used in generating unique IDs for search requests, so that multiple requests coming from the
161
- * same browser session can be identified.
162
- */
163
- async getSessionId() {
164
- try {
165
- const storedSessionId = sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.getItem('cb-session');
166
- if (storedSessionId) {
167
- return storedSessionId;
168
- }
169
- // If we enter this method a second time while a first session ID is already being generated,
170
- // ensure we produce the same ID from both calls instead of generating another one.
171
- if (this.sessionIdGenPromise) {
172
- return this.sessionIdGenPromise;
173
- }
174
- this.sessionIdGenPromise = sha1(Math.random().toString());
175
- const newSessionId = await this.sessionIdGenPromise;
176
- sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.setItem('cb-session', newSessionId);
177
- return newSessionId;
178
- }
179
- catch (err) {
180
- // Either we can't generate the hash or we're restricted from accessing sessionStorage
181
- return '';
182
- }
183
- }
184
- /**
185
- * Go to the given page of results
186
- *
187
- * @param pageNumber
188
- */
189
- goToPage(pageNumber) {
190
- this.initialPageNumber = pageNumber;
191
- this.pagesToRender = pageNumber;
192
- return this.scrollToPage(pageNumber);
193
- }
194
- /**
195
- * Clears all selected/negated facets, date ranges, and letter filters.
196
- *
197
- * By default, the current sort field/direction are not cleared,
198
- * but this can be overridden by setting the `sort` option to `true`.
199
- *
200
- * Similarly, it is possible to finely control what is cleared by
201
- * setting any of the `facets`, `dateRange`, or `letterFilters` flags
202
- * in the options object.
203
- */
204
- clearFilters({ facets = true, dateRange = true, letterFilters = true, sort = false, } = {}) {
205
- // Don't bother clearing facets if none are checked, so that we don't
206
- // trigger unnecessary update cycles.
207
- if (facets && this.hasCheckedFacets) {
208
- this.selectedFacets = getDefaultSelectedFacets();
209
- }
210
- if (dateRange) {
211
- this.minSelectedDate = undefined;
212
- this.maxSelectedDate = undefined;
213
- }
214
- if (letterFilters) {
215
- this.selectedTitleFilter = null;
216
- this.selectedCreatorFilter = null;
217
- }
218
- if (sort) {
219
- this.sortParam = null;
220
- this.sortDirection = null;
221
- this.selectedSort = SortField.default;
222
- }
223
- }
224
- /**
225
- * Returns true if the current value of `this.selectedFacets` contains
226
- * any facet buckets than have been selected or negated, or false otherwise.
227
- */
228
- get hasCheckedFacets() {
229
- if (!this.selectedFacets)
230
- return false;
231
- for (const facetGroup of Object.values(this.selectedFacets)) {
232
- for (const bucket of Object.values(facetGroup)) {
233
- if (bucket.state !== 'none')
234
- return true;
235
- }
236
- }
237
- return false;
238
- }
239
- /**
240
- * Returns true if there are any currently selected/negated facet buckets,
241
- * any selected date range, or any selected letter filters. False otherwise.
242
- *
243
- * Ignores sorting options.
244
- */
245
- get hasActiveFilters() {
246
- return !!(this.hasCheckedFacets ||
247
- this.minSelectedDate ||
248
- this.maxSelectedDate ||
249
- this.selectedTitleFilter ||
250
- this.selectedCreatorFilter);
251
- }
252
- render() {
253
- this.setPlaceholderType();
1
+ import { __decorate } from "tslib";
2
+ /* eslint-disable import/no-duplicates */
3
+ import { html, css, LitElement, nothing, } from 'lit';
4
+ import { customElement, property, query, state } from 'lit/decorators.js';
5
+ import { classMap } from 'lit/directives/class-map.js';
6
+ import { FilterConstraint, FilterMapBuilder, SearchType, } from '@internetarchive/search-service';
7
+ import '@internetarchive/infinite-scroller';
8
+ import './tiles/tile-dispatcher';
9
+ import './tiles/collection-browser-loading-tile';
10
+ import './sort-filter-bar/sort-filter-bar';
11
+ import './collection-facets';
12
+ import './circular-activity-indicator';
13
+ import './sort-filter-bar/sort-filter-bar';
14
+ import { SortField, getDefaultSelectedFacets, prefixFilterAggregationKeys, sortOptionFromAPIString, SORT_OPTIONS, } from './models';
15
+ import { RestorationStateHandler, } from './restoration-state-handler';
16
+ import chevronIcon from './assets/img/icons/chevron';
17
+ import './empty-placeholder';
18
+ import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
19
+ import { srOnlyStyle } from './styles/sr-only';
20
+ import { sha1 } from './utils/sha1';
21
+ let CollectionBrowser = class CollectionBrowser extends LitElement {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.baseImageUrl = 'https://archive.org';
25
+ this.searchType = SearchType.METADATA;
26
+ this.sortParam = null;
27
+ this.selectedSort = SortField.default;
28
+ this.selectedTitleFilter = null;
29
+ this.selectedCreatorFilter = null;
30
+ this.sortDirection = null;
31
+ this.pageSize = 50;
32
+ this.showHistogramDatePicker = false;
33
+ this.collectionPagePath = '/details/';
34
+ /** describes where this component is being used */
35
+ this.searchContext = analyticsCategories.default;
36
+ this.pageContext = 'search';
37
+ this.restorationStateHandler = new RestorationStateHandler({
38
+ context: this.pageContext,
39
+ });
40
+ this.mobileBreakpoint = 600;
41
+ this.loggedIn = false;
42
+ this.modalManager = undefined;
43
+ /**
44
+ * If item management UI active
45
+ */
46
+ this.isManageView = false;
47
+ /**
48
+ * The page that the consumer wants to load.
49
+ */
50
+ this.initialPageNumber = 1;
51
+ /**
52
+ * This the the number of pages that we want to show.
53
+ *
54
+ * The data isn't necessarily loaded for all of the pages, but this lets us
55
+ * know how many cells we should render.
56
+ */
57
+ this.pagesToRender = this.initialPageNumber;
58
+ /**
59
+ * Whether the initial page fetch for a new query is currently in progress.
60
+ */
61
+ this.searchResultsLoading = false;
62
+ this.facetsLoading = false;
63
+ this.fullYearAggregationLoading = false;
64
+ this.mobileView = false;
65
+ this.mobileFacetsVisible = false;
66
+ this.defaultSortField = SortField.relevance;
67
+ this.defaultSortDirection = null;
68
+ this.placeholderType = null;
69
+ this.prefixFilterCountMap = {};
70
+ /**
71
+ * When we're animated scrolling to the page, we don't want to fetch
72
+ * all of the pages as it scrolls so this lets us know if we're scrolling
73
+ */
74
+ this.isScrollingToCell = false;
75
+ /**
76
+ * When we've reached the end of the data, stop trying to fetch more
77
+ */
78
+ this.endOfDataReached = false;
79
+ /**
80
+ * When page width resizes from desktop to mobile, set true to
81
+ * disable expand/collapse transition when loading.
82
+ */
83
+ this.isResizeToMobile = false;
84
+ this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
85
+ /**
86
+ * The results per page so we can paginate.
87
+ *
88
+ * This allows us to start in the middle of the search results and
89
+ * fetch data before or after the current page. If we don't have a key
90
+ * for the previous/next page, we'll fetch the next/previous page to populate it
91
+ */
92
+ this.dataSource = {};
93
+ /**
94
+ * Updates the height of the left column according to its position on the page.
95
+ * Arrow function ensures proper `this` binding.
96
+ */
97
+ this.updateLeftColumnHeight = () => {
98
+ var _a, _b, _c, _d, _e;
99
+ if (this.mobileView) {
100
+ (_b = (_a = this.leftColumn) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b.removeProperty('height');
101
+ }
102
+ else {
103
+ const clientTop = (_c = this.leftColumn) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect().top;
104
+ (_e = (_d = this.leftColumn) === null || _d === void 0 ? void 0 : _d.style) === null || _e === void 0 ? void 0 : _e.setProperty('height', `${window.innerHeight - (clientTop !== null && clientTop !== void 0 ? clientTop : 0) - 3}px`);
105
+ }
106
+ };
107
+ /**
108
+ * Toggles whether the fade-out is visible at the bottom of the facets.
109
+ * It should only be visible if the facets are not scrolled to the bottom.
110
+ * Arrow function ensures proper `this` binding.
111
+ */
112
+ this.updateFacetFadeOut = (entries) => {
113
+ var _a, _b;
114
+ const fadeElmt = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('facets-bottom-fade');
115
+ fadeElmt === null || fadeElmt === void 0 ? void 0 : fadeElmt.classList.toggle('hidden', (_b = entries === null || entries === void 0 ? void 0 : entries[0]) === null || _b === void 0 ? void 0 : _b.isIntersecting);
116
+ };
117
+ // we only want to scroll on the very first query change
118
+ // so this keeps track of whether we've already set the initial query
119
+ this.initialQueryChangeHappened = false;
120
+ this.historyPopOccurred = false;
121
+ /**
122
+ * Internal property to store the private value backing the `initialSearchComplete` getter.
123
+ */
124
+ this._initialSearchCompletePromise = new Promise(res => {
125
+ this._initialSearchCompleteResolver = res;
126
+ });
127
+ // this maps the query to the pages being fetched for that query
128
+ this.pageFetchesInProgress = {};
129
+ }
130
+ tileModelAtCellIndex(index) {
131
+ var _a;
132
+ const pageNumber = Math.floor(index / this.pageSize) + 1;
133
+ const itemIndex = index % this.pageSize;
134
+ const model = (_a = this.dataSource[pageNumber]) === null || _a === void 0 ? void 0 : _a[itemIndex];
135
+ /**
136
+ * If we encounter a model we don't have yet and we're not in the middle of an
137
+ * automated scroll, fetch the page and just return undefined.
138
+ * The datasource will be updated once the page is loaded and the cell will be rendered.
139
+ *
140
+ * We disable it during the automated scroll since we may fetch pages for cells the
141
+ * user may never see.
142
+ */
143
+ if (!model && !this.isScrollingToCell) {
144
+ this.fetchPage(pageNumber);
145
+ }
146
+ return model;
147
+ }
148
+ get sortFilterQueries() {
149
+ const queries = [this.titleQuery, this.creatorQuery];
150
+ return queries.filter(q => q).join(' AND ');
151
+ }
152
+ // this is the total number of tiles we expect if
153
+ // the data returned is a full page worth
154
+ // this is useful for putting in placeholders for the expected number of tiles
155
+ get estimatedTileCount() {
156
+ return this.pagesToRender * this.pageSize;
157
+ }
158
+ /**
159
+ * Returns a promise resolving to a unique string that persists for the current browser session.
160
+ * Used in generating unique IDs for search requests, so that multiple requests coming from the
161
+ * same browser session can be identified.
162
+ */
163
+ async getSessionId() {
164
+ try {
165
+ const storedSessionId = sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.getItem('cb-session');
166
+ if (storedSessionId) {
167
+ return storedSessionId;
168
+ }
169
+ // If we enter this method a second time while a first session ID is already being generated,
170
+ // ensure we produce the same ID from both calls instead of generating another one.
171
+ if (this.sessionIdGenPromise) {
172
+ return this.sessionIdGenPromise;
173
+ }
174
+ this.sessionIdGenPromise = sha1(Math.random().toString());
175
+ const newSessionId = await this.sessionIdGenPromise;
176
+ sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.setItem('cb-session', newSessionId);
177
+ return newSessionId;
178
+ }
179
+ catch (err) {
180
+ // Either we can't generate the hash or we're restricted from accessing sessionStorage
181
+ return '';
182
+ }
183
+ }
184
+ /**
185
+ * Go to the given page of results
186
+ *
187
+ * @param pageNumber
188
+ */
189
+ goToPage(pageNumber) {
190
+ this.initialPageNumber = pageNumber;
191
+ this.pagesToRender = pageNumber;
192
+ return this.scrollToPage(pageNumber);
193
+ }
194
+ /**
195
+ * Clears all selected/negated facets, date ranges, and letter filters.
196
+ *
197
+ * By default, the current sort field/direction are not cleared,
198
+ * but this can be overridden by setting the `sort` option to `true`.
199
+ *
200
+ * Similarly, it is possible to finely control what is cleared by
201
+ * setting any of the `facets`, `dateRange`, or `letterFilters` flags
202
+ * in the options object.
203
+ */
204
+ clearFilters({ facets = true, dateRange = true, letterFilters = true, sort = false, } = {}) {
205
+ // Don't bother clearing facets if none are checked, so that we don't
206
+ // trigger unnecessary update cycles.
207
+ if (facets && this.hasCheckedFacets) {
208
+ this.selectedFacets = getDefaultSelectedFacets();
209
+ }
210
+ if (dateRange) {
211
+ this.minSelectedDate = undefined;
212
+ this.maxSelectedDate = undefined;
213
+ }
214
+ if (letterFilters) {
215
+ this.selectedTitleFilter = null;
216
+ this.selectedCreatorFilter = null;
217
+ }
218
+ if (sort) {
219
+ this.sortParam = null;
220
+ this.sortDirection = null;
221
+ this.selectedSort = SortField.default;
222
+ }
223
+ }
224
+ /**
225
+ * Returns true if the current value of `this.selectedFacets` contains
226
+ * any facet buckets than have been selected or negated, or false otherwise.
227
+ */
228
+ get hasCheckedFacets() {
229
+ if (!this.selectedFacets)
230
+ return false;
231
+ for (const facetGroup of Object.values(this.selectedFacets)) {
232
+ for (const bucket of Object.values(facetGroup)) {
233
+ if (bucket.state !== 'none')
234
+ return true;
235
+ }
236
+ }
237
+ return false;
238
+ }
239
+ /**
240
+ * Returns true if there are any currently selected/negated facet buckets,
241
+ * any selected date range, or any selected letter filters. False otherwise.
242
+ *
243
+ * Ignores sorting options.
244
+ */
245
+ get hasActiveFilters() {
246
+ return !!(this.hasCheckedFacets ||
247
+ this.minSelectedDate ||
248
+ this.maxSelectedDate ||
249
+ this.selectedTitleFilter ||
250
+ this.selectedCreatorFilter);
251
+ }
252
+ render() {
253
+ this.setPlaceholderType();
254
254
  return html `
255
255
  <div
256
256
  id="content-container"
257
257
  class=${this.mobileView ? 'mobile' : 'desktop'}
258
258
  >
259
- ${this.placeholderType
260
- ? this.emptyPlaceholderTemplate
259
+ ${this.placeholderType
260
+ ? this.emptyPlaceholderTemplate
261
261
  : this.collectionBrowserTemplate}
262
262
  </div>
263
- `;
264
- }
265
- setPlaceholderType() {
266
- var _a;
267
- const hasQuery = !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
268
- const isCollection = !!this.withinCollection;
269
- const noResults = !this.searchResultsLoading &&
270
- (this.totalResults === 0 || !this.searchService);
271
- this.placeholderType = null;
272
- if (!hasQuery && !isCollection) {
273
- this.placeholderType = 'empty-query';
274
- }
275
- else if (noResults) {
276
- // Within a collection, no query + no results means the collection simply has no viewable items.
277
- // Otherwise, we must have a user query that produced 0 results.
278
- this.placeholderType =
279
- !hasQuery && isCollection ? 'empty-collection' : 'no-results';
280
- }
281
- if (this.queryErrorMessage) {
282
- this.placeholderType = 'query-error';
283
- }
284
- }
285
- get emptyPlaceholderTemplate() {
286
- var _a;
263
+ `;
264
+ }
265
+ setPlaceholderType() {
266
+ var _a;
267
+ const hasQuery = !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
268
+ const isCollection = !!this.withinCollection;
269
+ const noResults = !this.searchResultsLoading &&
270
+ (this.totalResults === 0 || !this.searchService);
271
+ this.placeholderType = null;
272
+ if (!hasQuery && !isCollection) {
273
+ this.placeholderType = 'empty-query';
274
+ }
275
+ else if (noResults) {
276
+ // Within a collection, no query + no results means the collection simply has no viewable items.
277
+ // Otherwise, we must have a user query that produced 0 results.
278
+ this.placeholderType =
279
+ !hasQuery && isCollection ? 'empty-collection' : 'no-results';
280
+ }
281
+ if (this.queryErrorMessage) {
282
+ this.placeholderType = 'query-error';
283
+ }
284
+ }
285
+ get emptyPlaceholderTemplate() {
286
+ var _a;
287
287
  return html `
288
288
  <empty-placeholder
289
289
  .placeholderType=${this.placeholderType}
@@ -293,33 +293,33 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
293
293
  .baseNavigationUrl=${this.baseNavigationUrl}
294
294
  ></empty-placeholder>
295
295
  ${this.infiniteScrollerTemplate}
296
- `;
297
- }
298
- /**
299
- * Top-level template for rendering the left (facets) and right (results) columns.
300
- */
301
- get collectionBrowserTemplate() {
296
+ `;
297
+ }
298
+ /**
299
+ * Top-level template for rendering the left (facets) and right (results) columns.
300
+ */
301
+ get collectionBrowserTemplate() {
302
302
  return html `
303
303
  <div id="left-column-scroll-sentinel"></div>
304
304
  ${this.leftColumnTemplate} ${this.rightColumnTemplate}
305
- `;
306
- }
307
- /**
308
- * Template for either the mobile or desktop version of the left column, depending
309
- * on current component state.
310
- */
311
- get leftColumnTemplate() {
312
- if (this.mobileView) {
313
- return this.mobileLeftColumnTemplate;
314
- }
315
- return this.desktopLeftColumnTemplate;
316
- }
317
- /**
318
- * Template for the mobile version of the "left column" (which in this case, appears
319
- * *above* the search results rather than beside them), for rendering the
320
- * accordion-style facets.
321
- */
322
- get mobileLeftColumnTemplate() {
305
+ `;
306
+ }
307
+ /**
308
+ * Template for either the mobile or desktop version of the left column, depending
309
+ * on current component state.
310
+ */
311
+ get leftColumnTemplate() {
312
+ if (this.mobileView) {
313
+ return this.mobileLeftColumnTemplate;
314
+ }
315
+ return this.desktopLeftColumnTemplate;
316
+ }
317
+ /**
318
+ * Template for the mobile version of the "left column" (which in this case, appears
319
+ * *above* the search results rather than beside them), for rendering the
320
+ * accordion-style facets.
321
+ */
322
+ get mobileLeftColumnTemplate() {
323
323
  return html `
324
324
  <div
325
325
  id="left-column"
@@ -328,12 +328,12 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
328
328
  ${this.resultsCountTemplate}
329
329
  <div id="facets-header-container">${this.mobileFacetsTemplate}</div>
330
330
  </div>
331
- `;
332
- }
333
- /**
334
- * Template for the desktop version of the left column, displaying the facets sidebar.
335
- */
336
- get desktopLeftColumnTemplate() {
331
+ `;
332
+ }
333
+ /**
334
+ * Template for the desktop version of the left column, displaying the facets sidebar.
335
+ */
336
+ get desktopLeftColumnTemplate() {
337
337
  return html `
338
338
  <div id="left-column" class="column">
339
339
  <div id="facets-header-container">
@@ -346,17 +346,17 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
346
346
  </div>
347
347
  <div id="facets-bottom-fade"></div>
348
348
  </div>
349
- `;
350
- }
351
- /**
352
- * Template for the "X Results" count at the top of the search results.
353
- * Changes to the "Searching..." label if the search results are still loading.
354
- */
355
- get resultsCountTemplate() {
356
- var _a;
357
- const shouldShowSearching = this.searchResultsLoading || this.totalResults === undefined;
358
- const resultsCount = (_a = this.totalResults) === null || _a === void 0 ? void 0 : _a.toLocaleString();
359
- const resultsLabel = this.totalResults === 1 ? 'Result' : 'Results';
349
+ `;
350
+ }
351
+ /**
352
+ * Template for the "X Results" count at the top of the search results.
353
+ * Changes to the "Searching..." label if the search results are still loading.
354
+ */
355
+ get resultsCountTemplate() {
356
+ var _a;
357
+ const shouldShowSearching = this.searchResultsLoading || this.totalResults === undefined;
358
+ const resultsCount = (_a = this.totalResults) === null || _a === void 0 ? void 0 : _a.toLocaleString();
359
+ const resultsLabel = this.totalResults === 1 ? 'Result' : 'Results';
360
360
  return html `
361
361
  <div id="results-total">
362
362
  <span id="big-results-count">
@@ -366,24 +366,24 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
366
366
  ${shouldShowSearching ? nothing : resultsLabel}
367
367
  </span>
368
368
  </div>
369
- `;
370
- }
371
- /**
372
- * Template for the right column of the collection browser, where the result
373
- * tiles and sort/filter bar are shown.
374
- */
375
- get rightColumnTemplate() {
369
+ `;
370
+ }
371
+ /**
372
+ * Template for the right column of the collection browser, where the result
373
+ * tiles and sort/filter bar are shown.
374
+ */
375
+ get rightColumnTemplate() {
376
376
  return html `
377
377
  <div id="right-column" class="column">
378
378
  ${this.sortFilterBarTemplate}
379
- ${this.displayMode === `list-compact`
380
- ? this.listHeaderTemplate
379
+ ${this.displayMode === `list-compact`
380
+ ? this.listHeaderTemplate
381
381
  : nothing}
382
382
  ${this.infiniteScrollerTemplate}
383
383
  </div>
384
- `;
385
- }
386
- get infiniteScrollerTemplate() {
384
+ `;
385
+ }
386
+ get infiniteScrollerTemplate() {
387
387
  return html `<infinite-scroller
388
388
  class=${this.infiniteScrollerClasses}
389
389
  itemCount=${this.placeholderType ? 0 : nothing}
@@ -392,16 +392,16 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
392
392
  .placeholderCellTemplate=${this.placeholderCellTemplate}
393
393
  @scrollThresholdReached=${this.scrollThresholdReached}
394
394
  @visibleCellsChanged=${this.visibleCellsChanged}
395
- ></infinite-scroller>`;
396
- }
397
- get infiniteScrollerClasses() {
398
- var _a;
399
- return classMap({
400
- [(_a = this.displayMode) !== null && _a !== void 0 ? _a : '']: !!this.displayMode,
401
- hidden: !!this.placeholderType,
402
- });
403
- }
404
- get sortFilterBarTemplate() {
395
+ ></infinite-scroller>`;
396
+ }
397
+ get infiniteScrollerClasses() {
398
+ var _a;
399
+ return classMap({
400
+ [(_a = this.displayMode) !== null && _a !== void 0 ? _a : '']: !!this.displayMode,
401
+ hidden: !!this.placeholderType,
402
+ });
403
+ }
404
+ get sortFilterBarTemplate() {
405
405
  return html `
406
406
  <sort-filter-bar
407
407
  .defaultSortField=${this.defaultSortField}
@@ -420,129 +420,135 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
420
420
  @creatorLetterChanged=${this.creatorLetterSelected}
421
421
  >
422
422
  </sort-filter-bar>
423
- `;
424
- }
425
- userChangedSort(e) {
426
- var _a;
427
- const { selectedSort, sortDirection } = e.detail;
428
- this.selectedSort = selectedSort;
429
- this.sortDirection = sortDirection;
430
- if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
431
- this.goToPage(1);
432
- }
433
- this.currentPage = 1;
434
- }
435
- sendSortByAnalytics(prevSortDirection) {
436
- var _a;
437
- const directionCleared = prevSortDirection && !this.sortDirection;
438
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
439
- category: this.searchContext,
440
- action: analyticsActions.sortBy,
441
- label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
442
- });
443
- }
444
- selectedSortChanged() {
445
- if ([SortField.default, SortField.relevance].includes(this.selectedSort)) {
446
- this.sortParam = null;
447
- return;
448
- }
449
- const sortField = SortFieldToMetadataField[this.selectedSort];
450
- if (!this.sortDirection)
451
- this.sortDirection = 'desc';
452
- if (!sortField)
453
- return;
454
- this.sortParam = { field: sortField, direction: this.sortDirection };
455
- // Lazy-load the alphabet counts for title/creator sort bar as needed
456
- this.updatePrefixFiltersForCurrentSort();
457
- }
458
- displayModeChanged(e) {
459
- var _a;
460
- this.displayMode = e.detail.displayMode;
461
- if (this.displayMode) {
462
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
463
- category: this.searchContext,
464
- action: analyticsActions.displayMode,
465
- label: this.displayMode,
466
- });
467
- }
468
- }
469
- /**
470
- * Returns a query clause identifying the currently selected title filter,
471
- * e.g., `firstTitle:X`.
472
- */
473
- get titleQuery() {
474
- return this.selectedTitleFilter
475
- ? `firstTitle:${this.selectedTitleFilter}`
476
- : undefined;
477
- }
478
- /**
479
- * Returns a query clause identifying the currently selected creator filter,
480
- * e.g., `firstCreator:X`.
481
- */
482
- get creatorQuery() {
483
- return this.selectedCreatorFilter
484
- ? `firstCreator:${this.selectedCreatorFilter}`
485
- : undefined;
486
- }
487
- /**
488
- * Send Analytics when sorting by title's first letter
489
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
490
- */
491
- sendFilterByTitleAnalytics(prevSelectedLetter) {
492
- var _a;
493
- if (!prevSelectedLetter && !this.selectedTitleFilter) {
494
- return;
495
- }
496
- const cleared = prevSelectedLetter && !this.selectedTitleFilter;
497
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
498
- category: this.searchContext,
499
- action: analyticsActions.filterByTitle,
500
- label: cleared
501
- ? `clear-${prevSelectedLetter}`
502
- : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
503
- });
504
- }
505
- /**
506
- * Send Analytics when filtering by creator's first letter
507
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
508
- */
509
- sendFilterByCreatorAnalytics(prevSelectedLetter) {
510
- var _a;
511
- if (!prevSelectedLetter && !this.selectedCreatorFilter) {
512
- return;
513
- }
514
- const cleared = prevSelectedLetter && !this.selectedCreatorFilter;
515
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
516
- category: this.searchContext,
517
- action: analyticsActions.filterByCreator,
518
- label: cleared
519
- ? `clear-${prevSelectedLetter}`
520
- : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
521
- });
522
- }
523
- /**
524
- * Handler for changes to which letter is selected in the title alphabet bar.
525
- */
526
- titleLetterSelected(e) {
527
- this.selectedCreatorFilter = null;
528
- this.selectedTitleFilter = e.detail.selectedLetter;
529
- }
530
- /**
531
- * Handler for changes to which letter is selected in the creator alphabet bar.
532
- */
533
- creatorLetterSelected(e) {
534
- this.selectedTitleFilter = null;
535
- this.selectedCreatorFilter = e.detail.selectedLetter;
536
- }
537
- /**
538
- * The full template for how the facets should be structured in mobile view,
539
- * including the collapsible container (with header) and the facets themselves.
540
- */
541
- get mobileFacetsTemplate() {
542
- const toggleFacetsVisible = () => {
543
- this.isResizeToMobile = false;
544
- this.mobileFacetsVisible = !this.mobileFacetsVisible;
545
- };
423
+ `;
424
+ }
425
+ userChangedSort(e) {
426
+ var _a;
427
+ const { selectedSort, sortDirection } = e.detail;
428
+ this.selectedSort = selectedSort;
429
+ this.sortDirection = sortDirection;
430
+ if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
431
+ this.goToPage(1);
432
+ }
433
+ this.currentPage = 1;
434
+ }
435
+ sendSortByAnalytics(prevSortDirection) {
436
+ var _a;
437
+ const directionCleared = prevSortDirection && !this.sortDirection;
438
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
439
+ category: this.searchContext,
440
+ action: analyticsActions.sortBy,
441
+ label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
442
+ });
443
+ }
444
+ selectedSortChanged() {
445
+ var _a;
446
+ const sortOption = SORT_OPTIONS[this.selectedSort];
447
+ if (!sortOption.handledBySearchService) {
448
+ this.sortParam = null;
449
+ return;
450
+ }
451
+ // If the sort option specified in the URL is unrecognized, we just use it as-is
452
+ const urlSortParam = new URL(window.location.href).searchParams.get('sort');
453
+ const sortField = (_a = sortOption.searchServiceKey) !== null && _a !== void 0 ? _a : urlSortParam === null || urlSortParam === void 0 ? void 0 : urlSortParam.replace(/^-/, '');
454
+ // If the sort direction is still null at this point, then we assume ascending
455
+ // (i.e., it was unrecognized and had no directional flag)
456
+ if (!this.sortDirection)
457
+ this.sortDirection = 'asc';
458
+ if (!sortField)
459
+ return;
460
+ this.sortParam = { field: sortField, direction: this.sortDirection };
461
+ // Lazy-load the alphabet counts for title/creator sort bar as needed
462
+ this.updatePrefixFiltersForCurrentSort();
463
+ }
464
+ displayModeChanged(e) {
465
+ var _a;
466
+ this.displayMode = e.detail.displayMode;
467
+ if (this.displayMode) {
468
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
469
+ category: this.searchContext,
470
+ action: analyticsActions.displayMode,
471
+ label: this.displayMode,
472
+ });
473
+ }
474
+ }
475
+ /**
476
+ * Returns a query clause identifying the currently selected title filter,
477
+ * e.g., `firstTitle:X`.
478
+ */
479
+ get titleQuery() {
480
+ return this.selectedTitleFilter
481
+ ? `firstTitle:${this.selectedTitleFilter}`
482
+ : undefined;
483
+ }
484
+ /**
485
+ * Returns a query clause identifying the currently selected creator filter,
486
+ * e.g., `firstCreator:X`.
487
+ */
488
+ get creatorQuery() {
489
+ return this.selectedCreatorFilter
490
+ ? `firstCreator:${this.selectedCreatorFilter}`
491
+ : undefined;
492
+ }
493
+ /**
494
+ * Send Analytics when sorting by title's first letter
495
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
496
+ */
497
+ sendFilterByTitleAnalytics(prevSelectedLetter) {
498
+ var _a;
499
+ if (!prevSelectedLetter && !this.selectedTitleFilter) {
500
+ return;
501
+ }
502
+ const cleared = prevSelectedLetter && !this.selectedTitleFilter;
503
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
504
+ category: this.searchContext,
505
+ action: analyticsActions.filterByTitle,
506
+ label: cleared
507
+ ? `clear-${prevSelectedLetter}`
508
+ : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
509
+ });
510
+ }
511
+ /**
512
+ * Send Analytics when filtering by creator's first letter
513
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
514
+ */
515
+ sendFilterByCreatorAnalytics(prevSelectedLetter) {
516
+ var _a;
517
+ if (!prevSelectedLetter && !this.selectedCreatorFilter) {
518
+ return;
519
+ }
520
+ const cleared = prevSelectedLetter && !this.selectedCreatorFilter;
521
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
522
+ category: this.searchContext,
523
+ action: analyticsActions.filterByCreator,
524
+ label: cleared
525
+ ? `clear-${prevSelectedLetter}`
526
+ : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
527
+ });
528
+ }
529
+ /**
530
+ * Handler for changes to which letter is selected in the title alphabet bar.
531
+ */
532
+ titleLetterSelected(e) {
533
+ this.selectedCreatorFilter = null;
534
+ this.selectedTitleFilter = e.detail.selectedLetter;
535
+ }
536
+ /**
537
+ * Handler for changes to which letter is selected in the creator alphabet bar.
538
+ */
539
+ creatorLetterSelected(e) {
540
+ this.selectedTitleFilter = null;
541
+ this.selectedCreatorFilter = e.detail.selectedLetter;
542
+ }
543
+ /**
544
+ * The full template for how the facets should be structured in mobile view,
545
+ * including the collapsible container (with header) and the facets themselves.
546
+ */
547
+ get mobileFacetsTemplate() {
548
+ const toggleFacetsVisible = () => {
549
+ this.isResizeToMobile = false;
550
+ this.mobileFacetsVisible = !this.mobileFacetsVisible;
551
+ };
546
552
  return html `
547
553
  <details
548
554
  id="mobile-filter-collapse"
@@ -556,12 +562,12 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
556
562
  </summary>
557
563
  ${this.facetsTemplate}
558
564
  </details>
559
- `;
560
- }
561
- /**
562
- * The template for the facets component alone, without any surrounding wrappers.
563
- */
564
- get facetsTemplate() {
565
+ `;
566
+ }
567
+ /**
568
+ * The template for the facets component alone, without any surrounding wrappers.
569
+ */
570
+ get facetsTemplate() {
565
571
  return html `
566
572
  <collection-facets
567
573
  @facetsChanged=${this.facetsChanged}
@@ -592,41 +598,41 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
592
598
  .analyticsHandler=${this.analyticsHandler}
593
599
  >
594
600
  </collection-facets>
595
- `;
596
- }
597
- /**
598
- * The HTML template for the "Clear all filters" button, or `nothing` if no
599
- * filters are currently active.
600
- *
601
- * @param mobile Whether to style/shorten the button for mobile view
602
- */
603
- clearFiltersBtnTemplate(mobile) {
604
- if (!this.hasActiveFilters)
605
- return nothing;
606
- const buttonClasses = classMap({
607
- 'clear-filters-btn': true,
608
- mobile,
609
- });
610
- const buttonText = mobile ? 'Clear all' : 'Clear all filters';
601
+ `;
602
+ }
603
+ /**
604
+ * The HTML template for the "Clear all filters" button, or `nothing` if no
605
+ * filters are currently active.
606
+ *
607
+ * @param mobile Whether to style/shorten the button for mobile view
608
+ */
609
+ clearFiltersBtnTemplate(mobile) {
610
+ if (!this.hasActiveFilters)
611
+ return nothing;
612
+ const buttonClasses = classMap({
613
+ 'clear-filters-btn': true,
614
+ mobile,
615
+ });
616
+ const buttonText = mobile ? 'Clear all' : 'Clear all filters';
611
617
  return html `
612
618
  <div class="clear-filters-btn-row">
613
- ${mobile
614
- ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
619
+ ${mobile
620
+ ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
615
621
  : nothing}
616
622
  <button class=${buttonClasses} @click=${this.clearFilters}>
617
623
  ${buttonText}
618
624
  </button>
619
625
  </div>
620
- `;
621
- }
622
- get loadingTemplate() {
626
+ `;
627
+ }
628
+ get loadingTemplate() {
623
629
  return html `
624
630
  <div class="loading-cover">
625
631
  <circular-activity-indicator></circular-activity-indicator>
626
632
  </div>
627
- `;
628
- }
629
- get listHeaderTemplate() {
633
+ `;
634
+ }
635
+ get listHeaderTemplate() {
630
636
  return html `
631
637
  <div id="list-header">
632
638
  <tile-dispatcher
@@ -638,988 +644,1006 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
638
644
  >
639
645
  </tile-dispatcher>
640
646
  </div>
641
- `;
642
- }
643
- histogramDateRangeUpdated(e) {
644
- var _a;
645
- const { minDate, maxDate } = e.detail;
646
- [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
647
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
648
- category: this.searchContext,
649
- action: analyticsActions.histogramChanged,
650
- label: this.dateRangeQueryClause,
651
- });
652
- }
653
- get dateRangeQueryClause() {
654
- if (!this.minSelectedDate || !this.maxSelectedDate) {
655
- return undefined;
656
- }
657
- return `year:[${this.minSelectedDate} TO ${this.maxSelectedDate}]`;
658
- }
659
- firstUpdated() {
660
- this.setupStateRestorationObserver();
661
- this.restoreState();
662
- }
663
- updated(changed) {
664
- var _a;
665
- if (changed.has('placeholderType') && this.placeholderType === null) {
666
- if (!this.leftColIntersectionObserver) {
667
- this.setupLeftColumnScrollListeners();
668
- }
669
- if (!this.facetsIntersectionObserver) {
670
- this.setupFacetsScrollListeners();
671
- }
672
- this.updateLeftColumnHeight();
673
- }
674
- if (changed.has('displayMode') ||
675
- changed.has('baseNavigationUrl') ||
676
- changed.has('baseImageUrl') ||
677
- changed.has('loggedIn')) {
678
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
679
- }
680
- if (changed.has('baseQuery') || changed.has('searchType')) {
681
- // Unless this query/search type update is from the initial page load or the
682
- // result of hitting the back button,
683
- // we need to clear any existing filters since they may no longer be valid for
684
- // the new set of search results.
685
- if (!this.historyPopOccurred && this.initialQueryChangeHappened) {
686
- // Only clear filters that haven't been simultaneously applied in this update
687
- this.clearFilters({
688
- facets: !changed.has('selectedFacets'),
689
- dateRange: !(changed.has('minSelectedDate') || changed.has('maxSelectedDate')),
690
- letterFilters: !(changed.has('selectedTitleFilter') ||
691
- changed.has('selectedCreatorFilter')),
692
- });
693
- }
694
- }
695
- if (changed.has('baseQuery')) {
696
- this.emitBaseQueryChanged();
697
- }
698
- if (changed.has('searchType')) {
699
- this.emitSearchTypeChanged();
700
- }
701
- if (changed.has('currentPage') || changed.has('displayMode')) {
702
- this.persistState();
703
- }
704
- if (changed.has('baseQuery') ||
705
- changed.has('minSelectedDate') ||
706
- changed.has('maxSelectedDate') ||
707
- changed.has('selectedFacets') ||
708
- changed.has('searchService') ||
709
- changed.has('withinCollection')) {
710
- this.refreshLetterCounts();
711
- }
712
- if (changed.has('selectedSort') || changed.has('sortDirection')) {
713
- const prevSortDirection = changed.get('sortDirection');
714
- this.sendSortByAnalytics(prevSortDirection);
715
- this.selectedSortChanged();
716
- }
717
- if (changed.has('selectedTitleFilter')) {
718
- this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
719
- }
720
- if (changed.has('selectedCreatorFilter')) {
721
- this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
722
- }
723
- if (changed.has('baseQuery') ||
724
- changed.has('searchType') ||
725
- changed.has('selectedTitleFilter') ||
726
- changed.has('selectedCreatorFilter') ||
727
- changed.has('minSelectedDate') ||
728
- changed.has('maxSelectedDate') ||
729
- changed.has('sortParam') ||
730
- changed.has('selectedFacets') ||
731
- changed.has('searchService') ||
732
- changed.has('withinCollection')) {
733
- this.handleQueryChange();
734
- }
735
- if (changed.has('searchResultsLoading')) {
736
- this.emitSearchResultsLoadingChanged();
737
- }
738
- if (changed.has('facetsLoading') &&
739
- this.facetsLoading &&
740
- this.collectionFacets) {
741
- this.collectionFacets.moreLinksVisible =
742
- this.searchType !== SearchType.FULLTEXT;
743
- }
744
- if (changed.has('pagesToRender')) {
745
- if (!this.endOfDataReached && this.infiniteScroller) {
746
- this.infiniteScroller.itemCount = this.estimatedTileCount;
747
- }
748
- }
749
- if (changed.has('resizeObserver')) {
750
- const oldObserver = changed.get('resizeObserver');
751
- if (oldObserver)
752
- this.disconnectResizeObserver(oldObserver);
753
- this.setupResizeObserver();
754
- }
755
- }
756
- disconnectedCallback() {
757
- var _a, _b;
758
- if (this.resizeObserver) {
759
- this.disconnectResizeObserver(this.resizeObserver);
760
- }
761
- if (this.boundNavigationHandler) {
762
- window.removeEventListener('popstate', this.boundNavigationHandler);
763
- }
764
- (_a = this.leftColIntersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
765
- (_b = this.facetsIntersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
766
- window.removeEventListener('resize', this.updateLeftColumnHeight);
767
- }
768
- handleResize(entry) {
769
- const previousView = this.mobileView;
770
- if (entry.target === this.contentContainer) {
771
- this.contentWidth = entry.contentRect.width;
772
- this.mobileView =
773
- this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
774
- // If changing from desktop to mobile disable transition
775
- if (this.mobileView && !previousView) {
776
- this.isResizeToMobile = true;
777
- }
778
- }
779
- // Ensure the facet sidebar remains sized correctly
780
- this.updateLeftColumnHeight();
781
- }
782
- /**
783
- * Sets up listeners for events that may require updating the left column height.
784
- */
785
- setupLeftColumnScrollListeners() {
786
- var _a;
787
- // We observe intersections between the left column's scroll sentinel and
788
- // the viewport, so that we can ensure the left column is always sized to
789
- // match the _available_ viewport height. This should generally be more
790
- // performant than listening to scroll events on the page or column.
791
- const leftColumnSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#left-column-scroll-sentinel');
792
- if (leftColumnSentinel) {
793
- this.leftColIntersectionObserver = new IntersectionObserver(this.updateLeftColumnHeight, {
794
- threshold: [...Array(101).keys()].map(n => n / 100), // Threshold every 1%
795
- });
796
- this.leftColIntersectionObserver.observe(leftColumnSentinel);
797
- }
798
- // We also listen for window resize events, as they are not always captured
799
- // by the resize observer and can affect the desired height of the left column.
800
- window.addEventListener('resize', this.updateLeftColumnHeight);
801
- }
802
- /**
803
- * Sets up listeners to control whether the facet sidebar shows its bottom fade-out.
804
- * Note this uses a separate IntersectionObserver from the left column, because we
805
- * don't need granular intersection thresholds for this.
806
- */
807
- setupFacetsScrollListeners() {
808
- var _a;
809
- const facetsSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#facets-scroll-sentinel');
810
- if (facetsSentinel) {
811
- this.facetsIntersectionObserver = new IntersectionObserver(this.updateFacetFadeOut);
812
- this.facetsIntersectionObserver.observe(facetsSentinel);
813
- }
814
- }
815
- emitBaseQueryChanged() {
816
- this.dispatchEvent(new CustomEvent('baseQueryChanged', {
817
- detail: {
818
- baseQuery: this.baseQuery,
819
- },
820
- }));
821
- }
822
- emitSearchTypeChanged() {
823
- this.dispatchEvent(new CustomEvent('searchTypeChanged', {
824
- detail: this.searchType,
825
- }));
826
- }
827
- disconnectResizeObserver(resizeObserver) {
828
- resizeObserver.removeObserver({
829
- target: this.contentContainer,
830
- handler: this,
831
- });
832
- }
833
- setupResizeObserver() {
834
- if (!this.resizeObserver)
835
- return;
836
- this.resizeObserver.addObserver({
837
- target: this.contentContainer,
838
- handler: this,
839
- });
840
- }
841
- /**
842
- * When the visible cells change from the infinite scroller, we want to emit
843
- * which page is currently visible so the consumer can update its UI or the URL
844
- *
845
- * @param e
846
- * @returns
847
- */
848
- visibleCellsChanged(e) {
849
- if (this.isScrollingToCell)
850
- return;
851
- const { visibleCellIndices } = e.detail;
852
- if (visibleCellIndices.length === 0)
853
- return;
854
- const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
855
- const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
856
- if (this.currentPage !== lastVisibleCellPage) {
857
- this.currentPage = lastVisibleCellPage;
858
- }
859
- const event = new CustomEvent('visiblePageChanged', {
860
- detail: {
861
- pageNumber: lastVisibleCellPage,
862
- },
863
- });
864
- this.dispatchEvent(event);
865
- }
866
- /**
867
- * A Promise which, after each query change, resolves once the fetches for the initial
868
- * search have completed. Waits for *both* the hits and aggregations fetches to finish.
869
- *
870
- * Ensure you await this component's `updateComplete` promise before awaiting this
871
- * one, to ensure you do not await an obsolete promise from the previous update.
872
- */
873
- get initialSearchComplete() {
874
- return this._initialSearchCompletePromise;
875
- }
876
- async handleQueryChange() {
877
- var _a;
878
- // only reset if the query has actually changed
879
- if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
880
- return;
881
- // If the new state prevents us from updating the search results, don't reset
882
- if (!this.canPerformSearch)
883
- return;
884
- this.previousQueryKey = this.pageFetchQueryKey;
885
- this.dataSource = {};
886
- this.totalResults = undefined;
887
- this.aggregations = undefined;
888
- this.fullYearsHistogramAggregation = undefined;
889
- this.pageFetchesInProgress = {};
890
- this.endOfDataReached = false;
891
- this.pagesToRender =
892
- this.initialPageNumber === 1
893
- ? 2 // First two pages are batched into one request when starting from page 1
894
- : this.initialPageNumber;
895
- this.queryErrorMessage = undefined;
896
- // Reset the infinite scroller's item count, so that it
897
- // shows tile placeholders until the new query's results load in
898
- if (this.infiniteScroller) {
899
- this.infiniteScroller.itemCount = this.estimatedTileCount;
900
- this.infiniteScroller.reload();
901
- }
902
- if (this.withinCollection && ((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
903
- this.defaultSortField = SortField.relevance;
904
- this.defaultSortDirection = null;
905
- }
906
- if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
907
- this.scrollToPage(this.initialPageNumber);
908
- }
909
- this.initialQueryChangeHappened = true;
910
- // if the query changed as part of a window.history pop event, we don't want to
911
- // persist the state because it overwrites the forward history
912
- if (!this.historyPopOccurred) {
913
- this.persistState();
914
- }
915
- this.historyPopOccurred = false;
916
- // Reset the `initialSearchComplete` promise with a new value for the imminent search
917
- this._initialSearchCompletePromise = new Promise(res => {
918
- this._initialSearchCompleteResolver = res;
919
- });
920
- // Fire the initial page and facets requests
921
- await Promise.all([this.doInitialPageFetch(), this.fetchFacets()]);
922
- // Resolve the `initialSearchComplete` promise for this search
923
- this._initialSearchCompleteResolver(true);
924
- }
925
- setupStateRestorationObserver() {
926
- if (this.boundNavigationHandler)
927
- return;
928
- this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
929
- // when the user navigates back, we want to update the UI to match the URL
930
- window.addEventListener('popstate', this.boundNavigationHandler);
931
- }
932
- historyNavigationHandler() {
933
- this.historyPopOccurred = true;
934
- this.restoreState();
935
- }
936
- restoreState() {
937
- var _a, _b, _c, _d, _e;
938
- const restorationState = this.restorationStateHandler.getRestorationState();
939
- this.displayMode = restorationState.displayMode;
940
- if (restorationState.searchType != null)
941
- this.searchType = restorationState.searchType;
942
- this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.default;
943
- this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
944
- this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
945
- this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
946
- this.selectedFacets = restorationState.selectedFacets;
947
- this.baseQuery = restorationState.baseQuery;
948
- this.currentPage = (_e = restorationState.currentPage) !== null && _e !== void 0 ? _e : 1;
949
- this.minSelectedDate = restorationState.minSelectedDate;
950
- this.maxSelectedDate = restorationState.maxSelectedDate;
951
- if (this.currentPage > 1) {
952
- this.goToPage(this.currentPage);
953
- }
954
- }
955
- persistState() {
956
- var _a, _b, _c, _d, _e;
957
- const restorationState = {
958
- displayMode: this.displayMode,
959
- searchType: this.searchType,
960
- sortParam: (_a = this.sortParam) !== null && _a !== void 0 ? _a : undefined,
961
- selectedSort: this.selectedSort,
962
- sortDirection: (_b = this.sortDirection) !== null && _b !== void 0 ? _b : undefined,
963
- selectedFacets: (_c = this.selectedFacets) !== null && _c !== void 0 ? _c : getDefaultSelectedFacets(),
964
- baseQuery: this.baseQuery,
965
- currentPage: this.currentPage,
966
- titleQuery: this.titleQuery,
967
- creatorQuery: this.creatorQuery,
968
- minSelectedDate: this.minSelectedDate,
969
- maxSelectedDate: this.maxSelectedDate,
970
- selectedTitleFilter: (_d = this.selectedTitleFilter) !== null && _d !== void 0 ? _d : undefined,
971
- selectedCreatorFilter: (_e = this.selectedCreatorFilter) !== null && _e !== void 0 ? _e : undefined,
972
- };
973
- this.restorationStateHandler.persistState(restorationState);
974
- }
975
- async doInitialPageFetch() {
976
- this.searchResultsLoading = true;
977
- // Try to batch 2 initial page requests when possible
978
- await this.fetchPage(this.initialPageNumber, 2);
979
- this.searchResultsLoading = false;
980
- }
981
- emitSearchResultsLoadingChanged() {
982
- this.dispatchEvent(new CustomEvent('searchResultsLoadingChanged', {
983
- detail: {
984
- loading: this.searchResultsLoading,
985
- },
986
- }));
987
- }
988
- /**
989
- * Produces a compact unique ID for a search request that can help with debugging
990
- * on the backend by making related requests easier to trace through different services.
991
- * (e.g., tying the hits/aggregations requests for the same page back to a single hash).
992
- *
993
- * @param params The search service parameters for the request
994
- * @param kind The kind of request (hits-only, aggregations-only, or both)
995
- * @returns A Promise resolving to the uid to apply to the request
996
- */
997
- async requestUID(params, kind) {
998
- var _a;
999
- const paramsToHash = JSON.stringify({
1000
- pageType: params.pageType,
1001
- pageTarget: params.pageTarget,
1002
- query: params.query,
1003
- fields: params.fields,
1004
- filters: params.filters,
1005
- sort: params.sort,
1006
- searchType: this.searchType,
1007
- });
1008
- const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this
1009
- const sessionId = (await this.getSessionId()).slice(0, 20); // Likewise
1010
- const page = (_a = params.page) !== null && _a !== void 0 ? _a : 0;
1011
- const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations
1012
- const currentTime = Date.now();
1013
- return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;
1014
- }
1015
- /**
1016
- * Constructs a search service FilterMap object from the combination of
1017
- * all the currently-applied filters. This includes any facets, letter
1018
- * filters, and date range.
1019
- */
1020
- get filterMap() {
1021
- const builder = new FilterMapBuilder();
1022
- // Add the date range, if applicable
1023
- if (this.minSelectedDate) {
1024
- builder.addFilter('year', this.minSelectedDate, FilterConstraint.GREATER_OR_EQUAL);
1025
- }
1026
- if (this.maxSelectedDate) {
1027
- builder.addFilter('year', this.maxSelectedDate, FilterConstraint.LESS_OR_EQUAL);
1028
- }
1029
- // Add any selected facets
1030
- if (this.selectedFacets) {
1031
- for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1032
- const { name, values } = this.prepareFacetForFetch(facetName, facetValues);
1033
- for (const [value, bucket] of Object.entries(values)) {
1034
- let constraint;
1035
- if (bucket.state === 'selected') {
1036
- constraint = FilterConstraint.INCLUDE;
1037
- }
1038
- else if (bucket.state === 'hidden') {
1039
- constraint = FilterConstraint.EXCLUDE;
1040
- }
1041
- if (constraint) {
1042
- builder.addFilter(name, value, constraint);
1043
- }
1044
- }
1045
- }
1046
- }
1047
- // Add any letter filters
1048
- if (this.selectedTitleFilter) {
1049
- builder.addFilter('firstTitle', this.selectedTitleFilter, FilterConstraint.INCLUDE);
1050
- }
1051
- if (this.selectedCreatorFilter) {
1052
- builder.addFilter('firstCreator', this.selectedCreatorFilter, FilterConstraint.INCLUDE);
1053
- }
1054
- const filterMap = builder.build();
1055
- return filterMap;
1056
- }
1057
- /** The full query, including year facets and date range clauses */
1058
- get fullQuery() {
1059
- var _a, _b;
1060
- let fullQuery = (_b = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
1061
- const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;
1062
- if (facetQuery) {
1063
- fullQuery += ` AND ${facetQuery}`;
1064
- }
1065
- if (dateRangeQueryClause) {
1066
- fullQuery += ` AND ${dateRangeQueryClause}`;
1067
- }
1068
- if (sortFilterQueries) {
1069
- fullQuery += ` AND ${sortFilterQueries}`;
1070
- }
1071
- return fullQuery.trim();
1072
- }
1073
- /**
1074
- * Generates a query string for the given facets
1075
- *
1076
- * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
1077
- */
1078
- get facetQuery() {
1079
- var _a;
1080
- if (!this.selectedFacets)
1081
- return undefined;
1082
- const facetClauses = [];
1083
- for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1084
- facetClauses.push(this.buildFacetClause(facetName, facetValues));
1085
- }
1086
- return (_a = this.joinFacetClauses(facetClauses)) === null || _a === void 0 ? void 0 : _a.trim();
1087
- }
1088
- /**
1089
- * Builds an OR-joined facet clause for the given facet name and values.
1090
- *
1091
- * E.g., for name `subject` and values
1092
- * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`
1093
- * this will produce the clause
1094
- * `subject:("foo" OR -"bar")`.
1095
- *
1096
- * @param facetName The facet type (e.g., 'collection')
1097
- * @param facetValues The facet buckets, mapped by their keys
1098
- */
1099
- buildFacetClause(facetName, facetValues) {
1100
- const { name: facetQueryName, values } = this.prepareFacetForFetch(facetName, facetValues);
1101
- const facetEntries = Object.entries(values);
1102
- if (facetEntries.length === 0)
1103
- return '';
1104
- const facetValuesArray = [];
1105
- for (const [key, facetData] of facetEntries) {
1106
- const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
1107
- facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
1108
- }
1109
- const valueQuery = facetValuesArray.join(` OR `);
1110
- return `${facetQueryName}:(${valueQuery})`;
1111
- }
1112
- /**
1113
- * Handles some special pre-request normalization steps for certain facet types
1114
- * that require them.
1115
- *
1116
- * @param facetName The name of the facet type (e.g., 'language')
1117
- * @param facetValues An array of values for that facet type
1118
- */
1119
- prepareFacetForFetch(facetName, facetValues) {
1120
- // eslint-disable-next-line prefer-const
1121
- let [normalizedName, normalizedValues] = [facetName, facetValues];
1122
- // The full "search engine" name of the lending field is "lending___status"
1123
- if (facetName === 'lending') {
1124
- normalizedName = 'lending___status';
1125
- }
1126
- return {
1127
- name: normalizedName,
1128
- values: normalizedValues,
1129
- };
1130
- }
1131
- /**
1132
- * Takes an array of facet clauses, and combines them into a
1133
- * full AND-joined facet query string. Empty clauses are ignored.
1134
- */
1135
- joinFacetClauses(facetClauses) {
1136
- const nonEmptyFacetClauses = facetClauses.filter(clause => clause.length > 0);
1137
- return nonEmptyFacetClauses.length > 0
1138
- ? `(${nonEmptyFacetClauses.join(' AND ')})`
1139
- : undefined;
1140
- }
1141
- facetsChanged(e) {
1142
- this.selectedFacets = e.detail;
1143
- }
1144
- facetClickHandler({ detail: { key, state: facetState, negative }, }) {
1145
- var _a, _b;
1146
- if (negative) {
1147
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1148
- category: this.searchContext,
1149
- action: facetState !== 'none'
1150
- ? analyticsActions.facetNegativeSelected
1151
- : analyticsActions.facetNegativeDeselected,
1152
- label: key,
1153
- });
1154
- }
1155
- else {
1156
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1157
- category: this.searchContext,
1158
- action: facetState !== 'none'
1159
- ? analyticsActions.facetSelected
1160
- : analyticsActions.facetDeselected,
1161
- label: key,
1162
- });
1163
- }
1164
- }
1165
- async fetchFacets() {
1166
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1167
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1168
- if (!this.canPerformSearch)
1169
- return;
1170
- const { facetFetchQueryKey } = this;
1171
- const sortParams = this.sortParam ? [this.sortParam] : [];
1172
- const params = {
1173
- ...this.collectionParams,
1174
- query: trimmedQuery || '',
1175
- rows: 0,
1176
- filters: this.filterMap,
1177
- // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
1178
- aggregationsSize: 10,
1179
- // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
1180
- // The default aggregations for the search_results page type should be what we need here.
1181
- };
1182
- params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1183
- this.facetsLoading = true;
1184
- const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1185
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1186
- // This is checking to see if the query has changed since the data was fetched.
1187
- // If so, we just want to discard this set of aggregations because they are
1188
- // likely no longer valid for the newer query.
1189
- const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1190
- if (queryChangedSinceFetch)
1191
- return;
1192
- if (!success) {
1193
- const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
1194
- const detailMsg = (_e = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.details) === null || _e === void 0 ? void 0 : _e.message;
1195
- if (!errorMsg && !detailMsg) {
1196
- // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1197
- (_g = (_f = window === null || window === void 0 ? void 0 : window.Sentry) === null || _f === void 0 ? void 0 : _f.captureMessage) === null || _g === void 0 ? void 0 : _g.call(_f, 'Missing or malformed facet response from backend', 'error');
1198
- }
1199
- return;
1200
- }
1201
- const { aggregations, collectionTitles } = success.response;
1202
- this.aggregations = aggregations;
1203
- if (collectionTitles) {
1204
- (_h = this.collectionNameCache) === null || _h === void 0 ? void 0 : _h.addKnownTitles(collectionTitles);
1205
- }
1206
- else if ((_j = this.aggregations) === null || _j === void 0 ? void 0 : _j.collection) {
1207
- (_k = this.collectionNameCache) === null || _k === void 0 ? void 0 : _k.preloadIdentifiers(this.aggregations.collection.buckets.map(bucket => { var _a; return (_a = bucket.key) === null || _a === void 0 ? void 0 : _a.toString(); }));
1208
- }
1209
- this.fullYearsHistogramAggregation =
1210
- (_m = (_l = success === null || success === void 0 ? void 0 : success.response) === null || _l === void 0 ? void 0 : _l.aggregations) === null || _m === void 0 ? void 0 : _m.year_histogram;
1211
- this.facetsLoading = false;
1212
- }
1213
- scrollToPage(pageNumber) {
1214
- return new Promise(resolve => {
1215
- const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1216
- // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1217
- // then scrolls to the cell
1218
- setTimeout(() => {
1219
- var _a;
1220
- this.isScrollingToCell = true;
1221
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.scrollToCell(cellIndexToScrollTo, true);
1222
- // This timeout is to give the scroll animation time to finish
1223
- // then updating the infinite scroller once we're done scrolling
1224
- // There's no scroll animation completion callback so we're
1225
- // giving it 0.5s to finish.
1226
- setTimeout(() => {
1227
- var _a;
1228
- this.isScrollingToCell = false;
1229
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
1230
- resolve();
1231
- }, 500);
1232
- }, 0);
1233
- });
1234
- }
1235
- /**
1236
- * Whether sorting by relevance makes sense for the current state.
1237
- * Currently equivalent to having a non-empty query.
1238
- */
1239
- get isRelevanceSortAvailable() {
1240
- var _a;
1241
- return !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
1242
- }
1243
- /**
1244
- * Whether a search may be performed in the current state of the component.
1245
- * This is only true if the search service is defined, and either
1246
- * (a) a non-empty query is set, or
1247
- * (b) we are on a collection page in metadata search mode.
1248
- */
1249
- get canPerformSearch() {
1250
- var _a;
1251
- if (!this.searchService)
1252
- return false;
1253
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1254
- const hasNonEmptyQuery = !!trimmedQuery;
1255
- const isCollectionSearch = !!this.withinCollection;
1256
- const isMetadataSearch = this.searchType === SearchType.METADATA;
1257
- // Metadata searches within a collection are allowed to have no query.
1258
- // Otherwise, a non-empty query must be set.
1259
- return hasNonEmptyQuery || (isCollectionSearch && isMetadataSearch);
1260
- }
1261
- /**
1262
- * Additional params to pass to the search service if targeting a collection page,
1263
- * or null otherwise.
1264
- */
1265
- get collectionParams() {
1266
- return this.withinCollection
1267
- ? { pageType: 'collection_details', pageTarget: this.withinCollection }
1268
- : null;
1269
- }
1270
- /**
1271
- * The query key is a string that uniquely identifies the current search.
1272
- * It consists of:
1273
- * - The current base query
1274
- * - The current collection
1275
- * - The current search type
1276
- * - Any currently-applied facets
1277
- * - Any currently-applied date range
1278
- * - Any currently-applied prefix filters
1279
- * - The current sort options
1280
- *
1281
- * This lets us keep track of queries so we don't persist data that's
1282
- * no longer relevant.
1283
- */
1284
- get pageFetchQueryKey() {
1285
- var _a, _b, _c, _d;
1286
- const sortField = (_b = (_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : 'none';
1287
- const sortDirection = (_d = (_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.direction) !== null && _d !== void 0 ? _d : 'none';
1288
- return `${this.fullQuery}-${this.withinCollection}-${this.searchType}-${sortField}-${sortDirection}`;
1289
- }
1290
- /**
1291
- * Similar to `pageFetchQueryKey` above, but excludes sort fields since they
1292
- * are not relevant in determining aggregation queries.
1293
- */
1294
- get facetFetchQueryKey() {
1295
- return `${this.fullQuery}-${this.withinCollection}-${this.searchType}`;
1296
- }
1297
- /**
1298
- * Fetches one or more pages of results and updates the data source.
1299
- *
1300
- * @param pageNumber The page number to fetch
1301
- * @param numInitialPages If this is an initial page fetch (`pageNumber = 1`),
1302
- * specifies how many pages to batch together in one request. Ignored
1303
- * if `pageNumber != 1`, defaulting to a single page.
1304
- */
1305
- async fetchPage(pageNumber, numInitialPages = 1) {
1306
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1307
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1308
- if (!this.canPerformSearch)
1309
- return;
1310
- // if we already have data, don't fetch again
1311
- if (this.dataSource[pageNumber])
1312
- return;
1313
- if (this.endOfDataReached)
1314
- return;
1315
- // Batch multiple initial page requests together if needed (e.g., can request
1316
- // pages 1 and 2 together in a single request).
1317
- const numPages = pageNumber === 1 ? numInitialPages : 1;
1318
- const numRows = this.pageSize * numPages;
1319
- // if a fetch is already in progress for this query and page, don't fetch again
1320
- const { pageFetchQueryKey } = this;
1321
- const pageFetches = (_b = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _b !== void 0 ? _b : new Set();
1322
- if (pageFetches.has(pageNumber))
1323
- return;
1324
- for (let i = 0; i < numPages; i += 1) {
1325
- pageFetches.add(pageNumber + i);
1326
- }
1327
- this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
1328
- const sortParams = this.sortParam ? [this.sortParam] : [];
1329
- const params = {
1330
- ...this.collectionParams,
1331
- query: trimmedQuery || '',
1332
- page: pageNumber,
1333
- rows: numRows,
1334
- sort: sortParams,
1335
- filters: this.filterMap,
1336
- aggregations: { omit: true },
1337
- };
1338
- params.uid = await this.requestUID(params, 'hits');
1339
- const searchResponse = await ((_c = this.searchService) === null || _c === void 0 ? void 0 : _c.search(params, this.searchType));
1340
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1341
- // This is checking to see if the query has changed since the data was fetched.
1342
- // If so, we just want to discard the data since there should be a new query
1343
- // right behind it.
1344
- const queryChangedSinceFetch = pageFetchQueryKey !== this.pageFetchQueryKey;
1345
- if (queryChangedSinceFetch)
1346
- return;
1347
- if (!success) {
1348
- const errorMsg = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.message;
1349
- const detailMsg = (_f = (_e = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _e === void 0 ? void 0 : _e.details) === null || _f === void 0 ? void 0 : _f.message;
1350
- this.queryErrorMessage = `${errorMsg !== null && errorMsg !== void 0 ? errorMsg : ''}${detailMsg ? `; ${detailMsg}` : ''}`;
1351
- if (!this.queryErrorMessage) {
1352
- this.queryErrorMessage = 'Missing or malformed response from backend';
1353
- // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1354
- (_h = (_g = window === null || window === void 0 ? void 0 : window.Sentry) === null || _g === void 0 ? void 0 : _g.captureMessage) === null || _h === void 0 ? void 0 : _h.call(_g, this.queryErrorMessage, 'error');
1355
- }
1356
- for (let i = 0; i < numPages; i += 1) {
1357
- (_j = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _j === void 0 ? void 0 : _j.delete(pageNumber + i);
1358
- }
1359
- this.searchResultsLoading = false;
1360
- return;
1361
- }
1362
- this.totalResults = success.response.totalResults;
1363
- if (this.withinCollection) {
1364
- this.collectionInfo = success.response.collectionExtraInfo;
1365
- // For collections, we want the UI to respect the default sort option
1366
- // which can be specified in metadata, or otherwise assumed to be week:desc
1367
- this.applyDefaultCollectionSort(success.response.collectionExtraInfo);
1368
- }
1369
- const { results, collectionTitles } = success.response;
1370
- if (results && results.length > 0) {
1371
- // Load any collection titles present on the response into the cache,
1372
- // or queue up preload fetches for them if none were present.
1373
- if (collectionTitles) {
1374
- (_k = this.collectionNameCache) === null || _k === void 0 ? void 0 : _k.addKnownTitles(collectionTitles);
1375
- }
1376
- else {
1377
- this.preloadCollectionNames(results);
1378
- }
1379
- // Update the data source for each returned page
1380
- for (let i = 0; i < numPages; i += 1) {
1381
- const pageStartIndex = this.pageSize * i;
1382
- this.updateDataSource(pageNumber + i, results.slice(pageStartIndex, pageStartIndex + this.pageSize));
1383
- }
1384
- }
1385
- // When we reach the end of the data, we can set the infinite scroller's
1386
- // item count to the real total number of results (rather than the
1387
- // temporary estimates based on pages rendered so far).
1388
- const resultCountDiscrepancy = numRows - results.length;
1389
- if (resultCountDiscrepancy > 0) {
1390
- this.endOfDataReached = true;
1391
- if (this.infiniteScroller) {
1392
- this.infiniteScroller.itemCount =
1393
- this.estimatedTileCount - resultCountDiscrepancy;
1394
- }
1395
- }
1396
- for (let i = 0; i < numPages; i += 1) {
1397
- (_l = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _l === void 0 ? void 0 : _l.delete(pageNumber + i);
1398
- }
1399
- }
1400
- preloadCollectionNames(results) {
1401
- var _a;
1402
- const collectionIds = results
1403
- .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
1404
- .flat();
1405
- const collectionIdsArray = Array.from(new Set(collectionIds));
1406
- (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
1407
- }
1408
- /**
1409
- * Applies any default sort option for the current collection, by checking
1410
- * for one in the collection's metadata. If none is found, defaults to sorting
1411
- * descending by weekly views.
1412
- */
1413
- applyDefaultCollectionSort(collectionInfo) {
1414
- var _a, _b;
1415
- if (this.baseQuery) {
1416
- // If there's a query set, then we default to relevance sorting regardless of
1417
- // the collection metadata-specified sort.
1418
- this.defaultSortField = SortField.relevance;
1419
- this.defaultSortDirection = null;
1420
- return;
1421
- }
1422
- const defaultSort = (_b = (_a = collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.public_metadata) === null || _a === void 0 ? void 0 : _a['sort-by']) !== null && _b !== void 0 ? _b : '-week';
1423
- // Account for both -field and field:dir formats
1424
- let [field, dir] = defaultSort.split(':');
1425
- if (field.startsWith('-')) {
1426
- field = field.slice(1);
1427
- dir = 'desc';
1428
- }
1429
- else if (!['asc', 'desc'].includes(dir)) {
1430
- dir = 'asc';
1431
- }
1432
- const sortField = MetadataFieldToSortField[field];
1433
- if (sortField && sortField !== SortField.default) {
1434
- this.defaultSortField = sortField;
1435
- this.defaultSortDirection = dir;
1436
- }
1437
- }
1438
- /**
1439
- * This is useful for determining whether we need to reload the scroller.
1440
- *
1441
- * When the fetch completes, we need to reload the scroller if the cells for that
1442
- * page are visible, but if the page is not currenlty visible, we don't need to reload
1443
- */
1444
- get currentVisiblePageNumbers() {
1445
- var _a, _b;
1446
- const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
1447
- const visiblePages = new Set();
1448
- visibleCells.forEach(cellIndex => {
1449
- const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1450
- visiblePages.add(visiblePage);
1451
- });
1452
- return Array.from(visiblePages);
1453
- }
1454
- /**
1455
- * Update the datasource from the fetch response
1456
- *
1457
- * @param pageNumber
1458
- * @param results
1459
- */
1460
- updateDataSource(pageNumber, results) {
1461
- var _a;
1462
- // copy our existing datasource so when we set it below, it gets set
1463
- // instead of modifying the existing dataSource since object changes
1464
- // don't trigger a re-render
1465
- const datasource = { ...this.dataSource };
1466
- const tiles = [];
1467
- results === null || results === void 0 ? void 0 : results.forEach(result => {
1468
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
1469
- if (!result.identifier)
1470
- return;
1471
- let loginRequired = false;
1472
- let contentWarning = false;
1473
- // Check if item and item in "modifying" collection, setting above flags
1474
- if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
1475
- ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
1476
- for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
1477
- if (collection === 'loggedin') {
1478
- loginRequired = true;
1479
- if (contentWarning)
1480
- break;
1481
- }
1482
- if (collection === 'no-preview') {
1483
- contentWarning = true;
1484
- if (loginRequired)
1485
- break;
1486
- }
1487
- }
1488
- }
1489
- tiles.push({
1490
- averageRating: (_e = result.avg_rating) === null || _e === void 0 ? void 0 : _e.value,
1491
- collections: (_g = (_f = result.collection) === null || _f === void 0 ? void 0 : _f.values) !== null && _g !== void 0 ? _g : [],
1492
- collectionFilesCount: (_j = (_h = result.collection_files_count) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : 0,
1493
- collectionSize: (_l = (_k = result.collection_size) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : 0,
1494
- commentCount: (_o = (_m = result.num_reviews) === null || _m === void 0 ? void 0 : _m.value) !== null && _o !== void 0 ? _o : 0,
1495
- creator: (_p = result.creator) === null || _p === void 0 ? void 0 : _p.value,
1496
- creators: (_r = (_q = result.creator) === null || _q === void 0 ? void 0 : _q.values) !== null && _r !== void 0 ? _r : [],
1497
- dateAdded: (_s = result.addeddate) === null || _s === void 0 ? void 0 : _s.value,
1498
- dateArchived: (_t = result.publicdate) === null || _t === void 0 ? void 0 : _t.value,
1499
- datePublished: (_u = result.date) === null || _u === void 0 ? void 0 : _u.value,
1500
- dateReviewed: (_v = result.reviewdate) === null || _v === void 0 ? void 0 : _v.value,
1501
- description: (_w = result.description) === null || _w === void 0 ? void 0 : _w.values.join('\n'),
1502
- favCount: (_y = (_x = result.num_favorites) === null || _x === void 0 ? void 0 : _x.value) !== null && _y !== void 0 ? _y : 0,
1503
- href: this.collapseRepeatedQuotes((_z = result.__href__) === null || _z === void 0 ? void 0 : _z.value),
1504
- identifier: result.identifier,
1505
- issue: (_0 = result.issue) === null || _0 === void 0 ? void 0 : _0.value,
1506
- itemCount: (_2 = (_1 = result.item_count) === null || _1 === void 0 ? void 0 : _1.value) !== null && _2 !== void 0 ? _2 : 0,
1507
- mediatype: (_4 = (_3 = result.mediatype) === null || _3 === void 0 ? void 0 : _3.value) !== null && _4 !== void 0 ? _4 : 'data',
1508
- snippets: (_6 = (_5 = result.highlight) === null || _5 === void 0 ? void 0 : _5.values) !== null && _6 !== void 0 ? _6 : [],
1509
- source: (_7 = result.source) === null || _7 === void 0 ? void 0 : _7.value,
1510
- subjects: (_9 = (_8 = result.subject) === null || _8 === void 0 ? void 0 : _8.values) !== null && _9 !== void 0 ? _9 : [],
1511
- title: (_11 = (_10 = result.title) === null || _10 === void 0 ? void 0 : _10.value) !== null && _11 !== void 0 ? _11 : '',
1512
- volume: (_12 = result.volume) === null || _12 === void 0 ? void 0 : _12.value,
1513
- viewCount: (_14 = (_13 = result.downloads) === null || _13 === void 0 ? void 0 : _13.value) !== null && _14 !== void 0 ? _14 : 0,
1514
- weeklyViewCount: (_15 = result.week) === null || _15 === void 0 ? void 0 : _15.value,
1515
- loginRequired,
1516
- contentWarning,
1517
- });
1518
- });
1519
- datasource[pageNumber] = tiles;
1520
- this.dataSource = datasource;
1521
- const visiblePages = this.currentVisiblePageNumbers;
1522
- const needsReload = visiblePages.includes(pageNumber);
1523
- if (needsReload) {
1524
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
1525
- }
1526
- }
1527
- /**
1528
- * Returns the input string, but removing one set of quotes from all instances of
1529
- * ""clauses wrapped in two sets of quotes"". This assumes the quotes are already
1530
- * URL-encoded.
1531
- *
1532
- * This should be a temporary measure to address the fact that the __href__ field
1533
- * sometimes acquires extra quotation marks during query rewriting. Once there is a
1534
- * full Lucene parser in place that handles quoted queries correctly, this can likely
1535
- * be removed.
1536
- */
1537
- collapseRepeatedQuotes(str) {
1538
- return str === null || str === void 0 ? void 0 : str.replace(/%22%22(?!%22%22)(.+?)%22%22/g, '%22$1%22');
1539
- }
1540
- /** Fetches the aggregation buckets for the given prefix filter type. */
1541
- async fetchPrefixFilterBuckets(filterType) {
1542
- var _a, _b, _c, _d, _e, _f, _g;
1543
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1544
- if (!this.canPerformSearch)
1545
- return [];
1546
- const filterAggregationKey = prefixFilterAggregationKeys[filterType];
1547
- const sortParams = this.sortParam ? [this.sortParam] : [];
1548
- const params = {
1549
- ...this.collectionParams,
1550
- query: trimmedQuery || '',
1551
- rows: 0,
1552
- filters: this.filterMap,
1553
- // Only fetch the firstTitle or firstCreator aggregation
1554
- aggregations: { simpleParams: [filterAggregationKey] },
1555
- // Fetch all 26 letter buckets
1556
- aggregationsSize: 26,
1557
- };
1558
- params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1559
- const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1560
- return ((_g = (_f = (_e = (_d = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.aggregations) === null || _e === void 0 ? void 0 : _e[filterAggregationKey]) === null || _f === void 0 ? void 0 : _f.buckets) !== null && _g !== void 0 ? _g : []);
1561
- }
1562
- /** Fetches and caches the prefix filter counts for the given filter type. */
1563
- async updatePrefixFilterCounts(filterType) {
1564
- const { facetFetchQueryKey } = this;
1565
- const buckets = await this.fetchPrefixFilterBuckets(filterType);
1566
- // Don't update the filter counts for an outdated query (if it has been changed
1567
- // since we sent the request)
1568
- const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1569
- if (queryChangedSinceFetch)
1570
- return;
1571
- // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }
1572
- this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update
1573
- this.prefixFilterCountMap[filterType] = buckets.reduce((acc, bucket) => {
1574
- acc[bucket.key.toUpperCase()] = bucket.doc_count;
1575
- return acc;
1576
- }, {});
1577
- }
1578
- /**
1579
- * Fetches and caches the prefix filter counts for the current sort type,
1580
- * provided it is one that permits prefix filtering. (If not, this does nothing).
1581
- */
1582
- async updatePrefixFiltersForCurrentSort() {
1583
- if (['title', 'creator'].includes(this.selectedSort)) {
1584
- const filterType = this.selectedSort;
1585
- if (!this.prefixFilterCountMap[filterType]) {
1586
- this.updatePrefixFilterCounts(filterType);
1587
- }
1588
- }
1589
- }
1590
- /**
1591
- * Clears the cached letter counts for both title and creator, and
1592
- * fetches a new set of counts for whichever of them is the currently
1593
- * selected sort option (which may be neither).
1594
- *
1595
- * Call this whenever the counts are invalidated (e.g., by a query change).
1596
- */
1597
- refreshLetterCounts() {
1598
- if (Object.keys(this.prefixFilterCountMap).length > 0) {
1599
- this.prefixFilterCountMap = {};
1600
- }
1601
- this.updatePrefixFiltersForCurrentSort();
1602
- }
1603
- /**
1604
- * Callback when a result is selected
1605
- */
1606
- resultSelected(event) {
1607
- var _a, _b;
1608
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1609
- category: this.searchContext,
1610
- action: analyticsActions.resultSelected,
1611
- label: event.detail.mediatype,
1612
- });
1613
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1614
- category: this.searchContext,
1615
- action: analyticsActions.resultSelected,
1616
- label: `page-${this.currentPage}`,
1617
- });
1618
- }
1619
- cellForIndex(index) {
1620
- const model = this.tileModelAtCellIndex(index);
1621
- if (!model)
1622
- return undefined;
647
+ `;
648
+ }
649
+ histogramDateRangeUpdated(e) {
650
+ var _a;
651
+ const { minDate, maxDate } = e.detail;
652
+ [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
653
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
654
+ category: this.searchContext,
655
+ action: analyticsActions.histogramChanged,
656
+ label: this.dateRangeQueryClause,
657
+ });
658
+ }
659
+ get dateRangeQueryClause() {
660
+ if (!this.minSelectedDate || !this.maxSelectedDate) {
661
+ return undefined;
662
+ }
663
+ return `year:[${this.minSelectedDate} TO ${this.maxSelectedDate}]`;
664
+ }
665
+ firstUpdated() {
666
+ this.setupStateRestorationObserver();
667
+ this.restoreState();
668
+ }
669
+ updated(changed) {
670
+ var _a;
671
+ if (changed.has('placeholderType') && this.placeholderType === null) {
672
+ if (!this.leftColIntersectionObserver) {
673
+ this.setupLeftColumnScrollListeners();
674
+ }
675
+ if (!this.facetsIntersectionObserver) {
676
+ this.setupFacetsScrollListeners();
677
+ }
678
+ this.updateLeftColumnHeight();
679
+ }
680
+ if (changed.has('displayMode') ||
681
+ changed.has('baseNavigationUrl') ||
682
+ changed.has('baseImageUrl') ||
683
+ changed.has('loggedIn')) {
684
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
685
+ }
686
+ if (changed.has('baseQuery') || changed.has('searchType')) {
687
+ // Unless this query/search type update is from the initial page load or the
688
+ // result of hitting the back button,
689
+ // we need to clear any existing filters since they may no longer be valid for
690
+ // the new set of search results.
691
+ if (!this.historyPopOccurred && this.initialQueryChangeHappened) {
692
+ // Only clear filters that haven't been simultaneously applied in this update
693
+ this.clearFilters({
694
+ facets: !changed.has('selectedFacets'),
695
+ dateRange: !(changed.has('minSelectedDate') || changed.has('maxSelectedDate')),
696
+ letterFilters: !(changed.has('selectedTitleFilter') ||
697
+ changed.has('selectedCreatorFilter')),
698
+ });
699
+ }
700
+ }
701
+ if (changed.has('baseQuery')) {
702
+ this.emitBaseQueryChanged();
703
+ }
704
+ if (changed.has('searchType')) {
705
+ this.emitSearchTypeChanged();
706
+ }
707
+ if (changed.has('currentPage') || changed.has('displayMode')) {
708
+ this.persistState();
709
+ }
710
+ if (changed.has('baseQuery') ||
711
+ changed.has('minSelectedDate') ||
712
+ changed.has('maxSelectedDate') ||
713
+ changed.has('selectedFacets') ||
714
+ changed.has('searchService') ||
715
+ changed.has('withinCollection')) {
716
+ this.refreshLetterCounts();
717
+ }
718
+ if (changed.has('selectedSort') || changed.has('sortDirection')) {
719
+ const prevSortDirection = changed.get('sortDirection');
720
+ this.sendSortByAnalytics(prevSortDirection);
721
+ this.selectedSortChanged();
722
+ }
723
+ if (changed.has('selectedTitleFilter')) {
724
+ this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
725
+ }
726
+ if (changed.has('selectedCreatorFilter')) {
727
+ this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
728
+ }
729
+ if (changed.has('baseQuery') ||
730
+ changed.has('searchType') ||
731
+ changed.has('selectedTitleFilter') ||
732
+ changed.has('selectedCreatorFilter') ||
733
+ changed.has('minSelectedDate') ||
734
+ changed.has('maxSelectedDate') ||
735
+ changed.has('sortParam') ||
736
+ changed.has('selectedFacets') ||
737
+ changed.has('searchService') ||
738
+ changed.has('withinCollection')) {
739
+ this.handleQueryChange();
740
+ }
741
+ if (changed.has('searchResultsLoading')) {
742
+ this.emitSearchResultsLoadingChanged();
743
+ }
744
+ if (changed.has('facetsLoading') &&
745
+ this.facetsLoading &&
746
+ this.collectionFacets) {
747
+ this.collectionFacets.moreLinksVisible =
748
+ this.searchType !== SearchType.FULLTEXT;
749
+ }
750
+ if (changed.has('pagesToRender')) {
751
+ if (!this.endOfDataReached && this.infiniteScroller) {
752
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
753
+ }
754
+ }
755
+ if (changed.has('resizeObserver')) {
756
+ const oldObserver = changed.get('resizeObserver');
757
+ if (oldObserver)
758
+ this.disconnectResizeObserver(oldObserver);
759
+ this.setupResizeObserver();
760
+ }
761
+ }
762
+ disconnectedCallback() {
763
+ var _a, _b;
764
+ if (this.resizeObserver) {
765
+ this.disconnectResizeObserver(this.resizeObserver);
766
+ }
767
+ if (this.boundNavigationHandler) {
768
+ window.removeEventListener('popstate', this.boundNavigationHandler);
769
+ }
770
+ (_a = this.leftColIntersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
771
+ (_b = this.facetsIntersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
772
+ window.removeEventListener('resize', this.updateLeftColumnHeight);
773
+ }
774
+ handleResize(entry) {
775
+ const previousView = this.mobileView;
776
+ if (entry.target === this.contentContainer) {
777
+ this.contentWidth = entry.contentRect.width;
778
+ this.mobileView =
779
+ this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
780
+ // If changing from desktop to mobile disable transition
781
+ if (this.mobileView && !previousView) {
782
+ this.isResizeToMobile = true;
783
+ }
784
+ }
785
+ // Ensure the facet sidebar remains sized correctly
786
+ this.updateLeftColumnHeight();
787
+ }
788
+ /**
789
+ * Sets up listeners for events that may require updating the left column height.
790
+ */
791
+ setupLeftColumnScrollListeners() {
792
+ var _a;
793
+ // We observe intersections between the left column's scroll sentinel and
794
+ // the viewport, so that we can ensure the left column is always sized to
795
+ // match the _available_ viewport height. This should generally be more
796
+ // performant than listening to scroll events on the page or column.
797
+ const leftColumnSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#left-column-scroll-sentinel');
798
+ if (leftColumnSentinel) {
799
+ this.leftColIntersectionObserver = new IntersectionObserver(this.updateLeftColumnHeight, {
800
+ threshold: [...Array(101).keys()].map(n => n / 100), // Threshold every 1%
801
+ });
802
+ this.leftColIntersectionObserver.observe(leftColumnSentinel);
803
+ }
804
+ // We also listen for window resize events, as they are not always captured
805
+ // by the resize observer and can affect the desired height of the left column.
806
+ window.addEventListener('resize', this.updateLeftColumnHeight);
807
+ }
808
+ /**
809
+ * Sets up listeners to control whether the facet sidebar shows its bottom fade-out.
810
+ * Note this uses a separate IntersectionObserver from the left column, because we
811
+ * don't need granular intersection thresholds for this.
812
+ */
813
+ setupFacetsScrollListeners() {
814
+ var _a;
815
+ const facetsSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#facets-scroll-sentinel');
816
+ if (facetsSentinel) {
817
+ this.facetsIntersectionObserver = new IntersectionObserver(this.updateFacetFadeOut);
818
+ this.facetsIntersectionObserver.observe(facetsSentinel);
819
+ }
820
+ }
821
+ emitBaseQueryChanged() {
822
+ this.dispatchEvent(new CustomEvent('baseQueryChanged', {
823
+ detail: {
824
+ baseQuery: this.baseQuery,
825
+ },
826
+ }));
827
+ }
828
+ emitSearchTypeChanged() {
829
+ this.dispatchEvent(new CustomEvent('searchTypeChanged', {
830
+ detail: this.searchType,
831
+ }));
832
+ }
833
+ disconnectResizeObserver(resizeObserver) {
834
+ resizeObserver.removeObserver({
835
+ target: this.contentContainer,
836
+ handler: this,
837
+ });
838
+ }
839
+ setupResizeObserver() {
840
+ if (!this.resizeObserver)
841
+ return;
842
+ this.resizeObserver.addObserver({
843
+ target: this.contentContainer,
844
+ handler: this,
845
+ });
846
+ }
847
+ /**
848
+ * When the visible cells change from the infinite scroller, we want to emit
849
+ * which page is currently visible so the consumer can update its UI or the URL
850
+ *
851
+ * @param e
852
+ * @returns
853
+ */
854
+ visibleCellsChanged(e) {
855
+ if (this.isScrollingToCell)
856
+ return;
857
+ const { visibleCellIndices } = e.detail;
858
+ if (visibleCellIndices.length === 0)
859
+ return;
860
+ const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
861
+ const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
862
+ if (this.currentPage !== lastVisibleCellPage) {
863
+ this.currentPage = lastVisibleCellPage;
864
+ }
865
+ const event = new CustomEvent('visiblePageChanged', {
866
+ detail: {
867
+ pageNumber: lastVisibleCellPage,
868
+ },
869
+ });
870
+ this.dispatchEvent(event);
871
+ }
872
+ /**
873
+ * A Promise which, after each query change, resolves once the fetches for the initial
874
+ * search have completed. Waits for *both* the hits and aggregations fetches to finish.
875
+ *
876
+ * Ensure you await this component's `updateComplete` promise before awaiting this
877
+ * one, to ensure you do not await an obsolete promise from the previous update.
878
+ */
879
+ get initialSearchComplete() {
880
+ return this._initialSearchCompletePromise;
881
+ }
882
+ async handleQueryChange() {
883
+ var _a;
884
+ // only reset if the query has actually changed
885
+ if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
886
+ return;
887
+ // If the new state prevents us from updating the search results, don't reset
888
+ if (!this.canPerformSearch)
889
+ return;
890
+ this.previousQueryKey = this.pageFetchQueryKey;
891
+ this.dataSource = {};
892
+ this.totalResults = undefined;
893
+ this.aggregations = undefined;
894
+ this.fullYearsHistogramAggregation = undefined;
895
+ this.pageFetchesInProgress = {};
896
+ this.endOfDataReached = false;
897
+ this.pagesToRender =
898
+ this.initialPageNumber === 1
899
+ ? 2 // First two pages are batched into one request when starting from page 1
900
+ : this.initialPageNumber;
901
+ this.queryErrorMessage = undefined;
902
+ // Reset the infinite scroller's item count, so that it
903
+ // shows tile placeholders until the new query's results load in
904
+ if (this.infiniteScroller) {
905
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
906
+ this.infiniteScroller.reload();
907
+ }
908
+ if (this.withinCollection && ((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
909
+ this.defaultSortField = SortField.relevance;
910
+ this.defaultSortDirection = null;
911
+ }
912
+ if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
913
+ this.scrollToPage(this.initialPageNumber);
914
+ }
915
+ this.initialQueryChangeHappened = true;
916
+ // if the query changed as part of a window.history pop event, we don't want to
917
+ // persist the state because it overwrites the forward history
918
+ if (!this.historyPopOccurred) {
919
+ this.persistState();
920
+ }
921
+ this.historyPopOccurred = false;
922
+ // Reset the `initialSearchComplete` promise with a new value for the imminent search
923
+ this._initialSearchCompletePromise = new Promise(res => {
924
+ this._initialSearchCompleteResolver = res;
925
+ });
926
+ // Fire the initial page and facets requests
927
+ await Promise.all([this.doInitialPageFetch(), this.fetchFacets()]);
928
+ // Resolve the `initialSearchComplete` promise for this search
929
+ this._initialSearchCompleteResolver(true);
930
+ }
931
+ setupStateRestorationObserver() {
932
+ if (this.boundNavigationHandler)
933
+ return;
934
+ this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
935
+ // when the user navigates back, we want to update the UI to match the URL
936
+ window.addEventListener('popstate', this.boundNavigationHandler);
937
+ }
938
+ historyNavigationHandler() {
939
+ this.historyPopOccurred = true;
940
+ this.restoreState();
941
+ }
942
+ restoreState() {
943
+ var _a, _b, _c, _d, _e;
944
+ const restorationState = this.restorationStateHandler.getRestorationState();
945
+ this.displayMode = restorationState.displayMode;
946
+ if (restorationState.searchType != null)
947
+ this.searchType = restorationState.searchType;
948
+ this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.default;
949
+ this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
950
+ this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
951
+ this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
952
+ this.selectedFacets = restorationState.selectedFacets;
953
+ this.baseQuery = restorationState.baseQuery;
954
+ this.currentPage = (_e = restorationState.currentPage) !== null && _e !== void 0 ? _e : 1;
955
+ this.minSelectedDate = restorationState.minSelectedDate;
956
+ this.maxSelectedDate = restorationState.maxSelectedDate;
957
+ if (this.currentPage > 1) {
958
+ this.goToPage(this.currentPage);
959
+ }
960
+ }
961
+ persistState() {
962
+ var _a, _b, _c, _d;
963
+ const restorationState = {
964
+ displayMode: this.displayMode,
965
+ searchType: this.searchType,
966
+ selectedSort: this.selectedSort,
967
+ sortDirection: (_a = this.sortDirection) !== null && _a !== void 0 ? _a : undefined,
968
+ selectedFacets: (_b = this.selectedFacets) !== null && _b !== void 0 ? _b : getDefaultSelectedFacets(),
969
+ baseQuery: this.baseQuery,
970
+ currentPage: this.currentPage,
971
+ titleQuery: this.titleQuery,
972
+ creatorQuery: this.creatorQuery,
973
+ minSelectedDate: this.minSelectedDate,
974
+ maxSelectedDate: this.maxSelectedDate,
975
+ selectedTitleFilter: (_c = this.selectedTitleFilter) !== null && _c !== void 0 ? _c : undefined,
976
+ selectedCreatorFilter: (_d = this.selectedCreatorFilter) !== null && _d !== void 0 ? _d : undefined,
977
+ };
978
+ this.restorationStateHandler.persistState(restorationState);
979
+ }
980
+ async doInitialPageFetch() {
981
+ this.searchResultsLoading = true;
982
+ // Try to batch 2 initial page requests when possible
983
+ await this.fetchPage(this.initialPageNumber, 2);
984
+ this.searchResultsLoading = false;
985
+ }
986
+ emitSearchResultsLoadingChanged() {
987
+ this.dispatchEvent(new CustomEvent('searchResultsLoadingChanged', {
988
+ detail: {
989
+ loading: this.searchResultsLoading,
990
+ },
991
+ }));
992
+ }
993
+ /**
994
+ * Produces a compact unique ID for a search request that can help with debugging
995
+ * on the backend by making related requests easier to trace through different services.
996
+ * (e.g., tying the hits/aggregations requests for the same page back to a single hash).
997
+ *
998
+ * @param params The search service parameters for the request
999
+ * @param kind The kind of request (hits-only, aggregations-only, or both)
1000
+ * @returns A Promise resolving to the uid to apply to the request
1001
+ */
1002
+ async requestUID(params, kind) {
1003
+ var _a;
1004
+ const paramsToHash = JSON.stringify({
1005
+ pageType: params.pageType,
1006
+ pageTarget: params.pageTarget,
1007
+ query: params.query,
1008
+ fields: params.fields,
1009
+ filters: params.filters,
1010
+ sort: params.sort,
1011
+ searchType: this.searchType,
1012
+ });
1013
+ const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this
1014
+ const sessionId = (await this.getSessionId()).slice(0, 20); // Likewise
1015
+ const page = (_a = params.page) !== null && _a !== void 0 ? _a : 0;
1016
+ const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations
1017
+ const currentTime = Date.now();
1018
+ return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;
1019
+ }
1020
+ /**
1021
+ * Constructs a search service FilterMap object from the combination of
1022
+ * all the currently-applied filters. This includes any facets, letter
1023
+ * filters, and date range.
1024
+ */
1025
+ get filterMap() {
1026
+ const builder = new FilterMapBuilder();
1027
+ // Add the date range, if applicable
1028
+ if (this.minSelectedDate) {
1029
+ builder.addFilter('year', this.minSelectedDate, FilterConstraint.GREATER_OR_EQUAL);
1030
+ }
1031
+ if (this.maxSelectedDate) {
1032
+ builder.addFilter('year', this.maxSelectedDate, FilterConstraint.LESS_OR_EQUAL);
1033
+ }
1034
+ // Add any selected facets
1035
+ if (this.selectedFacets) {
1036
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1037
+ const { name, values } = this.prepareFacetForFetch(facetName, facetValues);
1038
+ for (const [value, bucket] of Object.entries(values)) {
1039
+ let constraint;
1040
+ if (bucket.state === 'selected') {
1041
+ constraint = FilterConstraint.INCLUDE;
1042
+ }
1043
+ else if (bucket.state === 'hidden') {
1044
+ constraint = FilterConstraint.EXCLUDE;
1045
+ }
1046
+ if (constraint) {
1047
+ builder.addFilter(name, value, constraint);
1048
+ }
1049
+ }
1050
+ }
1051
+ }
1052
+ // Add any letter filters
1053
+ if (this.selectedTitleFilter) {
1054
+ builder.addFilter('firstTitle', this.selectedTitleFilter, FilterConstraint.INCLUDE);
1055
+ }
1056
+ if (this.selectedCreatorFilter) {
1057
+ builder.addFilter('firstCreator', this.selectedCreatorFilter, FilterConstraint.INCLUDE);
1058
+ }
1059
+ const filterMap = builder.build();
1060
+ return filterMap;
1061
+ }
1062
+ /** The full query, including year facets and date range clauses */
1063
+ get fullQuery() {
1064
+ var _a, _b;
1065
+ let fullQuery = (_b = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
1066
+ const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;
1067
+ if (facetQuery) {
1068
+ fullQuery += ` AND ${facetQuery}`;
1069
+ }
1070
+ if (dateRangeQueryClause) {
1071
+ fullQuery += ` AND ${dateRangeQueryClause}`;
1072
+ }
1073
+ if (sortFilterQueries) {
1074
+ fullQuery += ` AND ${sortFilterQueries}`;
1075
+ }
1076
+ return fullQuery.trim();
1077
+ }
1078
+ /**
1079
+ * Generates a query string for the given facets
1080
+ *
1081
+ * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
1082
+ */
1083
+ get facetQuery() {
1084
+ var _a;
1085
+ if (!this.selectedFacets)
1086
+ return undefined;
1087
+ const facetClauses = [];
1088
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1089
+ facetClauses.push(this.buildFacetClause(facetName, facetValues));
1090
+ }
1091
+ return (_a = this.joinFacetClauses(facetClauses)) === null || _a === void 0 ? void 0 : _a.trim();
1092
+ }
1093
+ /**
1094
+ * Builds an OR-joined facet clause for the given facet name and values.
1095
+ *
1096
+ * E.g., for name `subject` and values
1097
+ * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`
1098
+ * this will produce the clause
1099
+ * `subject:("foo" OR -"bar")`.
1100
+ *
1101
+ * @param facetName The facet type (e.g., 'collection')
1102
+ * @param facetValues The facet buckets, mapped by their keys
1103
+ */
1104
+ buildFacetClause(facetName, facetValues) {
1105
+ const { name: facetQueryName, values } = this.prepareFacetForFetch(facetName, facetValues);
1106
+ const facetEntries = Object.entries(values);
1107
+ if (facetEntries.length === 0)
1108
+ return '';
1109
+ const facetValuesArray = [];
1110
+ for (const [key, facetData] of facetEntries) {
1111
+ const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
1112
+ facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
1113
+ }
1114
+ const valueQuery = facetValuesArray.join(` OR `);
1115
+ return `${facetQueryName}:(${valueQuery})`;
1116
+ }
1117
+ /**
1118
+ * Handles some special pre-request normalization steps for certain facet types
1119
+ * that require them.
1120
+ *
1121
+ * @param facetName The name of the facet type (e.g., 'language')
1122
+ * @param facetValues An array of values for that facet type
1123
+ */
1124
+ prepareFacetForFetch(facetName, facetValues) {
1125
+ // eslint-disable-next-line prefer-const
1126
+ let [normalizedName, normalizedValues] = [facetName, facetValues];
1127
+ // The full "search engine" name of the lending field is "lending___status"
1128
+ if (facetName === 'lending') {
1129
+ normalizedName = 'lending___status';
1130
+ }
1131
+ return {
1132
+ name: normalizedName,
1133
+ values: normalizedValues,
1134
+ };
1135
+ }
1136
+ /**
1137
+ * Takes an array of facet clauses, and combines them into a
1138
+ * full AND-joined facet query string. Empty clauses are ignored.
1139
+ */
1140
+ joinFacetClauses(facetClauses) {
1141
+ const nonEmptyFacetClauses = facetClauses.filter(clause => clause.length > 0);
1142
+ return nonEmptyFacetClauses.length > 0
1143
+ ? `(${nonEmptyFacetClauses.join(' AND ')})`
1144
+ : undefined;
1145
+ }
1146
+ facetsChanged(e) {
1147
+ this.selectedFacets = e.detail;
1148
+ }
1149
+ facetClickHandler({ detail: { key, state: facetState, negative }, }) {
1150
+ var _a, _b;
1151
+ if (negative) {
1152
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1153
+ category: this.searchContext,
1154
+ action: facetState !== 'none'
1155
+ ? analyticsActions.facetNegativeSelected
1156
+ : analyticsActions.facetNegativeDeselected,
1157
+ label: key,
1158
+ });
1159
+ }
1160
+ else {
1161
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1162
+ category: this.searchContext,
1163
+ action: facetState !== 'none'
1164
+ ? analyticsActions.facetSelected
1165
+ : analyticsActions.facetDeselected,
1166
+ label: key,
1167
+ });
1168
+ }
1169
+ }
1170
+ async fetchFacets() {
1171
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1172
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1173
+ if (!this.canPerformSearch)
1174
+ return;
1175
+ const { facetFetchQueryKey } = this;
1176
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1177
+ const params = {
1178
+ ...this.collectionParams,
1179
+ query: trimmedQuery || '',
1180
+ rows: 0,
1181
+ filters: this.filterMap,
1182
+ // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
1183
+ aggregationsSize: 10,
1184
+ // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
1185
+ // The default aggregations for the search_results page type should be what we need here.
1186
+ };
1187
+ params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1188
+ this.facetsLoading = true;
1189
+ const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1190
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1191
+ // This is checking to see if the query has changed since the data was fetched.
1192
+ // If so, we just want to discard this set of aggregations because they are
1193
+ // likely no longer valid for the newer query.
1194
+ const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1195
+ if (queryChangedSinceFetch)
1196
+ return;
1197
+ if (!success) {
1198
+ const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
1199
+ const detailMsg = (_e = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.details) === null || _e === void 0 ? void 0 : _e.message;
1200
+ if (!errorMsg && !detailMsg) {
1201
+ // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1202
+ (_g = (_f = window === null || window === void 0 ? void 0 : window.Sentry) === null || _f === void 0 ? void 0 : _f.captureMessage) === null || _g === void 0 ? void 0 : _g.call(_f, 'Missing or malformed facet response from backend', 'error');
1203
+ }
1204
+ return;
1205
+ }
1206
+ const { aggregations, collectionTitles } = success.response;
1207
+ this.aggregations = aggregations;
1208
+ if (collectionTitles) {
1209
+ (_h = this.collectionNameCache) === null || _h === void 0 ? void 0 : _h.addKnownTitles(collectionTitles);
1210
+ }
1211
+ else if ((_j = this.aggregations) === null || _j === void 0 ? void 0 : _j.collection) {
1212
+ (_k = this.collectionNameCache) === null || _k === void 0 ? void 0 : _k.preloadIdentifiers(this.aggregations.collection.buckets.map(bucket => { var _a; return (_a = bucket.key) === null || _a === void 0 ? void 0 : _a.toString(); }));
1213
+ }
1214
+ this.fullYearsHistogramAggregation =
1215
+ (_m = (_l = success === null || success === void 0 ? void 0 : success.response) === null || _l === void 0 ? void 0 : _l.aggregations) === null || _m === void 0 ? void 0 : _m.year_histogram;
1216
+ this.facetsLoading = false;
1217
+ }
1218
+ scrollToPage(pageNumber) {
1219
+ return new Promise(resolve => {
1220
+ const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1221
+ // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1222
+ // then scrolls to the cell
1223
+ setTimeout(() => {
1224
+ var _a;
1225
+ this.isScrollingToCell = true;
1226
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.scrollToCell(cellIndexToScrollTo, true);
1227
+ // This timeout is to give the scroll animation time to finish
1228
+ // then updating the infinite scroller once we're done scrolling
1229
+ // There's no scroll animation completion callback so we're
1230
+ // giving it 0.5s to finish.
1231
+ setTimeout(() => {
1232
+ var _a;
1233
+ this.isScrollingToCell = false;
1234
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
1235
+ resolve();
1236
+ }, 500);
1237
+ }, 0);
1238
+ });
1239
+ }
1240
+ /**
1241
+ * Whether sorting by relevance makes sense for the current state.
1242
+ * Currently equivalent to having a non-empty query.
1243
+ */
1244
+ get isRelevanceSortAvailable() {
1245
+ var _a;
1246
+ return !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
1247
+ }
1248
+ /**
1249
+ * Whether a search may be performed in the current state of the component.
1250
+ * This is only true if the search service is defined, and either
1251
+ * (a) a non-empty query is set, or
1252
+ * (b) we are on a collection page in metadata search mode.
1253
+ */
1254
+ get canPerformSearch() {
1255
+ var _a;
1256
+ if (!this.searchService)
1257
+ return false;
1258
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1259
+ const hasNonEmptyQuery = !!trimmedQuery;
1260
+ const isCollectionSearch = !!this.withinCollection;
1261
+ const isMetadataSearch = this.searchType === SearchType.METADATA;
1262
+ // Metadata searches within a collection are allowed to have no query.
1263
+ // Otherwise, a non-empty query must be set.
1264
+ return hasNonEmptyQuery || (isCollectionSearch && isMetadataSearch);
1265
+ }
1266
+ /**
1267
+ * Additional params to pass to the search service if targeting a collection page,
1268
+ * or null otherwise.
1269
+ */
1270
+ get collectionParams() {
1271
+ return this.withinCollection
1272
+ ? { pageType: 'collection_details', pageTarget: this.withinCollection }
1273
+ : null;
1274
+ }
1275
+ /**
1276
+ * The query key is a string that uniquely identifies the current search.
1277
+ * It consists of:
1278
+ * - The current base query
1279
+ * - The current collection
1280
+ * - The current search type
1281
+ * - Any currently-applied facets
1282
+ * - Any currently-applied date range
1283
+ * - Any currently-applied prefix filters
1284
+ * - The current sort options
1285
+ *
1286
+ * This lets us keep track of queries so we don't persist data that's
1287
+ * no longer relevant.
1288
+ */
1289
+ get pageFetchQueryKey() {
1290
+ var _a, _b, _c, _d;
1291
+ const sortField = (_b = (_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : 'none';
1292
+ const sortDirection = (_d = (_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.direction) !== null && _d !== void 0 ? _d : 'none';
1293
+ return `${this.fullQuery}-${this.withinCollection}-${this.searchType}-${sortField}-${sortDirection}`;
1294
+ }
1295
+ /**
1296
+ * Similar to `pageFetchQueryKey` above, but excludes sort fields since they
1297
+ * are not relevant in determining aggregation queries.
1298
+ */
1299
+ get facetFetchQueryKey() {
1300
+ return `${this.fullQuery}-${this.withinCollection}-${this.searchType}`;
1301
+ }
1302
+ /**
1303
+ * Fetches one or more pages of results and updates the data source.
1304
+ *
1305
+ * @param pageNumber The page number to fetch
1306
+ * @param numInitialPages If this is an initial page fetch (`pageNumber = 1`),
1307
+ * specifies how many pages to batch together in one request. Ignored
1308
+ * if `pageNumber != 1`, defaulting to a single page.
1309
+ */
1310
+ async fetchPage(pageNumber, numInitialPages = 1) {
1311
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1312
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1313
+ if (!this.canPerformSearch)
1314
+ return;
1315
+ // if we already have data, don't fetch again
1316
+ if (this.dataSource[pageNumber])
1317
+ return;
1318
+ if (this.endOfDataReached)
1319
+ return;
1320
+ // Batch multiple initial page requests together if needed (e.g., can request
1321
+ // pages 1 and 2 together in a single request).
1322
+ const numPages = pageNumber === 1 ? numInitialPages : 1;
1323
+ const numRows = this.pageSize * numPages;
1324
+ // if a fetch is already in progress for this query and page, don't fetch again
1325
+ const { pageFetchQueryKey } = this;
1326
+ const pageFetches = (_b = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _b !== void 0 ? _b : new Set();
1327
+ if (pageFetches.has(pageNumber))
1328
+ return;
1329
+ for (let i = 0; i < numPages; i += 1) {
1330
+ pageFetches.add(pageNumber + i);
1331
+ }
1332
+ this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
1333
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1334
+ const params = {
1335
+ ...this.collectionParams,
1336
+ query: trimmedQuery || '',
1337
+ page: pageNumber,
1338
+ rows: numRows,
1339
+ sort: sortParams,
1340
+ filters: this.filterMap,
1341
+ aggregations: { omit: true },
1342
+ };
1343
+ params.uid = await this.requestUID(params, 'hits');
1344
+ const searchResponse = await ((_c = this.searchService) === null || _c === void 0 ? void 0 : _c.search(params, this.searchType));
1345
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1346
+ // This is checking to see if the query has changed since the data was fetched.
1347
+ // If so, we just want to discard the data since there should be a new query
1348
+ // right behind it.
1349
+ const queryChangedSinceFetch = pageFetchQueryKey !== this.pageFetchQueryKey;
1350
+ if (queryChangedSinceFetch)
1351
+ return;
1352
+ if (!success) {
1353
+ const errorMsg = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.message;
1354
+ const detailMsg = (_f = (_e = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _e === void 0 ? void 0 : _e.details) === null || _f === void 0 ? void 0 : _f.message;
1355
+ this.queryErrorMessage = `${errorMsg !== null && errorMsg !== void 0 ? errorMsg : ''}${detailMsg ? `; ${detailMsg}` : ''}`;
1356
+ if (!this.queryErrorMessage) {
1357
+ this.queryErrorMessage = 'Missing or malformed response from backend';
1358
+ // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1359
+ (_h = (_g = window === null || window === void 0 ? void 0 : window.Sentry) === null || _g === void 0 ? void 0 : _g.captureMessage) === null || _h === void 0 ? void 0 : _h.call(_g, this.queryErrorMessage, 'error');
1360
+ }
1361
+ for (let i = 0; i < numPages; i += 1) {
1362
+ (_j = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _j === void 0 ? void 0 : _j.delete(pageNumber + i);
1363
+ }
1364
+ this.searchResultsLoading = false;
1365
+ return;
1366
+ }
1367
+ this.totalResults = success.response.totalResults;
1368
+ if (!this.totalResults || this.totalResults === 0) {
1369
+ console.log(this.totalResults);
1370
+ this.dispatchEvent(new CustomEvent('tabChanged', {
1371
+ bubbles: true,
1372
+ composed: true,
1373
+ detail: 'about',
1374
+ }));
1375
+ document.dispatchEvent(new CustomEvent('tabChanged', {
1376
+ bubbles: true,
1377
+ composed: true,
1378
+ detail: 'about1',
1379
+ }));
1380
+ window.dispatchEvent(new CustomEvent('tabChanged', {
1381
+ bubbles: true,
1382
+ composed: true,
1383
+ detail: 'about2',
1384
+ }));
1385
+ }
1386
+ if (this.withinCollection) {
1387
+ this.collectionInfo = success.response.collectionExtraInfo;
1388
+ // For collections, we want the UI to respect the default sort option
1389
+ // which can be specified in metadata, or otherwise assumed to be week:desc
1390
+ this.applyDefaultCollectionSort(success.response.collectionExtraInfo);
1391
+ }
1392
+ const { results, collectionTitles } = success.response;
1393
+ if (results && results.length > 0) {
1394
+ // Load any collection titles present on the response into the cache,
1395
+ // or queue up preload fetches for them if none were present.
1396
+ if (collectionTitles) {
1397
+ (_k = this.collectionNameCache) === null || _k === void 0 ? void 0 : _k.addKnownTitles(collectionTitles);
1398
+ }
1399
+ else {
1400
+ this.preloadCollectionNames(results);
1401
+ }
1402
+ // Update the data source for each returned page
1403
+ for (let i = 0; i < numPages; i += 1) {
1404
+ const pageStartIndex = this.pageSize * i;
1405
+ this.updateDataSource(pageNumber + i, results.slice(pageStartIndex, pageStartIndex + this.pageSize));
1406
+ }
1407
+ }
1408
+ // When we reach the end of the data, we can set the infinite scroller's
1409
+ // item count to the real total number of results (rather than the
1410
+ // temporary estimates based on pages rendered so far).
1411
+ const resultCountDiscrepancy = numRows - results.length;
1412
+ if (resultCountDiscrepancy > 0) {
1413
+ this.endOfDataReached = true;
1414
+ if (this.infiniteScroller) {
1415
+ this.infiniteScroller.itemCount =
1416
+ this.estimatedTileCount - resultCountDiscrepancy;
1417
+ }
1418
+ }
1419
+ for (let i = 0; i < numPages; i += 1) {
1420
+ (_l = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _l === void 0 ? void 0 : _l.delete(pageNumber + i);
1421
+ }
1422
+ }
1423
+ preloadCollectionNames(results) {
1424
+ var _a;
1425
+ const collectionIds = results
1426
+ .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
1427
+ .flat();
1428
+ const collectionIdsArray = Array.from(new Set(collectionIds));
1429
+ (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
1430
+ }
1431
+ /**
1432
+ * Applies any default sort option for the current collection, by checking
1433
+ * for one in the collection's metadata. If none is found, defaults to sorting
1434
+ * descending by weekly views.
1435
+ */
1436
+ applyDefaultCollectionSort(collectionInfo) {
1437
+ var _a, _b;
1438
+ if (this.baseQuery) {
1439
+ // If there's a query set, then we default to relevance sorting regardless of
1440
+ // the collection metadata-specified sort.
1441
+ this.defaultSortField = SortField.relevance;
1442
+ this.defaultSortDirection = null;
1443
+ return;
1444
+ }
1445
+ const defaultSort = (_b = (_a = collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.public_metadata) === null || _a === void 0 ? void 0 : _a['sort-by']) !== null && _b !== void 0 ? _b : '-week';
1446
+ // Account for both -field and field:dir formats
1447
+ let [field, dir] = defaultSort.split(':');
1448
+ if (field.startsWith('-')) {
1449
+ field = field.slice(1);
1450
+ dir = 'desc';
1451
+ }
1452
+ else if (!['asc', 'desc'].includes(dir)) {
1453
+ dir = 'asc';
1454
+ }
1455
+ const sortOption = sortOptionFromAPIString(field);
1456
+ const sortField = sortOption.field;
1457
+ if (sortField && sortField !== SortField.default) {
1458
+ this.defaultSortField = sortField;
1459
+ this.defaultSortDirection = dir;
1460
+ }
1461
+ }
1462
+ /**
1463
+ * This is useful for determining whether we need to reload the scroller.
1464
+ *
1465
+ * When the fetch completes, we need to reload the scroller if the cells for that
1466
+ * page are visible, but if the page is not currenlty visible, we don't need to reload
1467
+ */
1468
+ get currentVisiblePageNumbers() {
1469
+ var _a, _b;
1470
+ const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
1471
+ const visiblePages = new Set();
1472
+ visibleCells.forEach(cellIndex => {
1473
+ const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1474
+ visiblePages.add(visiblePage);
1475
+ });
1476
+ return Array.from(visiblePages);
1477
+ }
1478
+ /**
1479
+ * Update the datasource from the fetch response
1480
+ *
1481
+ * @param pageNumber
1482
+ * @param results
1483
+ */
1484
+ updateDataSource(pageNumber, results) {
1485
+ var _a;
1486
+ // copy our existing datasource so when we set it below, it gets set
1487
+ // instead of modifying the existing dataSource since object changes
1488
+ // don't trigger a re-render
1489
+ const datasource = { ...this.dataSource };
1490
+ const tiles = [];
1491
+ results === null || results === void 0 ? void 0 : results.forEach(result => {
1492
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
1493
+ if (!result.identifier)
1494
+ return;
1495
+ let loginRequired = false;
1496
+ let contentWarning = false;
1497
+ // Check if item and item in "modifying" collection, setting above flags
1498
+ if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
1499
+ ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
1500
+ for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
1501
+ if (collection === 'loggedin') {
1502
+ loginRequired = true;
1503
+ if (contentWarning)
1504
+ break;
1505
+ }
1506
+ if (collection === 'no-preview') {
1507
+ contentWarning = true;
1508
+ if (loginRequired)
1509
+ break;
1510
+ }
1511
+ }
1512
+ }
1513
+ tiles.push({
1514
+ averageRating: (_e = result.avg_rating) === null || _e === void 0 ? void 0 : _e.value,
1515
+ collections: (_g = (_f = result.collection) === null || _f === void 0 ? void 0 : _f.values) !== null && _g !== void 0 ? _g : [],
1516
+ collectionFilesCount: (_j = (_h = result.collection_files_count) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : 0,
1517
+ collectionSize: (_l = (_k = result.collection_size) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : 0,
1518
+ commentCount: (_o = (_m = result.num_reviews) === null || _m === void 0 ? void 0 : _m.value) !== null && _o !== void 0 ? _o : 0,
1519
+ creator: (_p = result.creator) === null || _p === void 0 ? void 0 : _p.value,
1520
+ creators: (_r = (_q = result.creator) === null || _q === void 0 ? void 0 : _q.values) !== null && _r !== void 0 ? _r : [],
1521
+ dateAdded: (_s = result.addeddate) === null || _s === void 0 ? void 0 : _s.value,
1522
+ dateArchived: (_t = result.publicdate) === null || _t === void 0 ? void 0 : _t.value,
1523
+ datePublished: (_u = result.date) === null || _u === void 0 ? void 0 : _u.value,
1524
+ dateReviewed: (_v = result.reviewdate) === null || _v === void 0 ? void 0 : _v.value,
1525
+ description: (_w = result.description) === null || _w === void 0 ? void 0 : _w.values.join('\n'),
1526
+ favCount: (_y = (_x = result.num_favorites) === null || _x === void 0 ? void 0 : _x.value) !== null && _y !== void 0 ? _y : 0,
1527
+ href: this.collapseRepeatedQuotes((_z = result.__href__) === null || _z === void 0 ? void 0 : _z.value),
1528
+ identifier: result.identifier,
1529
+ issue: (_0 = result.issue) === null || _0 === void 0 ? void 0 : _0.value,
1530
+ itemCount: (_2 = (_1 = result.item_count) === null || _1 === void 0 ? void 0 : _1.value) !== null && _2 !== void 0 ? _2 : 0,
1531
+ mediatype: (_4 = (_3 = result.mediatype) === null || _3 === void 0 ? void 0 : _3.value) !== null && _4 !== void 0 ? _4 : 'data',
1532
+ snippets: (_6 = (_5 = result.highlight) === null || _5 === void 0 ? void 0 : _5.values) !== null && _6 !== void 0 ? _6 : [],
1533
+ source: (_7 = result.source) === null || _7 === void 0 ? void 0 : _7.value,
1534
+ subjects: (_9 = (_8 = result.subject) === null || _8 === void 0 ? void 0 : _8.values) !== null && _9 !== void 0 ? _9 : [],
1535
+ title: (_11 = (_10 = result.title) === null || _10 === void 0 ? void 0 : _10.value) !== null && _11 !== void 0 ? _11 : '',
1536
+ volume: (_12 = result.volume) === null || _12 === void 0 ? void 0 : _12.value,
1537
+ viewCount: (_14 = (_13 = result.downloads) === null || _13 === void 0 ? void 0 : _13.value) !== null && _14 !== void 0 ? _14 : 0,
1538
+ weeklyViewCount: (_15 = result.week) === null || _15 === void 0 ? void 0 : _15.value,
1539
+ loginRequired,
1540
+ contentWarning,
1541
+ });
1542
+ });
1543
+ datasource[pageNumber] = tiles;
1544
+ this.dataSource = datasource;
1545
+ const visiblePages = this.currentVisiblePageNumbers;
1546
+ const needsReload = visiblePages.includes(pageNumber);
1547
+ if (needsReload) {
1548
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
1549
+ }
1550
+ }
1551
+ /**
1552
+ * Returns the input string, but removing one set of quotes from all instances of
1553
+ * ""clauses wrapped in two sets of quotes"". This assumes the quotes are already
1554
+ * URL-encoded.
1555
+ *
1556
+ * This should be a temporary measure to address the fact that the __href__ field
1557
+ * sometimes acquires extra quotation marks during query rewriting. Once there is a
1558
+ * full Lucene parser in place that handles quoted queries correctly, this can likely
1559
+ * be removed.
1560
+ */
1561
+ collapseRepeatedQuotes(str) {
1562
+ return str === null || str === void 0 ? void 0 : str.replace(/%22%22(?!%22%22)(.+?)%22%22/g, '%22$1%22');
1563
+ }
1564
+ /** Fetches the aggregation buckets for the given prefix filter type. */
1565
+ async fetchPrefixFilterBuckets(filterType) {
1566
+ var _a, _b, _c, _d, _e, _f, _g;
1567
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1568
+ if (!this.canPerformSearch)
1569
+ return [];
1570
+ const filterAggregationKey = prefixFilterAggregationKeys[filterType];
1571
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1572
+ const params = {
1573
+ ...this.collectionParams,
1574
+ query: trimmedQuery || '',
1575
+ rows: 0,
1576
+ filters: this.filterMap,
1577
+ // Only fetch the firstTitle or firstCreator aggregation
1578
+ aggregations: { simpleParams: [filterAggregationKey] },
1579
+ // Fetch all 26 letter buckets
1580
+ aggregationsSize: 26,
1581
+ };
1582
+ params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1583
+ const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1584
+ return ((_g = (_f = (_e = (_d = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.aggregations) === null || _e === void 0 ? void 0 : _e[filterAggregationKey]) === null || _f === void 0 ? void 0 : _f.buckets) !== null && _g !== void 0 ? _g : []);
1585
+ }
1586
+ /** Fetches and caches the prefix filter counts for the given filter type. */
1587
+ async updatePrefixFilterCounts(filterType) {
1588
+ const { facetFetchQueryKey } = this;
1589
+ const buckets = await this.fetchPrefixFilterBuckets(filterType);
1590
+ // Don't update the filter counts for an outdated query (if it has been changed
1591
+ // since we sent the request)
1592
+ const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1593
+ if (queryChangedSinceFetch)
1594
+ return;
1595
+ // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }
1596
+ this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update
1597
+ this.prefixFilterCountMap[filterType] = buckets.reduce((acc, bucket) => {
1598
+ acc[bucket.key.toUpperCase()] = bucket.doc_count;
1599
+ return acc;
1600
+ }, {});
1601
+ }
1602
+ /**
1603
+ * Fetches and caches the prefix filter counts for the current sort type,
1604
+ * provided it is one that permits prefix filtering. (If not, this does nothing).
1605
+ */
1606
+ async updatePrefixFiltersForCurrentSort() {
1607
+ if (['title', 'creator'].includes(this.selectedSort)) {
1608
+ const filterType = this.selectedSort;
1609
+ if (!this.prefixFilterCountMap[filterType]) {
1610
+ this.updatePrefixFilterCounts(filterType);
1611
+ }
1612
+ }
1613
+ }
1614
+ /**
1615
+ * Clears the cached letter counts for both title and creator, and
1616
+ * fetches a new set of counts for whichever of them is the currently
1617
+ * selected sort option (which may be neither).
1618
+ *
1619
+ * Call this whenever the counts are invalidated (e.g., by a query change).
1620
+ */
1621
+ refreshLetterCounts() {
1622
+ if (Object.keys(this.prefixFilterCountMap).length > 0) {
1623
+ this.prefixFilterCountMap = {};
1624
+ }
1625
+ this.updatePrefixFiltersForCurrentSort();
1626
+ }
1627
+ /**
1628
+ * Callback when a result is selected
1629
+ */
1630
+ resultSelected(event) {
1631
+ var _a, _b;
1632
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1633
+ category: this.searchContext,
1634
+ action: analyticsActions.resultSelected,
1635
+ label: event.detail.mediatype,
1636
+ });
1637
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1638
+ category: this.searchContext,
1639
+ action: analyticsActions.resultSelected,
1640
+ label: `page-${this.currentPage}`,
1641
+ });
1642
+ }
1643
+ cellForIndex(index) {
1644
+ const model = this.tileModelAtCellIndex(index);
1645
+ if (!model)
1646
+ return undefined;
1623
1647
  return html `
1624
1648
  <tile-dispatcher
1625
1649
  .collectionPagePath=${this.collectionPagePath}
@@ -1637,21 +1661,21 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1637
1661
  @resultSelected=${(e) => this.resultSelected(e)}
1638
1662
  >
1639
1663
  </tile-dispatcher>
1640
- `;
1641
- }
1642
- /**
1643
- * When the user scrolls near to the bottom of the page, fetch the next page
1644
- * increase the number of pages to render and start fetching data for the new page
1645
- */
1646
- scrollThresholdReached() {
1647
- if (!this.endOfDataReached) {
1648
- this.pagesToRender += 1;
1649
- this.fetchPage(this.pagesToRender);
1650
- }
1651
- }
1652
- static get styles() {
1653
- return [
1654
- srOnlyStyle,
1664
+ `;
1665
+ }
1666
+ /**
1667
+ * When the user scrolls near to the bottom of the page, fetch the next page
1668
+ * increase the number of pages to render and start fetching data for the new page
1669
+ */
1670
+ scrollThresholdReached() {
1671
+ if (!this.endOfDataReached) {
1672
+ this.pagesToRender += 1;
1673
+ this.fetchPage(this.pagesToRender);
1674
+ }
1675
+ }
1676
+ static get styles() {
1677
+ return [
1678
+ srOnlyStyle,
1655
1679
  css `
1656
1680
  :host {
1657
1681
  display: block;
@@ -2022,165 +2046,165 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
2022
2046
  infinite-scroller.hidden {
2023
2047
  display: none;
2024
2048
  }
2025
- `,
2026
- ];
2027
- }
2028
- };
2029
- __decorate([
2030
- property({ type: String })
2031
- ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
2032
- __decorate([
2033
- property({ type: String })
2034
- ], CollectionBrowser.prototype, "baseImageUrl", void 0);
2035
- __decorate([
2036
- property({ type: Object })
2037
- ], CollectionBrowser.prototype, "searchService", void 0);
2038
- __decorate([
2039
- property({ type: String })
2040
- ], CollectionBrowser.prototype, "searchType", void 0);
2041
- __decorate([
2042
- property({ type: String })
2043
- ], CollectionBrowser.prototype, "withinCollection", void 0);
2044
- __decorate([
2045
- property({ type: String })
2046
- ], CollectionBrowser.prototype, "baseQuery", void 0);
2047
- __decorate([
2048
- property({ type: String })
2049
- ], CollectionBrowser.prototype, "displayMode", void 0);
2050
- __decorate([
2051
- property({ type: Object })
2052
- ], CollectionBrowser.prototype, "sortParam", void 0);
2053
- __decorate([
2054
- property({ type: String })
2055
- ], CollectionBrowser.prototype, "selectedSort", void 0);
2056
- __decorate([
2057
- property({ type: String })
2058
- ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
2059
- __decorate([
2060
- property({ type: String })
2061
- ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
2062
- __decorate([
2063
- property({ type: String })
2064
- ], CollectionBrowser.prototype, "sortDirection", void 0);
2065
- __decorate([
2066
- property({ type: Number })
2067
- ], CollectionBrowser.prototype, "pageSize", void 0);
2068
- __decorate([
2069
- property({ type: Object })
2070
- ], CollectionBrowser.prototype, "resizeObserver", void 0);
2071
- __decorate([
2072
- property({ type: Number })
2073
- ], CollectionBrowser.prototype, "currentPage", void 0);
2074
- __decorate([
2075
- property({ type: String })
2076
- ], CollectionBrowser.prototype, "minSelectedDate", void 0);
2077
- __decorate([
2078
- property({ type: String })
2079
- ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
2080
- __decorate([
2081
- property({ type: Object })
2082
- ], CollectionBrowser.prototype, "selectedFacets", void 0);
2083
- __decorate([
2084
- property({ type: Boolean })
2085
- ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
2086
- __decorate([
2087
- property({ type: String })
2088
- ], CollectionBrowser.prototype, "collectionPagePath", void 0);
2089
- __decorate([
2090
- property({ type: Object })
2091
- ], CollectionBrowser.prototype, "collectionInfo", void 0);
2092
- __decorate([
2093
- property({ type: String, reflect: true })
2094
- ], CollectionBrowser.prototype, "searchContext", void 0);
2095
- __decorate([
2096
- property({ type: Object })
2097
- ], CollectionBrowser.prototype, "collectionNameCache", void 0);
2098
- __decorate([
2099
- property({ type: String })
2100
- ], CollectionBrowser.prototype, "pageContext", void 0);
2101
- __decorate([
2102
- property({ type: Object })
2103
- ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
2104
- __decorate([
2105
- property({ type: Number })
2106
- ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
2107
- __decorate([
2108
- property({ type: Boolean })
2109
- ], CollectionBrowser.prototype, "loggedIn", void 0);
2110
- __decorate([
2111
- property({ type: Object })
2112
- ], CollectionBrowser.prototype, "modalManager", void 0);
2113
- __decorate([
2114
- property({ type: Object })
2115
- ], CollectionBrowser.prototype, "featureFeedbackService", void 0);
2116
- __decorate([
2117
- property({ type: Object })
2118
- ], CollectionBrowser.prototype, "recaptchaManager", void 0);
2119
- __decorate([
2120
- property({ type: Boolean })
2121
- ], CollectionBrowser.prototype, "isManageView", void 0);
2122
- __decorate([
2123
- state()
2124
- ], CollectionBrowser.prototype, "pagesToRender", void 0);
2125
- __decorate([
2126
- state()
2127
- ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
2128
- __decorate([
2129
- state()
2130
- ], CollectionBrowser.prototype, "facetsLoading", void 0);
2131
- __decorate([
2132
- state()
2133
- ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
2134
- __decorate([
2135
- state()
2136
- ], CollectionBrowser.prototype, "aggregations", void 0);
2137
- __decorate([
2138
- state()
2139
- ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
2140
- __decorate([
2141
- state()
2142
- ], CollectionBrowser.prototype, "totalResults", void 0);
2143
- __decorate([
2144
- state()
2145
- ], CollectionBrowser.prototype, "queryErrorMessage", void 0);
2146
- __decorate([
2147
- state()
2148
- ], CollectionBrowser.prototype, "mobileView", void 0);
2149
- __decorate([
2150
- state()
2151
- ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
2152
- __decorate([
2153
- state()
2154
- ], CollectionBrowser.prototype, "contentWidth", void 0);
2155
- __decorate([
2156
- state()
2157
- ], CollectionBrowser.prototype, "defaultSortField", void 0);
2158
- __decorate([
2159
- state()
2160
- ], CollectionBrowser.prototype, "defaultSortDirection", void 0);
2161
- __decorate([
2162
- state()
2163
- ], CollectionBrowser.prototype, "placeholderType", void 0);
2164
- __decorate([
2165
- state()
2166
- ], CollectionBrowser.prototype, "prefixFilterCountMap", void 0);
2167
- __decorate([
2168
- query('#content-container')
2169
- ], CollectionBrowser.prototype, "contentContainer", void 0);
2170
- __decorate([
2171
- query('#left-column')
2172
- ], CollectionBrowser.prototype, "leftColumn", void 0);
2173
- __decorate([
2174
- query('collection-facets')
2175
- ], CollectionBrowser.prototype, "collectionFacets", void 0);
2176
- __decorate([
2177
- property({ type: Object, attribute: false })
2178
- ], CollectionBrowser.prototype, "analyticsHandler", void 0);
2179
- __decorate([
2180
- query('infinite-scroller')
2181
- ], CollectionBrowser.prototype, "infiniteScroller", void 0);
2182
- CollectionBrowser = __decorate([
2183
- customElement('collection-browser')
2184
- ], CollectionBrowser);
2185
- export { CollectionBrowser };
2049
+ `,
2050
+ ];
2051
+ }
2052
+ };
2053
+ __decorate([
2054
+ property({ type: String })
2055
+ ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
2056
+ __decorate([
2057
+ property({ type: String })
2058
+ ], CollectionBrowser.prototype, "baseImageUrl", void 0);
2059
+ __decorate([
2060
+ property({ type: Object })
2061
+ ], CollectionBrowser.prototype, "searchService", void 0);
2062
+ __decorate([
2063
+ property({ type: String })
2064
+ ], CollectionBrowser.prototype, "searchType", void 0);
2065
+ __decorate([
2066
+ property({ type: String })
2067
+ ], CollectionBrowser.prototype, "withinCollection", void 0);
2068
+ __decorate([
2069
+ property({ type: String })
2070
+ ], CollectionBrowser.prototype, "baseQuery", void 0);
2071
+ __decorate([
2072
+ property({ type: String })
2073
+ ], CollectionBrowser.prototype, "displayMode", void 0);
2074
+ __decorate([
2075
+ property({ type: Object })
2076
+ ], CollectionBrowser.prototype, "sortParam", void 0);
2077
+ __decorate([
2078
+ property({ type: String })
2079
+ ], CollectionBrowser.prototype, "selectedSort", void 0);
2080
+ __decorate([
2081
+ property({ type: String })
2082
+ ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
2083
+ __decorate([
2084
+ property({ type: String })
2085
+ ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
2086
+ __decorate([
2087
+ property({ type: String })
2088
+ ], CollectionBrowser.prototype, "sortDirection", void 0);
2089
+ __decorate([
2090
+ property({ type: Number })
2091
+ ], CollectionBrowser.prototype, "pageSize", void 0);
2092
+ __decorate([
2093
+ property({ type: Object })
2094
+ ], CollectionBrowser.prototype, "resizeObserver", void 0);
2095
+ __decorate([
2096
+ property({ type: Number })
2097
+ ], CollectionBrowser.prototype, "currentPage", void 0);
2098
+ __decorate([
2099
+ property({ type: String })
2100
+ ], CollectionBrowser.prototype, "minSelectedDate", void 0);
2101
+ __decorate([
2102
+ property({ type: String })
2103
+ ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
2104
+ __decorate([
2105
+ property({ type: Object })
2106
+ ], CollectionBrowser.prototype, "selectedFacets", void 0);
2107
+ __decorate([
2108
+ property({ type: Boolean })
2109
+ ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
2110
+ __decorate([
2111
+ property({ type: String })
2112
+ ], CollectionBrowser.prototype, "collectionPagePath", void 0);
2113
+ __decorate([
2114
+ property({ type: Object })
2115
+ ], CollectionBrowser.prototype, "collectionInfo", void 0);
2116
+ __decorate([
2117
+ property({ type: String, reflect: true })
2118
+ ], CollectionBrowser.prototype, "searchContext", void 0);
2119
+ __decorate([
2120
+ property({ type: Object })
2121
+ ], CollectionBrowser.prototype, "collectionNameCache", void 0);
2122
+ __decorate([
2123
+ property({ type: String })
2124
+ ], CollectionBrowser.prototype, "pageContext", void 0);
2125
+ __decorate([
2126
+ property({ type: Object })
2127
+ ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
2128
+ __decorate([
2129
+ property({ type: Number })
2130
+ ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
2131
+ __decorate([
2132
+ property({ type: Boolean })
2133
+ ], CollectionBrowser.prototype, "loggedIn", void 0);
2134
+ __decorate([
2135
+ property({ type: Object })
2136
+ ], CollectionBrowser.prototype, "modalManager", void 0);
2137
+ __decorate([
2138
+ property({ type: Object })
2139
+ ], CollectionBrowser.prototype, "featureFeedbackService", void 0);
2140
+ __decorate([
2141
+ property({ type: Object })
2142
+ ], CollectionBrowser.prototype, "recaptchaManager", void 0);
2143
+ __decorate([
2144
+ property({ type: Boolean })
2145
+ ], CollectionBrowser.prototype, "isManageView", void 0);
2146
+ __decorate([
2147
+ state()
2148
+ ], CollectionBrowser.prototype, "pagesToRender", void 0);
2149
+ __decorate([
2150
+ state()
2151
+ ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
2152
+ __decorate([
2153
+ state()
2154
+ ], CollectionBrowser.prototype, "facetsLoading", void 0);
2155
+ __decorate([
2156
+ state()
2157
+ ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
2158
+ __decorate([
2159
+ state()
2160
+ ], CollectionBrowser.prototype, "aggregations", void 0);
2161
+ __decorate([
2162
+ state()
2163
+ ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
2164
+ __decorate([
2165
+ state()
2166
+ ], CollectionBrowser.prototype, "totalResults", void 0);
2167
+ __decorate([
2168
+ state()
2169
+ ], CollectionBrowser.prototype, "queryErrorMessage", void 0);
2170
+ __decorate([
2171
+ state()
2172
+ ], CollectionBrowser.prototype, "mobileView", void 0);
2173
+ __decorate([
2174
+ state()
2175
+ ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
2176
+ __decorate([
2177
+ state()
2178
+ ], CollectionBrowser.prototype, "contentWidth", void 0);
2179
+ __decorate([
2180
+ state()
2181
+ ], CollectionBrowser.prototype, "defaultSortField", void 0);
2182
+ __decorate([
2183
+ state()
2184
+ ], CollectionBrowser.prototype, "defaultSortDirection", void 0);
2185
+ __decorate([
2186
+ state()
2187
+ ], CollectionBrowser.prototype, "placeholderType", void 0);
2188
+ __decorate([
2189
+ state()
2190
+ ], CollectionBrowser.prototype, "prefixFilterCountMap", void 0);
2191
+ __decorate([
2192
+ query('#content-container')
2193
+ ], CollectionBrowser.prototype, "contentContainer", void 0);
2194
+ __decorate([
2195
+ query('#left-column')
2196
+ ], CollectionBrowser.prototype, "leftColumn", void 0);
2197
+ __decorate([
2198
+ query('collection-facets')
2199
+ ], CollectionBrowser.prototype, "collectionFacets", void 0);
2200
+ __decorate([
2201
+ property({ type: Object, attribute: false })
2202
+ ], CollectionBrowser.prototype, "analyticsHandler", void 0);
2203
+ __decorate([
2204
+ query('infinite-scroller')
2205
+ ], CollectionBrowser.prototype, "infiniteScroller", void 0);
2206
+ CollectionBrowser = __decorate([
2207
+ customElement('collection-browser')
2208
+ ], CollectionBrowser);
2209
+ export { CollectionBrowser };
2186
2210
  //# sourceMappingURL=collection-browser.js.map