@internetarchive/collection-browser 1.14.4 → 1.14.5

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 (275) 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 +1869 -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 +506 -506
  88. package/dist/src/empty-placeholder.d.ts +23 -23
  89. package/dist/src/empty-placeholder.js +74 -74
  90. package/dist/src/expanded-date-picker.d.ts +43 -43
  91. package/dist/src/expanded-date-picker.js +109 -109
  92. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  93. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  94. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  95. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  96. package/dist/src/manage/manage-bar.d.ts +26 -26
  97. package/dist/src/manage/manage-bar.js +53 -53
  98. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  99. package/dist/src/mediatype/mediatype-config.js +91 -91
  100. package/dist/src/models.d.ts +164 -164
  101. package/dist/src/models.js +269 -269
  102. package/dist/src/restoration-state-handler.d.ts +70 -70
  103. package/dist/src/restoration-state-handler.js +355 -355
  104. package/dist/src/sort-filter-bar/alpha-bar-tooltip.d.ts +6 -6
  105. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js +24 -24
  106. package/dist/src/sort-filter-bar/alpha-bar.d.ts +21 -21
  107. package/dist/src/sort-filter-bar/alpha-bar.js +128 -128
  108. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  109. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  110. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  111. package/dist/src/sort-filter-bar/img/list.js +2 -2
  112. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.d.ts +1 -1
  113. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js +2 -2
  114. package/dist/src/sort-filter-bar/img/sort-toggle-down.d.ts +1 -1
  115. package/dist/src/sort-filter-bar/img/sort-toggle-down.js +2 -2
  116. package/dist/src/sort-filter-bar/img/sort-toggle-up.d.ts +1 -1
  117. package/dist/src/sort-filter-bar/img/sort-toggle-up.js +2 -2
  118. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  119. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  120. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  121. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  122. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +208 -208
  123. package/dist/src/sort-filter-bar/sort-filter-bar.js +637 -637
  124. package/dist/src/styles/item-image-styles.d.ts +8 -8
  125. package/dist/src/styles/item-image-styles.js +9 -9
  126. package/dist/src/styles/sr-only.d.ts +1 -1
  127. package/dist/src/styles/sr-only.js +2 -2
  128. package/dist/src/tiles/base-tile-component.d.ts +19 -18
  129. package/dist/src/tiles/base-tile-component.js +63 -59
  130. package/dist/src/tiles/base-tile-component.js.map +1 -1
  131. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  132. package/dist/src/tiles/collection-browser-loading-tile.js +15 -15
  133. package/dist/src/tiles/grid/account-tile.d.ts +18 -18
  134. package/dist/src/tiles/grid/account-tile.js +72 -72
  135. package/dist/src/tiles/grid/collection-tile.d.ts +15 -15
  136. package/dist/src/tiles/grid/collection-tile.js +80 -80
  137. package/dist/src/tiles/grid/item-tile.d.ts +27 -27
  138. package/dist/src/tiles/grid/item-tile.js +134 -134
  139. package/dist/src/tiles/grid/search-tile.d.ts +10 -10
  140. package/dist/src/tiles/grid/search-tile.js +51 -51
  141. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.d.ts +1 -1
  142. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +8 -8
  143. package/dist/src/tiles/grid/tile-stats.d.ts +11 -11
  144. package/dist/src/tiles/grid/tile-stats.js +48 -48
  145. package/dist/src/tiles/hover/hover-pane-controller.d.ts +219 -219
  146. package/dist/src/tiles/hover/hover-pane-controller.js +352 -352
  147. package/dist/src/tiles/hover/tile-hover-pane.d.ts +15 -15
  148. package/dist/src/tiles/hover/tile-hover-pane.js +38 -38
  149. package/dist/src/tiles/image-block.d.ts +17 -17
  150. package/dist/src/tiles/image-block.js +73 -73
  151. package/dist/src/tiles/item-image.d.ts +36 -36
  152. package/dist/src/tiles/item-image.js +127 -127
  153. package/dist/src/tiles/list/tile-list-compact-header.d.ts +6 -6
  154. package/dist/src/tiles/list/tile-list-compact-header.js +38 -38
  155. package/dist/src/tiles/list/tile-list-compact.d.ts +15 -15
  156. package/dist/src/tiles/list/tile-list-compact.js +114 -114
  157. package/dist/src/tiles/list/tile-list.d.ts +46 -46
  158. package/dist/src/tiles/list/tile-list.js +302 -302
  159. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  160. package/dist/src/tiles/mediatype-icon.js +47 -47
  161. package/dist/src/tiles/overlay/icon-overlay.d.ts +10 -10
  162. package/dist/src/tiles/overlay/icon-overlay.js +40 -40
  163. package/dist/src/tiles/overlay/icon-text-overlay.d.ts +9 -9
  164. package/dist/src/tiles/overlay/icon-text-overlay.js +38 -38
  165. package/dist/src/tiles/overlay/text-overlay.d.ts +10 -10
  166. package/dist/src/tiles/overlay/text-overlay.js +42 -42
  167. package/dist/src/tiles/text-snippet-block.d.ts +27 -27
  168. package/dist/src/tiles/text-snippet-block.js +73 -73
  169. package/dist/src/tiles/tile-dispatcher.d.ts +64 -64
  170. package/dist/src/tiles/tile-dispatcher.js +235 -235
  171. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  172. package/dist/src/tiles/tile-display-value-provider.d.ts +43 -43
  173. package/dist/src/tiles/tile-display-value-provider.js +80 -80
  174. package/dist/src/utils/analytics-events.d.ts +25 -25
  175. package/dist/src/utils/analytics-events.js +27 -27
  176. package/dist/src/utils/array-equals.d.ts +4 -4
  177. package/dist/src/utils/array-equals.js +10 -10
  178. package/dist/src/utils/format-count.d.ts +7 -7
  179. package/dist/src/utils/format-count.js +76 -76
  180. package/dist/src/utils/format-date.d.ts +2 -2
  181. package/dist/src/utils/format-date.js +25 -25
  182. package/dist/src/utils/format-unit-size.d.ts +2 -2
  183. package/dist/src/utils/format-unit-size.js +33 -33
  184. package/dist/src/utils/local-date-from-utc.d.ts +9 -9
  185. package/dist/src/utils/local-date-from-utc.js +15 -15
  186. package/dist/src/utils/sha1.d.ts +2 -2
  187. package/dist/src/utils/sha1.js +8 -8
  188. package/dist/test/collection-browser.test.d.ts +1 -1
  189. package/dist/test/collection-browser.test.js +1098 -1098
  190. package/dist/test/collection-facets/facets-template.test.d.ts +1 -1
  191. package/dist/test/collection-facets/facets-template.test.js +134 -134
  192. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -1
  193. package/dist/test/collection-facets/more-facets-content.test.js +133 -133
  194. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -1
  195. package/dist/test/collection-facets/more-facets-pagination.test.js +117 -117
  196. package/dist/test/collection-facets/toggle-switch.test.d.ts +1 -1
  197. package/dist/test/collection-facets/toggle-switch.test.js +73 -73
  198. package/dist/test/collection-facets.test.d.ts +2 -2
  199. package/dist/test/collection-facets.test.js +682 -682
  200. package/dist/test/empty-placeholder.test.d.ts +1 -1
  201. package/dist/test/empty-placeholder.test.js +63 -63
  202. package/dist/test/expanded-date-picker.test.d.ts +1 -1
  203. package/dist/test/expanded-date-picker.test.js +95 -95
  204. package/dist/test/icon-overlay.test.d.ts +1 -1
  205. package/dist/test/icon-overlay.test.js +24 -24
  206. package/dist/test/image-block.test.d.ts +1 -1
  207. package/dist/test/image-block.test.js +48 -48
  208. package/dist/test/item-image.test.d.ts +1 -1
  209. package/dist/test/item-image.test.js +86 -86
  210. package/dist/test/manage/manage-bar.test.d.ts +1 -1
  211. package/dist/test/manage/manage-bar.test.js +72 -72
  212. package/dist/test/mediatype-config.test.d.ts +1 -1
  213. package/dist/test/mediatype-config.test.js +16 -16
  214. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  215. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  216. package/dist/test/mocks/mock-collection-name-cache.d.ts +9 -9
  217. package/dist/test/mocks/mock-collection-name-cache.js +17 -17
  218. package/dist/test/mocks/mock-search-responses.d.ts +21 -21
  219. package/dist/test/mocks/mock-search-responses.js +709 -709
  220. package/dist/test/mocks/mock-search-service.d.ts +15 -15
  221. package/dist/test/mocks/mock-search-service.js +50 -50
  222. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  223. package/dist/test/restoration-state-handler.test.js +270 -270
  224. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.d.ts +1 -1
  225. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +12 -12
  226. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +1 -1
  227. package/dist/test/sort-filter-bar/alpha-bar.test.js +73 -73
  228. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -1
  229. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +378 -378
  230. package/dist/test/text-overlay.test.d.ts +1 -1
  231. package/dist/test/text-overlay.test.js +48 -48
  232. package/dist/test/text-snippet-block.test.d.ts +1 -1
  233. package/dist/test/text-snippet-block.test.js +57 -57
  234. package/dist/test/tile-stats.test.d.ts +1 -1
  235. package/dist/test/tile-stats.test.js +33 -33
  236. package/dist/test/tiles/grid/account-tile.test.d.ts +1 -1
  237. package/dist/test/tiles/grid/account-tile.test.js +76 -76
  238. package/dist/test/tiles/grid/collection-tile.test.d.ts +1 -1
  239. package/dist/test/tiles/grid/collection-tile.test.js +73 -73
  240. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -1
  241. package/dist/test/tiles/grid/item-tile.test.js +254 -254
  242. package/dist/test/tiles/grid/search-tile.test.d.ts +1 -1
  243. package/dist/test/tiles/grid/search-tile.test.js +51 -51
  244. package/dist/test/tiles/hover/hover-pane-controller.test.d.ts +1 -1
  245. package/dist/test/tiles/hover/hover-pane-controller.test.js +258 -258
  246. package/dist/test/tiles/hover/tile-hover-pane.test.d.ts +1 -1
  247. package/dist/test/tiles/hover/tile-hover-pane.test.js +13 -13
  248. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -1
  249. package/dist/test/tiles/list/tile-list-compact.test.js +143 -143
  250. package/dist/test/tiles/list/tile-list.test.d.ts +1 -1
  251. package/dist/test/tiles/list/tile-list.test.js +242 -242
  252. package/dist/test/tiles/tile-dispatcher.test.d.ts +1 -1
  253. package/dist/test/tiles/tile-dispatcher.test.js +94 -94
  254. package/dist/test/tiles/tile-display-value-provider.test.d.ts +1 -1
  255. package/dist/test/tiles/tile-display-value-provider.test.js +141 -141
  256. package/dist/test/utils/array-equals.test.d.ts +1 -1
  257. package/dist/test/utils/array-equals.test.js +26 -26
  258. package/dist/test/utils/format-count.test.d.ts +1 -1
  259. package/dist/test/utils/format-count.test.js +23 -23
  260. package/dist/test/utils/format-date.test.d.ts +1 -1
  261. package/dist/test/utils/format-date.test.js +17 -17
  262. package/dist/test/utils/format-unit-size.test.d.ts +1 -1
  263. package/dist/test/utils/format-unit-size.test.js +17 -17
  264. package/dist/test/utils/local-date-from-utc.test.d.ts +1 -1
  265. package/dist/test/utils/local-date-from-utc.test.js +26 -26
  266. package/local.archive.org.cert +86 -86
  267. package/local.archive.org.key +27 -27
  268. package/package.json +1 -1
  269. package/renovate.json +6 -6
  270. package/src/collection-browser.ts +8 -0
  271. package/src/tiles/base-tile-component.ts +2 -0
  272. package/src/tiles/tile-dispatcher.ts +7 -5
  273. package/tsconfig.json +21 -21
  274. package/web-dev-server.config.mjs +30 -30
  275. 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
+ ></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}
@@ -737,1105 +738,1110 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
737
738
  .analyticsHandler=${this.analyticsHandler}
738
739
  >
739
740
  </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';
741
+ `;
742
+ }
743
+ /**
744
+ * The HTML template for the "Clear all filters" button, or `nothing` if no
745
+ * filters are currently active.
746
+ *
747
+ * @param mobile Whether to style/shorten the button for mobile view
748
+ */
749
+ clearFiltersBtnTemplate(mobile) {
750
+ if (!this.hasActiveFilters)
751
+ return nothing;
752
+ const buttonClasses = classMap({
753
+ 'clear-filters-btn': true,
754
+ mobile,
755
+ });
756
+ const buttonText = mobile ? 'Clear all' : 'Clear all filters';
756
757
  return html `
757
758
  <div class="clear-filters-btn-row">
758
- ${mobile
759
- ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
759
+ ${mobile
760
+ ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
760
761
  : nothing}
761
762
  <button class=${buttonClasses} @click=${this.clearFilters}>
762
763
  ${buttonText}
763
764
  </button>
764
765
  </div>
765
- `;
766
- }
767
- get loadingTemplate() {
766
+ `;
767
+ }
768
+ get loadingTemplate() {
768
769
  return html `
769
770
  <div class="loading-cover">
770
771
  <circular-activity-indicator></circular-activity-indicator>
771
772
  </div>
772
- `;
773
- }
774
- get listHeaderTemplate() {
773
+ `;
774
+ }
775
+ get listHeaderTemplate() {
775
776
  return html `
776
777
  <div id="list-header">
777
778
  <tile-dispatcher
778
779
  .tileDisplayMode=${'list-header'}
779
780
  .resizeObserver=${this.resizeObserver}
780
781
  .sortParam=${this.sortParam}
782
+ .defaultSortParam=${this.defaultSortParam}
781
783
  .mobileBreakpoint=${this.mobileBreakpoint}
782
784
  .loggedIn=${this.loggedIn}
783
785
  >
784
786
  </tile-dispatcher>
785
787
  </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;
788
+ `;
789
+ }
790
+ histogramDateRangeUpdated(e) {
791
+ var _a;
792
+ const { minDate, maxDate } = e.detail;
793
+ [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
794
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
795
+ category: this.searchContext,
796
+ action: analyticsActions.histogramChanged,
797
+ label: this.dateRangeQueryClause,
798
+ });
799
+ }
800
+ get dateRangeQueryClause() {
801
+ if (!this.minSelectedDate || !this.maxSelectedDate) {
802
+ return undefined;
803
+ }
804
+ return `year:[${this.minSelectedDate} TO ${this.maxSelectedDate}]`;
805
+ }
806
+ /**
807
+ * Emits an event indicating a change in whether the manage mode is shown.
808
+ */
809
+ emitManageModeChangedEvent() {
810
+ this.dispatchEvent(new CustomEvent('manageModeChanged', {
811
+ detail: this.isManageView,
812
+ }));
813
+ }
814
+ firstUpdated() {
815
+ this.setupStateRestorationObserver();
816
+ this.restoreState();
817
+ }
818
+ updated(changed) {
819
+ var _a, _b;
820
+ if (changed.has('placeholderType') && this.placeholderType === null) {
821
+ if (!this.leftColIntersectionObserver) {
822
+ this.setupLeftColumnScrollListeners();
823
+ }
824
+ if (!this.facetsIntersectionObserver) {
825
+ this.setupFacetsScrollListeners();
826
+ }
827
+ this.updateLeftColumnHeight();
828
+ }
829
+ if (changed.has('displayMode') ||
830
+ changed.has('baseNavigationUrl') ||
831
+ changed.has('baseImageUrl') ||
832
+ changed.has('loggedIn')) {
833
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
834
+ }
835
+ if (changed.has('baseQuery') ||
836
+ changed.has('searchType') ||
837
+ changed.has('withinCollection')) {
838
+ // Unless this query/search type update is from the initial page load or the
839
+ // result of hitting the back button,
840
+ // we need to clear any existing filters since they may no longer be valid for
841
+ // the new set of search results.
842
+ if (!this.historyPopOccurred && this.initialQueryChangeHappened) {
843
+ // Ordinarily, we leave the sort param unchanged between searches.
844
+ // However, if we are changing the target collection itself, we want the sort cleared too,
845
+ // since different collections may have different sorting options available.
846
+ const shouldClearSort = changed.has('withinCollection') &&
847
+ !changed.has('selectedSort') &&
848
+ !changed.has('sortDirection');
849
+ // Otherwise, only clear filters that haven't been simultaneously applied in this update
850
+ this.clearFilters({
851
+ sort: shouldClearSort,
852
+ facets: !changed.has('selectedFacets'),
853
+ dateRange: !(changed.has('minSelectedDate') || changed.has('maxSelectedDate')),
854
+ letterFilters: !(changed.has('selectedTitleFilter') ||
855
+ changed.has('selectedCreatorFilter')),
856
+ });
857
+ }
858
+ }
859
+ if (changed.has('baseQuery')) {
860
+ this.emitBaseQueryChanged();
861
+ }
862
+ if (changed.has('searchType')) {
863
+ this.emitSearchTypeChanged();
864
+ }
865
+ if (changed.has('currentPage') || changed.has('displayMode')) {
866
+ this.persistState();
867
+ }
868
+ if (changed.has('baseQuery') ||
869
+ changed.has('minSelectedDate') ||
870
+ changed.has('maxSelectedDate') ||
871
+ changed.has('selectedFacets') ||
872
+ changed.has('searchService') ||
873
+ changed.has('withinCollection')) {
874
+ this.refreshLetterCounts();
875
+ }
876
+ if (changed.has('selectedSort') || changed.has('sortDirection')) {
877
+ const prevSortDirection = changed.get('sortDirection');
878
+ this.sendSortByAnalytics(prevSortDirection);
879
+ this.selectedSortChanged();
880
+ }
881
+ if (changed.has('selectedTitleFilter')) {
882
+ this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
883
+ }
884
+ if (changed.has('selectedCreatorFilter')) {
885
+ this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
886
+ }
887
+ if (changed.has('baseQuery') ||
888
+ changed.has('searchType') ||
889
+ changed.has('selectedTitleFilter') ||
890
+ changed.has('selectedCreatorFilter') ||
891
+ changed.has('minSelectedDate') ||
892
+ changed.has('maxSelectedDate') ||
893
+ changed.has('sortParam') ||
894
+ changed.has('selectedFacets') ||
895
+ changed.has('searchService') ||
896
+ changed.has('withinCollection')) {
897
+ this.handleQueryChange();
898
+ }
899
+ if (changed.has('searchResultsLoading')) {
900
+ this.emitSearchResultsLoadingChanged();
901
+ }
902
+ if (changed.has('facetsLoading') &&
903
+ this.facetsLoading &&
904
+ this.collectionFacets) {
905
+ this.collectionFacets.moreLinksVisible =
906
+ this.searchType !== SearchType.FULLTEXT;
907
+ }
908
+ if (changed.has('pagesToRender')) {
909
+ if (!this.endOfDataReached && this.infiniteScroller) {
910
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
911
+ }
912
+ }
913
+ if (changed.has('isManageView')) {
914
+ if (this.isManageView)
915
+ this.displayMode = 'grid';
916
+ (_b = this.infiniteScroller) === null || _b === void 0 ? void 0 : _b.refreshAllVisibleCells();
917
+ this.emitManageModeChangedEvent();
918
+ }
919
+ if (changed.has('resizeObserver')) {
920
+ const oldObserver = changed.get('resizeObserver');
921
+ if (oldObserver)
922
+ this.disconnectResizeObserver(oldObserver);
923
+ this.setupResizeObserver();
924
+ }
925
+ }
926
+ disconnectedCallback() {
927
+ var _a, _b;
928
+ if (this.resizeObserver) {
929
+ this.disconnectResizeObserver(this.resizeObserver);
930
+ }
931
+ if (this.boundNavigationHandler) {
932
+ window.removeEventListener('popstate', this.boundNavigationHandler);
933
+ }
934
+ (_a = this.leftColIntersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
935
+ (_b = this.facetsIntersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
936
+ window.removeEventListener('resize', this.updateLeftColumnHeight);
937
+ }
938
+ handleResize(entry) {
939
+ const previousView = this.mobileView;
940
+ if (entry.target === this.contentContainer) {
941
+ this.contentWidth = entry.contentRect.width;
942
+ this.mobileView =
943
+ this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
944
+ // If changing from desktop to mobile disable transition
945
+ if (this.mobileView && !previousView) {
946
+ this.isResizeToMobile = true;
947
+ }
948
+ }
949
+ // Ensure the facet sidebar remains sized correctly
950
+ this.updateLeftColumnHeight();
951
+ }
952
+ /**
953
+ * Sets up listeners for events that may require updating the left column height.
954
+ */
955
+ setupLeftColumnScrollListeners() {
956
+ var _a;
957
+ // We observe intersections between the left column's scroll sentinel and
958
+ // the viewport, so that we can ensure the left column is always sized to
959
+ // match the _available_ viewport height. This should generally be more
960
+ // performant than listening to scroll events on the page or column.
961
+ const leftColumnSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#left-column-scroll-sentinel');
962
+ if (leftColumnSentinel) {
963
+ this.leftColIntersectionObserver = new IntersectionObserver(this.updateLeftColumnHeight, {
964
+ threshold: [...Array(101).keys()].map(n => n / 100), // Threshold every 1%
965
+ });
966
+ this.leftColIntersectionObserver.observe(leftColumnSentinel);
967
+ }
968
+ // We also listen for window resize events, as they are not always captured
969
+ // by the resize observer and can affect the desired height of the left column.
970
+ window.addEventListener('resize', this.updateLeftColumnHeight);
971
+ }
972
+ /**
973
+ * Sets up listeners to control whether the facet sidebar shows its bottom fade-out.
974
+ * Note this uses a separate IntersectionObserver from the left column, because we
975
+ * don't need granular intersection thresholds for this.
976
+ */
977
+ setupFacetsScrollListeners() {
978
+ var _a;
979
+ const facetsSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#facets-scroll-sentinel');
980
+ if (facetsSentinel) {
981
+ this.facetsIntersectionObserver = new IntersectionObserver(this.updateFacetFadeOut);
982
+ this.facetsIntersectionObserver.observe(facetsSentinel);
983
+ }
984
+ }
985
+ emitBaseQueryChanged() {
986
+ this.dispatchEvent(new CustomEvent('baseQueryChanged', {
987
+ detail: {
988
+ baseQuery: this.baseQuery,
989
+ },
990
+ }));
991
+ }
992
+ emitSearchTypeChanged() {
993
+ this.dispatchEvent(new CustomEvent('searchTypeChanged', {
994
+ detail: this.searchType,
995
+ }));
996
+ }
997
+ emitEmptyResults() {
998
+ this.dispatchEvent(new Event('emptyResults'));
999
+ }
1000
+ disconnectResizeObserver(resizeObserver) {
1001
+ resizeObserver.removeObserver({
1002
+ target: this.contentContainer,
1003
+ handler: this,
1004
+ });
1005
+ }
1006
+ setupResizeObserver() {
1007
+ if (!this.resizeObserver)
1008
+ return;
1009
+ this.resizeObserver.addObserver({
1010
+ target: this.contentContainer,
1011
+ handler: this,
1012
+ });
1013
+ }
1014
+ /**
1015
+ * When the visible cells change from the infinite scroller, we want to emit
1016
+ * which page is currently visible so the consumer can update its UI or the URL
1017
+ *
1018
+ * @param e
1019
+ * @returns
1020
+ */
1021
+ visibleCellsChanged(e) {
1022
+ if (this.isScrollingToCell)
1023
+ return;
1024
+ const { visibleCellIndices } = e.detail;
1025
+ if (visibleCellIndices.length === 0)
1026
+ return;
1027
+ const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
1028
+ const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
1029
+ if (this.currentPage !== lastVisibleCellPage) {
1030
+ this.currentPage = lastVisibleCellPage;
1031
+ }
1032
+ const event = new CustomEvent('visiblePageChanged', {
1033
+ detail: {
1034
+ pageNumber: lastVisibleCellPage,
1035
+ },
1036
+ });
1037
+ this.dispatchEvent(event);
1038
+ }
1039
+ /**
1040
+ * A Promise which, after each query change, resolves once the fetches for the initial
1041
+ * search have completed. Waits for *both* the hits and aggregations fetches to finish.
1042
+ *
1043
+ * Ensure you await this component's `updateComplete` promise before awaiting this
1044
+ * one, to ensure you do not await an obsolete promise from the previous update.
1045
+ */
1046
+ get initialSearchComplete() {
1047
+ return this._initialSearchCompletePromise;
1048
+ }
1049
+ async handleQueryChange() {
1050
+ var _a;
1051
+ // only reset if the query has actually changed
1052
+ if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
1053
+ return;
1054
+ // If the new state prevents us from updating the search results, don't reset
1055
+ if (!this.canPerformSearch)
1056
+ return;
1057
+ this.previousQueryKey = this.pageFetchQueryKey;
1058
+ this.dataSource = {};
1059
+ this.tileModelOffset = 0;
1060
+ this.totalResults = undefined;
1061
+ this.aggregations = undefined;
1062
+ this.fullYearsHistogramAggregation = undefined;
1063
+ this.pageFetchesInProgress = {};
1064
+ this.endOfDataReached = false;
1065
+ this.pagesToRender =
1066
+ this.initialPageNumber === 1
1067
+ ? 2 // First two pages are batched into one request when starting from page 1
1068
+ : this.initialPageNumber;
1069
+ this.queryErrorMessage = undefined;
1070
+ // Reset the infinite scroller's item count, so that it
1071
+ // shows tile placeholders until the new query's results load in
1072
+ if (this.infiniteScroller) {
1073
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
1074
+ this.infiniteScroller.reload();
1075
+ }
1076
+ if (this.withinCollection && ((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
1077
+ this.defaultSortField = SortField.relevance;
1078
+ this.defaultSortDirection = null;
1079
+ }
1080
+ if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
1081
+ this.scrollToPage(this.initialPageNumber);
1082
+ }
1083
+ this.initialQueryChangeHappened = true;
1084
+ // if the query changed as part of a window.history pop event, we don't want to
1085
+ // persist the state because it overwrites the forward history
1086
+ if (!this.historyPopOccurred) {
1087
+ this.persistState();
1088
+ }
1089
+ this.historyPopOccurred = false;
1090
+ // Reset the `initialSearchComplete` promise with a new value for the imminent search
1091
+ this._initialSearchCompletePromise = new Promise(res => {
1092
+ this._initialSearchCompleteResolver = res;
1093
+ });
1094
+ // Fire the initial page and facets requests
1095
+ await Promise.all([this.doInitialPageFetch(), this.fetchFacets()]);
1096
+ // Resolve the `initialSearchComplete` promise for this search
1097
+ this._initialSearchCompleteResolver(true);
1098
+ }
1099
+ setupStateRestorationObserver() {
1100
+ if (this.boundNavigationHandler)
1101
+ return;
1102
+ this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
1103
+ // when the user navigates back, we want to update the UI to match the URL
1104
+ window.addEventListener('popstate', this.boundNavigationHandler);
1105
+ }
1106
+ historyNavigationHandler() {
1107
+ this.historyPopOccurred = true;
1108
+ this.restoreState();
1109
+ }
1110
+ restoreState() {
1111
+ var _a, _b, _c, _d, _e;
1112
+ const restorationState = this.restorationStateHandler.getRestorationState();
1113
+ this.displayMode = restorationState.displayMode;
1114
+ if (restorationState.searchType != null)
1115
+ this.searchType = restorationState.searchType;
1116
+ this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.default;
1117
+ this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
1118
+ this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
1119
+ this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
1120
+ this.selectedFacets = restorationState.selectedFacets;
1121
+ this.baseQuery = restorationState.baseQuery;
1122
+ this.currentPage = (_e = restorationState.currentPage) !== null && _e !== void 0 ? _e : 1;
1123
+ this.minSelectedDate = restorationState.minSelectedDate;
1124
+ this.maxSelectedDate = restorationState.maxSelectedDate;
1125
+ if (this.currentPage > 1) {
1126
+ this.goToPage(this.currentPage);
1127
+ }
1128
+ }
1129
+ persistState() {
1130
+ var _a, _b, _c, _d;
1131
+ const restorationState = {
1132
+ displayMode: this.displayMode,
1133
+ searchType: this.searchType,
1134
+ selectedSort: this.selectedSort,
1135
+ sortDirection: (_a = this.sortDirection) !== null && _a !== void 0 ? _a : undefined,
1136
+ selectedFacets: (_b = this.selectedFacets) !== null && _b !== void 0 ? _b : getDefaultSelectedFacets(),
1137
+ baseQuery: this.baseQuery,
1138
+ currentPage: this.currentPage,
1139
+ titleQuery: this.titleQuery,
1140
+ creatorQuery: this.creatorQuery,
1141
+ minSelectedDate: this.minSelectedDate,
1142
+ maxSelectedDate: this.maxSelectedDate,
1143
+ selectedTitleFilter: (_c = this.selectedTitleFilter) !== null && _c !== void 0 ? _c : undefined,
1144
+ selectedCreatorFilter: (_d = this.selectedCreatorFilter) !== null && _d !== void 0 ? _d : undefined,
1145
+ };
1146
+ this.restorationStateHandler.persistState(restorationState);
1147
+ }
1148
+ async doInitialPageFetch() {
1149
+ this.searchResultsLoading = true;
1150
+ // Try to batch 2 initial page requests when possible
1151
+ await this.fetchPage(this.initialPageNumber, 2);
1152
+ this.searchResultsLoading = false;
1153
+ }
1154
+ emitSearchResultsLoadingChanged() {
1155
+ this.dispatchEvent(new CustomEvent('searchResultsLoadingChanged', {
1156
+ detail: {
1157
+ loading: this.searchResultsLoading,
1158
+ },
1159
+ }));
1160
+ }
1161
+ /**
1162
+ * Produces a compact unique ID for a search request that can help with debugging
1163
+ * on the backend by making related requests easier to trace through different services.
1164
+ * (e.g., tying the hits/aggregations requests for the same page back to a single hash).
1165
+ *
1166
+ * @param params The search service parameters for the request
1167
+ * @param kind The kind of request (hits-only, aggregations-only, or both)
1168
+ * @returns A Promise resolving to the uid to apply to the request
1169
+ */
1170
+ async requestUID(params, kind) {
1171
+ var _a;
1172
+ const paramsToHash = JSON.stringify({
1173
+ pageType: params.pageType,
1174
+ pageTarget: params.pageTarget,
1175
+ query: params.query,
1176
+ fields: params.fields,
1177
+ filters: params.filters,
1178
+ sort: params.sort,
1179
+ searchType: this.searchType,
1180
+ });
1181
+ const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this
1182
+ const sessionId = (await this.getSessionId()).slice(0, 20); // Likewise
1183
+ const page = (_a = params.page) !== null && _a !== void 0 ? _a : 0;
1184
+ const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations
1185
+ const currentTime = Date.now();
1186
+ return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;
1187
+ }
1188
+ /**
1189
+ * Constructs a search service FilterMap object from the combination of
1190
+ * all the currently-applied filters. This includes any facets, letter
1191
+ * filters, and date range.
1192
+ */
1193
+ get filterMap() {
1194
+ const builder = new FilterMapBuilder();
1195
+ // Add the date range, if applicable
1196
+ if (this.minSelectedDate) {
1197
+ builder.addFilter('year', this.minSelectedDate, FilterConstraint.GREATER_OR_EQUAL);
1198
+ }
1199
+ if (this.maxSelectedDate) {
1200
+ builder.addFilter('year', this.maxSelectedDate, FilterConstraint.LESS_OR_EQUAL);
1201
+ }
1202
+ // Add any selected facets
1203
+ if (this.selectedFacets) {
1204
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1205
+ const { name, values } = this.prepareFacetForFetch(facetName, facetValues);
1206
+ for (const [value, bucket] of Object.entries(values)) {
1207
+ let constraint;
1208
+ if (bucket.state === 'selected') {
1209
+ constraint = FilterConstraint.INCLUDE;
1210
+ }
1211
+ else if (bucket.state === 'hidden') {
1212
+ constraint = FilterConstraint.EXCLUDE;
1213
+ }
1214
+ if (constraint) {
1215
+ builder.addFilter(name, value, constraint);
1216
+ }
1217
+ }
1218
+ }
1219
+ }
1220
+ // Add any letter filters
1221
+ if (this.selectedTitleFilter) {
1222
+ builder.addFilter('firstTitle', this.selectedTitleFilter, FilterConstraint.INCLUDE);
1223
+ }
1224
+ if (this.selectedCreatorFilter) {
1225
+ builder.addFilter('firstCreator', this.selectedCreatorFilter, FilterConstraint.INCLUDE);
1226
+ }
1227
+ const filterMap = builder.build();
1228
+ return filterMap;
1229
+ }
1230
+ /** The full query, including year facets and date range clauses */
1231
+ get fullQuery() {
1232
+ var _a, _b;
1233
+ let fullQuery = (_b = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
1234
+ const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;
1235
+ if (facetQuery) {
1236
+ fullQuery += ` AND ${facetQuery}`;
1237
+ }
1238
+ if (dateRangeQueryClause) {
1239
+ fullQuery += ` AND ${dateRangeQueryClause}`;
1240
+ }
1241
+ if (sortFilterQueries) {
1242
+ fullQuery += ` AND ${sortFilterQueries}`;
1243
+ }
1244
+ return fullQuery.trim();
1245
+ }
1246
+ /**
1247
+ * Generates a query string for the given facets
1248
+ *
1249
+ * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
1250
+ */
1251
+ get facetQuery() {
1252
+ var _a;
1253
+ if (!this.selectedFacets)
1254
+ return undefined;
1255
+ const facetClauses = [];
1256
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1257
+ facetClauses.push(this.buildFacetClause(facetName, facetValues));
1258
+ }
1259
+ return (_a = this.joinFacetClauses(facetClauses)) === null || _a === void 0 ? void 0 : _a.trim();
1260
+ }
1261
+ /**
1262
+ * Builds an OR-joined facet clause for the given facet name and values.
1263
+ *
1264
+ * E.g., for name `subject` and values
1265
+ * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`
1266
+ * this will produce the clause
1267
+ * `subject:("foo" OR -"bar")`.
1268
+ *
1269
+ * @param facetName The facet type (e.g., 'collection')
1270
+ * @param facetValues The facet buckets, mapped by their keys
1271
+ */
1272
+ buildFacetClause(facetName, facetValues) {
1273
+ const { name: facetQueryName, values } = this.prepareFacetForFetch(facetName, facetValues);
1274
+ const facetEntries = Object.entries(values);
1275
+ if (facetEntries.length === 0)
1276
+ return '';
1277
+ const facetValuesArray = [];
1278
+ for (const [key, facetData] of facetEntries) {
1279
+ const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
1280
+ facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
1281
+ }
1282
+ const valueQuery = facetValuesArray.join(` OR `);
1283
+ return `${facetQueryName}:(${valueQuery})`;
1284
+ }
1285
+ /**
1286
+ * Handles some special pre-request normalization steps for certain facet types
1287
+ * that require them.
1288
+ *
1289
+ * @param facetName The name of the facet type (e.g., 'language')
1290
+ * @param facetValues An array of values for that facet type
1291
+ */
1292
+ prepareFacetForFetch(facetName, facetValues) {
1293
+ // eslint-disable-next-line prefer-const
1294
+ let [normalizedName, normalizedValues] = [facetName, facetValues];
1295
+ // The full "search engine" name of the lending field is "lending___status"
1296
+ if (facetName === 'lending') {
1297
+ normalizedName = 'lending___status';
1298
+ }
1299
+ return {
1300
+ name: normalizedName,
1301
+ values: normalizedValues,
1302
+ };
1303
+ }
1304
+ /**
1305
+ * Takes an array of facet clauses, and combines them into a
1306
+ * full AND-joined facet query string. Empty clauses are ignored.
1307
+ */
1308
+ joinFacetClauses(facetClauses) {
1309
+ const nonEmptyFacetClauses = facetClauses.filter(clause => clause.length > 0);
1310
+ return nonEmptyFacetClauses.length > 0
1311
+ ? `(${nonEmptyFacetClauses.join(' AND ')})`
1312
+ : undefined;
1313
+ }
1314
+ facetsChanged(e) {
1315
+ this.selectedFacets = e.detail;
1316
+ }
1317
+ facetClickHandler({ detail: { key, state: facetState, negative }, }) {
1318
+ var _a, _b;
1319
+ if (negative) {
1320
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1321
+ category: this.searchContext,
1322
+ action: facetState !== 'none'
1323
+ ? analyticsActions.facetNegativeSelected
1324
+ : analyticsActions.facetNegativeDeselected,
1325
+ label: key,
1326
+ });
1327
+ }
1328
+ else {
1329
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1330
+ category: this.searchContext,
1331
+ action: facetState !== 'none'
1332
+ ? analyticsActions.facetSelected
1333
+ : analyticsActions.facetDeselected,
1334
+ label: key,
1335
+ });
1336
+ }
1337
+ }
1338
+ async fetchFacets() {
1339
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1340
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1341
+ if (!this.canPerformSearch)
1342
+ return;
1343
+ const { facetFetchQueryKey } = this;
1344
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1345
+ const params = {
1346
+ ...this.collectionParams,
1347
+ query: trimmedQuery || '',
1348
+ rows: 0,
1349
+ filters: this.filterMap,
1350
+ // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
1351
+ aggregationsSize: 10,
1352
+ // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
1353
+ // The default aggregations for the search_results page type should be what we need here.
1354
+ };
1355
+ params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1356
+ this.facetsLoading = true;
1357
+ const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1358
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1359
+ // This is checking to see if the query has changed since the data was fetched.
1360
+ // If so, we just want to discard this set of aggregations because they are
1361
+ // likely no longer valid for the newer query.
1362
+ const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1363
+ if (queryChangedSinceFetch)
1364
+ return;
1365
+ if (!success) {
1366
+ const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
1367
+ 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;
1368
+ if (!errorMsg && !detailMsg) {
1369
+ // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1370
+ (_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');
1371
+ }
1372
+ return;
1373
+ }
1374
+ const { aggregations, collectionTitles } = success.response;
1375
+ this.aggregations = aggregations;
1376
+ if (collectionTitles) {
1377
+ (_h = this.collectionNameCache) === null || _h === void 0 ? void 0 : _h.addKnownTitles(collectionTitles);
1378
+ }
1379
+ else if ((_j = this.aggregations) === null || _j === void 0 ? void 0 : _j.collection) {
1380
+ (_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(); }));
1381
+ }
1382
+ this.fullYearsHistogramAggregation =
1383
+ (_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;
1384
+ this.facetsLoading = false;
1385
+ }
1386
+ scrollToPage(pageNumber) {
1387
+ return new Promise(resolve => {
1388
+ const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1389
+ // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1390
+ // then scrolls to the cell
1391
+ setTimeout(() => {
1392
+ var _a;
1393
+ this.isScrollingToCell = true;
1394
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.scrollToCell(cellIndexToScrollTo, true);
1395
+ // This timeout is to give the scroll animation time to finish
1396
+ // then updating the infinite scroller once we're done scrolling
1397
+ // There's no scroll animation completion callback so we're
1398
+ // giving it 0.5s to finish.
1399
+ setTimeout(() => {
1400
+ var _a;
1401
+ this.isScrollingToCell = false;
1402
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1403
+ resolve();
1404
+ }, 500);
1405
+ }, 0);
1406
+ });
1407
+ }
1408
+ /**
1409
+ * Whether sorting by relevance makes sense for the current state.
1410
+ * Currently equivalent to having a non-empty query.
1411
+ */
1412
+ get isRelevanceSortAvailable() {
1413
+ var _a;
1414
+ return !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
1415
+ }
1416
+ /**
1417
+ * Whether a search may be performed in the current state of the component.
1418
+ * This is only true if the search service is defined, and either
1419
+ * (a) a non-empty query is set, or
1420
+ * (b) we are on a collection page in metadata search mode.
1421
+ */
1422
+ get canPerformSearch() {
1423
+ var _a;
1424
+ if (!this.searchService)
1425
+ return false;
1426
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1427
+ const hasNonEmptyQuery = !!trimmedQuery;
1428
+ const isCollectionSearch = !!this.withinCollection;
1429
+ const isMetadataSearch = this.searchType === SearchType.METADATA;
1430
+ // Metadata searches within a collection are allowed to have no query.
1431
+ // Otherwise, a non-empty query must be set.
1432
+ return hasNonEmptyQuery || (isCollectionSearch && isMetadataSearch);
1433
+ }
1434
+ /**
1435
+ * Additional params to pass to the search service if targeting a collection page,
1436
+ * or null otherwise.
1437
+ */
1438
+ get collectionParams() {
1439
+ return this.withinCollection
1440
+ ? { pageType: 'collection_details', pageTarget: this.withinCollection }
1441
+ : null;
1442
+ }
1443
+ /**
1444
+ * The query key is a string that uniquely identifies the current search.
1445
+ * It consists of:
1446
+ * - The current base query
1447
+ * - The current collection
1448
+ * - The current search type
1449
+ * - Any currently-applied facets
1450
+ * - Any currently-applied date range
1451
+ * - Any currently-applied prefix filters
1452
+ * - The current sort options
1453
+ *
1454
+ * This lets us keep track of queries so we don't persist data that's
1455
+ * no longer relevant.
1456
+ */
1457
+ get pageFetchQueryKey() {
1458
+ var _a, _b, _c, _d;
1459
+ const sortField = (_b = (_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : 'none';
1460
+ const sortDirection = (_d = (_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.direction) !== null && _d !== void 0 ? _d : 'none';
1461
+ return `${this.fullQuery}-${this.withinCollection}-${this.searchType}-${sortField}-${sortDirection}`;
1462
+ }
1463
+ /**
1464
+ * Similar to `pageFetchQueryKey` above, but excludes sort fields since they
1465
+ * are not relevant in determining aggregation queries.
1466
+ */
1467
+ get facetFetchQueryKey() {
1468
+ return `${this.fullQuery}-${this.withinCollection}-${this.searchType}`;
1469
+ }
1470
+ /**
1471
+ * Fetches one or more pages of results and updates the data source.
1472
+ *
1473
+ * @param pageNumber The page number to fetch
1474
+ * @param numInitialPages If this is an initial page fetch (`pageNumber = 1`),
1475
+ * specifies how many pages to batch together in one request. Ignored
1476
+ * if `pageNumber != 1`, defaulting to a single page.
1477
+ */
1478
+ async fetchPage(pageNumber, numInitialPages = 1) {
1479
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
1480
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1481
+ if (!this.canPerformSearch)
1482
+ return;
1483
+ // if we already have data, don't fetch again
1484
+ if (this.dataSource[pageNumber])
1485
+ return;
1486
+ if (this.endOfDataReached)
1487
+ return;
1488
+ // Batch multiple initial page requests together if needed (e.g., can request
1489
+ // pages 1 and 2 together in a single request).
1490
+ const numPages = pageNumber === 1 ? numInitialPages : 1;
1491
+ const numRows = this.pageSize * numPages;
1492
+ // if a fetch is already in progress for this query and page, don't fetch again
1493
+ const { pageFetchQueryKey } = this;
1494
+ const pageFetches = (_b = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _b !== void 0 ? _b : new Set();
1495
+ if (pageFetches.has(pageNumber))
1496
+ return;
1497
+ for (let i = 0; i < numPages; i += 1) {
1498
+ pageFetches.add(pageNumber + i);
1499
+ }
1500
+ this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
1501
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1502
+ const params = {
1503
+ ...this.collectionParams,
1504
+ query: trimmedQuery || '',
1505
+ page: pageNumber,
1506
+ rows: numRows,
1507
+ sort: sortParams,
1508
+ filters: this.filterMap,
1509
+ aggregations: { omit: true },
1510
+ };
1511
+ params.uid = await this.requestUID(params, 'hits');
1512
+ const searchResponse = await ((_c = this.searchService) === null || _c === void 0 ? void 0 : _c.search(params, this.searchType));
1513
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1514
+ // This is checking to see if the query has changed since the data was fetched.
1515
+ // If so, we just want to discard the data since there should be a new query
1516
+ // right behind it.
1517
+ const queryChangedSinceFetch = pageFetchQueryKey !== this.pageFetchQueryKey;
1518
+ if (queryChangedSinceFetch)
1519
+ return;
1520
+ if (!success) {
1521
+ const errorMsg = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.message;
1522
+ 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;
1523
+ this.queryErrorMessage = `${errorMsg !== null && errorMsg !== void 0 ? errorMsg : ''}${detailMsg ? `; ${detailMsg}` : ''}`;
1524
+ if (!this.queryErrorMessage) {
1525
+ this.queryErrorMessage = 'Missing or malformed response from backend';
1526
+ // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1527
+ (_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');
1528
+ }
1529
+ for (let i = 0; i < numPages; i += 1) {
1530
+ (_j = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _j === void 0 ? void 0 : _j.delete(pageNumber + i);
1531
+ }
1532
+ this.searchResultsLoading = false;
1533
+ return;
1534
+ }
1535
+ this.totalResults = success.response.totalResults - this.tileModelOffset;
1536
+ // display event to offshoot when result count is zero.
1537
+ if (this.totalResults === 0) {
1538
+ this.emitEmptyResults();
1539
+ }
1540
+ if (this.withinCollection) {
1541
+ this.collectionInfo = success.response.collectionExtraInfo;
1542
+ // For collections, we want the UI to respect the default sort option
1543
+ // which can be specified in metadata, or otherwise assumed to be week:desc
1544
+ this.applyDefaultCollectionSort(this.collectionInfo);
1545
+ if (this.collectionInfo) {
1546
+ this.parentCollections = [].concat((_l = (_k = this.collectionInfo.public_metadata) === null || _k === void 0 ? void 0 : _k.collection) !== null && _l !== void 0 ? _l : []);
1547
+ }
1548
+ }
1549
+ const { results, collectionTitles } = success.response;
1550
+ if (results && results.length > 0) {
1551
+ // Load any collection titles present on the response into the cache,
1552
+ // or queue up preload fetches for them if none were present.
1553
+ if (collectionTitles) {
1554
+ (_m = this.collectionNameCache) === null || _m === void 0 ? void 0 : _m.addKnownTitles(collectionTitles);
1555
+ }
1556
+ else {
1557
+ this.preloadCollectionNames(results);
1558
+ }
1559
+ // Update the data source for each returned page
1560
+ for (let i = 0; i < numPages; i += 1) {
1561
+ const pageStartIndex = this.pageSize * i;
1562
+ this.updateDataSource(pageNumber + i, results.slice(pageStartIndex, pageStartIndex + this.pageSize));
1563
+ }
1564
+ }
1565
+ // When we reach the end of the data, we can set the infinite scroller's
1566
+ // item count to the real total number of results (rather than the
1567
+ // temporary estimates based on pages rendered so far).
1568
+ const resultCountDiscrepancy = numRows - results.length;
1569
+ if (resultCountDiscrepancy > 0) {
1570
+ this.endOfDataReached = true;
1571
+ if (this.infiniteScroller) {
1572
+ this.infiniteScroller.itemCount = this.totalResults;
1573
+ }
1574
+ }
1575
+ for (let i = 0; i < numPages; i += 1) {
1576
+ (_o = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _o === void 0 ? void 0 : _o.delete(pageNumber + i);
1577
+ }
1578
+ }
1579
+ preloadCollectionNames(results) {
1580
+ var _a;
1581
+ const collectionIds = results
1582
+ .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
1583
+ .flat();
1584
+ const collectionIdsArray = Array.from(new Set(collectionIds));
1585
+ (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
1586
+ }
1587
+ /**
1588
+ * Applies any default sort option for the current collection, by checking
1589
+ * for one in the collection's metadata. If none is found, defaults to sorting
1590
+ * descending by:
1591
+ * - Date Favorited for fav-* collections
1592
+ * - Weekly views for all other collections
1593
+ */
1594
+ applyDefaultCollectionSort(collectionInfo) {
1595
+ var _a, _b, _c;
1596
+ if (this.baseQuery) {
1597
+ // If there's a query set, then we default to relevance sorting regardless of
1598
+ // the collection metadata-specified sort.
1599
+ this.defaultSortField = SortField.relevance;
1600
+ this.defaultSortDirection = null;
1601
+ return;
1602
+ }
1603
+ // Favorite collections sort on Date Favorited by default.
1604
+ // Other collections fall back to sorting on weekly views.
1605
+ 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-'))
1606
+ ? '-favoritedate'
1607
+ : '-week';
1608
+ // The collection metadata may override the default sorting with something else
1609
+ const metadataSort = (_c = collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.public_metadata) === null || _c === void 0 ? void 0 : _c['sort-by'];
1610
+ // Prefer the metadata-specified sort if one exists
1611
+ const defaultSortToApply = metadataSort !== null && metadataSort !== void 0 ? metadataSort : baseDefaultSort;
1612
+ // Account for both -field and field:dir formats
1613
+ let [field, dir] = defaultSortToApply.split(':');
1614
+ if (field.startsWith('-')) {
1615
+ field = field.slice(1);
1616
+ dir = 'desc';
1617
+ }
1618
+ else if (!['asc', 'desc'].includes(dir)) {
1619
+ dir = 'asc';
1620
+ }
1621
+ const sortOption = sortOptionFromAPIString(field);
1622
+ const sortField = sortOption.field;
1623
+ if (sortField && sortField !== SortField.default) {
1624
+ this.defaultSortField = sortField;
1625
+ this.defaultSortDirection = dir;
1626
+ this.defaultSortParam = {
1627
+ field: this.defaultSortField,
1628
+ direction: this.defaultSortDirection,
1629
+ };
1630
+ }
1631
+ }
1632
+ /**
1633
+ * This is useful for determining whether we need to reload the scroller.
1634
+ *
1635
+ * When the fetch completes, we need to reload the scroller if the cells for that
1636
+ * page are visible, but if the page is not currenlty visible, we don't need to reload
1637
+ */
1638
+ get currentVisiblePageNumbers() {
1639
+ var _a, _b;
1640
+ const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
1641
+ const visiblePages = new Set();
1642
+ visibleCells.forEach(cellIndex => {
1643
+ const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1644
+ visiblePages.add(visiblePage);
1645
+ });
1646
+ return Array.from(visiblePages);
1647
+ }
1648
+ /**
1649
+ * Update the datasource from the fetch response
1650
+ *
1651
+ * @param pageNumber
1652
+ * @param results
1653
+ */
1654
+ updateDataSource(pageNumber, results) {
1655
+ var _a;
1656
+ // copy our existing datasource so when we set it below, it gets set
1657
+ // instead of modifying the existing dataSource since object changes
1658
+ // don't trigger a re-render
1659
+ const datasource = { ...this.dataSource };
1660
+ const tiles = [];
1661
+ results === null || results === void 0 ? void 0 : results.forEach(result => {
1662
+ 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;
1663
+ if (!result.identifier)
1664
+ return;
1665
+ let loginRequired = false;
1666
+ let contentWarning = false;
1667
+ // Check if item and item in "modifying" collection, setting above flags
1668
+ if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
1669
+ ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
1670
+ for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
1671
+ if (collection === 'loggedin') {
1672
+ loginRequired = true;
1673
+ if (contentWarning)
1674
+ break;
1675
+ }
1676
+ if (collection === 'no-preview') {
1677
+ contentWarning = true;
1678
+ if (loginRequired)
1679
+ break;
1680
+ }
1681
+ }
1682
+ }
1683
+ tiles.push({
1684
+ averageRating: (_e = result.avg_rating) === null || _e === void 0 ? void 0 : _e.value,
1685
+ checked: false,
1686
+ collections: (_g = (_f = result.collection) === null || _f === void 0 ? void 0 : _f.values) !== null && _g !== void 0 ? _g : [],
1687
+ collectionFilesCount: (_j = (_h = result.collection_files_count) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : 0,
1688
+ collectionSize: (_l = (_k = result.collection_size) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : 0,
1689
+ commentCount: (_o = (_m = result.num_reviews) === null || _m === void 0 ? void 0 : _m.value) !== null && _o !== void 0 ? _o : 0,
1690
+ creator: (_p = result.creator) === null || _p === void 0 ? void 0 : _p.value,
1691
+ creators: (_r = (_q = result.creator) === null || _q === void 0 ? void 0 : _q.values) !== null && _r !== void 0 ? _r : [],
1692
+ dateAdded: (_s = result.addeddate) === null || _s === void 0 ? void 0 : _s.value,
1693
+ dateArchived: (_t = result.publicdate) === null || _t === void 0 ? void 0 : _t.value,
1694
+ datePublished: (_u = result.date) === null || _u === void 0 ? void 0 : _u.value,
1695
+ dateReviewed: (_v = result.reviewdate) === null || _v === void 0 ? void 0 : _v.value,
1696
+ description: (_w = result.description) === null || _w === void 0 ? void 0 : _w.values.join('\n'),
1697
+ favCount: (_y = (_x = result.num_favorites) === null || _x === void 0 ? void 0 : _x.value) !== null && _y !== void 0 ? _y : 0,
1698
+ href: this.collapseRepeatedQuotes((_z = result.__href__) === null || _z === void 0 ? void 0 : _z.value),
1699
+ identifier: result.identifier,
1700
+ issue: (_0 = result.issue) === null || _0 === void 0 ? void 0 : _0.value,
1701
+ itemCount: (_2 = (_1 = result.item_count) === null || _1 === void 0 ? void 0 : _1.value) !== null && _2 !== void 0 ? _2 : 0,
1702
+ mediatype: this.getMediatype(result),
1703
+ snippets: (_4 = (_3 = result.highlight) === null || _3 === void 0 ? void 0 : _3.values) !== null && _4 !== void 0 ? _4 : [],
1704
+ source: (_5 = result.source) === null || _5 === void 0 ? void 0 : _5.value,
1705
+ subjects: (_7 = (_6 = result.subject) === null || _6 === void 0 ? void 0 : _6.values) !== null && _7 !== void 0 ? _7 : [],
1706
+ title: (_9 = (_8 = result.title) === null || _8 === void 0 ? void 0 : _8.value) !== null && _9 !== void 0 ? _9 : '',
1707
+ volume: (_10 = result.volume) === null || _10 === void 0 ? void 0 : _10.value,
1708
+ viewCount: (_12 = (_11 = result.downloads) === null || _11 === void 0 ? void 0 : _11.value) !== null && _12 !== void 0 ? _12 : 0,
1709
+ weeklyViewCount: (_13 = result.week) === null || _13 === void 0 ? void 0 : _13.value,
1710
+ loginRequired,
1711
+ contentWarning,
1712
+ });
1713
+ });
1714
+ datasource[pageNumber] = tiles;
1715
+ this.dataSource = datasource;
1716
+ const visiblePages = this.currentVisiblePageNumbers;
1717
+ const needsReload = visiblePages.includes(pageNumber);
1718
+ if (needsReload) {
1719
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1720
+ }
1721
+ }
1722
+ getMediatype(result) {
1723
+ var _a, _b, _c;
1724
+ /**
1725
+ * hit_type == 'favorited_search' is basically a new hit_type
1726
+ * - we are getting from PPS.
1727
+ * - which gives response for fav- collection
1728
+ * - having favorited items like account/collection/item etc..
1729
+ * - as user can also favorite a search result (a search page)
1730
+ * - so we need to have response (having fav- items and fav- search results)
1731
+ *
1732
+ * if backend hit_type == 'favorited_search'
1733
+ * - let's assume a "search" as new mediatype
1734
+ */
1735
+ if (((_a = result === null || result === void 0 ? void 0 : result.rawMetadata) === null || _a === void 0 ? void 0 : _a.hit_type) === 'favorited_search') {
1736
+ return 'search';
1737
+ }
1738
+ return (_c = (_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 'data';
1739
+ }
1740
+ /**
1741
+ * Returns the input string, but removing one set of quotes from all instances of
1742
+ * ""clauses wrapped in two sets of quotes"". This assumes the quotes are already
1743
+ * URL-encoded.
1744
+ *
1745
+ * This should be a temporary measure to address the fact that the __href__ field
1746
+ * sometimes acquires extra quotation marks during query rewriting. Once there is a
1747
+ * full Lucene parser in place that handles quoted queries correctly, this can likely
1748
+ * be removed.
1749
+ */
1750
+ collapseRepeatedQuotes(str) {
1751
+ return str === null || str === void 0 ? void 0 : str.replace(/%22%22(?!%22%22)(.+?)%22%22/g, '%22$1%22');
1752
+ }
1753
+ /** Fetches the aggregation buckets for the given prefix filter type. */
1754
+ async fetchPrefixFilterBuckets(filterType) {
1755
+ var _a, _b, _c, _d, _e, _f, _g;
1756
+ const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1757
+ if (!this.canPerformSearch)
1758
+ return [];
1759
+ const filterAggregationKey = prefixFilterAggregationKeys[filterType];
1760
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1761
+ const params = {
1762
+ ...this.collectionParams,
1763
+ query: trimmedQuery || '',
1764
+ rows: 0,
1765
+ filters: this.filterMap,
1766
+ // Only fetch the firstTitle or firstCreator aggregation
1767
+ aggregations: { simpleParams: [filterAggregationKey] },
1768
+ // Fetch all 26 letter buckets
1769
+ aggregationsSize: 26,
1770
+ };
1771
+ params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1772
+ const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1773
+ 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 : []);
1774
+ }
1775
+ /** Fetches and caches the prefix filter counts for the given filter type. */
1776
+ async updatePrefixFilterCounts(filterType) {
1777
+ const { facetFetchQueryKey } = this;
1778
+ const buckets = await this.fetchPrefixFilterBuckets(filterType);
1779
+ // Don't update the filter counts for an outdated query (if it has been changed
1780
+ // since we sent the request)
1781
+ const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1782
+ if (queryChangedSinceFetch)
1783
+ return;
1784
+ // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }
1785
+ this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update
1786
+ this.prefixFilterCountMap[filterType] = buckets.reduce((acc, bucket) => {
1787
+ acc[bucket.key.toUpperCase()] = bucket.doc_count;
1788
+ return acc;
1789
+ }, {});
1790
+ }
1791
+ /**
1792
+ * Fetches and caches the prefix filter counts for the current sort type,
1793
+ * provided it is one that permits prefix filtering. (If not, this does nothing).
1794
+ */
1795
+ async updatePrefixFiltersForCurrentSort() {
1796
+ if (['title', 'creator'].includes(this.selectedSort)) {
1797
+ const filterType = this.selectedSort;
1798
+ if (!this.prefixFilterCountMap[filterType]) {
1799
+ this.updatePrefixFilterCounts(filterType);
1800
+ }
1801
+ }
1802
+ }
1803
+ /**
1804
+ * Clears the cached letter counts for both title and creator, and
1805
+ * fetches a new set of counts for whichever of them is the currently
1806
+ * selected sort option (which may be neither).
1807
+ *
1808
+ * Call this whenever the counts are invalidated (e.g., by a query change).
1809
+ */
1810
+ refreshLetterCounts() {
1811
+ if (Object.keys(this.prefixFilterCountMap).length > 0) {
1812
+ this.prefixFilterCountMap = {};
1813
+ }
1814
+ this.updatePrefixFiltersForCurrentSort();
1815
+ }
1816
+ /**
1817
+ * Callback when a result is selected
1818
+ */
1819
+ resultSelected(event) {
1820
+ var _a, _b, _c;
1821
+ if (this.isManageView) {
1822
+ // Checked/unchecked state change -- rerender to ensure it propagates
1823
+ // this.mapDataSource(model => ({ ...model }));
1824
+ const cellIndex = Object.values(this.dataSource)
1825
+ .flat()
1826
+ .indexOf(event.detail);
1827
+ if (cellIndex >= 0)
1828
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshCell(cellIndex - this.tileModelOffset);
1829
+ }
1830
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1831
+ category: this.searchContext,
1832
+ action: analyticsActions.resultSelected,
1833
+ label: event.detail.mediatype,
1834
+ });
1835
+ (_c = this.analyticsHandler) === null || _c === void 0 ? void 0 : _c.sendEvent({
1836
+ category: this.searchContext,
1837
+ action: analyticsActions.resultSelected,
1838
+ label: `page-${this.currentPage}`,
1839
+ });
1840
+ }
1841
+ cellForIndex(index) {
1842
+ const model = this.tileModelAtCellIndex(index);
1843
+ if (!model)
1844
+ return undefined;
1839
1845
  return html `
1840
1846
  <tile-dispatcher
1841
1847
  .collectionPagePath=${this.collectionPagePath}
@@ -1846,6 +1852,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1846
1852
  .resizeObserver=${this.resizeObserver}
1847
1853
  .collectionNameCache=${this.collectionNameCache}
1848
1854
  .sortParam=${this.sortParam}
1855
+ .defaultSortParam=${this.defaultSortParam}
1849
1856
  .creatorFilter=${this.selectedCreatorFilter}
1850
1857
  .mobileBreakpoint=${this.mobileBreakpoint}
1851
1858
  .loggedIn=${this.loggedIn}
@@ -1854,21 +1861,21 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1854
1861
  @resultSelected=${(e) => this.resultSelected(e)}
1855
1862
  >
1856
1863
  </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,
1864
+ `;
1865
+ }
1866
+ /**
1867
+ * When the user scrolls near to the bottom of the page, fetch the next page
1868
+ * increase the number of pages to render and start fetching data for the new page
1869
+ */
1870
+ scrollThresholdReached() {
1871
+ if (!this.endOfDataReached) {
1872
+ this.pagesToRender += 1;
1873
+ this.fetchPage(this.pagesToRender);
1874
+ }
1875
+ }
1876
+ static get styles() {
1877
+ return [
1878
+ srOnlyStyle,
1872
1879
  css `
1873
1880
  :host {
1874
1881
  display: block;
@@ -2239,168 +2246,171 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
2239
2246
  infinite-scroller.hidden {
2240
2247
  display: none;
2241
2248
  }
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 };
2249
+ `,
2250
+ ];
2251
+ }
2252
+ };
2253
+ __decorate([
2254
+ property({ type: String })
2255
+ ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
2256
+ __decorate([
2257
+ property({ type: String })
2258
+ ], CollectionBrowser.prototype, "baseImageUrl", void 0);
2259
+ __decorate([
2260
+ property({ type: Object })
2261
+ ], CollectionBrowser.prototype, "searchService", void 0);
2262
+ __decorate([
2263
+ property({ type: String })
2264
+ ], CollectionBrowser.prototype, "searchType", void 0);
2265
+ __decorate([
2266
+ property({ type: String })
2267
+ ], CollectionBrowser.prototype, "withinCollection", void 0);
2268
+ __decorate([
2269
+ property({ type: String })
2270
+ ], CollectionBrowser.prototype, "baseQuery", void 0);
2271
+ __decorate([
2272
+ property({ type: String })
2273
+ ], CollectionBrowser.prototype, "displayMode", void 0);
2274
+ __decorate([
2275
+ property({ type: Object })
2276
+ ], CollectionBrowser.prototype, "sortParam", void 0);
2277
+ __decorate([
2278
+ property({ type: Object })
2279
+ ], CollectionBrowser.prototype, "defaultSortParam", void 0);
2280
+ __decorate([
2281
+ property({ type: String })
2282
+ ], CollectionBrowser.prototype, "selectedSort", void 0);
2283
+ __decorate([
2284
+ property({ type: String })
2285
+ ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
2286
+ __decorate([
2287
+ property({ type: String })
2288
+ ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
2289
+ __decorate([
2290
+ property({ type: String })
2291
+ ], CollectionBrowser.prototype, "sortDirection", void 0);
2292
+ __decorate([
2293
+ property({ type: Number })
2294
+ ], CollectionBrowser.prototype, "pageSize", void 0);
2295
+ __decorate([
2296
+ property({ type: Object })
2297
+ ], CollectionBrowser.prototype, "resizeObserver", void 0);
2298
+ __decorate([
2299
+ property({ type: Number })
2300
+ ], CollectionBrowser.prototype, "currentPage", void 0);
2301
+ __decorate([
2302
+ property({ type: String })
2303
+ ], CollectionBrowser.prototype, "minSelectedDate", void 0);
2304
+ __decorate([
2305
+ property({ type: String })
2306
+ ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
2307
+ __decorate([
2308
+ property({ type: Object })
2309
+ ], CollectionBrowser.prototype, "selectedFacets", void 0);
2310
+ __decorate([
2311
+ property({ type: Boolean })
2312
+ ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
2313
+ __decorate([
2314
+ property({ type: String })
2315
+ ], CollectionBrowser.prototype, "collectionPagePath", void 0);
2316
+ __decorate([
2317
+ property({ type: Object })
2318
+ ], CollectionBrowser.prototype, "collectionInfo", void 0);
2319
+ __decorate([
2320
+ property({ type: Array })
2321
+ ], CollectionBrowser.prototype, "parentCollections", void 0);
2322
+ __decorate([
2323
+ property({ type: String, reflect: true })
2324
+ ], CollectionBrowser.prototype, "searchContext", void 0);
2325
+ __decorate([
2326
+ property({ type: Object })
2327
+ ], CollectionBrowser.prototype, "collectionNameCache", void 0);
2328
+ __decorate([
2329
+ property({ type: String })
2330
+ ], CollectionBrowser.prototype, "pageContext", void 0);
2331
+ __decorate([
2332
+ property({ type: Object })
2333
+ ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
2334
+ __decorate([
2335
+ property({ type: Number })
2336
+ ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
2337
+ __decorate([
2338
+ property({ type: Boolean })
2339
+ ], CollectionBrowser.prototype, "loggedIn", void 0);
2340
+ __decorate([
2341
+ property({ type: Object })
2342
+ ], CollectionBrowser.prototype, "modalManager", void 0);
2343
+ __decorate([
2344
+ property({ type: Object })
2345
+ ], CollectionBrowser.prototype, "featureFeedbackService", void 0);
2346
+ __decorate([
2347
+ property({ type: Object })
2348
+ ], CollectionBrowser.prototype, "recaptchaManager", void 0);
2349
+ __decorate([
2350
+ property({ type: Boolean })
2351
+ ], CollectionBrowser.prototype, "isManageView", void 0);
2352
+ __decorate([
2353
+ state()
2354
+ ], CollectionBrowser.prototype, "pagesToRender", void 0);
2355
+ __decorate([
2356
+ state()
2357
+ ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
2358
+ __decorate([
2359
+ state()
2360
+ ], CollectionBrowser.prototype, "facetsLoading", void 0);
2361
+ __decorate([
2362
+ state()
2363
+ ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
2364
+ __decorate([
2365
+ state()
2366
+ ], CollectionBrowser.prototype, "aggregations", void 0);
2367
+ __decorate([
2368
+ state()
2369
+ ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
2370
+ __decorate([
2371
+ state()
2372
+ ], CollectionBrowser.prototype, "totalResults", void 0);
2373
+ __decorate([
2374
+ state()
2375
+ ], CollectionBrowser.prototype, "queryErrorMessage", void 0);
2376
+ __decorate([
2377
+ state()
2378
+ ], CollectionBrowser.prototype, "mobileView", void 0);
2379
+ __decorate([
2380
+ state()
2381
+ ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
2382
+ __decorate([
2383
+ state()
2384
+ ], CollectionBrowser.prototype, "contentWidth", void 0);
2385
+ __decorate([
2386
+ state()
2387
+ ], CollectionBrowser.prototype, "defaultSortField", void 0);
2388
+ __decorate([
2389
+ state()
2390
+ ], CollectionBrowser.prototype, "defaultSortDirection", void 0);
2391
+ __decorate([
2392
+ state()
2393
+ ], CollectionBrowser.prototype, "placeholderType", void 0);
2394
+ __decorate([
2395
+ state()
2396
+ ], CollectionBrowser.prototype, "prefixFilterCountMap", void 0);
2397
+ __decorate([
2398
+ query('#content-container')
2399
+ ], CollectionBrowser.prototype, "contentContainer", void 0);
2400
+ __decorate([
2401
+ query('#left-column')
2402
+ ], CollectionBrowser.prototype, "leftColumn", void 0);
2403
+ __decorate([
2404
+ query('collection-facets')
2405
+ ], CollectionBrowser.prototype, "collectionFacets", void 0);
2406
+ __decorate([
2407
+ property({ type: Object, attribute: false })
2408
+ ], CollectionBrowser.prototype, "analyticsHandler", void 0);
2409
+ __decorate([
2410
+ query('infinite-scroller')
2411
+ ], CollectionBrowser.prototype, "infiniteScroller", void 0);
2412
+ CollectionBrowser = __decorate([
2413
+ customElement('collection-browser')
2414
+ ], CollectionBrowser);
2415
+ export { CollectionBrowser };
2406
2416
  //# sourceMappingURL=collection-browser.js.map