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