@internetarchive/collection-browser 1.14.1 → 1.14.2-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (289) 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 -0
  50. package/dist/src/assets/img/icons/mediatype/search.js +14 -0
  51. package/dist/src/assets/img/icons/mediatype/search.js.map +1 -0
  52. package/dist/src/assets/img/icons/mediatype/software.d.ts +1 -1
  53. package/dist/src/assets/img/icons/mediatype/software.js +2 -2
  54. package/dist/src/assets/img/icons/mediatype/texts.d.ts +1 -1
  55. package/dist/src/assets/img/icons/mediatype/texts.js +2 -2
  56. package/dist/src/assets/img/icons/mediatype/tv.d.ts +1 -1
  57. package/dist/src/assets/img/icons/mediatype/tv.js +2 -2
  58. package/dist/src/assets/img/icons/mediatype/video.d.ts +1 -1
  59. package/dist/src/assets/img/icons/mediatype/video.js +2 -2
  60. package/dist/src/assets/img/icons/mediatype/web.d.ts +1 -1
  61. package/dist/src/assets/img/icons/mediatype/web.js +2 -2
  62. package/dist/src/assets/img/icons/null-result.d.ts +2 -2
  63. package/dist/src/assets/img/icons/null-result.js +2 -2
  64. package/dist/src/assets/img/icons/restricted.d.ts +1 -1
  65. package/dist/src/assets/img/icons/restricted.js +2 -2
  66. package/dist/src/assets/img/icons/reviews.d.ts +1 -1
  67. package/dist/src/assets/img/icons/reviews.js +2 -2
  68. package/dist/src/assets/img/icons/upload.d.ts +1 -1
  69. package/dist/src/assets/img/icons/upload.js +2 -2
  70. package/dist/src/assets/img/icons/views.d.ts +1 -1
  71. package/dist/src/assets/img/icons/views.js +2 -2
  72. package/dist/src/circular-activity-indicator.d.ts +5 -5
  73. package/dist/src/circular-activity-indicator.js +17 -17
  74. package/dist/src/collection-browser.d.ts +524 -522
  75. package/dist/src/collection-browser.js +1859 -1834
  76. package/dist/src/collection-browser.js.map +1 -1
  77. package/dist/src/collection-facets/facet-tombstone-row.d.ts +5 -5
  78. package/dist/src/collection-facets/facet-tombstone-row.js +15 -15
  79. package/dist/src/collection-facets/facets-template.d.ts +20 -20
  80. package/dist/src/collection-facets/facets-template.js +152 -152
  81. package/dist/src/collection-facets/more-facets-content.d.ts +77 -77
  82. package/dist/src/collection-facets/more-facets-content.js +359 -359
  83. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -36
  84. package/dist/src/collection-facets/more-facets-pagination.js +196 -196
  85. package/dist/src/collection-facets/toggle-switch.d.ts +41 -41
  86. package/dist/src/collection-facets/toggle-switch.js +94 -94
  87. package/dist/src/collection-facets.d.ts +104 -104
  88. package/dist/src/collection-facets.js +506 -506
  89. package/dist/src/empty-placeholder.d.ts +23 -23
  90. package/dist/src/empty-placeholder.js +74 -74
  91. package/dist/src/expanded-date-picker.d.ts +43 -43
  92. package/dist/src/expanded-date-picker.js +109 -109
  93. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  94. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  95. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  96. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  97. package/dist/src/manage/manage-bar.d.ts +26 -26
  98. package/dist/src/manage/manage-bar.js +53 -53
  99. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  100. package/dist/src/mediatype/mediatype-config.js +91 -85
  101. package/dist/src/mediatype/mediatype-config.js.map +1 -1
  102. package/dist/src/models.d.ts +164 -164
  103. package/dist/src/models.js +269 -269
  104. package/dist/src/restoration-state-handler.d.ts +70 -70
  105. package/dist/src/restoration-state-handler.js +355 -355
  106. package/dist/src/sort-filter-bar/alpha-bar-tooltip.d.ts +6 -6
  107. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js +24 -24
  108. package/dist/src/sort-filter-bar/alpha-bar.d.ts +21 -21
  109. package/dist/src/sort-filter-bar/alpha-bar.js +128 -128
  110. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  111. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  112. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  113. package/dist/src/sort-filter-bar/img/list.js +2 -2
  114. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.d.ts +1 -1
  115. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js +2 -2
  116. package/dist/src/sort-filter-bar/img/sort-toggle-down.d.ts +1 -1
  117. package/dist/src/sort-filter-bar/img/sort-toggle-down.js +2 -2
  118. package/dist/src/sort-filter-bar/img/sort-toggle-up.d.ts +1 -1
  119. package/dist/src/sort-filter-bar/img/sort-toggle-up.js +2 -2
  120. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  121. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  122. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  123. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  124. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +208 -208
  125. package/dist/src/sort-filter-bar/sort-filter-bar.js +637 -637
  126. package/dist/src/styles/item-image-styles.d.ts +8 -8
  127. package/dist/src/styles/item-image-styles.js +13 -9
  128. package/dist/src/styles/item-image-styles.js.map +1 -1
  129. package/dist/src/styles/sr-only.d.ts +1 -1
  130. package/dist/src/styles/sr-only.js +2 -2
  131. package/dist/src/tiles/base-tile-component.d.ts +18 -18
  132. package/dist/src/tiles/base-tile-component.js +59 -59
  133. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  134. package/dist/src/tiles/collection-browser-loading-tile.js +15 -15
  135. package/dist/src/tiles/grid/account-tile.d.ts +18 -18
  136. package/dist/src/tiles/grid/account-tile.js +72 -72
  137. package/dist/src/tiles/grid/collection-tile.d.ts +15 -15
  138. package/dist/src/tiles/grid/collection-tile.js +80 -80
  139. package/dist/src/tiles/grid/item-tile.d.ts +27 -27
  140. package/dist/src/tiles/grid/item-tile.js +134 -134
  141. package/dist/src/tiles/grid/search-tile.d.ts +10 -0
  142. package/dist/src/tiles/grid/search-tile.js +92 -0
  143. package/dist/src/tiles/grid/search-tile.js.map +1 -0
  144. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.d.ts +1 -1
  145. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +8 -8
  146. package/dist/src/tiles/grid/tile-stats.d.ts +11 -11
  147. package/dist/src/tiles/grid/tile-stats.js +48 -48
  148. package/dist/src/tiles/hover/hover-pane-controller.d.ts +219 -219
  149. package/dist/src/tiles/hover/hover-pane-controller.js +352 -352
  150. package/dist/src/tiles/hover/tile-hover-pane.d.ts +15 -15
  151. package/dist/src/tiles/hover/tile-hover-pane.js +38 -38
  152. package/dist/src/tiles/image-block.d.ts +17 -17
  153. package/dist/src/tiles/image-block.js +75 -73
  154. package/dist/src/tiles/image-block.js.map +1 -1
  155. package/dist/src/tiles/item-image.d.ts +36 -35
  156. package/dist/src/tiles/item-image.js +148 -125
  157. package/dist/src/tiles/item-image.js.map +1 -1
  158. package/dist/src/tiles/list/tile-list-compact-header.d.ts +6 -6
  159. package/dist/src/tiles/list/tile-list-compact-header.js +38 -38
  160. package/dist/src/tiles/list/tile-list-compact.d.ts +15 -15
  161. package/dist/src/tiles/list/tile-list-compact.js +114 -114
  162. package/dist/src/tiles/list/tile-list.d.ts +46 -46
  163. package/dist/src/tiles/list/tile-list.js +302 -298
  164. package/dist/src/tiles/list/tile-list.js.map +1 -1
  165. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  166. package/dist/src/tiles/mediatype-icon.js +47 -47
  167. package/dist/src/tiles/overlay/icon-overlay.d.ts +10 -10
  168. package/dist/src/tiles/overlay/icon-overlay.js +40 -40
  169. package/dist/src/tiles/overlay/icon-text-overlay.d.ts +9 -9
  170. package/dist/src/tiles/overlay/icon-text-overlay.js +38 -38
  171. package/dist/src/tiles/overlay/text-overlay.d.ts +10 -10
  172. package/dist/src/tiles/overlay/text-overlay.js +42 -42
  173. package/dist/src/tiles/text-snippet-block.d.ts +27 -27
  174. package/dist/src/tiles/text-snippet-block.js +73 -73
  175. package/dist/src/tiles/tile-dispatcher.d.ts +64 -63
  176. package/dist/src/tiles/tile-dispatcher.js +249 -225
  177. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  178. package/dist/src/tiles/tile-display-value-provider.d.ts +43 -43
  179. package/dist/src/tiles/tile-display-value-provider.js +80 -80
  180. package/dist/src/utils/analytics-events.d.ts +25 -25
  181. package/dist/src/utils/analytics-events.js +27 -27
  182. package/dist/src/utils/array-equals.d.ts +4 -4
  183. package/dist/src/utils/array-equals.js +10 -10
  184. package/dist/src/utils/format-count.d.ts +7 -7
  185. package/dist/src/utils/format-count.js +76 -76
  186. package/dist/src/utils/format-date.d.ts +2 -2
  187. package/dist/src/utils/format-date.js +25 -25
  188. package/dist/src/utils/format-unit-size.d.ts +2 -2
  189. package/dist/src/utils/format-unit-size.js +33 -33
  190. package/dist/src/utils/local-date-from-utc.d.ts +9 -9
  191. package/dist/src/utils/local-date-from-utc.js +15 -15
  192. package/dist/src/utils/sha1.d.ts +2 -2
  193. package/dist/src/utils/sha1.js +8 -8
  194. package/dist/test/collection-browser.test.d.ts +1 -1
  195. package/dist/test/collection-browser.test.js +1098 -1098
  196. package/dist/test/collection-facets/facets-template.test.d.ts +1 -1
  197. package/dist/test/collection-facets/facets-template.test.js +134 -134
  198. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -1
  199. package/dist/test/collection-facets/more-facets-content.test.js +133 -133
  200. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -1
  201. package/dist/test/collection-facets/more-facets-pagination.test.js +117 -117
  202. package/dist/test/collection-facets/toggle-switch.test.d.ts +1 -1
  203. package/dist/test/collection-facets/toggle-switch.test.js +73 -73
  204. package/dist/test/collection-facets.test.d.ts +2 -2
  205. package/dist/test/collection-facets.test.js +682 -682
  206. package/dist/test/empty-placeholder.test.d.ts +1 -1
  207. package/dist/test/empty-placeholder.test.js +63 -63
  208. package/dist/test/expanded-date-picker.test.d.ts +1 -1
  209. package/dist/test/expanded-date-picker.test.js +95 -95
  210. package/dist/test/icon-overlay.test.d.ts +1 -1
  211. package/dist/test/icon-overlay.test.js +24 -24
  212. package/dist/test/image-block.test.d.ts +1 -1
  213. package/dist/test/image-block.test.js +48 -48
  214. package/dist/test/item-image.test.d.ts +1 -1
  215. package/dist/test/item-image.test.js +86 -86
  216. package/dist/test/manage/manage-bar.test.d.ts +1 -1
  217. package/dist/test/manage/manage-bar.test.js +72 -72
  218. package/dist/test/mediatype-config.test.d.ts +1 -1
  219. package/dist/test/mediatype-config.test.js +16 -16
  220. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  221. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  222. package/dist/test/mocks/mock-collection-name-cache.d.ts +9 -9
  223. package/dist/test/mocks/mock-collection-name-cache.js +17 -17
  224. package/dist/test/mocks/mock-search-responses.d.ts +21 -21
  225. package/dist/test/mocks/mock-search-responses.js +709 -709
  226. package/dist/test/mocks/mock-search-service.d.ts +15 -15
  227. package/dist/test/mocks/mock-search-service.js +50 -50
  228. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  229. package/dist/test/restoration-state-handler.test.js +270 -270
  230. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.d.ts +1 -1
  231. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +12 -12
  232. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +1 -1
  233. package/dist/test/sort-filter-bar/alpha-bar.test.js +73 -73
  234. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -1
  235. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +378 -378
  236. package/dist/test/text-overlay.test.d.ts +1 -1
  237. package/dist/test/text-overlay.test.js +48 -48
  238. package/dist/test/text-snippet-block.test.d.ts +1 -1
  239. package/dist/test/text-snippet-block.test.js +57 -57
  240. package/dist/test/tile-stats.test.d.ts +1 -1
  241. package/dist/test/tile-stats.test.js +33 -33
  242. package/dist/test/tiles/grid/account-tile.test.d.ts +1 -1
  243. package/dist/test/tiles/grid/account-tile.test.js +76 -76
  244. package/dist/test/tiles/grid/collection-tile.test.d.ts +1 -1
  245. package/dist/test/tiles/grid/collection-tile.test.js +73 -73
  246. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -1
  247. package/dist/test/tiles/grid/item-tile.test.js +254 -254
  248. package/dist/test/tiles/grid/search-tile.test.d.ts +1 -0
  249. package/dist/test/tiles/grid/search-tile.test.js +67 -0
  250. package/dist/test/tiles/grid/search-tile.test.js.map +1 -0
  251. package/dist/test/tiles/hover/hover-pane-controller.test.d.ts +1 -1
  252. package/dist/test/tiles/hover/hover-pane-controller.test.js +258 -258
  253. package/dist/test/tiles/hover/tile-hover-pane.test.d.ts +1 -1
  254. package/dist/test/tiles/hover/tile-hover-pane.test.js +13 -13
  255. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -1
  256. package/dist/test/tiles/list/tile-list-compact.test.js +143 -143
  257. package/dist/test/tiles/list/tile-list.test.d.ts +1 -1
  258. package/dist/test/tiles/list/tile-list.test.js +242 -242
  259. package/dist/test/tiles/tile-dispatcher.test.d.ts +1 -1
  260. package/dist/test/tiles/tile-dispatcher.test.js +94 -94
  261. package/dist/test/tiles/tile-display-value-provider.test.d.ts +1 -1
  262. package/dist/test/tiles/tile-display-value-provider.test.js +141 -141
  263. package/dist/test/utils/array-equals.test.d.ts +1 -1
  264. package/dist/test/utils/array-equals.test.js +26 -26
  265. package/dist/test/utils/format-count.test.d.ts +1 -1
  266. package/dist/test/utils/format-count.test.js +23 -23
  267. package/dist/test/utils/format-date.test.d.ts +1 -1
  268. package/dist/test/utils/format-date.test.js +17 -17
  269. package/dist/test/utils/format-unit-size.test.d.ts +1 -1
  270. package/dist/test/utils/format-unit-size.test.js +17 -17
  271. package/dist/test/utils/local-date-from-utc.test.d.ts +1 -1
  272. package/dist/test/utils/local-date-from-utc.test.js +26 -26
  273. package/local.archive.org.cert +86 -86
  274. package/local.archive.org.key +27 -27
  275. package/package.json +4 -4
  276. package/renovate.json +6 -6
  277. package/src/assets/img/icons/mediatype/search.ts +14 -0
  278. package/src/collection-browser.ts +29 -1
  279. package/src/mediatype/mediatype-config.ts +6 -0
  280. package/src/styles/item-image-styles.ts +4 -0
  281. package/src/tiles/grid/search-tile.ts +87 -0
  282. package/src/tiles/image-block.ts +3 -1
  283. package/src/tiles/item-image.ts +31 -8
  284. package/src/tiles/list/tile-list.ts +5 -0
  285. package/src/tiles/tile-dispatcher.ts +23 -1
  286. package/test/tiles/grid/search-tile.test.ts +76 -0
  287. package/tsconfig.json +21 -21
  288. package/web-dev-server.config.mjs +30 -30
  289. package/web-test-runner.config.mjs +41 -41
@@ -1,297 +1,297 @@
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.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();
261
261
  return html `
262
262
  <div
263
263
  id="content-container"
264
264
  class=${this.mobileView ? 'mobile' : 'desktop'}
265
265
  >
266
- ${this.placeholderType
267
- ? this.emptyPlaceholderTemplate
266
+ ${this.placeholderType
267
+ ? this.emptyPlaceholderTemplate
268
268
  : this.collectionBrowserTemplate}
269
269
  </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;
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;
295
295
  return html `
296
296
  <empty-placeholder
297
297
  .placeholderType=${this.placeholderType}
@@ -301,33 +301,33 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
301
301
  .baseNavigationUrl=${this.baseNavigationUrl}
302
302
  ></empty-placeholder>
303
303
  ${this.infiniteScrollerTemplate}
304
- `;
305
- }
306
- /**
307
- * Top-level template for rendering the left (facets) and right (results) columns.
308
- */
309
- get collectionBrowserTemplate() {
304
+ `;
305
+ }
306
+ /**
307
+ * Top-level template for rendering the left (facets) and right (results) columns.
308
+ */
309
+ get collectionBrowserTemplate() {
310
310
  return html `
311
311
  <div id="left-column-scroll-sentinel"></div>
312
312
  ${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() {
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() {
331
331
  return html `
332
332
  <div
333
333
  id="left-column"
@@ -336,12 +336,12 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
336
336
  ${this.resultsCountTemplate}
337
337
  <div id="facets-header-container">${this.mobileFacetsTemplate}</div>
338
338
  </div>
339
- `;
340
- }
341
- /**
342
- * Template for the desktop version of the left column, displaying the facets sidebar.
343
- */
344
- get desktopLeftColumnTemplate() {
339
+ `;
340
+ }
341
+ /**
342
+ * Template for the desktop version of the left column, displaying the facets sidebar.
343
+ */
344
+ get desktopLeftColumnTemplate() {
345
345
  return html `
346
346
  <div id="left-column" class="column">
347
347
  <div id="facets-header-container">
@@ -354,17 +354,17 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
354
354
  </div>
355
355
  <div id="facets-bottom-fade"></div>
356
356
  </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';
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';
368
368
  return html `
369
369
  <div id="results-total">
370
370
  <span id="big-results-count">
@@ -374,26 +374,26 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
374
374
  ${shouldShowSearching ? nothing : resultsLabel}
375
375
  </span>
376
376
  </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() {
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() {
384
384
  return html `
385
385
  <div id="right-column" class="column">
386
- ${this.isManageView
387
- ? this.manageBarTemplate
386
+ ${this.isManageView
387
+ ? this.manageBarTemplate
388
388
  : this.sortFilterBarTemplate}
389
- ${this.displayMode === `list-compact`
390
- ? this.listHeaderTemplate
389
+ ${this.displayMode === `list-compact`
390
+ ? this.listHeaderTemplate
391
391
  : nothing}
392
392
  ${this.infiniteScrollerTemplate}
393
393
  </div>
394
- `;
395
- }
396
- get infiniteScrollerTemplate() {
394
+ `;
395
+ }
396
+ get infiniteScrollerTemplate() {
397
397
  return html `<infinite-scroller
398
398
  class=${this.infiniteScrollerClasses}
399
399
  itemCount=${this.placeholderType ? 0 : nothing}
@@ -402,17 +402,17 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
402
402
  .placeholderCellTemplate=${this.placeholderCellTemplate}
403
403
  @scrollThresholdReached=${this.scrollThresholdReached}
404
404
  @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;
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;
416
416
  return html `
417
417
  <sort-filter-bar
418
418
  .defaultSortField=${this.defaultSortField}
@@ -432,9 +432,9 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
432
432
  @creatorLetterChanged=${this.creatorLetterSelected}
433
433
  >
434
434
  </sort-filter-bar>
435
- `;
436
- }
437
- get manageBarTemplate() {
435
+ `;
436
+ }
437
+ get manageBarTemplate() {
438
438
  return html `
439
439
  <manage-bar
440
440
  showSelectAll
@@ -442,249 +442,249 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
442
442
  @removeItems=${this.handleRemoveItems}
443
443
  @selectAll=${this.checkAllTiles}
444
444
  @unselectAll=${this.uncheckAllTiles}
445
- @cancel=${() => {
446
- this.isManageView = false;
447
- this.uncheckAllTiles();
445
+ @cancel=${() => {
446
+ this.isManageView = false;
447
+ this.uncheckAllTiles();
448
448
  }}
449
449
  ></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
- };
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
+ };
688
688
  return html `
689
689
  <details
690
690
  id="mobile-filter-collapse"
@@ -698,12 +698,12 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
698
698
  </summary>
699
699
  ${this.facetsTemplate}
700
700
  </details>
701
- `;
702
- }
703
- /**
704
- * The template for the facets component alone, without any surrounding wrappers.
705
- */
706
- get facetsTemplate() {
701
+ `;
702
+ }
703
+ /**
704
+ * The template for the facets component alone, without any surrounding wrappers.
705
+ */
706
+ get facetsTemplate() {
707
707
  return html `
708
708
  <collection-facets
709
709
  @facetsChanged=${this.facetsChanged}
@@ -737,41 +737,41 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
737
737
  .analyticsHandler=${this.analyticsHandler}
738
738
  >
739
739
  </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';
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';
756
756
  return html `
757
757
  <div class="clear-filters-btn-row">
758
- ${mobile
759
- ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
758
+ ${mobile
759
+ ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
760
760
  : nothing}
761
761
  <button class=${buttonClasses} @click=${this.clearFilters}>
762
762
  ${buttonText}
763
763
  </button>
764
764
  </div>
765
- `;
766
- }
767
- get loadingTemplate() {
765
+ `;
766
+ }
767
+ get loadingTemplate() {
768
768
  return html `
769
769
  <div class="loading-cover">
770
770
  <circular-activity-indicator></circular-activity-indicator>
771
771
  </div>
772
- `;
773
- }
774
- get listHeaderTemplate() {
772
+ `;
773
+ }
774
+ get listHeaderTemplate() {
775
775
  return html `
776
776
  <div id="list-header">
777
777
  <tile-dispatcher
@@ -783,1034 +783,1059 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
783
783
  >
784
784
  </tile-dispatcher>
785
785
  </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
- disconnectResizeObserver(resizeObserver) {
996
- resizeObserver.removeObserver({
997
- target: this.contentContainer,
998
- handler: this,
999
- });
1000
- }
1001
- setupResizeObserver() {
1002
- if (!this.resizeObserver)
1003
- return;
1004
- this.resizeObserver.addObserver({
1005
- target: this.contentContainer,
1006
- handler: this,
1007
- });
1008
- }
1009
- /**
1010
- * When the visible cells change from the infinite scroller, we want to emit
1011
- * which page is currently visible so the consumer can update its UI or the URL
1012
- *
1013
- * @param e
1014
- * @returns
1015
- */
1016
- visibleCellsChanged(e) {
1017
- if (this.isScrollingToCell)
1018
- return;
1019
- const { visibleCellIndices } = e.detail;
1020
- if (visibleCellIndices.length === 0)
1021
- return;
1022
- const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
1023
- const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
1024
- if (this.currentPage !== lastVisibleCellPage) {
1025
- this.currentPage = lastVisibleCellPage;
1026
- }
1027
- const event = new CustomEvent('visiblePageChanged', {
1028
- detail: {
1029
- pageNumber: lastVisibleCellPage,
1030
- },
1031
- });
1032
- this.dispatchEvent(event);
1033
- }
1034
- /**
1035
- * A Promise which, after each query change, resolves once the fetches for the initial
1036
- * search have completed. Waits for *both* the hits and aggregations fetches to finish.
1037
- *
1038
- * Ensure you await this component's `updateComplete` promise before awaiting this
1039
- * one, to ensure you do not await an obsolete promise from the previous update.
1040
- */
1041
- get initialSearchComplete() {
1042
- return this._initialSearchCompletePromise;
1043
- }
1044
- async handleQueryChange() {
1045
- var _a;
1046
- // only reset if the query has actually changed
1047
- if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
1048
- return;
1049
- // If the new state prevents us from updating the search results, don't reset
1050
- if (!this.canPerformSearch)
1051
- return;
1052
- this.previousQueryKey = this.pageFetchQueryKey;
1053
- this.dataSource = {};
1054
- this.tileModelOffset = 0;
1055
- this.totalResults = undefined;
1056
- this.aggregations = undefined;
1057
- this.fullYearsHistogramAggregation = undefined;
1058
- this.pageFetchesInProgress = {};
1059
- this.endOfDataReached = false;
1060
- this.pagesToRender =
1061
- this.initialPageNumber === 1
1062
- ? 2 // First two pages are batched into one request when starting from page 1
1063
- : this.initialPageNumber;
1064
- this.queryErrorMessage = undefined;
1065
- // Reset the infinite scroller's item count, so that it
1066
- // shows tile placeholders until the new query's results load in
1067
- if (this.infiniteScroller) {
1068
- this.infiniteScroller.itemCount = this.estimatedTileCount;
1069
- this.infiniteScroller.reload();
1070
- }
1071
- if (this.withinCollection && ((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
1072
- this.defaultSortField = SortField.relevance;
1073
- this.defaultSortDirection = null;
1074
- }
1075
- if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
1076
- this.scrollToPage(this.initialPageNumber);
1077
- }
1078
- this.initialQueryChangeHappened = true;
1079
- // if the query changed as part of a window.history pop event, we don't want to
1080
- // persist the state because it overwrites the forward history
1081
- if (!this.historyPopOccurred) {
1082
- this.persistState();
1083
- }
1084
- this.historyPopOccurred = false;
1085
- // Reset the `initialSearchComplete` promise with a new value for the imminent search
1086
- this._initialSearchCompletePromise = new Promise(res => {
1087
- this._initialSearchCompleteResolver = res;
1088
- });
1089
- // Fire the initial page and facets requests
1090
- await Promise.all([this.doInitialPageFetch(), this.fetchFacets()]);
1091
- // Resolve the `initialSearchComplete` promise for this search
1092
- this._initialSearchCompleteResolver(true);
1093
- }
1094
- setupStateRestorationObserver() {
1095
- if (this.boundNavigationHandler)
1096
- return;
1097
- this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
1098
- // when the user navigates back, we want to update the UI to match the URL
1099
- window.addEventListener('popstate', this.boundNavigationHandler);
1100
- }
1101
- historyNavigationHandler() {
1102
- this.historyPopOccurred = true;
1103
- this.restoreState();
1104
- }
1105
- restoreState() {
1106
- var _a, _b, _c, _d, _e;
1107
- const restorationState = this.restorationStateHandler.getRestorationState();
1108
- this.displayMode = restorationState.displayMode;
1109
- if (restorationState.searchType != null)
1110
- this.searchType = restorationState.searchType;
1111
- this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.default;
1112
- this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
1113
- this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
1114
- this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
1115
- this.selectedFacets = restorationState.selectedFacets;
1116
- this.baseQuery = restorationState.baseQuery;
1117
- this.currentPage = (_e = restorationState.currentPage) !== null && _e !== void 0 ? _e : 1;
1118
- this.minSelectedDate = restorationState.minSelectedDate;
1119
- this.maxSelectedDate = restorationState.maxSelectedDate;
1120
- if (this.currentPage > 1) {
1121
- this.goToPage(this.currentPage);
1122
- }
1123
- }
1124
- persistState() {
1125
- var _a, _b, _c, _d;
1126
- const restorationState = {
1127
- displayMode: this.displayMode,
1128
- searchType: this.searchType,
1129
- selectedSort: this.selectedSort,
1130
- sortDirection: (_a = this.sortDirection) !== null && _a !== void 0 ? _a : undefined,
1131
- selectedFacets: (_b = this.selectedFacets) !== null && _b !== void 0 ? _b : getDefaultSelectedFacets(),
1132
- baseQuery: this.baseQuery,
1133
- currentPage: this.currentPage,
1134
- titleQuery: this.titleQuery,
1135
- creatorQuery: this.creatorQuery,
1136
- minSelectedDate: this.minSelectedDate,
1137
- maxSelectedDate: this.maxSelectedDate,
1138
- selectedTitleFilter: (_c = this.selectedTitleFilter) !== null && _c !== void 0 ? _c : undefined,
1139
- selectedCreatorFilter: (_d = this.selectedCreatorFilter) !== null && _d !== void 0 ? _d : undefined,
1140
- };
1141
- this.restorationStateHandler.persistState(restorationState);
1142
- }
1143
- async doInitialPageFetch() {
1144
- this.searchResultsLoading = true;
1145
- // Try to batch 2 initial page requests when possible
1146
- await this.fetchPage(this.initialPageNumber, 2);
1147
- this.searchResultsLoading = false;
1148
- }
1149
- emitSearchResultsLoadingChanged() {
1150
- this.dispatchEvent(new CustomEvent('searchResultsLoadingChanged', {
1151
- detail: {
1152
- loading: this.searchResultsLoading,
1153
- },
1154
- }));
1155
- }
1156
- /**
1157
- * Produces a compact unique ID for a search request that can help with debugging
1158
- * on the backend by making related requests easier to trace through different services.
1159
- * (e.g., tying the hits/aggregations requests for the same page back to a single hash).
1160
- *
1161
- * @param params The search service parameters for the request
1162
- * @param kind The kind of request (hits-only, aggregations-only, or both)
1163
- * @returns A Promise resolving to the uid to apply to the request
1164
- */
1165
- async requestUID(params, kind) {
1166
- var _a;
1167
- const paramsToHash = JSON.stringify({
1168
- pageType: params.pageType,
1169
- pageTarget: params.pageTarget,
1170
- query: params.query,
1171
- fields: params.fields,
1172
- filters: params.filters,
1173
- sort: params.sort,
1174
- searchType: this.searchType,
1175
- });
1176
- const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this
1177
- const sessionId = (await this.getSessionId()).slice(0, 20); // Likewise
1178
- const page = (_a = params.page) !== null && _a !== void 0 ? _a : 0;
1179
- const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations
1180
- const currentTime = Date.now();
1181
- return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;
1182
- }
1183
- /**
1184
- * Constructs a search service FilterMap object from the combination of
1185
- * all the currently-applied filters. This includes any facets, letter
1186
- * filters, and date range.
1187
- */
1188
- get filterMap() {
1189
- const builder = new FilterMapBuilder();
1190
- // Add the date range, if applicable
1191
- if (this.minSelectedDate) {
1192
- builder.addFilter('year', this.minSelectedDate, FilterConstraint.GREATER_OR_EQUAL);
1193
- }
1194
- if (this.maxSelectedDate) {
1195
- builder.addFilter('year', this.maxSelectedDate, FilterConstraint.LESS_OR_EQUAL);
1196
- }
1197
- // Add any selected facets
1198
- if (this.selectedFacets) {
1199
- for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1200
- const { name, values } = this.prepareFacetForFetch(facetName, facetValues);
1201
- for (const [value, bucket] of Object.entries(values)) {
1202
- let constraint;
1203
- if (bucket.state === 'selected') {
1204
- constraint = FilterConstraint.INCLUDE;
1205
- }
1206
- else if (bucket.state === 'hidden') {
1207
- constraint = FilterConstraint.EXCLUDE;
1208
- }
1209
- if (constraint) {
1210
- builder.addFilter(name, value, constraint);
1211
- }
1212
- }
1213
- }
1214
- }
1215
- // Add any letter filters
1216
- if (this.selectedTitleFilter) {
1217
- builder.addFilter('firstTitle', this.selectedTitleFilter, FilterConstraint.INCLUDE);
1218
- }
1219
- if (this.selectedCreatorFilter) {
1220
- builder.addFilter('firstCreator', this.selectedCreatorFilter, FilterConstraint.INCLUDE);
1221
- }
1222
- const filterMap = builder.build();
1223
- return filterMap;
1224
- }
1225
- /** The full query, including year facets and date range clauses */
1226
- get fullQuery() {
1227
- var _a, _b;
1228
- let fullQuery = (_b = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
1229
- const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;
1230
- if (facetQuery) {
1231
- fullQuery += ` AND ${facetQuery}`;
1232
- }
1233
- if (dateRangeQueryClause) {
1234
- fullQuery += ` AND ${dateRangeQueryClause}`;
1235
- }
1236
- if (sortFilterQueries) {
1237
- fullQuery += ` AND ${sortFilterQueries}`;
1238
- }
1239
- return fullQuery.trim();
1240
- }
1241
- /**
1242
- * Generates a query string for the given facets
1243
- *
1244
- * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
1245
- */
1246
- get facetQuery() {
1247
- var _a;
1248
- if (!this.selectedFacets)
1249
- return undefined;
1250
- const facetClauses = [];
1251
- for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
1252
- facetClauses.push(this.buildFacetClause(facetName, facetValues));
1253
- }
1254
- return (_a = this.joinFacetClauses(facetClauses)) === null || _a === void 0 ? void 0 : _a.trim();
1255
- }
1256
- /**
1257
- * Builds an OR-joined facet clause for the given facet name and values.
1258
- *
1259
- * E.g., for name `subject` and values
1260
- * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`
1261
- * this will produce the clause
1262
- * `subject:("foo" OR -"bar")`.
1263
- *
1264
- * @param facetName The facet type (e.g., 'collection')
1265
- * @param facetValues The facet buckets, mapped by their keys
1266
- */
1267
- buildFacetClause(facetName, facetValues) {
1268
- const { name: facetQueryName, values } = this.prepareFacetForFetch(facetName, facetValues);
1269
- const facetEntries = Object.entries(values);
1270
- if (facetEntries.length === 0)
1271
- return '';
1272
- const facetValuesArray = [];
1273
- for (const [key, facetData] of facetEntries) {
1274
- const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
1275
- facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
1276
- }
1277
- const valueQuery = facetValuesArray.join(` OR `);
1278
- return `${facetQueryName}:(${valueQuery})`;
1279
- }
1280
- /**
1281
- * Handles some special pre-request normalization steps for certain facet types
1282
- * that require them.
1283
- *
1284
- * @param facetName The name of the facet type (e.g., 'language')
1285
- * @param facetValues An array of values for that facet type
1286
- */
1287
- prepareFacetForFetch(facetName, facetValues) {
1288
- // eslint-disable-next-line prefer-const
1289
- let [normalizedName, normalizedValues] = [facetName, facetValues];
1290
- // The full "search engine" name of the lending field is "lending___status"
1291
- if (facetName === 'lending') {
1292
- normalizedName = 'lending___status';
1293
- }
1294
- return {
1295
- name: normalizedName,
1296
- values: normalizedValues,
1297
- };
1298
- }
1299
- /**
1300
- * Takes an array of facet clauses, and combines them into a
1301
- * full AND-joined facet query string. Empty clauses are ignored.
1302
- */
1303
- joinFacetClauses(facetClauses) {
1304
- const nonEmptyFacetClauses = facetClauses.filter(clause => clause.length > 0);
1305
- return nonEmptyFacetClauses.length > 0
1306
- ? `(${nonEmptyFacetClauses.join(' AND ')})`
1307
- : undefined;
1308
- }
1309
- facetsChanged(e) {
1310
- this.selectedFacets = e.detail;
1311
- }
1312
- facetClickHandler({ detail: { key, state: facetState, negative }, }) {
1313
- var _a, _b;
1314
- if (negative) {
1315
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1316
- category: this.searchContext,
1317
- action: facetState !== 'none'
1318
- ? analyticsActions.facetNegativeSelected
1319
- : analyticsActions.facetNegativeDeselected,
1320
- label: key,
1321
- });
1322
- }
1323
- else {
1324
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1325
- category: this.searchContext,
1326
- action: facetState !== 'none'
1327
- ? analyticsActions.facetSelected
1328
- : analyticsActions.facetDeselected,
1329
- label: key,
1330
- });
1331
- }
1332
- }
1333
- async fetchFacets() {
1334
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1335
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1336
- if (!this.canPerformSearch)
1337
- return;
1338
- const { facetFetchQueryKey } = this;
1339
- const sortParams = this.sortParam ? [this.sortParam] : [];
1340
- const params = {
1341
- ...this.collectionParams,
1342
- query: trimmedQuery || '',
1343
- rows: 0,
1344
- filters: this.filterMap,
1345
- // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
1346
- aggregationsSize: 10,
1347
- // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
1348
- // The default aggregations for the search_results page type should be what we need here.
1349
- };
1350
- params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1351
- this.facetsLoading = true;
1352
- const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1353
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1354
- // This is checking to see if the query has changed since the data was fetched.
1355
- // If so, we just want to discard this set of aggregations because they are
1356
- // likely no longer valid for the newer query.
1357
- const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1358
- if (queryChangedSinceFetch)
1359
- return;
1360
- if (!success) {
1361
- const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
1362
- 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;
1363
- if (!errorMsg && !detailMsg) {
1364
- // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1365
- (_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');
1366
- }
1367
- return;
1368
- }
1369
- const { aggregations, collectionTitles } = success.response;
1370
- this.aggregations = aggregations;
1371
- if (collectionTitles) {
1372
- (_h = this.collectionNameCache) === null || _h === void 0 ? void 0 : _h.addKnownTitles(collectionTitles);
1373
- }
1374
- else if ((_j = this.aggregations) === null || _j === void 0 ? void 0 : _j.collection) {
1375
- (_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(); }));
1376
- }
1377
- this.fullYearsHistogramAggregation =
1378
- (_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;
1379
- this.facetsLoading = false;
1380
- }
1381
- scrollToPage(pageNumber) {
1382
- return new Promise(resolve => {
1383
- const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1384
- // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1385
- // then scrolls to the cell
1386
- setTimeout(() => {
1387
- var _a;
1388
- this.isScrollingToCell = true;
1389
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.scrollToCell(cellIndexToScrollTo, true);
1390
- // This timeout is to give the scroll animation time to finish
1391
- // then updating the infinite scroller once we're done scrolling
1392
- // There's no scroll animation completion callback so we're
1393
- // giving it 0.5s to finish.
1394
- setTimeout(() => {
1395
- var _a;
1396
- this.isScrollingToCell = false;
1397
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1398
- resolve();
1399
- }, 500);
1400
- }, 0);
1401
- });
1402
- }
1403
- /**
1404
- * Whether sorting by relevance makes sense for the current state.
1405
- * Currently equivalent to having a non-empty query.
1406
- */
1407
- get isRelevanceSortAvailable() {
1408
- var _a;
1409
- return !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
1410
- }
1411
- /**
1412
- * Whether a search may be performed in the current state of the component.
1413
- * This is only true if the search service is defined, and either
1414
- * (a) a non-empty query is set, or
1415
- * (b) we are on a collection page in metadata search mode.
1416
- */
1417
- get canPerformSearch() {
1418
- var _a;
1419
- if (!this.searchService)
1420
- return false;
1421
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1422
- const hasNonEmptyQuery = !!trimmedQuery;
1423
- const isCollectionSearch = !!this.withinCollection;
1424
- const isMetadataSearch = this.searchType === SearchType.METADATA;
1425
- // Metadata searches within a collection are allowed to have no query.
1426
- // Otherwise, a non-empty query must be set.
1427
- return hasNonEmptyQuery || (isCollectionSearch && isMetadataSearch);
1428
- }
1429
- /**
1430
- * Additional params to pass to the search service if targeting a collection page,
1431
- * or null otherwise.
1432
- */
1433
- get collectionParams() {
1434
- return this.withinCollection
1435
- ? { pageType: 'collection_details', pageTarget: this.withinCollection }
1436
- : null;
1437
- }
1438
- /**
1439
- * The query key is a string that uniquely identifies the current search.
1440
- * It consists of:
1441
- * - The current base query
1442
- * - The current collection
1443
- * - The current search type
1444
- * - Any currently-applied facets
1445
- * - Any currently-applied date range
1446
- * - Any currently-applied prefix filters
1447
- * - The current sort options
1448
- *
1449
- * This lets us keep track of queries so we don't persist data that's
1450
- * no longer relevant.
1451
- */
1452
- get pageFetchQueryKey() {
1453
- var _a, _b, _c, _d;
1454
- const sortField = (_b = (_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : 'none';
1455
- const sortDirection = (_d = (_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.direction) !== null && _d !== void 0 ? _d : 'none';
1456
- return `${this.fullQuery}-${this.withinCollection}-${this.searchType}-${sortField}-${sortDirection}`;
1457
- }
1458
- /**
1459
- * Similar to `pageFetchQueryKey` above, but excludes sort fields since they
1460
- * are not relevant in determining aggregation queries.
1461
- */
1462
- get facetFetchQueryKey() {
1463
- return `${this.fullQuery}-${this.withinCollection}-${this.searchType}`;
1464
- }
1465
- /**
1466
- * Fetches one or more pages of results and updates the data source.
1467
- *
1468
- * @param pageNumber The page number to fetch
1469
- * @param numInitialPages If this is an initial page fetch (`pageNumber = 1`),
1470
- * specifies how many pages to batch together in one request. Ignored
1471
- * if `pageNumber != 1`, defaulting to a single page.
1472
- */
1473
- async fetchPage(pageNumber, numInitialPages = 1) {
1474
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
1475
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1476
- if (!this.canPerformSearch)
1477
- return;
1478
- // if we already have data, don't fetch again
1479
- if (this.dataSource[pageNumber])
1480
- return;
1481
- if (this.endOfDataReached)
1482
- return;
1483
- // Batch multiple initial page requests together if needed (e.g., can request
1484
- // pages 1 and 2 together in a single request).
1485
- const numPages = pageNumber === 1 ? numInitialPages : 1;
1486
- const numRows = this.pageSize * numPages;
1487
- // if a fetch is already in progress for this query and page, don't fetch again
1488
- const { pageFetchQueryKey } = this;
1489
- const pageFetches = (_b = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _b !== void 0 ? _b : new Set();
1490
- if (pageFetches.has(pageNumber))
1491
- return;
1492
- for (let i = 0; i < numPages; i += 1) {
1493
- pageFetches.add(pageNumber + i);
1494
- }
1495
- this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
1496
- const sortParams = this.sortParam ? [this.sortParam] : [];
1497
- const params = {
1498
- ...this.collectionParams,
1499
- query: trimmedQuery || '',
1500
- page: pageNumber,
1501
- rows: numRows,
1502
- sort: sortParams,
1503
- filters: this.filterMap,
1504
- aggregations: { omit: true },
1505
- };
1506
- params.uid = await this.requestUID(params, 'hits');
1507
- const searchResponse = await ((_c = this.searchService) === null || _c === void 0 ? void 0 : _c.search(params, this.searchType));
1508
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1509
- // This is checking to see if the query has changed since the data was fetched.
1510
- // If so, we just want to discard the data since there should be a new query
1511
- // right behind it.
1512
- const queryChangedSinceFetch = pageFetchQueryKey !== this.pageFetchQueryKey;
1513
- if (queryChangedSinceFetch)
1514
- return;
1515
- if (!success) {
1516
- const errorMsg = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.message;
1517
- 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;
1518
- this.queryErrorMessage = `${errorMsg !== null && errorMsg !== void 0 ? errorMsg : ''}${detailMsg ? `; ${detailMsg}` : ''}`;
1519
- if (!this.queryErrorMessage) {
1520
- this.queryErrorMessage = 'Missing or malformed response from backend';
1521
- // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
1522
- (_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');
1523
- }
1524
- for (let i = 0; i < numPages; i += 1) {
1525
- (_j = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _j === void 0 ? void 0 : _j.delete(pageNumber + i);
1526
- }
1527
- this.searchResultsLoading = false;
1528
- return;
1529
- }
1530
- this.totalResults = success.response.totalResults - this.tileModelOffset;
1531
- if (this.withinCollection) {
1532
- this.collectionInfo = success.response.collectionExtraInfo;
1533
- // For collections, we want the UI to respect the default sort option
1534
- // which can be specified in metadata, or otherwise assumed to be week:desc
1535
- this.applyDefaultCollectionSort(this.collectionInfo);
1536
- if (this.collectionInfo) {
1537
- this.parentCollections = [].concat((_l = (_k = this.collectionInfo.public_metadata) === null || _k === void 0 ? void 0 : _k.collection) !== null && _l !== void 0 ? _l : []);
1538
- }
1539
- }
1540
- const { results, collectionTitles } = success.response;
1541
- if (results && results.length > 0) {
1542
- // Load any collection titles present on the response into the cache,
1543
- // or queue up preload fetches for them if none were present.
1544
- if (collectionTitles) {
1545
- (_m = this.collectionNameCache) === null || _m === void 0 ? void 0 : _m.addKnownTitles(collectionTitles);
1546
- }
1547
- else {
1548
- this.preloadCollectionNames(results);
1549
- }
1550
- // Update the data source for each returned page
1551
- for (let i = 0; i < numPages; i += 1) {
1552
- const pageStartIndex = this.pageSize * i;
1553
- this.updateDataSource(pageNumber + i, results.slice(pageStartIndex, pageStartIndex + this.pageSize));
1554
- }
1555
- }
1556
- // When we reach the end of the data, we can set the infinite scroller's
1557
- // item count to the real total number of results (rather than the
1558
- // temporary estimates based on pages rendered so far).
1559
- const resultCountDiscrepancy = numRows - results.length;
1560
- if (resultCountDiscrepancy > 0) {
1561
- this.endOfDataReached = true;
1562
- if (this.infiniteScroller) {
1563
- this.infiniteScroller.itemCount = this.totalResults;
1564
- }
1565
- }
1566
- for (let i = 0; i < numPages; i += 1) {
1567
- (_o = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _o === void 0 ? void 0 : _o.delete(pageNumber + i);
1568
- }
1569
- }
1570
- preloadCollectionNames(results) {
1571
- var _a;
1572
- const collectionIds = results
1573
- .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
1574
- .flat();
1575
- const collectionIdsArray = Array.from(new Set(collectionIds));
1576
- (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
1577
- }
1578
- /**
1579
- * Applies any default sort option for the current collection, by checking
1580
- * for one in the collection's metadata. If none is found, defaults to sorting
1581
- * descending by:
1582
- * - Date Favorited for fav-* collections
1583
- * - Weekly views for all other collections
1584
- */
1585
- applyDefaultCollectionSort(collectionInfo) {
1586
- var _a, _b, _c;
1587
- if (this.baseQuery) {
1588
- // If there's a query set, then we default to relevance sorting regardless of
1589
- // the collection metadata-specified sort.
1590
- this.defaultSortField = SortField.relevance;
1591
- this.defaultSortDirection = null;
1592
- return;
1593
- }
1594
- // Favorite collections sort on Date Favorited by default.
1595
- // Other collections fall back to sorting on weekly views.
1596
- 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-'))
1597
- ? '-favoritedate'
1598
- : '-week';
1599
- // The collection metadata may override the default sorting with something else
1600
- const metadataSort = (_c = collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.public_metadata) === null || _c === void 0 ? void 0 : _c['sort-by'];
1601
- // Prefer the metadata-specified sort if one exists
1602
- const defaultSortToApply = metadataSort !== null && metadataSort !== void 0 ? metadataSort : baseDefaultSort;
1603
- // Account for both -field and field:dir formats
1604
- let [field, dir] = defaultSortToApply.split(':');
1605
- if (field.startsWith('-')) {
1606
- field = field.slice(1);
1607
- dir = 'desc';
1608
- }
1609
- else if (!['asc', 'desc'].includes(dir)) {
1610
- dir = 'asc';
1611
- }
1612
- const sortOption = sortOptionFromAPIString(field);
1613
- const sortField = sortOption.field;
1614
- if (sortField && sortField !== SortField.default) {
1615
- this.defaultSortField = sortField;
1616
- this.defaultSortDirection = dir;
1617
- }
1618
- }
1619
- /**
1620
- * This is useful for determining whether we need to reload the scroller.
1621
- *
1622
- * When the fetch completes, we need to reload the scroller if the cells for that
1623
- * page are visible, but if the page is not currenlty visible, we don't need to reload
1624
- */
1625
- get currentVisiblePageNumbers() {
1626
- var _a, _b;
1627
- const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
1628
- const visiblePages = new Set();
1629
- visibleCells.forEach(cellIndex => {
1630
- const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1631
- visiblePages.add(visiblePage);
1632
- });
1633
- return Array.from(visiblePages);
1634
- }
1635
- /**
1636
- * Update the datasource from the fetch response
1637
- *
1638
- * @param pageNumber
1639
- * @param results
1640
- */
1641
- updateDataSource(pageNumber, results) {
1642
- var _a;
1643
- // copy our existing datasource so when we set it below, it gets set
1644
- // instead of modifying the existing dataSource since object changes
1645
- // don't trigger a re-render
1646
- const datasource = { ...this.dataSource };
1647
- const tiles = [];
1648
- results === null || results === void 0 ? void 0 : results.forEach(result => {
1649
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
1650
- if (!result.identifier)
1651
- return;
1652
- let loginRequired = false;
1653
- let contentWarning = false;
1654
- // Check if item and item in "modifying" collection, setting above flags
1655
- if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
1656
- ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
1657
- for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
1658
- if (collection === 'loggedin') {
1659
- loginRequired = true;
1660
- if (contentWarning)
1661
- break;
1662
- }
1663
- if (collection === 'no-preview') {
1664
- contentWarning = true;
1665
- if (loginRequired)
1666
- break;
1667
- }
1668
- }
1669
- }
1670
- tiles.push({
1671
- averageRating: (_e = result.avg_rating) === null || _e === void 0 ? void 0 : _e.value,
1672
- checked: false,
1673
- collections: (_g = (_f = result.collection) === null || _f === void 0 ? void 0 : _f.values) !== null && _g !== void 0 ? _g : [],
1674
- collectionFilesCount: (_j = (_h = result.collection_files_count) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : 0,
1675
- collectionSize: (_l = (_k = result.collection_size) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : 0,
1676
- commentCount: (_o = (_m = result.num_reviews) === null || _m === void 0 ? void 0 : _m.value) !== null && _o !== void 0 ? _o : 0,
1677
- creator: (_p = result.creator) === null || _p === void 0 ? void 0 : _p.value,
1678
- creators: (_r = (_q = result.creator) === null || _q === void 0 ? void 0 : _q.values) !== null && _r !== void 0 ? _r : [],
1679
- dateAdded: (_s = result.addeddate) === null || _s === void 0 ? void 0 : _s.value,
1680
- dateArchived: (_t = result.publicdate) === null || _t === void 0 ? void 0 : _t.value,
1681
- datePublished: (_u = result.date) === null || _u === void 0 ? void 0 : _u.value,
1682
- dateReviewed: (_v = result.reviewdate) === null || _v === void 0 ? void 0 : _v.value,
1683
- description: (_w = result.description) === null || _w === void 0 ? void 0 : _w.values.join('\n'),
1684
- favCount: (_y = (_x = result.num_favorites) === null || _x === void 0 ? void 0 : _x.value) !== null && _y !== void 0 ? _y : 0,
1685
- href: this.collapseRepeatedQuotes((_z = result.__href__) === null || _z === void 0 ? void 0 : _z.value),
1686
- identifier: result.identifier,
1687
- issue: (_0 = result.issue) === null || _0 === void 0 ? void 0 : _0.value,
1688
- itemCount: (_2 = (_1 = result.item_count) === null || _1 === void 0 ? void 0 : _1.value) !== null && _2 !== void 0 ? _2 : 0,
1689
- mediatype: (_4 = (_3 = result.mediatype) === null || _3 === void 0 ? void 0 : _3.value) !== null && _4 !== void 0 ? _4 : 'data',
1690
- snippets: (_6 = (_5 = result.highlight) === null || _5 === void 0 ? void 0 : _5.values) !== null && _6 !== void 0 ? _6 : [],
1691
- source: (_7 = result.source) === null || _7 === void 0 ? void 0 : _7.value,
1692
- subjects: (_9 = (_8 = result.subject) === null || _8 === void 0 ? void 0 : _8.values) !== null && _9 !== void 0 ? _9 : [],
1693
- title: (_11 = (_10 = result.title) === null || _10 === void 0 ? void 0 : _10.value) !== null && _11 !== void 0 ? _11 : '',
1694
- volume: (_12 = result.volume) === null || _12 === void 0 ? void 0 : _12.value,
1695
- viewCount: (_14 = (_13 = result.downloads) === null || _13 === void 0 ? void 0 : _13.value) !== null && _14 !== void 0 ? _14 : 0,
1696
- weeklyViewCount: (_15 = result.week) === null || _15 === void 0 ? void 0 : _15.value,
1697
- loginRequired,
1698
- contentWarning,
1699
- });
1700
- });
1701
- datasource[pageNumber] = tiles;
1702
- this.dataSource = datasource;
1703
- const visiblePages = this.currentVisiblePageNumbers;
1704
- const needsReload = visiblePages.includes(pageNumber);
1705
- if (needsReload) {
1706
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1707
- }
1708
- }
1709
- /**
1710
- * Returns the input string, but removing one set of quotes from all instances of
1711
- * ""clauses wrapped in two sets of quotes"". This assumes the quotes are already
1712
- * URL-encoded.
1713
- *
1714
- * This should be a temporary measure to address the fact that the __href__ field
1715
- * sometimes acquires extra quotation marks during query rewriting. Once there is a
1716
- * full Lucene parser in place that handles quoted queries correctly, this can likely
1717
- * be removed.
1718
- */
1719
- collapseRepeatedQuotes(str) {
1720
- return str === null || str === void 0 ? void 0 : str.replace(/%22%22(?!%22%22)(.+?)%22%22/g, '%22$1%22');
1721
- }
1722
- /** Fetches the aggregation buckets for the given prefix filter type. */
1723
- async fetchPrefixFilterBuckets(filterType) {
1724
- var _a, _b, _c, _d, _e, _f, _g;
1725
- const trimmedQuery = (_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1726
- if (!this.canPerformSearch)
1727
- return [];
1728
- const filterAggregationKey = prefixFilterAggregationKeys[filterType];
1729
- const sortParams = this.sortParam ? [this.sortParam] : [];
1730
- const params = {
1731
- ...this.collectionParams,
1732
- query: trimmedQuery || '',
1733
- rows: 0,
1734
- filters: this.filterMap,
1735
- // Only fetch the firstTitle or firstCreator aggregation
1736
- aggregations: { simpleParams: [filterAggregationKey] },
1737
- // Fetch all 26 letter buckets
1738
- aggregationsSize: 26,
1739
- };
1740
- params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1741
- const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1742
- 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 : []);
1743
- }
1744
- /** Fetches and caches the prefix filter counts for the given filter type. */
1745
- async updatePrefixFilterCounts(filterType) {
1746
- const { facetFetchQueryKey } = this;
1747
- const buckets = await this.fetchPrefixFilterBuckets(filterType);
1748
- // Don't update the filter counts for an outdated query (if it has been changed
1749
- // since we sent the request)
1750
- const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1751
- if (queryChangedSinceFetch)
1752
- return;
1753
- // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }
1754
- this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update
1755
- this.prefixFilterCountMap[filterType] = buckets.reduce((acc, bucket) => {
1756
- acc[bucket.key.toUpperCase()] = bucket.doc_count;
1757
- return acc;
1758
- }, {});
1759
- }
1760
- /**
1761
- * Fetches and caches the prefix filter counts for the current sort type,
1762
- * provided it is one that permits prefix filtering. (If not, this does nothing).
1763
- */
1764
- async updatePrefixFiltersForCurrentSort() {
1765
- if (['title', 'creator'].includes(this.selectedSort)) {
1766
- const filterType = this.selectedSort;
1767
- if (!this.prefixFilterCountMap[filterType]) {
1768
- this.updatePrefixFilterCounts(filterType);
1769
- }
1770
- }
1771
- }
1772
- /**
1773
- * Clears the cached letter counts for both title and creator, and
1774
- * fetches a new set of counts for whichever of them is the currently
1775
- * selected sort option (which may be neither).
1776
- *
1777
- * Call this whenever the counts are invalidated (e.g., by a query change).
1778
- */
1779
- refreshLetterCounts() {
1780
- if (Object.keys(this.prefixFilterCountMap).length > 0) {
1781
- this.prefixFilterCountMap = {};
1782
- }
1783
- this.updatePrefixFiltersForCurrentSort();
1784
- }
1785
- /**
1786
- * Callback when a result is selected
1787
- */
1788
- resultSelected(event) {
1789
- var _a, _b, _c;
1790
- if (this.isManageView) {
1791
- // Checked/unchecked state change -- rerender to ensure it propagates
1792
- // this.mapDataSource(model => ({ ...model }));
1793
- const cellIndex = Object.values(this.dataSource)
1794
- .flat()
1795
- .indexOf(event.detail);
1796
- if (cellIndex >= 0)
1797
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshCell(cellIndex - this.tileModelOffset);
1798
- }
1799
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1800
- category: this.searchContext,
1801
- action: analyticsActions.resultSelected,
1802
- label: event.detail.mediatype,
1803
- });
1804
- (_c = this.analyticsHandler) === null || _c === void 0 ? void 0 : _c.sendEvent({
1805
- category: this.searchContext,
1806
- action: analyticsActions.resultSelected,
1807
- label: `page-${this.currentPage}`,
1808
- });
1809
- }
1810
- cellForIndex(index) {
1811
- const model = this.tileModelAtCellIndex(index);
1812
- if (!model)
1813
- return undefined;
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;
1814
1839
  return html `
1815
1840
  <tile-dispatcher
1816
1841
  .collectionPagePath=${this.collectionPagePath}
@@ -1829,21 +1854,21 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1829
1854
  @resultSelected=${(e) => this.resultSelected(e)}
1830
1855
  >
1831
1856
  </tile-dispatcher>
1832
- `;
1833
- }
1834
- /**
1835
- * When the user scrolls near to the bottom of the page, fetch the next page
1836
- * increase the number of pages to render and start fetching data for the new page
1837
- */
1838
- scrollThresholdReached() {
1839
- if (!this.endOfDataReached) {
1840
- this.pagesToRender += 1;
1841
- this.fetchPage(this.pagesToRender);
1842
- }
1843
- }
1844
- static get styles() {
1845
- return [
1846
- srOnlyStyle,
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,
1847
1872
  css `
1848
1873
  :host {
1849
1874
  display: block;
@@ -2214,168 +2239,168 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
2214
2239
  infinite-scroller.hidden {
2215
2240
  display: none;
2216
2241
  }
2217
- `,
2218
- ];
2219
- }
2220
- };
2221
- __decorate([
2222
- property({ type: String })
2223
- ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
2224
- __decorate([
2225
- property({ type: String })
2226
- ], CollectionBrowser.prototype, "baseImageUrl", void 0);
2227
- __decorate([
2228
- property({ type: Object })
2229
- ], CollectionBrowser.prototype, "searchService", void 0);
2230
- __decorate([
2231
- property({ type: String })
2232
- ], CollectionBrowser.prototype, "searchType", void 0);
2233
- __decorate([
2234
- property({ type: String })
2235
- ], CollectionBrowser.prototype, "withinCollection", void 0);
2236
- __decorate([
2237
- property({ type: String })
2238
- ], CollectionBrowser.prototype, "baseQuery", void 0);
2239
- __decorate([
2240
- property({ type: String })
2241
- ], CollectionBrowser.prototype, "displayMode", void 0);
2242
- __decorate([
2243
- property({ type: Object })
2244
- ], CollectionBrowser.prototype, "sortParam", void 0);
2245
- __decorate([
2246
- property({ type: String })
2247
- ], CollectionBrowser.prototype, "selectedSort", void 0);
2248
- __decorate([
2249
- property({ type: String })
2250
- ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
2251
- __decorate([
2252
- property({ type: String })
2253
- ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
2254
- __decorate([
2255
- property({ type: String })
2256
- ], CollectionBrowser.prototype, "sortDirection", void 0);
2257
- __decorate([
2258
- property({ type: Number })
2259
- ], CollectionBrowser.prototype, "pageSize", void 0);
2260
- __decorate([
2261
- property({ type: Object })
2262
- ], CollectionBrowser.prototype, "resizeObserver", void 0);
2263
- __decorate([
2264
- property({ type: Number })
2265
- ], CollectionBrowser.prototype, "currentPage", void 0);
2266
- __decorate([
2267
- property({ type: String })
2268
- ], CollectionBrowser.prototype, "minSelectedDate", void 0);
2269
- __decorate([
2270
- property({ type: String })
2271
- ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
2272
- __decorate([
2273
- property({ type: Object })
2274
- ], CollectionBrowser.prototype, "selectedFacets", void 0);
2275
- __decorate([
2276
- property({ type: Boolean })
2277
- ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
2278
- __decorate([
2279
- property({ type: String })
2280
- ], CollectionBrowser.prototype, "collectionPagePath", void 0);
2281
- __decorate([
2282
- property({ type: Object })
2283
- ], CollectionBrowser.prototype, "collectionInfo", void 0);
2284
- __decorate([
2285
- property({ type: Array })
2286
- ], CollectionBrowser.prototype, "parentCollections", void 0);
2287
- __decorate([
2288
- property({ type: String, reflect: true })
2289
- ], CollectionBrowser.prototype, "searchContext", void 0);
2290
- __decorate([
2291
- property({ type: Object })
2292
- ], CollectionBrowser.prototype, "collectionNameCache", void 0);
2293
- __decorate([
2294
- property({ type: String })
2295
- ], CollectionBrowser.prototype, "pageContext", void 0);
2296
- __decorate([
2297
- property({ type: Object })
2298
- ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
2299
- __decorate([
2300
- property({ type: Number })
2301
- ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
2302
- __decorate([
2303
- property({ type: Boolean })
2304
- ], CollectionBrowser.prototype, "loggedIn", void 0);
2305
- __decorate([
2306
- property({ type: Object })
2307
- ], CollectionBrowser.prototype, "modalManager", void 0);
2308
- __decorate([
2309
- property({ type: Object })
2310
- ], CollectionBrowser.prototype, "featureFeedbackService", void 0);
2311
- __decorate([
2312
- property({ type: Object })
2313
- ], CollectionBrowser.prototype, "recaptchaManager", void 0);
2314
- __decorate([
2315
- property({ type: Boolean })
2316
- ], CollectionBrowser.prototype, "isManageView", void 0);
2317
- __decorate([
2318
- state()
2319
- ], CollectionBrowser.prototype, "pagesToRender", void 0);
2320
- __decorate([
2321
- state()
2322
- ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
2323
- __decorate([
2324
- state()
2325
- ], CollectionBrowser.prototype, "facetsLoading", void 0);
2326
- __decorate([
2327
- state()
2328
- ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
2329
- __decorate([
2330
- state()
2331
- ], CollectionBrowser.prototype, "aggregations", void 0);
2332
- __decorate([
2333
- state()
2334
- ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
2335
- __decorate([
2336
- state()
2337
- ], CollectionBrowser.prototype, "totalResults", void 0);
2338
- __decorate([
2339
- state()
2340
- ], CollectionBrowser.prototype, "queryErrorMessage", void 0);
2341
- __decorate([
2342
- state()
2343
- ], CollectionBrowser.prototype, "mobileView", void 0);
2344
- __decorate([
2345
- state()
2346
- ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
2347
- __decorate([
2348
- state()
2349
- ], CollectionBrowser.prototype, "contentWidth", void 0);
2350
- __decorate([
2351
- state()
2352
- ], CollectionBrowser.prototype, "defaultSortField", void 0);
2353
- __decorate([
2354
- state()
2355
- ], CollectionBrowser.prototype, "defaultSortDirection", void 0);
2356
- __decorate([
2357
- state()
2358
- ], CollectionBrowser.prototype, "placeholderType", void 0);
2359
- __decorate([
2360
- state()
2361
- ], CollectionBrowser.prototype, "prefixFilterCountMap", void 0);
2362
- __decorate([
2363
- query('#content-container')
2364
- ], CollectionBrowser.prototype, "contentContainer", void 0);
2365
- __decorate([
2366
- query('#left-column')
2367
- ], CollectionBrowser.prototype, "leftColumn", void 0);
2368
- __decorate([
2369
- query('collection-facets')
2370
- ], CollectionBrowser.prototype, "collectionFacets", void 0);
2371
- __decorate([
2372
- property({ type: Object, attribute: false })
2373
- ], CollectionBrowser.prototype, "analyticsHandler", void 0);
2374
- __decorate([
2375
- query('infinite-scroller')
2376
- ], CollectionBrowser.prototype, "infiniteScroller", void 0);
2377
- CollectionBrowser = __decorate([
2378
- customElement('collection-browser')
2379
- ], CollectionBrowser);
2380
- export { CollectionBrowser };
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 };
2381
2406
  //# sourceMappingURL=collection-browser.js.map