@internetarchive/collection-browser 1.14.9-alpha.2 → 1.14.9-alpha1

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 (271) hide show
  1. package/.editorconfig +29 -29
  2. package/.husky/pre-commit +4 -4
  3. package/LICENSE +661 -661
  4. package/README.md +83 -83
  5. package/dist/index.d.ts +9 -9
  6. package/dist/index.js +9 -9
  7. package/dist/src/app-root.d.ts +72 -72
  8. package/dist/src/app-root.js +347 -347
  9. package/dist/src/assets/img/icons/arrow-left.d.ts +2 -2
  10. package/dist/src/assets/img/icons/arrow-left.js +2 -2
  11. package/dist/src/assets/img/icons/arrow-right.d.ts +2 -2
  12. package/dist/src/assets/img/icons/arrow-right.js +2 -2
  13. package/dist/src/assets/img/icons/chevron.d.ts +2 -2
  14. package/dist/src/assets/img/icons/chevron.js +2 -2
  15. package/dist/src/assets/img/icons/contract.d.ts +2 -2
  16. package/dist/src/assets/img/icons/contract.js +2 -2
  17. package/dist/src/assets/img/icons/empty-query.d.ts +2 -2
  18. package/dist/src/assets/img/icons/empty-query.js +2 -2
  19. package/dist/src/assets/img/icons/expand.d.ts +2 -2
  20. package/dist/src/assets/img/icons/expand.js +2 -2
  21. package/dist/src/assets/img/icons/eye-closed.d.ts +2 -2
  22. package/dist/src/assets/img/icons/eye-closed.js +2 -2
  23. package/dist/src/assets/img/icons/eye.d.ts +2 -2
  24. package/dist/src/assets/img/icons/eye.js +2 -2
  25. package/dist/src/assets/img/icons/favorite-filled.d.ts +1 -1
  26. package/dist/src/assets/img/icons/favorite-filled.js +2 -2
  27. package/dist/src/assets/img/icons/login-required.d.ts +1 -1
  28. package/dist/src/assets/img/icons/login-required.js +2 -2
  29. package/dist/src/assets/img/icons/mediatype/account.d.ts +1 -1
  30. package/dist/src/assets/img/icons/mediatype/account.js +2 -2
  31. package/dist/src/assets/img/icons/mediatype/audio.d.ts +1 -1
  32. package/dist/src/assets/img/icons/mediatype/audio.js +2 -2
  33. package/dist/src/assets/img/icons/mediatype/collection.d.ts +1 -1
  34. package/dist/src/assets/img/icons/mediatype/collection.js +2 -2
  35. package/dist/src/assets/img/icons/mediatype/data.d.ts +1 -1
  36. package/dist/src/assets/img/icons/mediatype/data.js +2 -2
  37. package/dist/src/assets/img/icons/mediatype/etree.d.ts +1 -1
  38. package/dist/src/assets/img/icons/mediatype/etree.js +2 -2
  39. package/dist/src/assets/img/icons/mediatype/film.d.ts +1 -1
  40. package/dist/src/assets/img/icons/mediatype/film.js +2 -2
  41. package/dist/src/assets/img/icons/mediatype/images.d.ts +1 -1
  42. package/dist/src/assets/img/icons/mediatype/images.js +2 -2
  43. package/dist/src/assets/img/icons/mediatype/radio.d.ts +1 -1
  44. package/dist/src/assets/img/icons/mediatype/radio.js +2 -2
  45. package/dist/src/assets/img/icons/mediatype/search.d.ts +1 -1
  46. package/dist/src/assets/img/icons/mediatype/search.js +2 -2
  47. package/dist/src/assets/img/icons/mediatype/software.d.ts +1 -1
  48. package/dist/src/assets/img/icons/mediatype/software.js +2 -2
  49. package/dist/src/assets/img/icons/mediatype/texts.d.ts +1 -1
  50. package/dist/src/assets/img/icons/mediatype/texts.js +2 -2
  51. package/dist/src/assets/img/icons/mediatype/tv.d.ts +1 -1
  52. package/dist/src/assets/img/icons/mediatype/tv.js +2 -2
  53. package/dist/src/assets/img/icons/mediatype/video.d.ts +1 -1
  54. package/dist/src/assets/img/icons/mediatype/video.js +2 -2
  55. package/dist/src/assets/img/icons/mediatype/web.d.ts +1 -1
  56. package/dist/src/assets/img/icons/mediatype/web.js +2 -2
  57. package/dist/src/assets/img/icons/null-result.d.ts +2 -2
  58. package/dist/src/assets/img/icons/null-result.js +2 -2
  59. package/dist/src/assets/img/icons/restricted.d.ts +1 -1
  60. package/dist/src/assets/img/icons/restricted.js +2 -2
  61. package/dist/src/assets/img/icons/reviews.d.ts +1 -1
  62. package/dist/src/assets/img/icons/reviews.js +2 -2
  63. package/dist/src/assets/img/icons/upload.d.ts +1 -1
  64. package/dist/src/assets/img/icons/upload.js +2 -2
  65. package/dist/src/assets/img/icons/views.d.ts +1 -1
  66. package/dist/src/assets/img/icons/views.js +2 -2
  67. package/dist/src/circular-activity-indicator.d.ts +5 -5
  68. package/dist/src/circular-activity-indicator.js +17 -17
  69. package/dist/src/collection-browser.d.ts +533 -533
  70. package/dist/src/collection-browser.js +1889 -1893
  71. package/dist/src/collection-browser.js.map +1 -1
  72. package/dist/src/collection-facets/facet-tombstone-row.d.ts +5 -5
  73. package/dist/src/collection-facets/facet-tombstone-row.js +15 -15
  74. package/dist/src/collection-facets/facets-template.d.ts +20 -20
  75. package/dist/src/collection-facets/facets-template.js +152 -152
  76. package/dist/src/collection-facets/more-facets-content.d.ts +77 -77
  77. package/dist/src/collection-facets/more-facets-content.js +359 -359
  78. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -36
  79. package/dist/src/collection-facets/more-facets-pagination.js +196 -196
  80. package/dist/src/collection-facets/toggle-switch.d.ts +41 -41
  81. package/dist/src/collection-facets/toggle-switch.js +94 -94
  82. package/dist/src/collection-facets.d.ts +104 -104
  83. package/dist/src/collection-facets.js +506 -506
  84. package/dist/src/empty-placeholder.d.ts +23 -23
  85. package/dist/src/empty-placeholder.js +74 -74
  86. package/dist/src/expanded-date-picker.d.ts +43 -43
  87. package/dist/src/expanded-date-picker.js +109 -109
  88. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  89. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  90. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  91. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  92. package/dist/src/manage/manage-bar.d.ts +26 -26
  93. package/dist/src/manage/manage-bar.js +53 -53
  94. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  95. package/dist/src/mediatype/mediatype-config.js +91 -91
  96. package/dist/src/models.d.ts +164 -164
  97. package/dist/src/models.js +269 -269
  98. package/dist/src/restoration-state-handler.d.ts +70 -70
  99. package/dist/src/restoration-state-handler.js +355 -355
  100. package/dist/src/sort-filter-bar/alpha-bar-tooltip.d.ts +6 -6
  101. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js +24 -24
  102. package/dist/src/sort-filter-bar/alpha-bar.d.ts +21 -21
  103. package/dist/src/sort-filter-bar/alpha-bar.js +128 -128
  104. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  105. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  106. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  107. package/dist/src/sort-filter-bar/img/list.js +2 -2
  108. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.d.ts +1 -1
  109. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js +2 -2
  110. package/dist/src/sort-filter-bar/img/sort-toggle-down.d.ts +1 -1
  111. package/dist/src/sort-filter-bar/img/sort-toggle-down.js +2 -2
  112. package/dist/src/sort-filter-bar/img/sort-toggle-up.d.ts +1 -1
  113. package/dist/src/sort-filter-bar/img/sort-toggle-up.js +2 -2
  114. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  115. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  116. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  117. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  118. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +208 -208
  119. package/dist/src/sort-filter-bar/sort-filter-bar.js +637 -637
  120. package/dist/src/styles/item-image-styles.d.ts +8 -8
  121. package/dist/src/styles/item-image-styles.js +9 -9
  122. package/dist/src/styles/sr-only.d.ts +1 -1
  123. package/dist/src/styles/sr-only.js +2 -2
  124. package/dist/src/tiles/base-tile-component.d.ts +19 -19
  125. package/dist/src/tiles/base-tile-component.js +63 -63
  126. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  127. package/dist/src/tiles/collection-browser-loading-tile.js +15 -15
  128. package/dist/src/tiles/grid/account-tile.d.ts +18 -18
  129. package/dist/src/tiles/grid/account-tile.js +72 -72
  130. package/dist/src/tiles/grid/collection-tile.d.ts +15 -15
  131. package/dist/src/tiles/grid/collection-tile.js +80 -80
  132. package/dist/src/tiles/grid/item-tile.d.ts +27 -27
  133. package/dist/src/tiles/grid/item-tile.js +134 -134
  134. package/dist/src/tiles/grid/search-tile.d.ts +10 -10
  135. package/dist/src/tiles/grid/search-tile.js +51 -51
  136. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.d.ts +1 -1
  137. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +8 -8
  138. package/dist/src/tiles/grid/tile-stats.d.ts +11 -11
  139. package/dist/src/tiles/grid/tile-stats.js +48 -48
  140. package/dist/src/tiles/hover/hover-pane-controller.d.ts +219 -219
  141. package/dist/src/tiles/hover/hover-pane-controller.js +352 -352
  142. package/dist/src/tiles/hover/tile-hover-pane.d.ts +15 -15
  143. package/dist/src/tiles/hover/tile-hover-pane.js +38 -38
  144. package/dist/src/tiles/image-block.d.ts +17 -17
  145. package/dist/src/tiles/image-block.js +73 -73
  146. package/dist/src/tiles/item-image.d.ts +36 -36
  147. package/dist/src/tiles/item-image.js +127 -127
  148. package/dist/src/tiles/list/tile-list-compact-header.d.ts +6 -6
  149. package/dist/src/tiles/list/tile-list-compact-header.js +38 -38
  150. package/dist/src/tiles/list/tile-list-compact.d.ts +15 -15
  151. package/dist/src/tiles/list/tile-list-compact.js +114 -114
  152. package/dist/src/tiles/list/tile-list.d.ts +46 -46
  153. package/dist/src/tiles/list/tile-list.js +302 -302
  154. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  155. package/dist/src/tiles/mediatype-icon.js +47 -47
  156. package/dist/src/tiles/overlay/icon-overlay.d.ts +10 -10
  157. package/dist/src/tiles/overlay/icon-overlay.js +40 -40
  158. package/dist/src/tiles/overlay/icon-text-overlay.d.ts +9 -9
  159. package/dist/src/tiles/overlay/icon-text-overlay.js +38 -38
  160. package/dist/src/tiles/overlay/text-overlay.d.ts +10 -10
  161. package/dist/src/tiles/overlay/text-overlay.js +42 -42
  162. package/dist/src/tiles/text-snippet-block.d.ts +27 -27
  163. package/dist/src/tiles/text-snippet-block.js +73 -73
  164. package/dist/src/tiles/tile-dispatcher.d.ts +64 -64
  165. package/dist/src/tiles/tile-dispatcher.js +231 -231
  166. package/dist/src/tiles/tile-display-value-provider.d.ts +43 -43
  167. package/dist/src/tiles/tile-display-value-provider.js +80 -80
  168. package/dist/src/utils/analytics-events.d.ts +25 -25
  169. package/dist/src/utils/analytics-events.js +27 -27
  170. package/dist/src/utils/array-equals.d.ts +4 -4
  171. package/dist/src/utils/array-equals.js +10 -10
  172. package/dist/src/utils/format-count.d.ts +7 -7
  173. package/dist/src/utils/format-count.js +76 -76
  174. package/dist/src/utils/format-date.d.ts +2 -2
  175. package/dist/src/utils/format-date.js +25 -25
  176. package/dist/src/utils/format-unit-size.d.ts +2 -2
  177. package/dist/src/utils/format-unit-size.js +33 -33
  178. package/dist/src/utils/local-date-from-utc.d.ts +9 -9
  179. package/dist/src/utils/local-date-from-utc.js +15 -15
  180. package/dist/src/utils/sha1.d.ts +2 -2
  181. package/dist/src/utils/sha1.js +8 -8
  182. package/dist/test/collection-browser.test.d.ts +1 -1
  183. package/dist/test/collection-browser.test.js +1098 -1098
  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 -63
  196. package/dist/test/expanded-date-picker.test.d.ts +1 -1
  197. package/dist/test/expanded-date-picker.test.js +95 -95
  198. package/dist/test/icon-overlay.test.d.ts +1 -1
  199. package/dist/test/icon-overlay.test.js +24 -24
  200. package/dist/test/image-block.test.d.ts +1 -1
  201. package/dist/test/image-block.test.js +48 -48
  202. package/dist/test/item-image.test.d.ts +1 -1
  203. package/dist/test/item-image.test.js +86 -86
  204. package/dist/test/manage/manage-bar.test.d.ts +1 -1
  205. package/dist/test/manage/manage-bar.test.js +72 -72
  206. package/dist/test/mediatype-config.test.d.ts +1 -1
  207. package/dist/test/mediatype-config.test.js +16 -16
  208. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  209. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  210. package/dist/test/mocks/mock-collection-name-cache.d.ts +9 -9
  211. package/dist/test/mocks/mock-collection-name-cache.js +17 -17
  212. package/dist/test/mocks/mock-search-responses.d.ts +21 -21
  213. package/dist/test/mocks/mock-search-responses.js +709 -709
  214. package/dist/test/mocks/mock-search-service.d.ts +15 -15
  215. package/dist/test/mocks/mock-search-service.js +50 -50
  216. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  217. package/dist/test/restoration-state-handler.test.js +270 -270
  218. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.d.ts +1 -1
  219. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +12 -12
  220. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +1 -1
  221. package/dist/test/sort-filter-bar/alpha-bar.test.js +73 -73
  222. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -1
  223. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +378 -378
  224. package/dist/test/text-overlay.test.d.ts +1 -1
  225. package/dist/test/text-overlay.test.js +48 -48
  226. package/dist/test/text-snippet-block.test.d.ts +1 -1
  227. package/dist/test/text-snippet-block.test.js +57 -57
  228. package/dist/test/tile-stats.test.d.ts +1 -1
  229. package/dist/test/tile-stats.test.js +33 -33
  230. package/dist/test/tiles/grid/account-tile.test.d.ts +1 -1
  231. package/dist/test/tiles/grid/account-tile.test.js +76 -76
  232. package/dist/test/tiles/grid/collection-tile.test.d.ts +1 -1
  233. package/dist/test/tiles/grid/collection-tile.test.js +73 -73
  234. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -1
  235. package/dist/test/tiles/grid/item-tile.test.js +254 -254
  236. package/dist/test/tiles/grid/search-tile.test.d.ts +1 -1
  237. package/dist/test/tiles/grid/search-tile.test.js +51 -51
  238. package/dist/test/tiles/hover/hover-pane-controller.test.d.ts +1 -1
  239. package/dist/test/tiles/hover/hover-pane-controller.test.js +258 -258
  240. package/dist/test/tiles/hover/tile-hover-pane.test.d.ts +1 -1
  241. package/dist/test/tiles/hover/tile-hover-pane.test.js +13 -13
  242. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -1
  243. package/dist/test/tiles/list/tile-list-compact.test.js +143 -143
  244. package/dist/test/tiles/list/tile-list.test.d.ts +1 -1
  245. package/dist/test/tiles/list/tile-list.test.js +242 -242
  246. package/dist/test/tiles/tile-dispatcher.test.d.ts +1 -1
  247. package/dist/test/tiles/tile-dispatcher.test.js +94 -94
  248. package/dist/test/tiles/tile-display-value-provider.test.d.ts +1 -1
  249. package/dist/test/tiles/tile-display-value-provider.test.js +141 -141
  250. package/dist/test/utils/array-equals.test.d.ts +1 -1
  251. package/dist/test/utils/array-equals.test.js +26 -26
  252. package/dist/test/utils/format-count.test.d.ts +1 -1
  253. package/dist/test/utils/format-count.test.js +23 -23
  254. package/dist/test/utils/format-date.test.d.ts +1 -1
  255. package/dist/test/utils/format-date.test.js +17 -17
  256. package/dist/test/utils/format-unit-size.test.d.ts +1 -1
  257. package/dist/test/utils/format-unit-size.test.js +17 -17
  258. package/dist/test/utils/local-date-from-utc.test.d.ts +1 -1
  259. package/dist/test/utils/local-date-from-utc.test.js +26 -26
  260. package/local.archive.org.cert +86 -86
  261. package/local.archive.org.key +27 -27
  262. package/package.json +1 -1
  263. package/renovate.json +6 -6
  264. package/src/collection-browser.ts +7 -7
  265. package/tsconfig.json +21 -21
  266. package/web-dev-server.config.mjs +30 -30
  267. package/web-test-runner.config.mjs +41 -41
  268. package/dist/src/selected-facets.d.ts +0 -67
  269. package/dist/src/selected-facets.js +0 -149
  270. package/dist/src/selected-facets.js.map +0 -1
  271. package/src/selected-facets.ts +0 -216
@@ -1,303 +1,301 @@
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 './manage/manage-bar';
12
- import './collection-facets';
13
- import './circular-activity-indicator';
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
- import { formatDate } from './utils/format-date';
22
- let CollectionBrowser = class CollectionBrowser extends LitElement {
23
- constructor() {
24
- super(...arguments);
25
- this.baseImageUrl = 'https://archive.org';
26
- this.searchType = SearchType.METADATA;
27
- this.sortParam = null;
28
- this.defaultSortParam = null;
29
- this.selectedSort = SortField.default;
30
- this.selectedTitleFilter = null;
31
- this.selectedCreatorFilter = null;
32
- this.sortDirection = null;
33
- this.pageSize = 50;
34
- this.showHistogramDatePicker = false;
35
- this.suppressPlaceholders = false;
36
- this.suppressResultCount = false;
37
- this.clearResultsOnEmptyQuery = false;
38
- this.collectionPagePath = '/details/';
39
- this.parentCollections = [];
40
- /** describes where this component is being used */
41
- this.searchContext = analyticsCategories.default;
42
- this.pageContext = 'search';
43
- this.restorationStateHandler = new RestorationStateHandler({
44
- context: this.pageContext,
45
- });
46
- this.mobileBreakpoint = 600;
47
- this.loggedIn = false;
48
- this.modalManager = undefined;
49
- /**
50
- * If item management UI active
51
- */
52
- this.isManageView = false;
53
- /**
54
- * The page that the consumer wants to load.
55
- */
56
- this.initialPageNumber = 1;
57
- /**
58
- * This the the number of pages that we want to show.
59
- *
60
- * The data isn't necessarily loaded for all of the pages, but this lets us
61
- * know how many cells we should render.
62
- */
63
- this.pagesToRender = this.initialPageNumber;
64
- /**
65
- * Whether the initial page fetch for a new query is currently in progress.
66
- */
67
- this.searchResultsLoading = false;
68
- this.facetsLoading = false;
69
- this.fullYearAggregationLoading = false;
70
- this.mobileView = false;
71
- this.mobileFacetsVisible = false;
72
- this.defaultSortField = SortField.relevance;
73
- this.defaultSortDirection = null;
74
- this.placeholderType = null;
75
- this.prefixFilterCountMap = {};
76
- /**
77
- * When we're animated scrolling to the page, we don't want to fetch
78
- * all of the pages as it scrolls so this lets us know if we're scrolling
79
- */
80
- this.isScrollingToCell = false;
81
- /**
82
- * When we've reached the end of the data, stop trying to fetch more
83
- */
84
- this.endOfDataReached = false;
85
- /**
86
- * When page width resizes from desktop to mobile, set true to
87
- * disable expand/collapse transition when loading.
88
- */
89
- this.isResizeToMobile = false;
90
- this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
91
- /**
92
- * The results per page so we can paginate.
93
- *
94
- * This allows us to start in the middle of the search results and
95
- * fetch data before or after the current page. If we don't have a key
96
- * for the previous/next page, we'll fetch the next/previous page to populate it
97
- */
98
- this.dataSource = {};
99
- /**
100
- * How many tiles to offset the data source by, to account for any removed tiles.
101
- */
102
- this.tileModelOffset = 0;
103
- /**
104
- * Updates the height of the left column according to its position on the page.
105
- * Arrow function ensures proper `this` binding.
106
- */
107
- this.updateLeftColumnHeight = () => {
108
- var _a, _b, _c, _d, _e;
109
- if (this.mobileView) {
110
- (_b = (_a = this.leftColumn) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b.removeProperty('height');
111
- }
112
- else {
113
- const clientTop = (_c = this.leftColumn) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect().top;
114
- (_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`);
115
- }
116
- };
117
- /**
118
- * Toggles whether the fade-out is visible at the bottom of the facets.
119
- * It should only be visible if the facets are not scrolled to the bottom.
120
- * Arrow function ensures proper `this` binding.
121
- */
122
- this.updateFacetFadeOut = (entries) => {
123
- var _a, _b;
124
- const fadeElmt = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('facets-bottom-fade');
125
- 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);
126
- };
127
- // we only want to scroll on the very first query change
128
- // so this keeps track of whether we've already set the initial query
129
- this.initialQueryChangeHappened = false;
130
- this.historyPopOccurred = false;
131
- /**
132
- * Internal property to store the private value backing the `initialSearchComplete` getter.
133
- */
134
- this._initialSearchCompletePromise = new Promise(res => {
135
- this._initialSearchCompleteResolver = res;
136
- });
137
- // this maps the query to the pages being fetched for that query
138
- this.pageFetchesInProgress = {};
139
- }
140
- tileModelAtCellIndex(index) {
141
- var _a;
142
- const offsetIndex = index + this.tileModelOffset;
143
- const pageNumber = Math.floor(offsetIndex / this.pageSize) + 1;
144
- const itemIndex = offsetIndex % this.pageSize;
145
- const model = (_a = this.dataSource[pageNumber]) === null || _a === void 0 ? void 0 : _a[itemIndex];
146
- /**
147
- * If we encounter a model we don't have yet and we're not in the middle of an
148
- * automated scroll, fetch the page and just return undefined.
149
- * The datasource will be updated once the page is loaded and the cell will be rendered.
150
- *
151
- * We disable it during the automated scroll since we may fetch pages for cells the
152
- * user may never see.
153
- */
154
- if (!model && !this.isScrollingToCell) {
155
- this.fetchPage(pageNumber);
156
- }
157
- return model;
158
- }
159
- get sortFilterQueries() {
160
- const queries = [this.titleQuery, this.creatorQuery];
161
- return queries.filter(q => q).join(' AND ');
162
- }
163
- // this is the total number of tiles we expect if
164
- // the data returned is a full page worth
165
- // this is useful for putting in placeholders for the expected number of tiles
166
- get estimatedTileCount() {
167
- return this.pagesToRender * this.pageSize;
168
- }
169
- /**
170
- * Returns a promise resolving to a unique string that persists for the current browser session.
171
- * Used in generating unique IDs for search requests, so that multiple requests coming from the
172
- * same browser session can be identified.
173
- */
174
- async getSessionId() {
175
- try {
176
- const storedSessionId = sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.getItem('cb-session');
177
- if (storedSessionId) {
178
- return storedSessionId;
179
- }
180
- // If we enter this method a second time while a first session ID is already being generated,
181
- // ensure we produce the same ID from both calls instead of generating another one.
182
- if (this.sessionIdGenPromise) {
183
- return this.sessionIdGenPromise;
184
- }
185
- this.sessionIdGenPromise = sha1(Math.random().toString());
186
- const newSessionId = await this.sessionIdGenPromise;
187
- sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.setItem('cb-session', newSessionId);
188
- return newSessionId;
189
- }
190
- catch (err) {
191
- // Either we can't generate the hash or we're restricted from accessing sessionStorage
192
- return '';
193
- }
194
- }
195
- /**
196
- * Go to the given page of results
197
- *
198
- * @param pageNumber
199
- */
200
- goToPage(pageNumber) {
201
- this.initialPageNumber = pageNumber;
202
- this.pagesToRender = pageNumber;
203
- return this.scrollToPage(pageNumber);
204
- }
205
- /**
206
- * Clears all selected/negated facets, date ranges, and letter filters.
207
- *
208
- * By default, the current sort field/direction are not cleared,
209
- * but this can be overridden by setting the `sort` option to `true`.
210
- *
211
- * Similarly, it is possible to finely control what is cleared by
212
- * setting any of the `facets`, `dateRange`, or `letterFilters` flags
213
- * in the options object.
214
- */
215
- clearFilters({ facets = true, dateRange = true, letterFilters = true, sort = false, } = {}) {
216
- // Don't bother clearing facets if none are checked, so that we don't
217
- // trigger unnecessary update cycles.
218
- if (facets && this.hasCheckedFacets) {
219
- this.selectedFacets = getDefaultSelectedFacets();
220
- }
221
- if (dateRange) {
222
- this.minSelectedDate = undefined;
223
- this.maxSelectedDate = undefined;
224
- }
225
- if (letterFilters) {
226
- this.selectedTitleFilter = null;
227
- this.selectedCreatorFilter = null;
228
- }
229
- if (sort) {
230
- this.sortParam = null;
231
- this.sortDirection = null;
232
- this.selectedSort = SortField.default;
233
- }
234
- }
235
- /**
236
- * Returns true if the current value of `this.selectedFacets` contains
237
- * any facet buckets than have been selected or negated, or false otherwise.
238
- */
239
- get hasCheckedFacets() {
240
- if (!this.selectedFacets)
241
- return false;
242
- for (const facetGroup of Object.values(this.selectedFacets)) {
243
- for (const bucket of Object.values(facetGroup)) {
244
- if (bucket.state !== 'none')
245
- return true;
246
- }
247
- }
248
- return false;
249
- }
250
- /**
251
- * Returns true if there are any currently selected/negated facet buckets,
252
- * any selected date range, or any selected letter filters. False otherwise.
253
- *
254
- * Ignores sorting options.
255
- */
256
- get hasActiveFilters() {
257
- return !!(this.hasCheckedFacets ||
258
- this.minSelectedDate ||
259
- this.maxSelectedDate ||
260
- this.selectedTitleFilter ||
261
- this.selectedCreatorFilter);
262
- }
263
- render() {
264
- 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 './manage/manage-bar';
12
+ import './collection-facets';
13
+ import './circular-activity-indicator';
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
+ import { formatDate } from './utils/format-date';
22
+ let CollectionBrowser = class CollectionBrowser extends LitElement {
23
+ constructor() {
24
+ super(...arguments);
25
+ this.baseImageUrl = 'https://archive.org';
26
+ this.searchType = SearchType.METADATA;
27
+ this.sortParam = null;
28
+ this.defaultSortParam = null;
29
+ this.selectedSort = SortField.default;
30
+ this.selectedTitleFilter = null;
31
+ this.selectedCreatorFilter = null;
32
+ this.sortDirection = null;
33
+ this.pageSize = 50;
34
+ this.showHistogramDatePicker = false;
35
+ this.suppressEmptyPlaceholder = false;
36
+ this.suppressResultCount = false;
37
+ this.clearResultsOnEmptyQuery = false;
38
+ this.collectionPagePath = '/details/';
39
+ this.parentCollections = [];
40
+ /** describes where this component is being used */
41
+ this.searchContext = analyticsCategories.default;
42
+ this.pageContext = 'search';
43
+ this.restorationStateHandler = new RestorationStateHandler({
44
+ context: this.pageContext,
45
+ });
46
+ this.mobileBreakpoint = 600;
47
+ this.loggedIn = false;
48
+ this.modalManager = undefined;
49
+ /**
50
+ * If item management UI active
51
+ */
52
+ this.isManageView = false;
53
+ /**
54
+ * The page that the consumer wants to load.
55
+ */
56
+ this.initialPageNumber = 1;
57
+ /**
58
+ * This the the number of pages that we want to show.
59
+ *
60
+ * The data isn't necessarily loaded for all of the pages, but this lets us
61
+ * know how many cells we should render.
62
+ */
63
+ this.pagesToRender = this.initialPageNumber;
64
+ /**
65
+ * Whether the initial page fetch for a new query is currently in progress.
66
+ */
67
+ this.searchResultsLoading = false;
68
+ this.facetsLoading = false;
69
+ this.fullYearAggregationLoading = false;
70
+ this.mobileView = false;
71
+ this.mobileFacetsVisible = false;
72
+ this.defaultSortField = SortField.relevance;
73
+ this.defaultSortDirection = null;
74
+ this.placeholderType = null;
75
+ this.prefixFilterCountMap = {};
76
+ /**
77
+ * When we're animated scrolling to the page, we don't want to fetch
78
+ * all of the pages as it scrolls so this lets us know if we're scrolling
79
+ */
80
+ this.isScrollingToCell = false;
81
+ /**
82
+ * When we've reached the end of the data, stop trying to fetch more
83
+ */
84
+ this.endOfDataReached = false;
85
+ /**
86
+ * When page width resizes from desktop to mobile, set true to
87
+ * disable expand/collapse transition when loading.
88
+ */
89
+ this.isResizeToMobile = false;
90
+ this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
91
+ /**
92
+ * The results per page so we can paginate.
93
+ *
94
+ * This allows us to start in the middle of the search results and
95
+ * fetch data before or after the current page. If we don't have a key
96
+ * for the previous/next page, we'll fetch the next/previous page to populate it
97
+ */
98
+ this.dataSource = {};
99
+ /**
100
+ * How many tiles to offset the data source by, to account for any removed tiles.
101
+ */
102
+ this.tileModelOffset = 0;
103
+ /**
104
+ * Updates the height of the left column according to its position on the page.
105
+ * Arrow function ensures proper `this` binding.
106
+ */
107
+ this.updateLeftColumnHeight = () => {
108
+ var _a, _b, _c, _d, _e;
109
+ if (this.mobileView) {
110
+ (_b = (_a = this.leftColumn) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b.removeProperty('height');
111
+ }
112
+ else {
113
+ const clientTop = (_c = this.leftColumn) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect().top;
114
+ (_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`);
115
+ }
116
+ };
117
+ /**
118
+ * Toggles whether the fade-out is visible at the bottom of the facets.
119
+ * It should only be visible if the facets are not scrolled to the bottom.
120
+ * Arrow function ensures proper `this` binding.
121
+ */
122
+ this.updateFacetFadeOut = (entries) => {
123
+ var _a, _b;
124
+ const fadeElmt = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('facets-bottom-fade');
125
+ 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);
126
+ };
127
+ // we only want to scroll on the very first query change
128
+ // so this keeps track of whether we've already set the initial query
129
+ this.initialQueryChangeHappened = false;
130
+ this.historyPopOccurred = false;
131
+ /**
132
+ * Internal property to store the private value backing the `initialSearchComplete` getter.
133
+ */
134
+ this._initialSearchCompletePromise = new Promise(res => {
135
+ this._initialSearchCompleteResolver = res;
136
+ });
137
+ // this maps the query to the pages being fetched for that query
138
+ this.pageFetchesInProgress = {};
139
+ }
140
+ tileModelAtCellIndex(index) {
141
+ var _a;
142
+ const offsetIndex = index + this.tileModelOffset;
143
+ const pageNumber = Math.floor(offsetIndex / this.pageSize) + 1;
144
+ const itemIndex = offsetIndex % this.pageSize;
145
+ const model = (_a = this.dataSource[pageNumber]) === null || _a === void 0 ? void 0 : _a[itemIndex];
146
+ /**
147
+ * If we encounter a model we don't have yet and we're not in the middle of an
148
+ * automated scroll, fetch the page and just return undefined.
149
+ * The datasource will be updated once the page is loaded and the cell will be rendered.
150
+ *
151
+ * We disable it during the automated scroll since we may fetch pages for cells the
152
+ * user may never see.
153
+ */
154
+ if (!model && !this.isScrollingToCell) {
155
+ this.fetchPage(pageNumber);
156
+ }
157
+ return model;
158
+ }
159
+ get sortFilterQueries() {
160
+ const queries = [this.titleQuery, this.creatorQuery];
161
+ return queries.filter(q => q).join(' AND ');
162
+ }
163
+ // this is the total number of tiles we expect if
164
+ // the data returned is a full page worth
165
+ // this is useful for putting in placeholders for the expected number of tiles
166
+ get estimatedTileCount() {
167
+ return this.pagesToRender * this.pageSize;
168
+ }
169
+ /**
170
+ * Returns a promise resolving to a unique string that persists for the current browser session.
171
+ * Used in generating unique IDs for search requests, so that multiple requests coming from the
172
+ * same browser session can be identified.
173
+ */
174
+ async getSessionId() {
175
+ try {
176
+ const storedSessionId = sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.getItem('cb-session');
177
+ if (storedSessionId) {
178
+ return storedSessionId;
179
+ }
180
+ // If we enter this method a second time while a first session ID is already being generated,
181
+ // ensure we produce the same ID from both calls instead of generating another one.
182
+ if (this.sessionIdGenPromise) {
183
+ return this.sessionIdGenPromise;
184
+ }
185
+ this.sessionIdGenPromise = sha1(Math.random().toString());
186
+ const newSessionId = await this.sessionIdGenPromise;
187
+ sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.setItem('cb-session', newSessionId);
188
+ return newSessionId;
189
+ }
190
+ catch (err) {
191
+ // Either we can't generate the hash or we're restricted from accessing sessionStorage
192
+ return '';
193
+ }
194
+ }
195
+ /**
196
+ * Go to the given page of results
197
+ *
198
+ * @param pageNumber
199
+ */
200
+ goToPage(pageNumber) {
201
+ this.initialPageNumber = pageNumber;
202
+ this.pagesToRender = pageNumber;
203
+ return this.scrollToPage(pageNumber);
204
+ }
205
+ /**
206
+ * Clears all selected/negated facets, date ranges, and letter filters.
207
+ *
208
+ * By default, the current sort field/direction are not cleared,
209
+ * but this can be overridden by setting the `sort` option to `true`.
210
+ *
211
+ * Similarly, it is possible to finely control what is cleared by
212
+ * setting any of the `facets`, `dateRange`, or `letterFilters` flags
213
+ * in the options object.
214
+ */
215
+ clearFilters({ facets = true, dateRange = true, letterFilters = true, sort = false, } = {}) {
216
+ // Don't bother clearing facets if none are checked, so that we don't
217
+ // trigger unnecessary update cycles.
218
+ if (facets && this.hasCheckedFacets) {
219
+ this.selectedFacets = getDefaultSelectedFacets();
220
+ }
221
+ if (dateRange) {
222
+ this.minSelectedDate = undefined;
223
+ this.maxSelectedDate = undefined;
224
+ }
225
+ if (letterFilters) {
226
+ this.selectedTitleFilter = null;
227
+ this.selectedCreatorFilter = null;
228
+ }
229
+ if (sort) {
230
+ this.sortParam = null;
231
+ this.sortDirection = null;
232
+ this.selectedSort = SortField.default;
233
+ }
234
+ }
235
+ /**
236
+ * Returns true if the current value of `this.selectedFacets` contains
237
+ * any facet buckets than have been selected or negated, or false otherwise.
238
+ */
239
+ get hasCheckedFacets() {
240
+ if (!this.selectedFacets)
241
+ return false;
242
+ for (const facetGroup of Object.values(this.selectedFacets)) {
243
+ for (const bucket of Object.values(facetGroup)) {
244
+ if (bucket.state !== 'none')
245
+ return true;
246
+ }
247
+ }
248
+ return false;
249
+ }
250
+ /**
251
+ * Returns true if there are any currently selected/negated facet buckets,
252
+ * any selected date range, or any selected letter filters. False otherwise.
253
+ *
254
+ * Ignores sorting options.
255
+ */
256
+ get hasActiveFilters() {
257
+ return !!(this.hasCheckedFacets ||
258
+ this.minSelectedDate ||
259
+ this.maxSelectedDate ||
260
+ this.selectedTitleFilter ||
261
+ this.selectedCreatorFilter);
262
+ }
263
+ render() {
264
+ this.setPlaceholderType();
265
265
  return html `
266
266
  <div
267
267
  id="content-container"
268
268
  class=${this.mobileView ? 'mobile' : 'desktop'}
269
269
  >
270
- ${this.placeholderType
271
- ? this.emptyPlaceholderTemplate
270
+ ${this.placeholderType
271
+ ? this.emptyPlaceholderTemplate
272
272
  : this.collectionBrowserTemplate}
273
273
  </div>
274
- `;
275
- }
276
- setPlaceholderType() {
277
- var _a;
278
- const hasQuery = !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
279
- const isCollection = !!this.withinCollection;
280
- const noResults = !this.searchResultsLoading &&
281
- (this.totalResults === 0 || !this.searchService);
282
- this.placeholderType = null;
283
- if (this.suppressPlaceholders)
284
- return;
285
- if (!hasQuery && !isCollection) {
286
- this.placeholderType = 'empty-query';
287
- }
288
- else if (noResults) {
289
- // Within a collection, no query + no results means the collection simply has no viewable items.
290
- // Otherwise, we must have a user query that produced 0 results.
291
- this.placeholderType =
292
- !hasQuery && isCollection ? 'empty-collection' : 'no-results';
293
- }
294
- if (this.queryErrorMessage) {
295
- this.placeholderType =
296
- !hasQuery && isCollection ? 'collection-error' : 'query-error';
297
- }
298
- }
299
- get emptyPlaceholderTemplate() {
300
- var _a;
274
+ `;
275
+ }
276
+ setPlaceholderType() {
277
+ var _a;
278
+ const hasQuery = !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
279
+ const isCollection = !!this.withinCollection;
280
+ const noResults = !this.searchResultsLoading &&
281
+ (this.totalResults === 0 || !this.searchService);
282
+ this.placeholderType = null;
283
+ if (!hasQuery && !isCollection) {
284
+ this.placeholderType = 'empty-query';
285
+ }
286
+ else if (noResults && !this.suppressEmptyPlaceholder) {
287
+ // Within a collection, no query + no results means the collection simply has no viewable items.
288
+ // Otherwise, we must have a user query that produced 0 results.
289
+ this.placeholderType =
290
+ !hasQuery && isCollection ? 'empty-collection' : 'no-results';
291
+ }
292
+ if (this.queryErrorMessage) {
293
+ this.placeholderType =
294
+ !hasQuery && isCollection ? 'collection-error' : 'query-error';
295
+ }
296
+ }
297
+ get emptyPlaceholderTemplate() {
298
+ var _a;
301
299
  return html `
302
300
  <empty-placeholder
303
301
  .placeholderType=${this.placeholderType}
@@ -307,33 +305,33 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
307
305
  .baseNavigationUrl=${this.baseNavigationUrl}
308
306
  ></empty-placeholder>
309
307
  ${this.infiniteScrollerTemplate}
310
- `;
311
- }
312
- /**
313
- * Top-level template for rendering the left (facets) and right (results) columns.
314
- */
315
- get collectionBrowserTemplate() {
308
+ `;
309
+ }
310
+ /**
311
+ * Top-level template for rendering the left (facets) and right (results) columns.
312
+ */
313
+ get collectionBrowserTemplate() {
316
314
  return html `
317
315
  <div id="left-column-scroll-sentinel"></div>
318
316
  ${this.leftColumnTemplate} ${this.rightColumnTemplate}
319
- `;
320
- }
321
- /**
322
- * Template for either the mobile or desktop version of the left column, depending
323
- * on current component state.
324
- */
325
- get leftColumnTemplate() {
326
- if (this.mobileView) {
327
- return this.mobileLeftColumnTemplate;
328
- }
329
- return this.desktopLeftColumnTemplate;
330
- }
331
- /**
332
- * Template for the mobile version of the "left column" (which in this case, appears
333
- * *above* the search results rather than beside them), for rendering the
334
- * accordion-style facets.
335
- */
336
- get mobileLeftColumnTemplate() {
317
+ `;
318
+ }
319
+ /**
320
+ * Template for either the mobile or desktop version of the left column, depending
321
+ * on current component state.
322
+ */
323
+ get leftColumnTemplate() {
324
+ if (this.mobileView) {
325
+ return this.mobileLeftColumnTemplate;
326
+ }
327
+ return this.desktopLeftColumnTemplate;
328
+ }
329
+ /**
330
+ * Template for the mobile version of the "left column" (which in this case, appears
331
+ * *above* the search results rather than beside them), for rendering the
332
+ * accordion-style facets.
333
+ */
334
+ get mobileLeftColumnTemplate() {
337
335
  return html `
338
336
  <div
339
337
  id="left-column"
@@ -342,12 +340,12 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
342
340
  ${this.facetTopViewSlot} ${this.resultsCountTemplate}
343
341
  <div id="facets-header-container">${this.mobileFacetsTemplate}</div>
344
342
  </div>
345
- `;
346
- }
347
- /**
348
- * Template for the desktop version of the left column, displaying the facets sidebar.
349
- */
350
- get desktopLeftColumnTemplate() {
343
+ `;
344
+ }
345
+ /**
346
+ * Template for the desktop version of the left column, displaying the facets sidebar.
347
+ */
348
+ get desktopLeftColumnTemplate() {
351
349
  return html `
352
350
  <div id="left-column" class="column">
353
351
  ${this.facetTopViewSlot}
@@ -361,28 +359,28 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
361
359
  </div>
362
360
  <div id="facets-bottom-fade"></div>
363
361
  </div>
364
- `;
365
- }
366
- /**
367
- * Slot which is placed at top of the facets area for user-profile page
368
- * - mainly used to render userlists
369
- */
370
- get facetTopViewSlot() {
362
+ `;
363
+ }
364
+ /**
365
+ * Slot which is placed at top of the facets area for user-profile page
366
+ * - mainly used to render userlists
367
+ */
368
+ get facetTopViewSlot() {
371
369
  return html `<div id="facet-top-view">
372
370
  <slot name="facet-top-slot"></slot>
373
- </div>`;
374
- }
375
- /**
376
- * Template for the "X Results" count at the top of the search results.
377
- * Changes to the "Searching..." label if the search results are still loading.
378
- */
379
- get resultsCountTemplate() {
380
- var _a;
381
- if (this.suppressResultCount)
382
- return nothing;
383
- const shouldShowSearching = this.searchResultsLoading || this.totalResults === undefined;
384
- const resultsCount = (_a = this.totalResults) === null || _a === void 0 ? void 0 : _a.toLocaleString();
385
- const resultsLabel = this.totalResults === 1 ? 'Result' : 'Results';
371
+ </div>`;
372
+ }
373
+ /**
374
+ * Template for the "X Results" count at the top of the search results.
375
+ * Changes to the "Searching..." label if the search results are still loading.
376
+ */
377
+ get resultsCountTemplate() {
378
+ var _a;
379
+ if (this.suppressResultCount)
380
+ return nothing;
381
+ const shouldShowSearching = this.searchResultsLoading || this.totalResults === undefined;
382
+ const resultsCount = (_a = this.totalResults) === null || _a === void 0 ? void 0 : _a.toLocaleString();
383
+ const resultsLabel = this.totalResults === 1 ? 'Result' : 'Results';
386
384
  return html `
387
385
  <div id="results-total">
388
386
  <span id="big-results-count">
@@ -392,30 +390,30 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
392
390
  ${shouldShowSearching ? nothing : resultsLabel}
393
391
  </span>
394
392
  </div>
395
- `;
396
- }
397
- /**
398
- * Template for the right column of the collection browser, where the result
399
- * tiles and sort/filter bar are shown.
400
- */
401
- get rightColumnTemplate() {
393
+ `;
394
+ }
395
+ /**
396
+ * Template for the right column of the collection browser, where the result
397
+ * tiles and sort/filter bar are shown.
398
+ */
399
+ get rightColumnTemplate() {
402
400
  return html `
403
401
  <div id="right-column" class="column">
404
402
  <div id="cb-top-view">
405
403
  <slot name="cb-top-slot"></slot>
406
404
  </div>
407
- ${this.isManageView
408
- ? this.manageBarTemplate
405
+ ${this.isManageView
406
+ ? this.manageBarTemplate
409
407
  : this.sortFilterBarTemplate}
410
408
  <slot name="cb-results"></slot>
411
- ${this.displayMode === `list-compact`
412
- ? this.listHeaderTemplate
409
+ ${this.displayMode === `list-compact`
410
+ ? this.listHeaderTemplate
413
411
  : nothing}
414
412
  ${this.infiniteScrollerTemplate}
415
413
  </div>
416
- `;
417
- }
418
- get infiniteScrollerTemplate() {
414
+ `;
415
+ }
416
+ get infiniteScrollerTemplate() {
419
417
  return html `<infinite-scroller
420
418
  class=${this.infiniteScrollerClasses}
421
419
  itemCount=${this.placeholderType ? 0 : nothing}
@@ -424,17 +422,17 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
424
422
  .placeholderCellTemplate=${this.placeholderCellTemplate}
425
423
  @scrollThresholdReached=${this.scrollThresholdReached}
426
424
  @visibleCellsChanged=${this.visibleCellsChanged}
427
- ></infinite-scroller>`;
428
- }
429
- get infiniteScrollerClasses() {
430
- var _a;
431
- return classMap({
432
- [(_a = this.displayMode) !== null && _a !== void 0 ? _a : '']: !!this.displayMode,
433
- hidden: !!this.placeholderType,
434
- });
435
- }
436
- get sortFilterBarTemplate() {
437
- var _a;
425
+ ></infinite-scroller>`;
426
+ }
427
+ get infiniteScrollerClasses() {
428
+ var _a;
429
+ return classMap({
430
+ [(_a = this.displayMode) !== null && _a !== void 0 ? _a : '']: !!this.displayMode,
431
+ hidden: !!this.placeholderType,
432
+ });
433
+ }
434
+ get sortFilterBarTemplate() {
435
+ var _a;
438
436
  return html `
439
437
  <sort-filter-bar
440
438
  .defaultSortField=${this.defaultSortField}
@@ -454,9 +452,9 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
454
452
  @creatorLetterChanged=${this.creatorLetterSelected}
455
453
  >
456
454
  </sort-filter-bar>
457
- `;
458
- }
459
- get manageBarTemplate() {
455
+ `;
456
+ }
457
+ get manageBarTemplate() {
460
458
  return html `
461
459
  <manage-bar
462
460
  showSelectAll
@@ -464,249 +462,249 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
464
462
  @removeItems=${this.handleRemoveItems}
465
463
  @selectAll=${this.checkAllTiles}
466
464
  @unselectAll=${this.uncheckAllTiles}
467
- @cancel=${() => {
468
- this.isManageView = false;
469
- this.uncheckAllTiles();
465
+ @cancel=${() => {
466
+ this.isManageView = false;
467
+ this.uncheckAllTiles();
470
468
  }}
471
469
  ></manage-bar>
472
- `;
473
- }
474
- /**
475
- * Handler for when the user requests to remove all checked items via the manage bar.
476
- * Emits an `itemRemovalRequested` event with all checked tile models.
477
- */
478
- handleRemoveItems() {
479
- this.dispatchEvent(new CustomEvent('itemRemovalRequested', {
480
- detail: {
481
- items: this.checkedTileModels.map(model => ({
482
- ...model,
483
- date: formatDate(model.datePublished, 'long'),
484
- })),
485
- },
486
- }));
487
- }
488
- /**
489
- * Removes all tile models that are currently checked & adjusts the paging
490
- * of the data source to account for any new gaps in the data.
491
- */
492
- removeCheckedTiles() {
493
- // To make sure our data source remains page-aligned, we will offset our data source by
494
- // the number of removed tiles, so that we can just add the offset when the infinite
495
- // scroller queries for cell contents.
496
- // This only matters while we're still viewing the same set of results. If the user changes
497
- // their query/filters/sort, then the data source is overwritten and the offset cleared.
498
- const { checkedTileModels, uncheckedTileModels } = this;
499
- const numChecked = checkedTileModels.length;
500
- if (numChecked === 0)
501
- return;
502
- this.tileModelOffset += numChecked;
503
- const newDataSource = {};
504
- // Which page the remaining tile models start on, post-offset
505
- let offsetPageNumber = Math.floor(this.tileModelOffset / this.pageSize) + 1;
506
- let indexOnPage = this.tileModelOffset % this.pageSize;
507
- // Fill the pages up to that point with empty models
508
- for (let page = 1; page <= offsetPageNumber; page += 1) {
509
- const remainingHidden = this.tileModelOffset - this.pageSize * (page - 1);
510
- const offsetCellsOnPage = Math.min(this.pageSize, remainingHidden);
511
- newDataSource[page] = Array(offsetCellsOnPage).fill(undefined);
512
- }
513
- // Shift all the remaining tiles into their new positions in the data source
514
- for (const model of uncheckedTileModels) {
515
- if (!newDataSource[offsetPageNumber])
516
- newDataSource[offsetPageNumber] = [];
517
- newDataSource[offsetPageNumber].push(model);
518
- indexOnPage += 1;
519
- if (indexOnPage >= this.pageSize) {
520
- offsetPageNumber += 1;
521
- indexOnPage = 0;
522
- }
523
- }
524
- // Swap in the new data source and update the infinite scroller
525
- this.dataSource = newDataSource;
526
- if (this.totalResults)
527
- this.totalResults -= numChecked;
528
- if (this.infiniteScroller) {
529
- this.infiniteScroller.itemCount -= numChecked;
530
- this.infiniteScroller.refreshAllVisibleCells();
531
- }
532
- }
533
- /**
534
- * Checks every tile's management checkbox
535
- */
536
- checkAllTiles() {
537
- this.mapDataSource(model => ({ ...model, checked: true }));
538
- }
539
- /**
540
- * Unchecks every tile's management checkbox
541
- */
542
- uncheckAllTiles() {
543
- this.mapDataSource(model => ({ ...model, checked: false }));
544
- }
545
- /**
546
- * Applies the given map function to all of the tile models in every page of the data
547
- * source. This method updates the data source object in immutable fashion.
548
- *
549
- * @param mapFn A callback function to apply on each tile model, as with Array.map
550
- */
551
- mapDataSource(mapFn) {
552
- var _a;
553
- this.dataSource = Object.fromEntries(Object.entries(this.dataSource).map(([page, tileModels]) => [
554
- page,
555
- tileModels.map((model, index, array) => model ? mapFn(model, index, array) : model),
556
- ]));
557
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
558
- }
559
- /**
560
- * An array of all the tile models whose management checkboxes are checked
561
- */
562
- get checkedTileModels() {
563
- return this.getFilteredTileModels(model => model.checked);
564
- }
565
- /**
566
- * An array of all the tile models whose management checkboxes are unchecked
567
- */
568
- get uncheckedTileModels() {
569
- return this.getFilteredTileModels(model => !model.checked);
570
- }
571
- /**
572
- * Returns a flattened, filtered array of all the tile models in the data source
573
- * for which the given predicate returns a truthy value.
574
- *
575
- * @param predicate A callback function to apply on each tile model, as with Array.filter
576
- * @returns A filtered array of tile models satisfying the predicate
577
- */
578
- getFilteredTileModels(predicate) {
579
- return Object.values(this.dataSource)
580
- .flat()
581
- .filter((model, index, array) => model ? predicate(model, index, array) : false);
582
- }
583
- userChangedSort(e) {
584
- var _a;
585
- const { selectedSort, sortDirection } = e.detail;
586
- this.selectedSort = selectedSort;
587
- this.sortDirection = sortDirection;
588
- if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
589
- this.goToPage(1);
590
- }
591
- this.currentPage = 1;
592
- }
593
- sendSortByAnalytics(prevSortDirection) {
594
- var _a;
595
- const directionCleared = prevSortDirection && !this.sortDirection;
596
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
597
- category: this.searchContext,
598
- action: analyticsActions.sortBy,
599
- label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
600
- });
601
- }
602
- selectedSortChanged() {
603
- var _a;
604
- const sortOption = SORT_OPTIONS[this.selectedSort];
605
- if (!sortOption.handledBySearchService) {
606
- this.sortParam = null;
607
- return;
608
- }
609
- // If the sort option specified in the URL is unrecognized, we just use it as-is
610
- const urlSortParam = new URL(window.location.href).searchParams.get('sort');
611
- const sortField = (_a = sortOption.searchServiceKey) !== null && _a !== void 0 ? _a : urlSortParam === null || urlSortParam === void 0 ? void 0 : urlSortParam.replace(/^-/, '');
612
- // If the sort direction is still null at this point, then we assume ascending
613
- // (i.e., it was unrecognized and had no directional flag)
614
- if (!this.sortDirection)
615
- this.sortDirection = 'asc';
616
- if (!sortField)
617
- return;
618
- this.sortParam = { field: sortField, direction: this.sortDirection };
619
- // Lazy-load the alphabet counts for title/creator sort bar as needed
620
- this.updatePrefixFiltersForCurrentSort();
621
- }
622
- displayModeChanged(e) {
623
- var _a;
624
- this.displayMode = e.detail.displayMode;
625
- if (this.displayMode) {
626
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
627
- category: this.searchContext,
628
- action: analyticsActions.displayMode,
629
- label: this.displayMode,
630
- });
631
- }
632
- }
633
- /**
634
- * Returns a query clause identifying the currently selected title filter,
635
- * e.g., `firstTitle:X`.
636
- */
637
- get titleQuery() {
638
- return this.selectedTitleFilter
639
- ? `firstTitle:${this.selectedTitleFilter}`
640
- : undefined;
641
- }
642
- /**
643
- * Returns a query clause identifying the currently selected creator filter,
644
- * e.g., `firstCreator:X`.
645
- */
646
- get creatorQuery() {
647
- return this.selectedCreatorFilter
648
- ? `firstCreator:${this.selectedCreatorFilter}`
649
- : undefined;
650
- }
651
- /**
652
- * Send Analytics when sorting by title's first letter
653
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
654
- */
655
- sendFilterByTitleAnalytics(prevSelectedLetter) {
656
- var _a;
657
- if (!prevSelectedLetter && !this.selectedTitleFilter) {
658
- return;
659
- }
660
- const cleared = prevSelectedLetter && !this.selectedTitleFilter;
661
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
662
- category: this.searchContext,
663
- action: analyticsActions.filterByTitle,
664
- label: cleared
665
- ? `clear-${prevSelectedLetter}`
666
- : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
667
- });
668
- }
669
- /**
670
- * Send Analytics when filtering by creator's first letter
671
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
672
- */
673
- sendFilterByCreatorAnalytics(prevSelectedLetter) {
674
- var _a;
675
- if (!prevSelectedLetter && !this.selectedCreatorFilter) {
676
- return;
677
- }
678
- const cleared = prevSelectedLetter && !this.selectedCreatorFilter;
679
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
680
- category: this.searchContext,
681
- action: analyticsActions.filterByCreator,
682
- label: cleared
683
- ? `clear-${prevSelectedLetter}`
684
- : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
685
- });
686
- }
687
- /**
688
- * Handler for changes to which letter is selected in the title alphabet bar.
689
- */
690
- titleLetterSelected(e) {
691
- this.selectedCreatorFilter = null;
692
- this.selectedTitleFilter = e.detail.selectedLetter;
693
- }
694
- /**
695
- * Handler for changes to which letter is selected in the creator alphabet bar.
696
- */
697
- creatorLetterSelected(e) {
698
- this.selectedTitleFilter = null;
699
- this.selectedCreatorFilter = e.detail.selectedLetter;
700
- }
701
- /**
702
- * The full template for how the facets should be structured in mobile view,
703
- * including the collapsible container (with header) and the facets themselves.
704
- */
705
- get mobileFacetsTemplate() {
706
- const toggleFacetsVisible = () => {
707
- this.isResizeToMobile = false;
708
- this.mobileFacetsVisible = !this.mobileFacetsVisible;
709
- };
470
+ `;
471
+ }
472
+ /**
473
+ * Handler for when the user requests to remove all checked items via the manage bar.
474
+ * Emits an `itemRemovalRequested` event with all checked tile models.
475
+ */
476
+ handleRemoveItems() {
477
+ this.dispatchEvent(new CustomEvent('itemRemovalRequested', {
478
+ detail: {
479
+ items: this.checkedTileModels.map(model => ({
480
+ ...model,
481
+ date: formatDate(model.datePublished, 'long'),
482
+ })),
483
+ },
484
+ }));
485
+ }
486
+ /**
487
+ * Removes all tile models that are currently checked & adjusts the paging
488
+ * of the data source to account for any new gaps in the data.
489
+ */
490
+ removeCheckedTiles() {
491
+ // To make sure our data source remains page-aligned, we will offset our data source by
492
+ // the number of removed tiles, so that we can just add the offset when the infinite
493
+ // scroller queries for cell contents.
494
+ // This only matters while we're still viewing the same set of results. If the user changes
495
+ // their query/filters/sort, then the data source is overwritten and the offset cleared.
496
+ const { checkedTileModels, uncheckedTileModels } = this;
497
+ const numChecked = checkedTileModels.length;
498
+ if (numChecked === 0)
499
+ return;
500
+ this.tileModelOffset += numChecked;
501
+ const newDataSource = {};
502
+ // Which page the remaining tile models start on, post-offset
503
+ let offsetPageNumber = Math.floor(this.tileModelOffset / this.pageSize) + 1;
504
+ let indexOnPage = this.tileModelOffset % this.pageSize;
505
+ // Fill the pages up to that point with empty models
506
+ for (let page = 1; page <= offsetPageNumber; page += 1) {
507
+ const remainingHidden = this.tileModelOffset - this.pageSize * (page - 1);
508
+ const offsetCellsOnPage = Math.min(this.pageSize, remainingHidden);
509
+ newDataSource[page] = Array(offsetCellsOnPage).fill(undefined);
510
+ }
511
+ // Shift all the remaining tiles into their new positions in the data source
512
+ for (const model of uncheckedTileModels) {
513
+ if (!newDataSource[offsetPageNumber])
514
+ newDataSource[offsetPageNumber] = [];
515
+ newDataSource[offsetPageNumber].push(model);
516
+ indexOnPage += 1;
517
+ if (indexOnPage >= this.pageSize) {
518
+ offsetPageNumber += 1;
519
+ indexOnPage = 0;
520
+ }
521
+ }
522
+ // Swap in the new data source and update the infinite scroller
523
+ this.dataSource = newDataSource;
524
+ if (this.totalResults)
525
+ this.totalResults -= numChecked;
526
+ if (this.infiniteScroller) {
527
+ this.infiniteScroller.itemCount -= numChecked;
528
+ this.infiniteScroller.refreshAllVisibleCells();
529
+ }
530
+ }
531
+ /**
532
+ * Checks every tile's management checkbox
533
+ */
534
+ checkAllTiles() {
535
+ this.mapDataSource(model => ({ ...model, checked: true }));
536
+ }
537
+ /**
538
+ * Unchecks every tile's management checkbox
539
+ */
540
+ uncheckAllTiles() {
541
+ this.mapDataSource(model => ({ ...model, checked: false }));
542
+ }
543
+ /**
544
+ * Applies the given map function to all of the tile models in every page of the data
545
+ * source. This method updates the data source object in immutable fashion.
546
+ *
547
+ * @param mapFn A callback function to apply on each tile model, as with Array.map
548
+ */
549
+ mapDataSource(mapFn) {
550
+ var _a;
551
+ this.dataSource = Object.fromEntries(Object.entries(this.dataSource).map(([page, tileModels]) => [
552
+ page,
553
+ tileModels.map((model, index, array) => model ? mapFn(model, index, array) : model),
554
+ ]));
555
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
556
+ }
557
+ /**
558
+ * An array of all the tile models whose management checkboxes are checked
559
+ */
560
+ get checkedTileModels() {
561
+ return this.getFilteredTileModels(model => model.checked);
562
+ }
563
+ /**
564
+ * An array of all the tile models whose management checkboxes are unchecked
565
+ */
566
+ get uncheckedTileModels() {
567
+ return this.getFilteredTileModels(model => !model.checked);
568
+ }
569
+ /**
570
+ * Returns a flattened, filtered array of all the tile models in the data source
571
+ * for which the given predicate returns a truthy value.
572
+ *
573
+ * @param predicate A callback function to apply on each tile model, as with Array.filter
574
+ * @returns A filtered array of tile models satisfying the predicate
575
+ */
576
+ getFilteredTileModels(predicate) {
577
+ return Object.values(this.dataSource)
578
+ .flat()
579
+ .filter((model, index, array) => model ? predicate(model, index, array) : false);
580
+ }
581
+ userChangedSort(e) {
582
+ var _a;
583
+ const { selectedSort, sortDirection } = e.detail;
584
+ this.selectedSort = selectedSort;
585
+ this.sortDirection = sortDirection;
586
+ if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
587
+ this.goToPage(1);
588
+ }
589
+ this.currentPage = 1;
590
+ }
591
+ sendSortByAnalytics(prevSortDirection) {
592
+ var _a;
593
+ const directionCleared = prevSortDirection && !this.sortDirection;
594
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
595
+ category: this.searchContext,
596
+ action: analyticsActions.sortBy,
597
+ label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
598
+ });
599
+ }
600
+ selectedSortChanged() {
601
+ var _a;
602
+ const sortOption = SORT_OPTIONS[this.selectedSort];
603
+ if (!sortOption.handledBySearchService) {
604
+ this.sortParam = null;
605
+ return;
606
+ }
607
+ // If the sort option specified in the URL is unrecognized, we just use it as-is
608
+ const urlSortParam = new URL(window.location.href).searchParams.get('sort');
609
+ const sortField = (_a = sortOption.searchServiceKey) !== null && _a !== void 0 ? _a : urlSortParam === null || urlSortParam === void 0 ? void 0 : urlSortParam.replace(/^-/, '');
610
+ // If the sort direction is still null at this point, then we assume ascending
611
+ // (i.e., it was unrecognized and had no directional flag)
612
+ if (!this.sortDirection)
613
+ this.sortDirection = 'asc';
614
+ if (!sortField)
615
+ return;
616
+ this.sortParam = { field: sortField, direction: this.sortDirection };
617
+ // Lazy-load the alphabet counts for title/creator sort bar as needed
618
+ this.updatePrefixFiltersForCurrentSort();
619
+ }
620
+ displayModeChanged(e) {
621
+ var _a;
622
+ this.displayMode = e.detail.displayMode;
623
+ if (this.displayMode) {
624
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
625
+ category: this.searchContext,
626
+ action: analyticsActions.displayMode,
627
+ label: this.displayMode,
628
+ });
629
+ }
630
+ }
631
+ /**
632
+ * Returns a query clause identifying the currently selected title filter,
633
+ * e.g., `firstTitle:X`.
634
+ */
635
+ get titleQuery() {
636
+ return this.selectedTitleFilter
637
+ ? `firstTitle:${this.selectedTitleFilter}`
638
+ : undefined;
639
+ }
640
+ /**
641
+ * Returns a query clause identifying the currently selected creator filter,
642
+ * e.g., `firstCreator:X`.
643
+ */
644
+ get creatorQuery() {
645
+ return this.selectedCreatorFilter
646
+ ? `firstCreator:${this.selectedCreatorFilter}`
647
+ : undefined;
648
+ }
649
+ /**
650
+ * Send Analytics when sorting by title's first letter
651
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
652
+ */
653
+ sendFilterByTitleAnalytics(prevSelectedLetter) {
654
+ var _a;
655
+ if (!prevSelectedLetter && !this.selectedTitleFilter) {
656
+ return;
657
+ }
658
+ const cleared = prevSelectedLetter && !this.selectedTitleFilter;
659
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
660
+ category: this.searchContext,
661
+ action: analyticsActions.filterByTitle,
662
+ label: cleared
663
+ ? `clear-${prevSelectedLetter}`
664
+ : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
665
+ });
666
+ }
667
+ /**
668
+ * Send Analytics when filtering by creator's first letter
669
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
670
+ */
671
+ sendFilterByCreatorAnalytics(prevSelectedLetter) {
672
+ var _a;
673
+ if (!prevSelectedLetter && !this.selectedCreatorFilter) {
674
+ return;
675
+ }
676
+ const cleared = prevSelectedLetter && !this.selectedCreatorFilter;
677
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
678
+ category: this.searchContext,
679
+ action: analyticsActions.filterByCreator,
680
+ label: cleared
681
+ ? `clear-${prevSelectedLetter}`
682
+ : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
683
+ });
684
+ }
685
+ /**
686
+ * Handler for changes to which letter is selected in the title alphabet bar.
687
+ */
688
+ titleLetterSelected(e) {
689
+ this.selectedCreatorFilter = null;
690
+ this.selectedTitleFilter = e.detail.selectedLetter;
691
+ }
692
+ /**
693
+ * Handler for changes to which letter is selected in the creator alphabet bar.
694
+ */
695
+ creatorLetterSelected(e) {
696
+ this.selectedTitleFilter = null;
697
+ this.selectedCreatorFilter = e.detail.selectedLetter;
698
+ }
699
+ /**
700
+ * The full template for how the facets should be structured in mobile view,
701
+ * including the collapsible container (with header) and the facets themselves.
702
+ */
703
+ get mobileFacetsTemplate() {
704
+ const toggleFacetsVisible = () => {
705
+ this.isResizeToMobile = false;
706
+ this.mobileFacetsVisible = !this.mobileFacetsVisible;
707
+ };
710
708
  return html `
711
709
  <details
712
710
  id="mobile-filter-collapse"
@@ -720,12 +718,12 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
720
718
  </summary>
721
719
  ${this.facetsTemplate}
722
720
  </details>
723
- `;
724
- }
725
- /**
726
- * The template for the facets component alone, without any surrounding wrappers.
727
- */
728
- get facetsTemplate() {
721
+ `;
722
+ }
723
+ /**
724
+ * The template for the facets component alone, without any surrounding wrappers.
725
+ */
726
+ get facetsTemplate() {
729
727
  return html `
730
728
  <collection-facets
731
729
  @facetsChanged=${this.facetsChanged}
@@ -759,41 +757,41 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
759
757
  .analyticsHandler=${this.analyticsHandler}
760
758
  >
761
759
  </collection-facets>
762
- `;
763
- }
764
- /**
765
- * The HTML template for the "Clear all filters" button, or `nothing` if no
766
- * filters are currently active.
767
- *
768
- * @param mobile Whether to style/shorten the button for mobile view
769
- */
770
- clearFiltersBtnTemplate(mobile) {
771
- if (!this.hasActiveFilters)
772
- return nothing;
773
- const buttonClasses = classMap({
774
- 'clear-filters-btn': true,
775
- mobile,
776
- });
777
- const buttonText = mobile ? 'Clear all' : 'Clear all filters';
760
+ `;
761
+ }
762
+ /**
763
+ * The HTML template for the "Clear all filters" button, or `nothing` if no
764
+ * filters are currently active.
765
+ *
766
+ * @param mobile Whether to style/shorten the button for mobile view
767
+ */
768
+ clearFiltersBtnTemplate(mobile) {
769
+ if (!this.hasActiveFilters)
770
+ return nothing;
771
+ const buttonClasses = classMap({
772
+ 'clear-filters-btn': true,
773
+ mobile,
774
+ });
775
+ const buttonText = mobile ? 'Clear all' : 'Clear all filters';
778
776
  return html `
779
777
  <div class="clear-filters-btn-row">
780
- ${mobile
781
- ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
778
+ ${mobile
779
+ ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
782
780
  : nothing}
783
781
  <button class=${buttonClasses} @click=${this.clearFilters}>
784
782
  ${buttonText}
785
783
  </button>
786
784
  </div>
787
- `;
788
- }
789
- get loadingTemplate() {
785
+ `;
786
+ }
787
+ get loadingTemplate() {
790
788
  return html `
791
789
  <div class="loading-cover">
792
790
  <circular-activity-indicator></circular-activity-indicator>
793
791
  </div>
794
- `;
795
- }
796
- get listHeaderTemplate() {
792
+ `;
793
+ }
794
+ get listHeaderTemplate() {
797
795
  return html `
798
796
  <div id="list-header">
799
797
  <tile-dispatcher
@@ -806,1066 +804,1064 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
806
804
  >
807
805
  </tile-dispatcher>
808
806
  </div>
809
- `;
810
- }
811
- histogramDateRangeUpdated(e) {
812
- var _a;
813
- const { minDate, maxDate } = e.detail;
814
- [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
815
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
816
- category: this.searchContext,
817
- action: analyticsActions.histogramChanged,
818
- label: this.dateRangeQueryClause,
819
- });
820
- }
821
- get dateRangeQueryClause() {
822
- if (!this.minSelectedDate || !this.maxSelectedDate) {
823
- return undefined;
824
- }
825
- return `year:[${this.minSelectedDate} TO ${this.maxSelectedDate}]`;
826
- }
827
- /**
828
- * Emits an event indicating a change in whether the manage mode is shown.
829
- */
830
- emitManageModeChangedEvent() {
831
- this.dispatchEvent(new CustomEvent('manageModeChanged', {
832
- detail: this.isManageView,
833
- }));
834
- }
835
- firstUpdated() {
836
- this.setupStateRestorationObserver();
837
- this.restoreState();
838
- }
839
- updated(changed) {
840
- var _a, _b;
841
- if (changed.has('placeholderType') && this.placeholderType === null) {
842
- if (!this.leftColIntersectionObserver) {
843
- this.setupLeftColumnScrollListeners();
844
- }
845
- if (!this.facetsIntersectionObserver) {
846
- this.setupFacetsScrollListeners();
847
- }
848
- this.updateLeftColumnHeight();
849
- }
850
- if (changed.has('displayMode') ||
851
- changed.has('baseNavigationUrl') ||
852
- changed.has('baseImageUrl') ||
853
- changed.has('loggedIn')) {
854
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
855
- }
856
- if (changed.has('baseQuery') ||
857
- changed.has('searchType') ||
858
- changed.has('withinCollection')) {
859
- // Unless this query/search type update is from the initial page load or the
860
- // result of hitting the back button,
861
- // we need to clear any existing filters since they may no longer be valid for
862
- // the new set of search results.
863
- if (!this.historyPopOccurred && this.initialQueryChangeHappened) {
864
- // Ordinarily, we leave the sort param unchanged between searches.
865
- // However, if we are changing the target collection itself, we want the sort cleared too,
866
- // since different collections may have different sorting options available.
867
- const shouldClearSort = changed.has('withinCollection') &&
868
- !changed.has('selectedSort') &&
869
- !changed.has('sortDirection');
870
- // Otherwise, only clear filters that haven't been simultaneously applied in this update
871
- this.clearFilters({
872
- sort: shouldClearSort,
873
- facets: !changed.has('selectedFacets'),
874
- dateRange: !(changed.has('minSelectedDate') || changed.has('maxSelectedDate')),
875
- letterFilters: !(changed.has('selectedTitleFilter') ||
876
- changed.has('selectedCreatorFilter')),
877
- });
878
- }
879
- }
880
- if (changed.has('baseQuery')) {
881
- this.emitBaseQueryChanged();
882
- }
883
- if (changed.has('searchType')) {
884
- this.emitSearchTypeChanged();
885
- }
886
- if (changed.has('currentPage') || changed.has('displayMode')) {
887
- this.persistState();
888
- }
889
- if (changed.has('baseQuery') ||
890
- changed.has('minSelectedDate') ||
891
- changed.has('maxSelectedDate') ||
892
- changed.has('selectedFacets') ||
893
- changed.has('searchService') ||
894
- changed.has('withinCollection')) {
895
- this.refreshLetterCounts();
896
- }
897
- if (changed.has('selectedSort') || changed.has('sortDirection')) {
898
- const prevSortDirection = changed.get('sortDirection');
899
- this.sendSortByAnalytics(prevSortDirection);
900
- this.selectedSortChanged();
901
- }
902
- if (changed.has('selectedTitleFilter')) {
903
- this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
904
- }
905
- if (changed.has('selectedCreatorFilter')) {
906
- this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
907
- }
908
- if (changed.has('baseQuery') ||
909
- changed.has('searchType') ||
910
- changed.has('selectedTitleFilter') ||
911
- changed.has('selectedCreatorFilter') ||
912
- changed.has('minSelectedDate') ||
913
- changed.has('maxSelectedDate') ||
914
- changed.has('sortParam') ||
915
- changed.has('selectedFacets') ||
916
- changed.has('searchService') ||
917
- changed.has('withinCollection')) {
918
- this.handleQueryChange();
919
- }
920
- if (changed.has('searchResultsLoading')) {
921
- this.emitSearchResultsLoadingChanged();
922
- }
923
- if (changed.has('facetsLoading') &&
924
- this.facetsLoading &&
925
- this.collectionFacets) {
926
- this.collectionFacets.moreLinksVisible =
927
- this.searchType !== SearchType.FULLTEXT;
928
- }
929
- if (changed.has('pagesToRender')) {
930
- if (!this.endOfDataReached && this.infiniteScroller) {
931
- this.infiniteScroller.itemCount = this.estimatedTileCount;
932
- }
933
- }
934
- if (changed.has('isManageView')) {
935
- if (this.isManageView)
936
- this.displayMode = 'grid';
937
- (_b = this.infiniteScroller) === null || _b === void 0 ? void 0 : _b.refreshAllVisibleCells();
938
- this.emitManageModeChangedEvent();
939
- }
940
- if (changed.has('resizeObserver')) {
941
- const oldObserver = changed.get('resizeObserver');
942
- if (oldObserver)
943
- this.disconnectResizeObserver(oldObserver);
944
- this.setupResizeObserver();
945
- }
946
- }
947
- disconnectedCallback() {
948
- var _a, _b;
949
- if (this.resizeObserver) {
950
- this.disconnectResizeObserver(this.resizeObserver);
951
- }
952
- if (this.boundNavigationHandler) {
953
- window.removeEventListener('popstate', this.boundNavigationHandler);
954
- }
955
- (_a = this.leftColIntersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
956
- (_b = this.facetsIntersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
957
- window.removeEventListener('resize', this.updateLeftColumnHeight);
958
- }
959
- handleResize(entry) {
960
- const previousView = this.mobileView;
961
- if (entry.target === this.contentContainer) {
962
- this.contentWidth = entry.contentRect.width;
963
- this.mobileView =
964
- this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
965
- // If changing from desktop to mobile disable transition
966
- if (this.mobileView && !previousView) {
967
- this.isResizeToMobile = true;
968
- }
969
- }
970
- // Ensure the facet sidebar remains sized correctly
971
- this.updateLeftColumnHeight();
972
- }
973
- /**
974
- * Sets up listeners for events that may require updating the left column height.
975
- */
976
- setupLeftColumnScrollListeners() {
977
- var _a;
978
- // We observe intersections between the left column's scroll sentinel and
979
- // the viewport, so that we can ensure the left column is always sized to
980
- // match the _available_ viewport height. This should generally be more
981
- // performant than listening to scroll events on the page or column.
982
- const leftColumnSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#left-column-scroll-sentinel');
983
- if (leftColumnSentinel) {
984
- this.leftColIntersectionObserver = new IntersectionObserver(this.updateLeftColumnHeight, {
985
- threshold: [...Array(101).keys()].map(n => n / 100), // Threshold every 1%
986
- });
987
- this.leftColIntersectionObserver.observe(leftColumnSentinel);
988
- }
989
- // We also listen for window resize events, as they are not always captured
990
- // by the resize observer and can affect the desired height of the left column.
991
- window.addEventListener('resize', this.updateLeftColumnHeight);
992
- }
993
- /**
994
- * Sets up listeners to control whether the facet sidebar shows its bottom fade-out.
995
- * Note this uses a separate IntersectionObserver from the left column, because we
996
- * don't need granular intersection thresholds for this.
997
- */
998
- setupFacetsScrollListeners() {
999
- var _a;
1000
- const facetsSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#facets-scroll-sentinel');
1001
- if (facetsSentinel) {
1002
- this.facetsIntersectionObserver = new IntersectionObserver(this.updateFacetFadeOut);
1003
- this.facetsIntersectionObserver.observe(facetsSentinel);
1004
- }
1005
- }
1006
- emitBaseQueryChanged() {
1007
- this.dispatchEvent(new CustomEvent('baseQueryChanged', {
1008
- detail: {
1009
- baseQuery: this.baseQuery,
1010
- },
1011
- }));
1012
- }
1013
- emitSearchTypeChanged() {
1014
- this.dispatchEvent(new CustomEvent('searchTypeChanged', {
1015
- detail: this.searchType,
1016
- }));
1017
- }
1018
- emitEmptyResults() {
1019
- this.dispatchEvent(new Event('emptyResults'));
1020
- }
1021
- disconnectResizeObserver(resizeObserver) {
1022
- resizeObserver.removeObserver({
1023
- target: this.contentContainer,
1024
- handler: this,
1025
- });
1026
- }
1027
- setupResizeObserver() {
1028
- if (!this.resizeObserver)
1029
- return;
1030
- this.resizeObserver.addObserver({
1031
- target: this.contentContainer,
1032
- handler: this,
1033
- });
1034
- }
1035
- /**
1036
- * When the visible cells change from the infinite scroller, we want to emit
1037
- * which page is currently visible so the consumer can update its UI or the URL
1038
- *
1039
- * @param e
1040
- * @returns
1041
- */
1042
- visibleCellsChanged(e) {
1043
- if (this.isScrollingToCell)
1044
- return;
1045
- const { visibleCellIndices } = e.detail;
1046
- if (visibleCellIndices.length === 0)
1047
- return;
1048
- const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
1049
- const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
1050
- if (this.currentPage !== lastVisibleCellPage) {
1051
- this.currentPage = lastVisibleCellPage;
1052
- }
1053
- const event = new CustomEvent('visiblePageChanged', {
1054
- detail: {
1055
- pageNumber: lastVisibleCellPage,
1056
- },
1057
- });
1058
- this.dispatchEvent(event);
1059
- }
1060
- /**
1061
- * A Promise which, after each query change, resolves once the fetches for the initial
1062
- * search have completed. Waits for *both* the hits and aggregations fetches to finish.
1063
- *
1064
- * Ensure you await this component's `updateComplete` promise before awaiting this
1065
- * one, to ensure you do not await an obsolete promise from the previous update.
1066
- */
1067
- get initialSearchComplete() {
1068
- return this._initialSearchCompletePromise;
1069
- }
1070
- async handleQueryChange() {
1071
- var _a;
1072
- console.log('handlequerychange');
1073
- // only reset if the query has actually changed
1074
- if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
1075
- return;
1076
- console.log(1);
1077
- // If the new state prevents us from updating the search results, don't reset
1078
- if (!this.canPerformSearch && !(this.clearResultsOnEmptyQuery && this.baseQuery === ''))
1079
- return;
1080
- console.log(2);
1081
- this.previousQueryKey = this.pageFetchQueryKey;
1082
- this.dataSource = {};
1083
- this.tileModelOffset = 0;
1084
- this.totalResults = undefined;
1085
- this.aggregations = undefined;
1086
- this.fullYearsHistogramAggregation = undefined;
1087
- this.pageFetchesInProgress = {};
1088
- this.endOfDataReached = false;
1089
- this.pagesToRender =
1090
- this.initialPageNumber === 1
1091
- ? 2 // First two pages are batched into one request when starting from page 1
1092
- : this.initialPageNumber;
1093
- this.queryErrorMessage = undefined;
1094
- // Reset the infinite scroller's item count, so that it
1095
- // shows tile placeholders until the new query's results load in
1096
- if (this.infiniteScroller) {
1097
- this.infiniteScroller.itemCount = this.estimatedTileCount;
1098
- this.infiniteScroller.reload();
1099
- }
1100
- if (this.withinCollection && ((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
1101
- this.defaultSortField = SortField.relevance;
1102
- this.defaultSortDirection = null;
1103
- }
1104
- if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
1105
- this.scrollToPage(this.initialPageNumber);
1106
- }
1107
- this.initialQueryChangeHappened = true;
1108
- // if the query changed as part of a window.history pop event, we don't want to
1109
- // persist the state because it overwrites the forward history
1110
- if (!this.historyPopOccurred) {
1111
- this.persistState();
1112
- }
1113
- this.historyPopOccurred = false;
1114
- // Reset the `initialSearchComplete` promise with a new value for the imminent search
1115
- this._initialSearchCompletePromise = new Promise(res => {
1116
- this._initialSearchCompleteResolver = res;
1117
- });
1118
- // Fire the initial page and facets requests
1119
- await Promise.all([this.doInitialPageFetch(), this.fetchFacets()]);
1120
- // Resolve the `initialSearchComplete` promise for this search
1121
- this._initialSearchCompleteResolver(true);
1122
- }
1123
- setupStateRestorationObserver() {
1124
- if (this.boundNavigationHandler)
1125
- return;
1126
- this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
1127
- // when the user navigates back, we want to update the UI to match the URL
1128
- window.addEventListener('popstate', this.boundNavigationHandler);
1129
- }
1130
- historyNavigationHandler() {
1131
- this.historyPopOccurred = true;
1132
- this.restoreState();
1133
- }
1134
- restoreState() {
1135
- var _a, _b, _c, _d, _e;
1136
- const restorationState = this.restorationStateHandler.getRestorationState();
1137
- this.displayMode = restorationState.displayMode;
1138
- if (restorationState.searchType != null)
1139
- this.searchType = restorationState.searchType;
1140
- this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.default;
1141
- this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
1142
- this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
1143
- this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
1144
- this.selectedFacets = restorationState.selectedFacets;
1145
- this.baseQuery = restorationState.baseQuery;
1146
- this.currentPage = (_e = restorationState.currentPage) !== null && _e !== void 0 ? _e : 1;
1147
- this.minSelectedDate = restorationState.minSelectedDate;
1148
- this.maxSelectedDate = restorationState.maxSelectedDate;
1149
- if (this.currentPage > 1) {
1150
- this.goToPage(this.currentPage);
1151
- }
1152
- }
1153
- persistState() {
1154
- var _a, _b, _c, _d;
1155
- const restorationState = {
1156
- displayMode: this.displayMode,
1157
- searchType: this.searchType,
1158
- selectedSort: this.selectedSort,
1159
- sortDirection: (_a = this.sortDirection) !== null && _a !== void 0 ? _a : undefined,
1160
- selectedFacets: (_b = this.selectedFacets) !== null && _b !== void 0 ? _b : getDefaultSelectedFacets(),
1161
- baseQuery: this.baseQuery,
1162
- currentPage: this.currentPage,
1163
- titleQuery: this.titleQuery,
1164
- creatorQuery: this.creatorQuery,
1165
- minSelectedDate: this.minSelectedDate,
1166
- maxSelectedDate: this.maxSelectedDate,
1167
- selectedTitleFilter: (_c = this.selectedTitleFilter) !== null && _c !== void 0 ? _c : undefined,
1168
- selectedCreatorFilter: (_d = this.selectedCreatorFilter) !== null && _d !== void 0 ? _d : undefined,
1169
- };
1170
- this.restorationStateHandler.persistState(restorationState);
1171
- }
1172
- async doInitialPageFetch() {
1173
- this.searchResultsLoading = true;
1174
- // Try to batch 2 initial page requests when possible
1175
- await this.fetchPage(this.initialPageNumber, 2);
1176
- this.searchResultsLoading = false;
1177
- }
1178
- emitSearchResultsLoadingChanged() {
1179
- this.dispatchEvent(new CustomEvent('searchResultsLoadingChanged', {
1180
- detail: {
1181
- loading: this.searchResultsLoading,
1182
- },
1183
- }));
1184
- }
1185
- /**
1186
- * Produces a compact unique ID for a search request that can help with debugging
1187
- * on the backend by making related requests easier to trace through different services.
1188
- * (e.g., tying the hits/aggregations requests for the same page back to a single hash).
1189
- *
1190
- * @param params The search service parameters for the request
1191
- * @param kind The kind of request (hits-only, aggregations-only, or both)
1192
- * @returns A Promise resolving to the uid to apply to the request
1193
- */
1194
- async requestUID(params, kind) {
1195
- var _a;
1196
- const paramsToHash = JSON.stringify({
1197
- pageType: params.pageType,
1198
- pageTarget: params.pageTarget,
1199
- query: params.query,
1200
- fields: params.fields,
1201
- filters: params.filters,
1202
- sort: params.sort,
1203
- searchType: this.searchType,
1204
- });
1205
- const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this
1206
- const sessionId = (await this.getSessionId()).slice(0, 20); // Likewise
1207
- const page = (_a = params.page) !== null && _a !== void 0 ? _a : 0;
1208
- const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations
1209
- const currentTime = Date.now();
1210
- return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;
1211
- }
1212
- /**
1213
- * Constructs a search service FilterMap object from the combination of
1214
- * all the currently-applied filters. This includes any facets, letter
1215
- * filters, and date range.
1216
- */
1217
- get filterMap() {
1218
- const builder = new FilterMapBuilder();
1219
- // Add the date range, if applicable
1220
- if (this.minSelectedDate) {
1221
- builder.addFilter('year', this.minSelectedDate, FilterConstraint.GREATER_OR_EQUAL);
1222
- }
1223
- if (this.maxSelectedDate) {
1224
- builder.addFilter('year', this.maxSelectedDate, FilterConstraint.LESS_OR_EQUAL);
1225
- }
1226
- // Add any selected facets
1227
- if (this.selectedFacets) {
1228
- for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1229
- const { name, values } = this.prepareFacetForFetch(facetName, facetValues);
1230
- for (const [value, bucket] of Object.entries(values)) {
1231
- let constraint;
1232
- if (bucket.state === 'selected') {
1233
- constraint = FilterConstraint.INCLUDE;
1234
- }
1235
- else if (bucket.state === 'hidden') {
1236
- constraint = FilterConstraint.EXCLUDE;
1237
- }
1238
- if (constraint) {
1239
- builder.addFilter(name, value, constraint);
1240
- }
1241
- }
1242
- }
1243
- }
1244
- // Add any letter filters
1245
- if (this.selectedTitleFilter) {
1246
- builder.addFilter('firstTitle', this.selectedTitleFilter, FilterConstraint.INCLUDE);
1247
- }
1248
- if (this.selectedCreatorFilter) {
1249
- builder.addFilter('firstCreator', this.selectedCreatorFilter, FilterConstraint.INCLUDE);
1250
- }
1251
- const filterMap = builder.build();
1252
- return filterMap;
1253
- }
1254
- /** The full query, including year facets and date range clauses */
1255
- get fullQuery() {
1256
- var _a, _b;
1257
- let fullQuery = (_b = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
1258
- const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;
1259
- if (facetQuery) {
1260
- fullQuery += ` AND ${facetQuery}`;
1261
- }
1262
- if (dateRangeQueryClause) {
1263
- fullQuery += ` AND ${dateRangeQueryClause}`;
1264
- }
1265
- if (sortFilterQueries) {
1266
- fullQuery += ` AND ${sortFilterQueries}`;
1267
- }
1268
- return fullQuery.trim();
1269
- }
1270
- /**
1271
- * Generates a query string for the given facets
1272
- *
1273
- * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
1274
- */
1275
- get facetQuery() {
1276
- var _a;
1277
- if (!this.selectedFacets)
1278
- return undefined;
1279
- const facetClauses = [];
1280
- for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1281
- facetClauses.push(this.buildFacetClause(facetName, facetValues));
1282
- }
1283
- return (_a = this.joinFacetClauses(facetClauses)) === null || _a === void 0 ? void 0 : _a.trim();
1284
- }
1285
- /**
1286
- * Builds an OR-joined facet clause for the given facet name and values.
1287
- *
1288
- * E.g., for name `subject` and values
1289
- * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`
1290
- * this will produce the clause
1291
- * `subject:("foo" OR -"bar")`.
1292
- *
1293
- * @param facetName The facet type (e.g., 'collection')
1294
- * @param facetValues The facet buckets, mapped by their keys
1295
- */
1296
- buildFacetClause(facetName, facetValues) {
1297
- const { name: facetQueryName, values } = this.prepareFacetForFetch(facetName, facetValues);
1298
- const facetEntries = Object.entries(values);
1299
- if (facetEntries.length === 0)
1300
- return '';
1301
- const facetValuesArray = [];
1302
- for (const [key, facetData] of facetEntries) {
1303
- const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
1304
- facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
1305
- }
1306
- const valueQuery = facetValuesArray.join(` OR `);
1307
- return `${facetQueryName}:(${valueQuery})`;
1308
- }
1309
- /**
1310
- * Handles some special pre-request normalization steps for certain facet types
1311
- * that require them.
1312
- *
1313
- * @param facetName The name of the facet type (e.g., 'language')
1314
- * @param facetValues An array of values for that facet type
1315
- */
1316
- prepareFacetForFetch(facetName, facetValues) {
1317
- // eslint-disable-next-line prefer-const
1318
- let [normalizedName, normalizedValues] = [facetName, facetValues];
1319
- // The full "search engine" name of the lending field is "lending___status"
1320
- if (facetName === 'lending') {
1321
- normalizedName = 'lending___status';
1322
- }
1323
- return {
1324
- name: normalizedName,
1325
- values: normalizedValues,
1326
- };
1327
- }
1328
- /**
1329
- * Takes an array of facet clauses, and combines them into a
1330
- * full AND-joined facet query string. Empty clauses are ignored.
1331
- */
1332
- joinFacetClauses(facetClauses) {
1333
- const nonEmptyFacetClauses = facetClauses.filter(clause => clause.length > 0);
1334
- return nonEmptyFacetClauses.length > 0
1335
- ? `(${nonEmptyFacetClauses.join(' AND ')})`
1336
- : undefined;
1337
- }
1338
- facetsChanged(e) {
1339
- this.selectedFacets = e.detail;
1340
- }
1341
- facetClickHandler({ detail: { key, state: facetState, negative }, }) {
1342
- var _a, _b;
1343
- if (negative) {
1344
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1345
- category: this.searchContext,
1346
- action: facetState !== 'none'
1347
- ? analyticsActions.facetNegativeSelected
1348
- : analyticsActions.facetNegativeDeselected,
1349
- label: key,
1350
- });
1351
- }
1352
- else {
1353
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1354
- category: this.searchContext,
1355
- action: facetState !== 'none'
1356
- ? analyticsActions.facetSelected
1357
- : analyticsActions.facetDeselected,
1358
- label: key,
1359
- });
1360
- }
1361
- }
1362
- async fetchFacets() {
1363
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1364
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1365
- if (!this.canPerformSearch)
1366
- return;
1367
- const { facetFetchQueryKey } = this;
1368
- const sortParams = this.sortParam ? [this.sortParam] : [];
1369
- const params = {
1370
- ...this.collectionParams,
1371
- query: trimmedQuery || '',
1372
- rows: 0,
1373
- filters: this.filterMap,
1374
- // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
1375
- aggregationsSize: 10,
1376
- // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
1377
- // The default aggregations for the search_results page type should be what we need here.
1378
- };
1379
- params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1380
- this.facetsLoading = true;
1381
- const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1382
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1383
- // This is checking to see if the query has changed since the data was fetched.
1384
- // If so, we just want to discard this set of aggregations because they are
1385
- // likely no longer valid for the newer query.
1386
- const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1387
- if (queryChangedSinceFetch)
1388
- return;
1389
- if (!success) {
1390
- const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
1391
- 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;
1392
- if (!errorMsg && !detailMsg) {
1393
- // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1394
- (_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');
1395
- }
1396
- return;
1397
- }
1398
- const { aggregations, collectionTitles } = success.response;
1399
- this.aggregations = aggregations;
1400
- if (collectionTitles) {
1401
- (_h = this.collectionNameCache) === null || _h === void 0 ? void 0 : _h.addKnownTitles(collectionTitles);
1402
- }
1403
- else if ((_j = this.aggregations) === null || _j === void 0 ? void 0 : _j.collection) {
1404
- (_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(); }));
1405
- }
1406
- this.fullYearsHistogramAggregation =
1407
- (_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;
1408
- this.facetsLoading = false;
1409
- }
1410
- scrollToPage(pageNumber) {
1411
- return new Promise(resolve => {
1412
- const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1413
- // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1414
- // then scrolls to the cell
1415
- setTimeout(() => {
1416
- var _a;
1417
- this.isScrollingToCell = true;
1418
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.scrollToCell(cellIndexToScrollTo, true);
1419
- // This timeout is to give the scroll animation time to finish
1420
- // then updating the infinite scroller once we're done scrolling
1421
- // There's no scroll animation completion callback so we're
1422
- // giving it 0.5s to finish.
1423
- setTimeout(() => {
1424
- var _a;
1425
- this.isScrollingToCell = false;
1426
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1427
- resolve();
1428
- }, 500);
1429
- }, 0);
1430
- });
1431
- }
1432
- /**
1433
- * Whether sorting by relevance makes sense for the current state.
1434
- * Currently equivalent to having a non-empty query.
1435
- */
1436
- get isRelevanceSortAvailable() {
1437
- var _a;
1438
- return !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
1439
- }
1440
- /**
1441
- * Whether a search may be performed in the current state of the component.
1442
- * This is only true if the search service is defined, and either
1443
- * (a) a non-empty query is set, or
1444
- * (b) we are on a collection page in metadata search mode.
1445
- */
1446
- get canPerformSearch() {
1447
- var _a;
1448
- if (!this.searchService)
1449
- return false;
1450
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1451
- const hasNonEmptyQuery = !!trimmedQuery;
1452
- const isCollectionSearch = !!this.withinCollection;
1453
- const isMetadataSearch = this.searchType === SearchType.METADATA;
1454
- // Metadata searches within a collection are allowed to have no query.
1455
- // Otherwise, a non-empty query must be set.
1456
- return hasNonEmptyQuery || (isCollectionSearch && isMetadataSearch);
1457
- }
1458
- /**
1459
- * Additional params to pass to the search service if targeting a collection page,
1460
- * or null otherwise.
1461
- */
1462
- get collectionParams() {
1463
- return this.withinCollection
1464
- ? { pageType: 'collection_details', pageTarget: this.withinCollection }
1465
- : null;
1466
- }
1467
- /**
1468
- * The query key is a string that uniquely identifies the current search.
1469
- * It consists of:
1470
- * - The current base query
1471
- * - The current collection
1472
- * - The current search type
1473
- * - Any currently-applied facets
1474
- * - Any currently-applied date range
1475
- * - Any currently-applied prefix filters
1476
- * - The current sort options
1477
- *
1478
- * This lets us keep track of queries so we don't persist data that's
1479
- * no longer relevant.
1480
- */
1481
- get pageFetchQueryKey() {
1482
- var _a, _b, _c, _d;
1483
- const sortField = (_b = (_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : 'none';
1484
- const sortDirection = (_d = (_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.direction) !== null && _d !== void 0 ? _d : 'none';
1485
- return `${this.fullQuery}-${this.withinCollection}-${this.searchType}-${sortField}-${sortDirection}`;
1486
- }
1487
- /**
1488
- * Similar to `pageFetchQueryKey` above, but excludes sort fields since they
1489
- * are not relevant in determining aggregation queries.
1490
- */
1491
- get facetFetchQueryKey() {
1492
- return `${this.fullQuery}-${this.withinCollection}-${this.searchType}`;
1493
- }
1494
- /**
1495
- * Fetches one or more pages of results and updates the data source.
1496
- *
1497
- * @param pageNumber The page number to fetch
1498
- * @param numInitialPages If this is an initial page fetch (`pageNumber = 1`),
1499
- * specifies how many pages to batch together in one request. Ignored
1500
- * if `pageNumber != 1`, defaulting to a single page.
1501
- */
1502
- async fetchPage(pageNumber, numInitialPages = 1) {
1503
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
1504
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1505
- if (!this.canPerformSearch)
1506
- return;
1507
- // if we already have data, don't fetch again
1508
- if (this.dataSource[pageNumber])
1509
- return;
1510
- if (this.endOfDataReached)
1511
- return;
1512
- // Batch multiple initial page requests together if needed (e.g., can request
1513
- // pages 1 and 2 together in a single request).
1514
- const numPages = pageNumber === 1 ? numInitialPages : 1;
1515
- const numRows = this.pageSize * numPages;
1516
- // if a fetch is already in progress for this query and page, don't fetch again
1517
- const { pageFetchQueryKey } = this;
1518
- const pageFetches = (_b = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _b !== void 0 ? _b : new Set();
1519
- if (pageFetches.has(pageNumber))
1520
- return;
1521
- for (let i = 0; i < numPages; i += 1) {
1522
- pageFetches.add(pageNumber + i);
1523
- }
1524
- this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
1525
- const sortParams = this.sortParam ? [this.sortParam] : [];
1526
- const params = {
1527
- ...this.collectionParams,
1528
- query: trimmedQuery || '',
1529
- page: pageNumber,
1530
- rows: numRows,
1531
- sort: sortParams,
1532
- filters: this.filterMap,
1533
- aggregations: { omit: true },
1534
- };
1535
- params.uid = await this.requestUID(params, 'hits');
1536
- const searchResponse = await ((_c = this.searchService) === null || _c === void 0 ? void 0 : _c.search(params, this.searchType));
1537
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1538
- // This is checking to see if the query has changed since the data was fetched.
1539
- // If so, we just want to discard the data since there should be a new query
1540
- // right behind it.
1541
- const queryChangedSinceFetch = pageFetchQueryKey !== this.pageFetchQueryKey;
1542
- if (queryChangedSinceFetch)
1543
- return;
1544
- if (!success) {
1545
- const errorMsg = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.message;
1546
- 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;
1547
- this.queryErrorMessage = `${errorMsg !== null && errorMsg !== void 0 ? errorMsg : ''}${detailMsg ? `; ${detailMsg}` : ''}`;
1548
- if (!this.queryErrorMessage) {
1549
- this.queryErrorMessage = 'Missing or malformed response from backend';
1550
- // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1551
- (_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');
1552
- }
1553
- for (let i = 0; i < numPages; i += 1) {
1554
- (_j = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _j === void 0 ? void 0 : _j.delete(pageNumber + i);
1555
- }
1556
- this.searchResultsLoading = false;
1557
- return;
1558
- }
1559
- this.totalResults = success.response.totalResults - this.tileModelOffset;
1560
- // display event to offshoot when result count is zero.
1561
- if (this.totalResults === 0) {
1562
- this.emitEmptyResults();
1563
- }
1564
- if (this.withinCollection) {
1565
- this.collectionInfo = success.response.collectionExtraInfo;
1566
- // For collections, we want the UI to respect the default sort option
1567
- // which can be specified in metadata, or otherwise assumed to be week:desc
1568
- this.applyDefaultCollectionSort(this.collectionInfo);
1569
- if (this.collectionInfo) {
1570
- this.parentCollections = [].concat((_l = (_k = this.collectionInfo.public_metadata) === null || _k === void 0 ? void 0 : _k.collection) !== null && _l !== void 0 ? _l : []);
1571
- }
1572
- }
1573
- const { results, collectionTitles } = success.response;
1574
- if (results && results.length > 0) {
1575
- // Load any collection titles present on the response into the cache,
1576
- // or queue up preload fetches for them if none were present.
1577
- if (collectionTitles) {
1578
- (_m = this.collectionNameCache) === null || _m === void 0 ? void 0 : _m.addKnownTitles(collectionTitles);
1579
- }
1580
- else {
1581
- this.preloadCollectionNames(results);
1582
- }
1583
- // Update the data source for each returned page
1584
- for (let i = 0; i < numPages; i += 1) {
1585
- const pageStartIndex = this.pageSize * i;
1586
- this.updateDataSource(pageNumber + i, results.slice(pageStartIndex, pageStartIndex + this.pageSize));
1587
- }
1588
- }
1589
- // When we reach the end of the data, we can set the infinite scroller's
1590
- // item count to the real total number of results (rather than the
1591
- // temporary estimates based on pages rendered so far).
1592
- const resultCountDiscrepancy = numRows - results.length;
1593
- if (resultCountDiscrepancy > 0) {
1594
- this.endOfDataReached = true;
1595
- if (this.infiniteScroller) {
1596
- this.infiniteScroller.itemCount = this.totalResults;
1597
- }
1598
- }
1599
- for (let i = 0; i < numPages; i += 1) {
1600
- (_o = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _o === void 0 ? void 0 : _o.delete(pageNumber + i);
1601
- }
1602
- }
1603
- preloadCollectionNames(results) {
1604
- var _a;
1605
- const collectionIds = results
1606
- .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
1607
- .flat();
1608
- const collectionIdsArray = Array.from(new Set(collectionIds));
1609
- (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
1610
- }
1611
- /**
1612
- * Applies any default sort option for the current collection, by checking
1613
- * for one in the collection's metadata. If none is found, defaults to sorting
1614
- * descending by:
1615
- * - Date Favorited for fav-* collections
1616
- * - Weekly views for all other collections
1617
- */
1618
- applyDefaultCollectionSort(collectionInfo) {
1619
- var _a, _b, _c;
1620
- if (this.baseQuery) {
1621
- // If there's a query set, then we default to relevance sorting regardless of
1622
- // the collection metadata-specified sort.
1623
- this.defaultSortField = SortField.relevance;
1624
- this.defaultSortDirection = null;
1625
- return;
1626
- }
1627
- // Favorite collections sort on Date Favorited by default.
1628
- // Other collections fall back to sorting on weekly views.
1629
- 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-'))
1630
- ? '-favoritedate'
1631
- : '-week';
1632
- // The collection metadata may override the default sorting with something else
1633
- const metadataSort = (_c = collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.public_metadata) === null || _c === void 0 ? void 0 : _c['sort-by'];
1634
- // Prefer the metadata-specified sort if one exists
1635
- const defaultSortToApply = metadataSort !== null && metadataSort !== void 0 ? metadataSort : baseDefaultSort;
1636
- // Account for both -field and field:dir formats
1637
- let [field, dir] = defaultSortToApply.split(':');
1638
- if (field.startsWith('-')) {
1639
- field = field.slice(1);
1640
- dir = 'desc';
1641
- }
1642
- else if (!['asc', 'desc'].includes(dir)) {
1643
- dir = 'asc';
1644
- }
1645
- const sortOption = sortOptionFromAPIString(field);
1646
- const sortField = sortOption.field;
1647
- if (sortField && sortField !== SortField.default) {
1648
- this.defaultSortField = sortField;
1649
- this.defaultSortDirection = dir;
1650
- this.defaultSortParam = {
1651
- field: this.defaultSortField,
1652
- direction: this.defaultSortDirection,
1653
- };
1654
- }
1655
- }
1656
- /**
1657
- * This is useful for determining whether we need to reload the scroller.
1658
- *
1659
- * When the fetch completes, we need to reload the scroller if the cells for that
1660
- * page are visible, but if the page is not currenlty visible, we don't need to reload
1661
- */
1662
- get currentVisiblePageNumbers() {
1663
- var _a, _b;
1664
- const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
1665
- const visiblePages = new Set();
1666
- visibleCells.forEach(cellIndex => {
1667
- const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1668
- visiblePages.add(visiblePage);
1669
- });
1670
- return Array.from(visiblePages);
1671
- }
1672
- /**
1673
- * Update the datasource from the fetch response
1674
- *
1675
- * @param pageNumber
1676
- * @param results
1677
- */
1678
- updateDataSource(pageNumber, results) {
1679
- var _a;
1680
- // copy our existing datasource so when we set it below, it gets set
1681
- // instead of modifying the existing dataSource since object changes
1682
- // don't trigger a re-render
1683
- const datasource = { ...this.dataSource };
1684
- const tiles = [];
1685
- results === null || results === void 0 ? void 0 : results.forEach(result => {
1686
- 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;
1687
- if (!result.identifier)
1688
- return;
1689
- let loginRequired = false;
1690
- let contentWarning = false;
1691
- // Check if item and item in "modifying" collection, setting above flags
1692
- if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
1693
- ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
1694
- for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
1695
- if (collection === 'loggedin') {
1696
- loginRequired = true;
1697
- if (contentWarning)
1698
- break;
1699
- }
1700
- if (collection === 'no-preview') {
1701
- contentWarning = true;
1702
- if (loginRequired)
1703
- break;
1704
- }
1705
- }
1706
- }
1707
- tiles.push({
1708
- averageRating: (_e = result.avg_rating) === null || _e === void 0 ? void 0 : _e.value,
1709
- checked: false,
1710
- collections: (_g = (_f = result.collection) === null || _f === void 0 ? void 0 : _f.values) !== null && _g !== void 0 ? _g : [],
1711
- collectionFilesCount: (_j = (_h = result.collection_files_count) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : 0,
1712
- collectionSize: (_l = (_k = result.collection_size) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : 0,
1713
- commentCount: (_o = (_m = result.num_reviews) === null || _m === void 0 ? void 0 : _m.value) !== null && _o !== void 0 ? _o : 0,
1714
- creator: (_p = result.creator) === null || _p === void 0 ? void 0 : _p.value,
1715
- creators: (_r = (_q = result.creator) === null || _q === void 0 ? void 0 : _q.values) !== null && _r !== void 0 ? _r : [],
1716
- dateAdded: (_s = result.addeddate) === null || _s === void 0 ? void 0 : _s.value,
1717
- dateArchived: (_t = result.publicdate) === null || _t === void 0 ? void 0 : _t.value,
1718
- datePublished: (_u = result.date) === null || _u === void 0 ? void 0 : _u.value,
1719
- dateReviewed: (_v = result.reviewdate) === null || _v === void 0 ? void 0 : _v.value,
1720
- description: (_w = result.description) === null || _w === void 0 ? void 0 : _w.values.join('\n'),
1721
- favCount: (_y = (_x = result.num_favorites) === null || _x === void 0 ? void 0 : _x.value) !== null && _y !== void 0 ? _y : 0,
1722
- href: this.collapseRepeatedQuotes((_z = result.__href__) === null || _z === void 0 ? void 0 : _z.value),
1723
- identifier: result.identifier,
1724
- issue: (_0 = result.issue) === null || _0 === void 0 ? void 0 : _0.value,
1725
- itemCount: (_2 = (_1 = result.item_count) === null || _1 === void 0 ? void 0 : _1.value) !== null && _2 !== void 0 ? _2 : 0,
1726
- mediatype: this.getMediatype(result),
1727
- snippets: (_4 = (_3 = result.highlight) === null || _3 === void 0 ? void 0 : _3.values) !== null && _4 !== void 0 ? _4 : [],
1728
- source: (_5 = result.source) === null || _5 === void 0 ? void 0 : _5.value,
1729
- subjects: (_7 = (_6 = result.subject) === null || _6 === void 0 ? void 0 : _6.values) !== null && _7 !== void 0 ? _7 : [],
1730
- title: (_9 = (_8 = result.title) === null || _8 === void 0 ? void 0 : _8.value) !== null && _9 !== void 0 ? _9 : '',
1731
- volume: (_10 = result.volume) === null || _10 === void 0 ? void 0 : _10.value,
1732
- viewCount: (_12 = (_11 = result.downloads) === null || _11 === void 0 ? void 0 : _11.value) !== null && _12 !== void 0 ? _12 : 0,
1733
- weeklyViewCount: (_13 = result.week) === null || _13 === void 0 ? void 0 : _13.value,
1734
- loginRequired,
1735
- contentWarning,
1736
- });
1737
- });
1738
- datasource[pageNumber] = tiles;
1739
- this.dataSource = datasource;
1740
- const visiblePages = this.currentVisiblePageNumbers;
1741
- const needsReload = visiblePages.includes(pageNumber);
1742
- if (needsReload) {
1743
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1744
- }
1745
- }
1746
- getMediatype(result) {
1747
- var _a, _b, _c;
1748
- /**
1749
- * hit_type == 'favorited_search' is basically a new hit_type
1750
- * - we are getting from PPS.
1751
- * - which gives response for fav- collection
1752
- * - having favorited items like account/collection/item etc..
1753
- * - as user can also favorite a search result (a search page)
1754
- * - so we need to have response (having fav- items and fav- search results)
1755
- *
1756
- * if backend hit_type == 'favorited_search'
1757
- * - let's assume a "search" as new mediatype
1758
- */
1759
- if (((_a = result === null || result === void 0 ? void 0 : result.rawMetadata) === null || _a === void 0 ? void 0 : _a.hit_type) === 'favorited_search') {
1760
- return 'search';
1761
- }
1762
- return (_c = (_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 'data';
1763
- }
1764
- /**
1765
- * Returns the input string, but removing one set of quotes from all instances of
1766
- * ""clauses wrapped in two sets of quotes"". This assumes the quotes are already
1767
- * URL-encoded.
1768
- *
1769
- * This should be a temporary measure to address the fact that the __href__ field
1770
- * sometimes acquires extra quotation marks during query rewriting. Once there is a
1771
- * full Lucene parser in place that handles quoted queries correctly, this can likely
1772
- * be removed.
1773
- */
1774
- collapseRepeatedQuotes(str) {
1775
- return str === null || str === void 0 ? void 0 : str.replace(/%22%22(?!%22%22)(.+?)%22%22/g, '%22$1%22');
1776
- }
1777
- /** Fetches the aggregation buckets for the given prefix filter type. */
1778
- async fetchPrefixFilterBuckets(filterType) {
1779
- var _a, _b, _c, _d, _e, _f, _g;
1780
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1781
- if (!this.canPerformSearch)
1782
- return [];
1783
- const filterAggregationKey = prefixFilterAggregationKeys[filterType];
1784
- const sortParams = this.sortParam ? [this.sortParam] : [];
1785
- const params = {
1786
- ...this.collectionParams,
1787
- query: trimmedQuery || '',
1788
- rows: 0,
1789
- filters: this.filterMap,
1790
- // Only fetch the firstTitle or firstCreator aggregation
1791
- aggregations: { simpleParams: [filterAggregationKey] },
1792
- // Fetch all 26 letter buckets
1793
- aggregationsSize: 26,
1794
- };
1795
- params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1796
- const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1797
- 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 : []);
1798
- }
1799
- /** Fetches and caches the prefix filter counts for the given filter type. */
1800
- async updatePrefixFilterCounts(filterType) {
1801
- const { facetFetchQueryKey } = this;
1802
- const buckets = await this.fetchPrefixFilterBuckets(filterType);
1803
- // Don't update the filter counts for an outdated query (if it has been changed
1804
- // since we sent the request)
1805
- const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1806
- if (queryChangedSinceFetch)
1807
- return;
1808
- // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }
1809
- this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update
1810
- this.prefixFilterCountMap[filterType] = buckets.reduce((acc, bucket) => {
1811
- acc[bucket.key.toUpperCase()] = bucket.doc_count;
1812
- return acc;
1813
- }, {});
1814
- }
1815
- /**
1816
- * Fetches and caches the prefix filter counts for the current sort type,
1817
- * provided it is one that permits prefix filtering. (If not, this does nothing).
1818
- */
1819
- async updatePrefixFiltersForCurrentSort() {
1820
- if (['title', 'creator'].includes(this.selectedSort)) {
1821
- const filterType = this.selectedSort;
1822
- if (!this.prefixFilterCountMap[filterType]) {
1823
- this.updatePrefixFilterCounts(filterType);
1824
- }
1825
- }
1826
- }
1827
- /**
1828
- * Clears the cached letter counts for both title and creator, and
1829
- * fetches a new set of counts for whichever of them is the currently
1830
- * selected sort option (which may be neither).
1831
- *
1832
- * Call this whenever the counts are invalidated (e.g., by a query change).
1833
- */
1834
- refreshLetterCounts() {
1835
- if (Object.keys(this.prefixFilterCountMap).length > 0) {
1836
- this.prefixFilterCountMap = {};
1837
- }
1838
- this.updatePrefixFiltersForCurrentSort();
1839
- }
1840
- /**
1841
- * Callback when a result is selected
1842
- */
1843
- resultSelected(event) {
1844
- var _a, _b, _c;
1845
- if (this.isManageView) {
1846
- // Checked/unchecked state change -- rerender to ensure it propagates
1847
- // this.mapDataSource(model => ({ ...model }));
1848
- const cellIndex = Object.values(this.dataSource)
1849
- .flat()
1850
- .indexOf(event.detail);
1851
- if (cellIndex >= 0)
1852
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshCell(cellIndex - this.tileModelOffset);
1853
- }
1854
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1855
- category: this.searchContext,
1856
- action: analyticsActions.resultSelected,
1857
- label: event.detail.mediatype,
1858
- });
1859
- (_c = this.analyticsHandler) === null || _c === void 0 ? void 0 : _c.sendEvent({
1860
- category: this.searchContext,
1861
- action: analyticsActions.resultSelected,
1862
- label: `page-${this.currentPage}`,
1863
- });
1864
- }
1865
- cellForIndex(index) {
1866
- const model = this.tileModelAtCellIndex(index);
1867
- if (!model)
1868
- return undefined;
807
+ `;
808
+ }
809
+ histogramDateRangeUpdated(e) {
810
+ var _a;
811
+ const { minDate, maxDate } = e.detail;
812
+ [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
813
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
814
+ category: this.searchContext,
815
+ action: analyticsActions.histogramChanged,
816
+ label: this.dateRangeQueryClause,
817
+ });
818
+ }
819
+ get dateRangeQueryClause() {
820
+ if (!this.minSelectedDate || !this.maxSelectedDate) {
821
+ return undefined;
822
+ }
823
+ return `year:[${this.minSelectedDate} TO ${this.maxSelectedDate}]`;
824
+ }
825
+ /**
826
+ * Emits an event indicating a change in whether the manage mode is shown.
827
+ */
828
+ emitManageModeChangedEvent() {
829
+ this.dispatchEvent(new CustomEvent('manageModeChanged', {
830
+ detail: this.isManageView,
831
+ }));
832
+ }
833
+ firstUpdated() {
834
+ this.setupStateRestorationObserver();
835
+ this.restoreState();
836
+ }
837
+ updated(changed) {
838
+ var _a, _b;
839
+ if (changed.has('placeholderType') && this.placeholderType === null) {
840
+ if (!this.leftColIntersectionObserver) {
841
+ this.setupLeftColumnScrollListeners();
842
+ }
843
+ if (!this.facetsIntersectionObserver) {
844
+ this.setupFacetsScrollListeners();
845
+ }
846
+ this.updateLeftColumnHeight();
847
+ }
848
+ if (changed.has('displayMode') ||
849
+ changed.has('baseNavigationUrl') ||
850
+ changed.has('baseImageUrl') ||
851
+ changed.has('loggedIn')) {
852
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
853
+ }
854
+ if (changed.has('baseQuery') ||
855
+ changed.has('searchType') ||
856
+ changed.has('withinCollection')) {
857
+ // Unless this query/search type update is from the initial page load or the
858
+ // result of hitting the back button,
859
+ // we need to clear any existing filters since they may no longer be valid for
860
+ // the new set of search results.
861
+ if (!this.historyPopOccurred && this.initialQueryChangeHappened) {
862
+ // Ordinarily, we leave the sort param unchanged between searches.
863
+ // However, if we are changing the target collection itself, we want the sort cleared too,
864
+ // since different collections may have different sorting options available.
865
+ const shouldClearSort = changed.has('withinCollection') &&
866
+ !changed.has('selectedSort') &&
867
+ !changed.has('sortDirection');
868
+ // Otherwise, only clear filters that haven't been simultaneously applied in this update
869
+ this.clearFilters({
870
+ sort: shouldClearSort,
871
+ facets: !changed.has('selectedFacets'),
872
+ dateRange: !(changed.has('minSelectedDate') || changed.has('maxSelectedDate')),
873
+ letterFilters: !(changed.has('selectedTitleFilter') ||
874
+ changed.has('selectedCreatorFilter')),
875
+ });
876
+ }
877
+ }
878
+ if (changed.has('baseQuery')) {
879
+ this.emitBaseQueryChanged();
880
+ }
881
+ if (changed.has('searchType')) {
882
+ this.emitSearchTypeChanged();
883
+ }
884
+ if (changed.has('currentPage') || changed.has('displayMode')) {
885
+ this.persistState();
886
+ }
887
+ if (changed.has('baseQuery') ||
888
+ changed.has('minSelectedDate') ||
889
+ changed.has('maxSelectedDate') ||
890
+ changed.has('selectedFacets') ||
891
+ changed.has('searchService') ||
892
+ changed.has('withinCollection')) {
893
+ this.refreshLetterCounts();
894
+ }
895
+ if (changed.has('selectedSort') || changed.has('sortDirection')) {
896
+ const prevSortDirection = changed.get('sortDirection');
897
+ this.sendSortByAnalytics(prevSortDirection);
898
+ this.selectedSortChanged();
899
+ }
900
+ if (changed.has('selectedTitleFilter')) {
901
+ this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
902
+ }
903
+ if (changed.has('selectedCreatorFilter')) {
904
+ this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
905
+ }
906
+ if (changed.has('baseQuery') ||
907
+ changed.has('searchType') ||
908
+ changed.has('selectedTitleFilter') ||
909
+ changed.has('selectedCreatorFilter') ||
910
+ changed.has('minSelectedDate') ||
911
+ changed.has('maxSelectedDate') ||
912
+ changed.has('sortParam') ||
913
+ changed.has('selectedFacets') ||
914
+ changed.has('searchService') ||
915
+ changed.has('withinCollection')) {
916
+ this.handleQueryChange();
917
+ }
918
+ if (changed.has('searchResultsLoading')) {
919
+ this.emitSearchResultsLoadingChanged();
920
+ }
921
+ if (changed.has('facetsLoading') &&
922
+ this.facetsLoading &&
923
+ this.collectionFacets) {
924
+ this.collectionFacets.moreLinksVisible =
925
+ this.searchType !== SearchType.FULLTEXT;
926
+ }
927
+ if (changed.has('pagesToRender')) {
928
+ if (!this.endOfDataReached && this.infiniteScroller) {
929
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
930
+ }
931
+ }
932
+ if (changed.has('isManageView')) {
933
+ if (this.isManageView)
934
+ this.displayMode = 'grid';
935
+ (_b = this.infiniteScroller) === null || _b === void 0 ? void 0 : _b.refreshAllVisibleCells();
936
+ this.emitManageModeChangedEvent();
937
+ }
938
+ if (changed.has('resizeObserver')) {
939
+ const oldObserver = changed.get('resizeObserver');
940
+ if (oldObserver)
941
+ this.disconnectResizeObserver(oldObserver);
942
+ this.setupResizeObserver();
943
+ }
944
+ }
945
+ disconnectedCallback() {
946
+ var _a, _b;
947
+ if (this.resizeObserver) {
948
+ this.disconnectResizeObserver(this.resizeObserver);
949
+ }
950
+ if (this.boundNavigationHandler) {
951
+ window.removeEventListener('popstate', this.boundNavigationHandler);
952
+ }
953
+ (_a = this.leftColIntersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
954
+ (_b = this.facetsIntersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
955
+ window.removeEventListener('resize', this.updateLeftColumnHeight);
956
+ }
957
+ handleResize(entry) {
958
+ const previousView = this.mobileView;
959
+ if (entry.target === this.contentContainer) {
960
+ this.contentWidth = entry.contentRect.width;
961
+ this.mobileView =
962
+ this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
963
+ // If changing from desktop to mobile disable transition
964
+ if (this.mobileView && !previousView) {
965
+ this.isResizeToMobile = true;
966
+ }
967
+ }
968
+ // Ensure the facet sidebar remains sized correctly
969
+ this.updateLeftColumnHeight();
970
+ }
971
+ /**
972
+ * Sets up listeners for events that may require updating the left column height.
973
+ */
974
+ setupLeftColumnScrollListeners() {
975
+ var _a;
976
+ // We observe intersections between the left column's scroll sentinel and
977
+ // the viewport, so that we can ensure the left column is always sized to
978
+ // match the _available_ viewport height. This should generally be more
979
+ // performant than listening to scroll events on the page or column.
980
+ const leftColumnSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#left-column-scroll-sentinel');
981
+ if (leftColumnSentinel) {
982
+ this.leftColIntersectionObserver = new IntersectionObserver(this.updateLeftColumnHeight, {
983
+ threshold: [...Array(101).keys()].map(n => n / 100), // Threshold every 1%
984
+ });
985
+ this.leftColIntersectionObserver.observe(leftColumnSentinel);
986
+ }
987
+ // We also listen for window resize events, as they are not always captured
988
+ // by the resize observer and can affect the desired height of the left column.
989
+ window.addEventListener('resize', this.updateLeftColumnHeight);
990
+ }
991
+ /**
992
+ * Sets up listeners to control whether the facet sidebar shows its bottom fade-out.
993
+ * Note this uses a separate IntersectionObserver from the left column, because we
994
+ * don't need granular intersection thresholds for this.
995
+ */
996
+ setupFacetsScrollListeners() {
997
+ var _a;
998
+ const facetsSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#facets-scroll-sentinel');
999
+ if (facetsSentinel) {
1000
+ this.facetsIntersectionObserver = new IntersectionObserver(this.updateFacetFadeOut);
1001
+ this.facetsIntersectionObserver.observe(facetsSentinel);
1002
+ }
1003
+ }
1004
+ emitBaseQueryChanged() {
1005
+ this.dispatchEvent(new CustomEvent('baseQueryChanged', {
1006
+ detail: {
1007
+ baseQuery: this.baseQuery,
1008
+ },
1009
+ }));
1010
+ }
1011
+ emitSearchTypeChanged() {
1012
+ this.dispatchEvent(new CustomEvent('searchTypeChanged', {
1013
+ detail: this.searchType,
1014
+ }));
1015
+ }
1016
+ emitEmptyResults() {
1017
+ this.dispatchEvent(new Event('emptyResults'));
1018
+ }
1019
+ disconnectResizeObserver(resizeObserver) {
1020
+ resizeObserver.removeObserver({
1021
+ target: this.contentContainer,
1022
+ handler: this,
1023
+ });
1024
+ }
1025
+ setupResizeObserver() {
1026
+ if (!this.resizeObserver)
1027
+ return;
1028
+ this.resizeObserver.addObserver({
1029
+ target: this.contentContainer,
1030
+ handler: this,
1031
+ });
1032
+ }
1033
+ /**
1034
+ * When the visible cells change from the infinite scroller, we want to emit
1035
+ * which page is currently visible so the consumer can update its UI or the URL
1036
+ *
1037
+ * @param e
1038
+ * @returns
1039
+ */
1040
+ visibleCellsChanged(e) {
1041
+ if (this.isScrollingToCell)
1042
+ return;
1043
+ const { visibleCellIndices } = e.detail;
1044
+ if (visibleCellIndices.length === 0)
1045
+ return;
1046
+ const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
1047
+ const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
1048
+ if (this.currentPage !== lastVisibleCellPage) {
1049
+ this.currentPage = lastVisibleCellPage;
1050
+ }
1051
+ const event = new CustomEvent('visiblePageChanged', {
1052
+ detail: {
1053
+ pageNumber: lastVisibleCellPage,
1054
+ },
1055
+ });
1056
+ this.dispatchEvent(event);
1057
+ }
1058
+ /**
1059
+ * A Promise which, after each query change, resolves once the fetches for the initial
1060
+ * search have completed. Waits for *both* the hits and aggregations fetches to finish.
1061
+ *
1062
+ * Ensure you await this component's `updateComplete` promise before awaiting this
1063
+ * one, to ensure you do not await an obsolete promise from the previous update.
1064
+ */
1065
+ get initialSearchComplete() {
1066
+ return this._initialSearchCompletePromise;
1067
+ }
1068
+ async handleQueryChange() {
1069
+ var _a;
1070
+ // only reset if the query has actually changed
1071
+ if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
1072
+ return;
1073
+ // If the new state prevents us from updating the search results, don't reset
1074
+ if (!this.canPerformSearch &&
1075
+ !(this.clearResultsOnEmptyQuery && this.baseQuery === ''))
1076
+ return;
1077
+ this.previousQueryKey = this.pageFetchQueryKey;
1078
+ this.dataSource = {};
1079
+ this.tileModelOffset = 0;
1080
+ this.totalResults = undefined;
1081
+ this.aggregations = undefined;
1082
+ this.fullYearsHistogramAggregation = undefined;
1083
+ this.pageFetchesInProgress = {};
1084
+ this.endOfDataReached = false;
1085
+ this.pagesToRender =
1086
+ this.initialPageNumber === 1
1087
+ ? 2 // First two pages are batched into one request when starting from page 1
1088
+ : this.initialPageNumber;
1089
+ this.queryErrorMessage = undefined;
1090
+ // Reset the infinite scroller's item count, so that it
1091
+ // shows tile placeholders until the new query's results load in
1092
+ if (this.infiniteScroller) {
1093
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
1094
+ this.infiniteScroller.reload();
1095
+ }
1096
+ if (this.withinCollection && ((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
1097
+ this.defaultSortField = SortField.relevance;
1098
+ this.defaultSortDirection = null;
1099
+ }
1100
+ if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
1101
+ this.scrollToPage(this.initialPageNumber);
1102
+ }
1103
+ this.initialQueryChangeHappened = true;
1104
+ // if the query changed as part of a window.history pop event, we don't want to
1105
+ // persist the state because it overwrites the forward history
1106
+ if (!this.historyPopOccurred) {
1107
+ this.persistState();
1108
+ }
1109
+ this.historyPopOccurred = false;
1110
+ // Reset the `initialSearchComplete` promise with a new value for the imminent search
1111
+ this._initialSearchCompletePromise = new Promise(res => {
1112
+ this._initialSearchCompleteResolver = res;
1113
+ });
1114
+ // Fire the initial page and facets requests
1115
+ await Promise.all([this.doInitialPageFetch(), this.fetchFacets()]);
1116
+ // Resolve the `initialSearchComplete` promise for this search
1117
+ this._initialSearchCompleteResolver(true);
1118
+ }
1119
+ setupStateRestorationObserver() {
1120
+ if (this.boundNavigationHandler)
1121
+ return;
1122
+ this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
1123
+ // when the user navigates back, we want to update the UI to match the URL
1124
+ window.addEventListener('popstate', this.boundNavigationHandler);
1125
+ }
1126
+ historyNavigationHandler() {
1127
+ this.historyPopOccurred = true;
1128
+ this.restoreState();
1129
+ }
1130
+ restoreState() {
1131
+ var _a, _b, _c, _d, _e;
1132
+ const restorationState = this.restorationStateHandler.getRestorationState();
1133
+ this.displayMode = restorationState.displayMode;
1134
+ if (restorationState.searchType != null)
1135
+ this.searchType = restorationState.searchType;
1136
+ this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.default;
1137
+ this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
1138
+ this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
1139
+ this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
1140
+ this.selectedFacets = restorationState.selectedFacets;
1141
+ this.baseQuery = restorationState.baseQuery;
1142
+ this.currentPage = (_e = restorationState.currentPage) !== null && _e !== void 0 ? _e : 1;
1143
+ this.minSelectedDate = restorationState.minSelectedDate;
1144
+ this.maxSelectedDate = restorationState.maxSelectedDate;
1145
+ if (this.currentPage > 1) {
1146
+ this.goToPage(this.currentPage);
1147
+ }
1148
+ }
1149
+ persistState() {
1150
+ var _a, _b, _c, _d;
1151
+ const restorationState = {
1152
+ displayMode: this.displayMode,
1153
+ searchType: this.searchType,
1154
+ selectedSort: this.selectedSort,
1155
+ sortDirection: (_a = this.sortDirection) !== null && _a !== void 0 ? _a : undefined,
1156
+ selectedFacets: (_b = this.selectedFacets) !== null && _b !== void 0 ? _b : getDefaultSelectedFacets(),
1157
+ baseQuery: this.baseQuery,
1158
+ currentPage: this.currentPage,
1159
+ titleQuery: this.titleQuery,
1160
+ creatorQuery: this.creatorQuery,
1161
+ minSelectedDate: this.minSelectedDate,
1162
+ maxSelectedDate: this.maxSelectedDate,
1163
+ selectedTitleFilter: (_c = this.selectedTitleFilter) !== null && _c !== void 0 ? _c : undefined,
1164
+ selectedCreatorFilter: (_d = this.selectedCreatorFilter) !== null && _d !== void 0 ? _d : undefined,
1165
+ };
1166
+ this.restorationStateHandler.persistState(restorationState);
1167
+ }
1168
+ async doInitialPageFetch() {
1169
+ this.searchResultsLoading = true;
1170
+ // Try to batch 2 initial page requests when possible
1171
+ await this.fetchPage(this.initialPageNumber, 2);
1172
+ this.searchResultsLoading = false;
1173
+ }
1174
+ emitSearchResultsLoadingChanged() {
1175
+ this.dispatchEvent(new CustomEvent('searchResultsLoadingChanged', {
1176
+ detail: {
1177
+ loading: this.searchResultsLoading,
1178
+ },
1179
+ }));
1180
+ }
1181
+ /**
1182
+ * Produces a compact unique ID for a search request that can help with debugging
1183
+ * on the backend by making related requests easier to trace through different services.
1184
+ * (e.g., tying the hits/aggregations requests for the same page back to a single hash).
1185
+ *
1186
+ * @param params The search service parameters for the request
1187
+ * @param kind The kind of request (hits-only, aggregations-only, or both)
1188
+ * @returns A Promise resolving to the uid to apply to the request
1189
+ */
1190
+ async requestUID(params, kind) {
1191
+ var _a;
1192
+ const paramsToHash = JSON.stringify({
1193
+ pageType: params.pageType,
1194
+ pageTarget: params.pageTarget,
1195
+ query: params.query,
1196
+ fields: params.fields,
1197
+ filters: params.filters,
1198
+ sort: params.sort,
1199
+ searchType: this.searchType,
1200
+ });
1201
+ const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this
1202
+ const sessionId = (await this.getSessionId()).slice(0, 20); // Likewise
1203
+ const page = (_a = params.page) !== null && _a !== void 0 ? _a : 0;
1204
+ const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations
1205
+ const currentTime = Date.now();
1206
+ return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;
1207
+ }
1208
+ /**
1209
+ * Constructs a search service FilterMap object from the combination of
1210
+ * all the currently-applied filters. This includes any facets, letter
1211
+ * filters, and date range.
1212
+ */
1213
+ get filterMap() {
1214
+ const builder = new FilterMapBuilder();
1215
+ // Add the date range, if applicable
1216
+ if (this.minSelectedDate) {
1217
+ builder.addFilter('year', this.minSelectedDate, FilterConstraint.GREATER_OR_EQUAL);
1218
+ }
1219
+ if (this.maxSelectedDate) {
1220
+ builder.addFilter('year', this.maxSelectedDate, FilterConstraint.LESS_OR_EQUAL);
1221
+ }
1222
+ // Add any selected facets
1223
+ if (this.selectedFacets) {
1224
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1225
+ const { name, values } = this.prepareFacetForFetch(facetName, facetValues);
1226
+ for (const [value, bucket] of Object.entries(values)) {
1227
+ let constraint;
1228
+ if (bucket.state === 'selected') {
1229
+ constraint = FilterConstraint.INCLUDE;
1230
+ }
1231
+ else if (bucket.state === 'hidden') {
1232
+ constraint = FilterConstraint.EXCLUDE;
1233
+ }
1234
+ if (constraint) {
1235
+ builder.addFilter(name, value, constraint);
1236
+ }
1237
+ }
1238
+ }
1239
+ }
1240
+ // Add any letter filters
1241
+ if (this.selectedTitleFilter) {
1242
+ builder.addFilter('firstTitle', this.selectedTitleFilter, FilterConstraint.INCLUDE);
1243
+ }
1244
+ if (this.selectedCreatorFilter) {
1245
+ builder.addFilter('firstCreator', this.selectedCreatorFilter, FilterConstraint.INCLUDE);
1246
+ }
1247
+ const filterMap = builder.build();
1248
+ return filterMap;
1249
+ }
1250
+ /** The full query, including year facets and date range clauses */
1251
+ get fullQuery() {
1252
+ var _a, _b;
1253
+ let fullQuery = (_b = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
1254
+ const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;
1255
+ if (facetQuery) {
1256
+ fullQuery += ` AND ${facetQuery}`;
1257
+ }
1258
+ if (dateRangeQueryClause) {
1259
+ fullQuery += ` AND ${dateRangeQueryClause}`;
1260
+ }
1261
+ if (sortFilterQueries) {
1262
+ fullQuery += ` AND ${sortFilterQueries}`;
1263
+ }
1264
+ return fullQuery.trim();
1265
+ }
1266
+ /**
1267
+ * Generates a query string for the given facets
1268
+ *
1269
+ * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
1270
+ */
1271
+ get facetQuery() {
1272
+ var _a;
1273
+ if (!this.selectedFacets)
1274
+ return undefined;
1275
+ const facetClauses = [];
1276
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1277
+ facetClauses.push(this.buildFacetClause(facetName, facetValues));
1278
+ }
1279
+ return (_a = this.joinFacetClauses(facetClauses)) === null || _a === void 0 ? void 0 : _a.trim();
1280
+ }
1281
+ /**
1282
+ * Builds an OR-joined facet clause for the given facet name and values.
1283
+ *
1284
+ * E.g., for name `subject` and values
1285
+ * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`
1286
+ * this will produce the clause
1287
+ * `subject:("foo" OR -"bar")`.
1288
+ *
1289
+ * @param facetName The facet type (e.g., 'collection')
1290
+ * @param facetValues The facet buckets, mapped by their keys
1291
+ */
1292
+ buildFacetClause(facetName, facetValues) {
1293
+ const { name: facetQueryName, values } = this.prepareFacetForFetch(facetName, facetValues);
1294
+ const facetEntries = Object.entries(values);
1295
+ if (facetEntries.length === 0)
1296
+ return '';
1297
+ const facetValuesArray = [];
1298
+ for (const [key, facetData] of facetEntries) {
1299
+ const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
1300
+ facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
1301
+ }
1302
+ const valueQuery = facetValuesArray.join(` OR `);
1303
+ return `${facetQueryName}:(${valueQuery})`;
1304
+ }
1305
+ /**
1306
+ * Handles some special pre-request normalization steps for certain facet types
1307
+ * that require them.
1308
+ *
1309
+ * @param facetName The name of the facet type (e.g., 'language')
1310
+ * @param facetValues An array of values for that facet type
1311
+ */
1312
+ prepareFacetForFetch(facetName, facetValues) {
1313
+ // eslint-disable-next-line prefer-const
1314
+ let [normalizedName, normalizedValues] = [facetName, facetValues];
1315
+ // The full "search engine" name of the lending field is "lending___status"
1316
+ if (facetName === 'lending') {
1317
+ normalizedName = 'lending___status';
1318
+ }
1319
+ return {
1320
+ name: normalizedName,
1321
+ values: normalizedValues,
1322
+ };
1323
+ }
1324
+ /**
1325
+ * Takes an array of facet clauses, and combines them into a
1326
+ * full AND-joined facet query string. Empty clauses are ignored.
1327
+ */
1328
+ joinFacetClauses(facetClauses) {
1329
+ const nonEmptyFacetClauses = facetClauses.filter(clause => clause.length > 0);
1330
+ return nonEmptyFacetClauses.length > 0
1331
+ ? `(${nonEmptyFacetClauses.join(' AND ')})`
1332
+ : undefined;
1333
+ }
1334
+ facetsChanged(e) {
1335
+ this.selectedFacets = e.detail;
1336
+ }
1337
+ facetClickHandler({ detail: { key, state: facetState, negative }, }) {
1338
+ var _a, _b;
1339
+ if (negative) {
1340
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1341
+ category: this.searchContext,
1342
+ action: facetState !== 'none'
1343
+ ? analyticsActions.facetNegativeSelected
1344
+ : analyticsActions.facetNegativeDeselected,
1345
+ label: key,
1346
+ });
1347
+ }
1348
+ else {
1349
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1350
+ category: this.searchContext,
1351
+ action: facetState !== 'none'
1352
+ ? analyticsActions.facetSelected
1353
+ : analyticsActions.facetDeselected,
1354
+ label: key,
1355
+ });
1356
+ }
1357
+ }
1358
+ async fetchFacets() {
1359
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1360
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1361
+ if (!this.canPerformSearch)
1362
+ return;
1363
+ const { facetFetchQueryKey } = this;
1364
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1365
+ const params = {
1366
+ ...this.collectionParams,
1367
+ query: trimmedQuery || '',
1368
+ rows: 0,
1369
+ filters: this.filterMap,
1370
+ // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
1371
+ aggregationsSize: 10,
1372
+ // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
1373
+ // The default aggregations for the search_results page type should be what we need here.
1374
+ };
1375
+ params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1376
+ this.facetsLoading = true;
1377
+ const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1378
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1379
+ // This is checking to see if the query has changed since the data was fetched.
1380
+ // If so, we just want to discard this set of aggregations because they are
1381
+ // likely no longer valid for the newer query.
1382
+ const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1383
+ if (queryChangedSinceFetch)
1384
+ return;
1385
+ if (!success) {
1386
+ const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
1387
+ 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;
1388
+ if (!errorMsg && !detailMsg) {
1389
+ // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1390
+ (_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');
1391
+ }
1392
+ return;
1393
+ }
1394
+ const { aggregations, collectionTitles } = success.response;
1395
+ this.aggregations = aggregations;
1396
+ if (collectionTitles) {
1397
+ (_h = this.collectionNameCache) === null || _h === void 0 ? void 0 : _h.addKnownTitles(collectionTitles);
1398
+ }
1399
+ else if ((_j = this.aggregations) === null || _j === void 0 ? void 0 : _j.collection) {
1400
+ (_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(); }));
1401
+ }
1402
+ this.fullYearsHistogramAggregation =
1403
+ (_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;
1404
+ this.facetsLoading = false;
1405
+ }
1406
+ scrollToPage(pageNumber) {
1407
+ return new Promise(resolve => {
1408
+ const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1409
+ // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1410
+ // then scrolls to the cell
1411
+ setTimeout(() => {
1412
+ var _a;
1413
+ this.isScrollingToCell = true;
1414
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.scrollToCell(cellIndexToScrollTo, true);
1415
+ // This timeout is to give the scroll animation time to finish
1416
+ // then updating the infinite scroller once we're done scrolling
1417
+ // There's no scroll animation completion callback so we're
1418
+ // giving it 0.5s to finish.
1419
+ setTimeout(() => {
1420
+ var _a;
1421
+ this.isScrollingToCell = false;
1422
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1423
+ resolve();
1424
+ }, 500);
1425
+ }, 0);
1426
+ });
1427
+ }
1428
+ /**
1429
+ * Whether sorting by relevance makes sense for the current state.
1430
+ * Currently equivalent to having a non-empty query.
1431
+ */
1432
+ get isRelevanceSortAvailable() {
1433
+ var _a;
1434
+ return !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
1435
+ }
1436
+ /**
1437
+ * Whether a search may be performed in the current state of the component.
1438
+ * This is only true if the search service is defined, and either
1439
+ * (a) a non-empty query is set, or
1440
+ * (b) we are on a collection page in metadata search mode.
1441
+ */
1442
+ get canPerformSearch() {
1443
+ var _a;
1444
+ if (!this.searchService)
1445
+ return false;
1446
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1447
+ const hasNonEmptyQuery = !!trimmedQuery;
1448
+ const isCollectionSearch = !!this.withinCollection;
1449
+ const isMetadataSearch = this.searchType === SearchType.METADATA;
1450
+ // Metadata searches within a collection are allowed to have no query.
1451
+ // Otherwise, a non-empty query must be set.
1452
+ return hasNonEmptyQuery || (isCollectionSearch && isMetadataSearch);
1453
+ }
1454
+ /**
1455
+ * Additional params to pass to the search service if targeting a collection page,
1456
+ * or null otherwise.
1457
+ */
1458
+ get collectionParams() {
1459
+ return this.withinCollection
1460
+ ? { pageType: 'collection_details', pageTarget: this.withinCollection }
1461
+ : null;
1462
+ }
1463
+ /**
1464
+ * The query key is a string that uniquely identifies the current search.
1465
+ * It consists of:
1466
+ * - The current base query
1467
+ * - The current collection
1468
+ * - The current search type
1469
+ * - Any currently-applied facets
1470
+ * - Any currently-applied date range
1471
+ * - Any currently-applied prefix filters
1472
+ * - The current sort options
1473
+ *
1474
+ * This lets us keep track of queries so we don't persist data that's
1475
+ * no longer relevant.
1476
+ */
1477
+ get pageFetchQueryKey() {
1478
+ var _a, _b, _c, _d;
1479
+ const sortField = (_b = (_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : 'none';
1480
+ const sortDirection = (_d = (_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.direction) !== null && _d !== void 0 ? _d : 'none';
1481
+ return `${this.fullQuery}-${this.withinCollection}-${this.searchType}-${sortField}-${sortDirection}`;
1482
+ }
1483
+ /**
1484
+ * Similar to `pageFetchQueryKey` above, but excludes sort fields since they
1485
+ * are not relevant in determining aggregation queries.
1486
+ */
1487
+ get facetFetchQueryKey() {
1488
+ return `${this.fullQuery}-${this.withinCollection}-${this.searchType}`;
1489
+ }
1490
+ /**
1491
+ * Fetches one or more pages of results and updates the data source.
1492
+ *
1493
+ * @param pageNumber The page number to fetch
1494
+ * @param numInitialPages If this is an initial page fetch (`pageNumber = 1`),
1495
+ * specifies how many pages to batch together in one request. Ignored
1496
+ * if `pageNumber != 1`, defaulting to a single page.
1497
+ */
1498
+ async fetchPage(pageNumber, numInitialPages = 1) {
1499
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
1500
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1501
+ if (!this.canPerformSearch)
1502
+ return;
1503
+ // if we already have data, don't fetch again
1504
+ if (this.dataSource[pageNumber])
1505
+ return;
1506
+ if (this.endOfDataReached)
1507
+ return;
1508
+ // Batch multiple initial page requests together if needed (e.g., can request
1509
+ // pages 1 and 2 together in a single request).
1510
+ const numPages = pageNumber === 1 ? numInitialPages : 1;
1511
+ const numRows = this.pageSize * numPages;
1512
+ // if a fetch is already in progress for this query and page, don't fetch again
1513
+ const { pageFetchQueryKey } = this;
1514
+ const pageFetches = (_b = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _b !== void 0 ? _b : new Set();
1515
+ if (pageFetches.has(pageNumber))
1516
+ return;
1517
+ for (let i = 0; i < numPages; i += 1) {
1518
+ pageFetches.add(pageNumber + i);
1519
+ }
1520
+ this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
1521
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1522
+ const params = {
1523
+ ...this.collectionParams,
1524
+ query: trimmedQuery || '',
1525
+ page: pageNumber,
1526
+ rows: numRows,
1527
+ sort: sortParams,
1528
+ filters: this.filterMap,
1529
+ aggregations: { omit: true },
1530
+ };
1531
+ params.uid = await this.requestUID(params, 'hits');
1532
+ const searchResponse = await ((_c = this.searchService) === null || _c === void 0 ? void 0 : _c.search(params, this.searchType));
1533
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1534
+ // This is checking to see if the query has changed since the data was fetched.
1535
+ // If so, we just want to discard the data since there should be a new query
1536
+ // right behind it.
1537
+ const queryChangedSinceFetch = pageFetchQueryKey !== this.pageFetchQueryKey;
1538
+ if (queryChangedSinceFetch)
1539
+ return;
1540
+ if (!success) {
1541
+ const errorMsg = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.message;
1542
+ 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;
1543
+ this.queryErrorMessage = `${errorMsg !== null && errorMsg !== void 0 ? errorMsg : ''}${detailMsg ? `; ${detailMsg}` : ''}`;
1544
+ if (!this.queryErrorMessage) {
1545
+ this.queryErrorMessage = 'Missing or malformed response from backend';
1546
+ // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1547
+ (_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');
1548
+ }
1549
+ for (let i = 0; i < numPages; i += 1) {
1550
+ (_j = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _j === void 0 ? void 0 : _j.delete(pageNumber + i);
1551
+ }
1552
+ this.searchResultsLoading = false;
1553
+ return;
1554
+ }
1555
+ this.totalResults = success.response.totalResults - this.tileModelOffset;
1556
+ // display event to offshoot when result count is zero.
1557
+ if (this.totalResults === 0) {
1558
+ this.emitEmptyResults();
1559
+ }
1560
+ if (this.withinCollection) {
1561
+ this.collectionInfo = success.response.collectionExtraInfo;
1562
+ // For collections, we want the UI to respect the default sort option
1563
+ // which can be specified in metadata, or otherwise assumed to be week:desc
1564
+ this.applyDefaultCollectionSort(this.collectionInfo);
1565
+ if (this.collectionInfo) {
1566
+ this.parentCollections = [].concat((_l = (_k = this.collectionInfo.public_metadata) === null || _k === void 0 ? void 0 : _k.collection) !== null && _l !== void 0 ? _l : []);
1567
+ }
1568
+ }
1569
+ const { results, collectionTitles } = success.response;
1570
+ if (results && results.length > 0) {
1571
+ // Load any collection titles present on the response into the cache,
1572
+ // or queue up preload fetches for them if none were present.
1573
+ if (collectionTitles) {
1574
+ (_m = this.collectionNameCache) === null || _m === void 0 ? void 0 : _m.addKnownTitles(collectionTitles);
1575
+ }
1576
+ else {
1577
+ this.preloadCollectionNames(results);
1578
+ }
1579
+ // Update the data source for each returned page
1580
+ for (let i = 0; i < numPages; i += 1) {
1581
+ const pageStartIndex = this.pageSize * i;
1582
+ this.updateDataSource(pageNumber + i, results.slice(pageStartIndex, pageStartIndex + this.pageSize));
1583
+ }
1584
+ }
1585
+ // When we reach the end of the data, we can set the infinite scroller's
1586
+ // item count to the real total number of results (rather than the
1587
+ // temporary estimates based on pages rendered so far).
1588
+ const resultCountDiscrepancy = numRows - results.length;
1589
+ if (resultCountDiscrepancy > 0) {
1590
+ this.endOfDataReached = true;
1591
+ if (this.infiniteScroller) {
1592
+ this.infiniteScroller.itemCount = this.totalResults;
1593
+ }
1594
+ }
1595
+ for (let i = 0; i < numPages; i += 1) {
1596
+ (_o = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _o === void 0 ? void 0 : _o.delete(pageNumber + i);
1597
+ }
1598
+ }
1599
+ preloadCollectionNames(results) {
1600
+ var _a;
1601
+ const collectionIds = results
1602
+ .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
1603
+ .flat();
1604
+ const collectionIdsArray = Array.from(new Set(collectionIds));
1605
+ (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
1606
+ }
1607
+ /**
1608
+ * Applies any default sort option for the current collection, by checking
1609
+ * for one in the collection's metadata. If none is found, defaults to sorting
1610
+ * descending by:
1611
+ * - Date Favorited for fav-* collections
1612
+ * - Weekly views for all other collections
1613
+ */
1614
+ applyDefaultCollectionSort(collectionInfo) {
1615
+ var _a, _b, _c;
1616
+ if (this.baseQuery) {
1617
+ // If there's a query set, then we default to relevance sorting regardless of
1618
+ // the collection metadata-specified sort.
1619
+ this.defaultSortField = SortField.relevance;
1620
+ this.defaultSortDirection = null;
1621
+ return;
1622
+ }
1623
+ // Favorite collections sort on Date Favorited by default.
1624
+ // Other collections fall back to sorting on weekly views.
1625
+ 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-'))
1626
+ ? '-favoritedate'
1627
+ : '-week';
1628
+ // The collection metadata may override the default sorting with something else
1629
+ const metadataSort = (_c = collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.public_metadata) === null || _c === void 0 ? void 0 : _c['sort-by'];
1630
+ // Prefer the metadata-specified sort if one exists
1631
+ const defaultSortToApply = metadataSort !== null && metadataSort !== void 0 ? metadataSort : baseDefaultSort;
1632
+ // Account for both -field and field:dir formats
1633
+ let [field, dir] = defaultSortToApply.split(':');
1634
+ if (field.startsWith('-')) {
1635
+ field = field.slice(1);
1636
+ dir = 'desc';
1637
+ }
1638
+ else if (!['asc', 'desc'].includes(dir)) {
1639
+ dir = 'asc';
1640
+ }
1641
+ const sortOption = sortOptionFromAPIString(field);
1642
+ const sortField = sortOption.field;
1643
+ if (sortField && sortField !== SortField.default) {
1644
+ this.defaultSortField = sortField;
1645
+ this.defaultSortDirection = dir;
1646
+ this.defaultSortParam = {
1647
+ field: this.defaultSortField,
1648
+ direction: this.defaultSortDirection,
1649
+ };
1650
+ }
1651
+ }
1652
+ /**
1653
+ * This is useful for determining whether we need to reload the scroller.
1654
+ *
1655
+ * When the fetch completes, we need to reload the scroller if the cells for that
1656
+ * page are visible, but if the page is not currenlty visible, we don't need to reload
1657
+ */
1658
+ get currentVisiblePageNumbers() {
1659
+ var _a, _b;
1660
+ const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
1661
+ const visiblePages = new Set();
1662
+ visibleCells.forEach(cellIndex => {
1663
+ const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1664
+ visiblePages.add(visiblePage);
1665
+ });
1666
+ return Array.from(visiblePages);
1667
+ }
1668
+ /**
1669
+ * Update the datasource from the fetch response
1670
+ *
1671
+ * @param pageNumber
1672
+ * @param results
1673
+ */
1674
+ updateDataSource(pageNumber, results) {
1675
+ var _a;
1676
+ // copy our existing datasource so when we set it below, it gets set
1677
+ // instead of modifying the existing dataSource since object changes
1678
+ // don't trigger a re-render
1679
+ const datasource = { ...this.dataSource };
1680
+ const tiles = [];
1681
+ results === null || results === void 0 ? void 0 : results.forEach(result => {
1682
+ 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;
1683
+ if (!result.identifier)
1684
+ return;
1685
+ let loginRequired = false;
1686
+ let contentWarning = false;
1687
+ // Check if item and item in "modifying" collection, setting above flags
1688
+ if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
1689
+ ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
1690
+ for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
1691
+ if (collection === 'loggedin') {
1692
+ loginRequired = true;
1693
+ if (contentWarning)
1694
+ break;
1695
+ }
1696
+ if (collection === 'no-preview') {
1697
+ contentWarning = true;
1698
+ if (loginRequired)
1699
+ break;
1700
+ }
1701
+ }
1702
+ }
1703
+ tiles.push({
1704
+ averageRating: (_e = result.avg_rating) === null || _e === void 0 ? void 0 : _e.value,
1705
+ checked: false,
1706
+ collections: (_g = (_f = result.collection) === null || _f === void 0 ? void 0 : _f.values) !== null && _g !== void 0 ? _g : [],
1707
+ collectionFilesCount: (_j = (_h = result.collection_files_count) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : 0,
1708
+ collectionSize: (_l = (_k = result.collection_size) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : 0,
1709
+ commentCount: (_o = (_m = result.num_reviews) === null || _m === void 0 ? void 0 : _m.value) !== null && _o !== void 0 ? _o : 0,
1710
+ creator: (_p = result.creator) === null || _p === void 0 ? void 0 : _p.value,
1711
+ creators: (_r = (_q = result.creator) === null || _q === void 0 ? void 0 : _q.values) !== null && _r !== void 0 ? _r : [],
1712
+ dateAdded: (_s = result.addeddate) === null || _s === void 0 ? void 0 : _s.value,
1713
+ dateArchived: (_t = result.publicdate) === null || _t === void 0 ? void 0 : _t.value,
1714
+ datePublished: (_u = result.date) === null || _u === void 0 ? void 0 : _u.value,
1715
+ dateReviewed: (_v = result.reviewdate) === null || _v === void 0 ? void 0 : _v.value,
1716
+ description: (_w = result.description) === null || _w === void 0 ? void 0 : _w.values.join('\n'),
1717
+ favCount: (_y = (_x = result.num_favorites) === null || _x === void 0 ? void 0 : _x.value) !== null && _y !== void 0 ? _y : 0,
1718
+ href: this.collapseRepeatedQuotes((_z = result.__href__) === null || _z === void 0 ? void 0 : _z.value),
1719
+ identifier: result.identifier,
1720
+ issue: (_0 = result.issue) === null || _0 === void 0 ? void 0 : _0.value,
1721
+ itemCount: (_2 = (_1 = result.item_count) === null || _1 === void 0 ? void 0 : _1.value) !== null && _2 !== void 0 ? _2 : 0,
1722
+ mediatype: this.getMediatype(result),
1723
+ snippets: (_4 = (_3 = result.highlight) === null || _3 === void 0 ? void 0 : _3.values) !== null && _4 !== void 0 ? _4 : [],
1724
+ source: (_5 = result.source) === null || _5 === void 0 ? void 0 : _5.value,
1725
+ subjects: (_7 = (_6 = result.subject) === null || _6 === void 0 ? void 0 : _6.values) !== null && _7 !== void 0 ? _7 : [],
1726
+ title: (_9 = (_8 = result.title) === null || _8 === void 0 ? void 0 : _8.value) !== null && _9 !== void 0 ? _9 : '',
1727
+ volume: (_10 = result.volume) === null || _10 === void 0 ? void 0 : _10.value,
1728
+ viewCount: (_12 = (_11 = result.downloads) === null || _11 === void 0 ? void 0 : _11.value) !== null && _12 !== void 0 ? _12 : 0,
1729
+ weeklyViewCount: (_13 = result.week) === null || _13 === void 0 ? void 0 : _13.value,
1730
+ loginRequired,
1731
+ contentWarning,
1732
+ });
1733
+ });
1734
+ datasource[pageNumber] = tiles;
1735
+ this.dataSource = datasource;
1736
+ const visiblePages = this.currentVisiblePageNumbers;
1737
+ const needsReload = visiblePages.includes(pageNumber);
1738
+ if (needsReload) {
1739
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1740
+ }
1741
+ }
1742
+ getMediatype(result) {
1743
+ var _a, _b, _c;
1744
+ /**
1745
+ * hit_type == 'favorited_search' is basically a new hit_type
1746
+ * - we are getting from PPS.
1747
+ * - which gives response for fav- collection
1748
+ * - having favorited items like account/collection/item etc..
1749
+ * - as user can also favorite a search result (a search page)
1750
+ * - so we need to have response (having fav- items and fav- search results)
1751
+ *
1752
+ * if backend hit_type == 'favorited_search'
1753
+ * - let's assume a "search" as new mediatype
1754
+ */
1755
+ if (((_a = result === null || result === void 0 ? void 0 : result.rawMetadata) === null || _a === void 0 ? void 0 : _a.hit_type) === 'favorited_search') {
1756
+ return 'search';
1757
+ }
1758
+ return (_c = (_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 'data';
1759
+ }
1760
+ /**
1761
+ * Returns the input string, but removing one set of quotes from all instances of
1762
+ * ""clauses wrapped in two sets of quotes"". This assumes the quotes are already
1763
+ * URL-encoded.
1764
+ *
1765
+ * This should be a temporary measure to address the fact that the __href__ field
1766
+ * sometimes acquires extra quotation marks during query rewriting. Once there is a
1767
+ * full Lucene parser in place that handles quoted queries correctly, this can likely
1768
+ * be removed.
1769
+ */
1770
+ collapseRepeatedQuotes(str) {
1771
+ return str === null || str === void 0 ? void 0 : str.replace(/%22%22(?!%22%22)(.+?)%22%22/g, '%22$1%22');
1772
+ }
1773
+ /** Fetches the aggregation buckets for the given prefix filter type. */
1774
+ async fetchPrefixFilterBuckets(filterType) {
1775
+ var _a, _b, _c, _d, _e, _f, _g;
1776
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1777
+ if (!this.canPerformSearch)
1778
+ return [];
1779
+ const filterAggregationKey = prefixFilterAggregationKeys[filterType];
1780
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1781
+ const params = {
1782
+ ...this.collectionParams,
1783
+ query: trimmedQuery || '',
1784
+ rows: 0,
1785
+ filters: this.filterMap,
1786
+ // Only fetch the firstTitle or firstCreator aggregation
1787
+ aggregations: { simpleParams: [filterAggregationKey] },
1788
+ // Fetch all 26 letter buckets
1789
+ aggregationsSize: 26,
1790
+ };
1791
+ params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1792
+ const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1793
+ 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 : []);
1794
+ }
1795
+ /** Fetches and caches the prefix filter counts for the given filter type. */
1796
+ async updatePrefixFilterCounts(filterType) {
1797
+ const { facetFetchQueryKey } = this;
1798
+ const buckets = await this.fetchPrefixFilterBuckets(filterType);
1799
+ // Don't update the filter counts for an outdated query (if it has been changed
1800
+ // since we sent the request)
1801
+ const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1802
+ if (queryChangedSinceFetch)
1803
+ return;
1804
+ // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }
1805
+ this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update
1806
+ this.prefixFilterCountMap[filterType] = buckets.reduce((acc, bucket) => {
1807
+ acc[bucket.key.toUpperCase()] = bucket.doc_count;
1808
+ return acc;
1809
+ }, {});
1810
+ }
1811
+ /**
1812
+ * Fetches and caches the prefix filter counts for the current sort type,
1813
+ * provided it is one that permits prefix filtering. (If not, this does nothing).
1814
+ */
1815
+ async updatePrefixFiltersForCurrentSort() {
1816
+ if (['title', 'creator'].includes(this.selectedSort)) {
1817
+ const filterType = this.selectedSort;
1818
+ if (!this.prefixFilterCountMap[filterType]) {
1819
+ this.updatePrefixFilterCounts(filterType);
1820
+ }
1821
+ }
1822
+ }
1823
+ /**
1824
+ * Clears the cached letter counts for both title and creator, and
1825
+ * fetches a new set of counts for whichever of them is the currently
1826
+ * selected sort option (which may be neither).
1827
+ *
1828
+ * Call this whenever the counts are invalidated (e.g., by a query change).
1829
+ */
1830
+ refreshLetterCounts() {
1831
+ if (Object.keys(this.prefixFilterCountMap).length > 0) {
1832
+ this.prefixFilterCountMap = {};
1833
+ }
1834
+ this.updatePrefixFiltersForCurrentSort();
1835
+ }
1836
+ /**
1837
+ * Callback when a result is selected
1838
+ */
1839
+ resultSelected(event) {
1840
+ var _a, _b, _c;
1841
+ if (this.isManageView) {
1842
+ // Checked/unchecked state change -- rerender to ensure it propagates
1843
+ // this.mapDataSource(model => ({ ...model }));
1844
+ const cellIndex = Object.values(this.dataSource)
1845
+ .flat()
1846
+ .indexOf(event.detail);
1847
+ if (cellIndex >= 0)
1848
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshCell(cellIndex - this.tileModelOffset);
1849
+ }
1850
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1851
+ category: this.searchContext,
1852
+ action: analyticsActions.resultSelected,
1853
+ label: event.detail.mediatype,
1854
+ });
1855
+ (_c = this.analyticsHandler) === null || _c === void 0 ? void 0 : _c.sendEvent({
1856
+ category: this.searchContext,
1857
+ action: analyticsActions.resultSelected,
1858
+ label: `page-${this.currentPage}`,
1859
+ });
1860
+ }
1861
+ cellForIndex(index) {
1862
+ const model = this.tileModelAtCellIndex(index);
1863
+ if (!model)
1864
+ return undefined;
1869
1865
  return html `
1870
1866
  <tile-dispatcher
1871
1867
  .collectionPagePath=${this.collectionPagePath}
@@ -1885,21 +1881,21 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1885
1881
  @resultSelected=${(e) => this.resultSelected(e)}
1886
1882
  >
1887
1883
  </tile-dispatcher>
1888
- `;
1889
- }
1890
- /**
1891
- * When the user scrolls near to the bottom of the page, fetch the next page
1892
- * increase the number of pages to render and start fetching data for the new page
1893
- */
1894
- scrollThresholdReached() {
1895
- if (!this.endOfDataReached) {
1896
- this.pagesToRender += 1;
1897
- this.fetchPage(this.pagesToRender);
1898
- }
1899
- }
1900
- static get styles() {
1901
- return [
1902
- srOnlyStyle,
1884
+ `;
1885
+ }
1886
+ /**
1887
+ * When the user scrolls near to the bottom of the page, fetch the next page
1888
+ * increase the number of pages to render and start fetching data for the new page
1889
+ */
1890
+ scrollThresholdReached() {
1891
+ if (!this.endOfDataReached) {
1892
+ this.pagesToRender += 1;
1893
+ this.fetchPage(this.pagesToRender);
1894
+ }
1895
+ }
1896
+ static get styles() {
1897
+ return [
1898
+ srOnlyStyle,
1903
1899
  css `
1904
1900
  :host {
1905
1901
  display: block;
@@ -2270,180 +2266,180 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
2270
2266
  infinite-scroller.hidden {
2271
2267
  display: none;
2272
2268
  }
2273
- `,
2274
- ];
2275
- }
2276
- };
2277
- __decorate([
2278
- property({ type: String })
2279
- ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
2280
- __decorate([
2281
- property({ type: String })
2282
- ], CollectionBrowser.prototype, "baseImageUrl", void 0);
2283
- __decorate([
2284
- property({ type: Object })
2285
- ], CollectionBrowser.prototype, "searchService", void 0);
2286
- __decorate([
2287
- property({ type: String })
2288
- ], CollectionBrowser.prototype, "searchType", void 0);
2289
- __decorate([
2290
- property({ type: String })
2291
- ], CollectionBrowser.prototype, "withinCollection", void 0);
2292
- __decorate([
2293
- property({ type: String })
2294
- ], CollectionBrowser.prototype, "baseQuery", void 0);
2295
- __decorate([
2296
- property({ type: String })
2297
- ], CollectionBrowser.prototype, "displayMode", void 0);
2298
- __decorate([
2299
- property({ type: Object })
2300
- ], CollectionBrowser.prototype, "sortParam", void 0);
2301
- __decorate([
2302
- property({ type: Object })
2303
- ], CollectionBrowser.prototype, "defaultSortParam", void 0);
2304
- __decorate([
2305
- property({ type: String })
2306
- ], CollectionBrowser.prototype, "selectedSort", void 0);
2307
- __decorate([
2308
- property({ type: String })
2309
- ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
2310
- __decorate([
2311
- property({ type: String })
2312
- ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
2313
- __decorate([
2314
- property({ type: String })
2315
- ], CollectionBrowser.prototype, "sortDirection", void 0);
2316
- __decorate([
2317
- property({ type: Number })
2318
- ], CollectionBrowser.prototype, "pageSize", void 0);
2319
- __decorate([
2320
- property({ type: Object })
2321
- ], CollectionBrowser.prototype, "resizeObserver", void 0);
2322
- __decorate([
2323
- property({ type: Number })
2324
- ], CollectionBrowser.prototype, "currentPage", void 0);
2325
- __decorate([
2326
- property({ type: String })
2327
- ], CollectionBrowser.prototype, "minSelectedDate", void 0);
2328
- __decorate([
2329
- property({ type: String })
2330
- ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
2331
- __decorate([
2332
- property({ type: Object })
2333
- ], CollectionBrowser.prototype, "selectedFacets", void 0);
2334
- __decorate([
2335
- property({ type: Boolean })
2336
- ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
2337
- __decorate([
2338
- property({ type: Boolean })
2339
- ], CollectionBrowser.prototype, "suppressPlaceholders", void 0);
2340
- __decorate([
2341
- property({ type: Boolean })
2342
- ], CollectionBrowser.prototype, "suppressResultCount", void 0);
2343
- __decorate([
2344
- property({ type: Boolean })
2345
- ], CollectionBrowser.prototype, "clearResultsOnEmptyQuery", void 0);
2346
- __decorate([
2347
- property({ type: String })
2348
- ], CollectionBrowser.prototype, "collectionPagePath", void 0);
2349
- __decorate([
2350
- property({ type: Object })
2351
- ], CollectionBrowser.prototype, "collectionInfo", void 0);
2352
- __decorate([
2353
- property({ type: Array })
2354
- ], CollectionBrowser.prototype, "parentCollections", void 0);
2355
- __decorate([
2356
- property({ type: String, reflect: true })
2357
- ], CollectionBrowser.prototype, "searchContext", void 0);
2358
- __decorate([
2359
- property({ type: Object })
2360
- ], CollectionBrowser.prototype, "collectionNameCache", void 0);
2361
- __decorate([
2362
- property({ type: String })
2363
- ], CollectionBrowser.prototype, "pageContext", void 0);
2364
- __decorate([
2365
- property({ type: Object })
2366
- ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
2367
- __decorate([
2368
- property({ type: Number })
2369
- ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
2370
- __decorate([
2371
- property({ type: Boolean })
2372
- ], CollectionBrowser.prototype, "loggedIn", void 0);
2373
- __decorate([
2374
- property({ type: Object })
2375
- ], CollectionBrowser.prototype, "modalManager", void 0);
2376
- __decorate([
2377
- property({ type: Object })
2378
- ], CollectionBrowser.prototype, "featureFeedbackService", void 0);
2379
- __decorate([
2380
- property({ type: Object })
2381
- ], CollectionBrowser.prototype, "recaptchaManager", void 0);
2382
- __decorate([
2383
- property({ type: Boolean })
2384
- ], CollectionBrowser.prototype, "isManageView", void 0);
2385
- __decorate([
2386
- state()
2387
- ], CollectionBrowser.prototype, "pagesToRender", void 0);
2388
- __decorate([
2389
- state()
2390
- ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
2391
- __decorate([
2392
- state()
2393
- ], CollectionBrowser.prototype, "facetsLoading", void 0);
2394
- __decorate([
2395
- state()
2396
- ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
2397
- __decorate([
2398
- state()
2399
- ], CollectionBrowser.prototype, "aggregations", void 0);
2400
- __decorate([
2401
- state()
2402
- ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
2403
- __decorate([
2404
- state()
2405
- ], CollectionBrowser.prototype, "totalResults", void 0);
2406
- __decorate([
2407
- state()
2408
- ], CollectionBrowser.prototype, "queryErrorMessage", void 0);
2409
- __decorate([
2410
- state()
2411
- ], CollectionBrowser.prototype, "mobileView", void 0);
2412
- __decorate([
2413
- state()
2414
- ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
2415
- __decorate([
2416
- state()
2417
- ], CollectionBrowser.prototype, "contentWidth", void 0);
2418
- __decorate([
2419
- state()
2420
- ], CollectionBrowser.prototype, "defaultSortField", void 0);
2421
- __decorate([
2422
- state()
2423
- ], CollectionBrowser.prototype, "defaultSortDirection", void 0);
2424
- __decorate([
2425
- state()
2426
- ], CollectionBrowser.prototype, "placeholderType", void 0);
2427
- __decorate([
2428
- state()
2429
- ], CollectionBrowser.prototype, "prefixFilterCountMap", void 0);
2430
- __decorate([
2431
- query('#content-container')
2432
- ], CollectionBrowser.prototype, "contentContainer", void 0);
2433
- __decorate([
2434
- query('#left-column')
2435
- ], CollectionBrowser.prototype, "leftColumn", void 0);
2436
- __decorate([
2437
- query('collection-facets')
2438
- ], CollectionBrowser.prototype, "collectionFacets", void 0);
2439
- __decorate([
2440
- property({ type: Object, attribute: false })
2441
- ], CollectionBrowser.prototype, "analyticsHandler", void 0);
2442
- __decorate([
2443
- query('infinite-scroller')
2444
- ], CollectionBrowser.prototype, "infiniteScroller", void 0);
2445
- CollectionBrowser = __decorate([
2446
- customElement('collection-browser')
2447
- ], CollectionBrowser);
2448
- export { CollectionBrowser };
2269
+ `,
2270
+ ];
2271
+ }
2272
+ };
2273
+ __decorate([
2274
+ property({ type: String })
2275
+ ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
2276
+ __decorate([
2277
+ property({ type: String })
2278
+ ], CollectionBrowser.prototype, "baseImageUrl", void 0);
2279
+ __decorate([
2280
+ property({ type: Object })
2281
+ ], CollectionBrowser.prototype, "searchService", void 0);
2282
+ __decorate([
2283
+ property({ type: String })
2284
+ ], CollectionBrowser.prototype, "searchType", void 0);
2285
+ __decorate([
2286
+ property({ type: String })
2287
+ ], CollectionBrowser.prototype, "withinCollection", void 0);
2288
+ __decorate([
2289
+ property({ type: String })
2290
+ ], CollectionBrowser.prototype, "baseQuery", void 0);
2291
+ __decorate([
2292
+ property({ type: String })
2293
+ ], CollectionBrowser.prototype, "displayMode", void 0);
2294
+ __decorate([
2295
+ property({ type: Object })
2296
+ ], CollectionBrowser.prototype, "sortParam", void 0);
2297
+ __decorate([
2298
+ property({ type: Object })
2299
+ ], CollectionBrowser.prototype, "defaultSortParam", void 0);
2300
+ __decorate([
2301
+ property({ type: String })
2302
+ ], CollectionBrowser.prototype, "selectedSort", void 0);
2303
+ __decorate([
2304
+ property({ type: String })
2305
+ ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
2306
+ __decorate([
2307
+ property({ type: String })
2308
+ ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
2309
+ __decorate([
2310
+ property({ type: String })
2311
+ ], CollectionBrowser.prototype, "sortDirection", void 0);
2312
+ __decorate([
2313
+ property({ type: Number })
2314
+ ], CollectionBrowser.prototype, "pageSize", void 0);
2315
+ __decorate([
2316
+ property({ type: Object })
2317
+ ], CollectionBrowser.prototype, "resizeObserver", void 0);
2318
+ __decorate([
2319
+ property({ type: Number })
2320
+ ], CollectionBrowser.prototype, "currentPage", void 0);
2321
+ __decorate([
2322
+ property({ type: String })
2323
+ ], CollectionBrowser.prototype, "minSelectedDate", void 0);
2324
+ __decorate([
2325
+ property({ type: String })
2326
+ ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
2327
+ __decorate([
2328
+ property({ type: Object })
2329
+ ], CollectionBrowser.prototype, "selectedFacets", void 0);
2330
+ __decorate([
2331
+ property({ type: Boolean })
2332
+ ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
2333
+ __decorate([
2334
+ property({ type: Boolean })
2335
+ ], CollectionBrowser.prototype, "suppressEmptyPlaceholder", void 0);
2336
+ __decorate([
2337
+ property({ type: Boolean })
2338
+ ], CollectionBrowser.prototype, "suppressResultCount", void 0);
2339
+ __decorate([
2340
+ property({ type: Boolean })
2341
+ ], CollectionBrowser.prototype, "clearResultsOnEmptyQuery", void 0);
2342
+ __decorate([
2343
+ property({ type: String })
2344
+ ], CollectionBrowser.prototype, "collectionPagePath", void 0);
2345
+ __decorate([
2346
+ property({ type: Object })
2347
+ ], CollectionBrowser.prototype, "collectionInfo", void 0);
2348
+ __decorate([
2349
+ property({ type: Array })
2350
+ ], CollectionBrowser.prototype, "parentCollections", void 0);
2351
+ __decorate([
2352
+ property({ type: String, reflect: true })
2353
+ ], CollectionBrowser.prototype, "searchContext", void 0);
2354
+ __decorate([
2355
+ property({ type: Object })
2356
+ ], CollectionBrowser.prototype, "collectionNameCache", void 0);
2357
+ __decorate([
2358
+ property({ type: String })
2359
+ ], CollectionBrowser.prototype, "pageContext", void 0);
2360
+ __decorate([
2361
+ property({ type: Object })
2362
+ ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
2363
+ __decorate([
2364
+ property({ type: Number })
2365
+ ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
2366
+ __decorate([
2367
+ property({ type: Boolean })
2368
+ ], CollectionBrowser.prototype, "loggedIn", void 0);
2369
+ __decorate([
2370
+ property({ type: Object })
2371
+ ], CollectionBrowser.prototype, "modalManager", void 0);
2372
+ __decorate([
2373
+ property({ type: Object })
2374
+ ], CollectionBrowser.prototype, "featureFeedbackService", void 0);
2375
+ __decorate([
2376
+ property({ type: Object })
2377
+ ], CollectionBrowser.prototype, "recaptchaManager", void 0);
2378
+ __decorate([
2379
+ property({ type: Boolean })
2380
+ ], CollectionBrowser.prototype, "isManageView", void 0);
2381
+ __decorate([
2382
+ state()
2383
+ ], CollectionBrowser.prototype, "pagesToRender", void 0);
2384
+ __decorate([
2385
+ state()
2386
+ ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
2387
+ __decorate([
2388
+ state()
2389
+ ], CollectionBrowser.prototype, "facetsLoading", void 0);
2390
+ __decorate([
2391
+ state()
2392
+ ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
2393
+ __decorate([
2394
+ state()
2395
+ ], CollectionBrowser.prototype, "aggregations", void 0);
2396
+ __decorate([
2397
+ state()
2398
+ ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
2399
+ __decorate([
2400
+ state()
2401
+ ], CollectionBrowser.prototype, "totalResults", void 0);
2402
+ __decorate([
2403
+ state()
2404
+ ], CollectionBrowser.prototype, "queryErrorMessage", void 0);
2405
+ __decorate([
2406
+ state()
2407
+ ], CollectionBrowser.prototype, "mobileView", void 0);
2408
+ __decorate([
2409
+ state()
2410
+ ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
2411
+ __decorate([
2412
+ state()
2413
+ ], CollectionBrowser.prototype, "contentWidth", void 0);
2414
+ __decorate([
2415
+ state()
2416
+ ], CollectionBrowser.prototype, "defaultSortField", void 0);
2417
+ __decorate([
2418
+ state()
2419
+ ], CollectionBrowser.prototype, "defaultSortDirection", void 0);
2420
+ __decorate([
2421
+ state()
2422
+ ], CollectionBrowser.prototype, "placeholderType", void 0);
2423
+ __decorate([
2424
+ state()
2425
+ ], CollectionBrowser.prototype, "prefixFilterCountMap", void 0);
2426
+ __decorate([
2427
+ query('#content-container')
2428
+ ], CollectionBrowser.prototype, "contentContainer", void 0);
2429
+ __decorate([
2430
+ query('#left-column')
2431
+ ], CollectionBrowser.prototype, "leftColumn", void 0);
2432
+ __decorate([
2433
+ query('collection-facets')
2434
+ ], CollectionBrowser.prototype, "collectionFacets", void 0);
2435
+ __decorate([
2436
+ property({ type: Object, attribute: false })
2437
+ ], CollectionBrowser.prototype, "analyticsHandler", void 0);
2438
+ __decorate([
2439
+ query('infinite-scroller')
2440
+ ], CollectionBrowser.prototype, "infiniteScroller", void 0);
2441
+ CollectionBrowser = __decorate([
2442
+ customElement('collection-browser')
2443
+ ], CollectionBrowser);
2444
+ export { CollectionBrowser };
2449
2445
  //# sourceMappingURL=collection-browser.js.map