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