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