@internetarchive/collection-browser 1.14.4 → 1.14.5-alpha2

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