@internetarchive/collection-browser 2.5.2 → 2.6.1

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 (308) 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 +12 -12
  6. package/dist/index.js +12 -12
  7. package/dist/src/app-root.d.ts +91 -91
  8. package/dist/src/app-root.js +487 -487
  9. package/dist/src/assets/img/icons/arrow-left.d.ts +2 -2
  10. package/dist/src/assets/img/icons/arrow-left.js +2 -2
  11. package/dist/src/assets/img/icons/arrow-right.d.ts +2 -2
  12. package/dist/src/assets/img/icons/arrow-right.js +2 -2
  13. package/dist/src/assets/img/icons/chevron.d.ts +2 -2
  14. package/dist/src/assets/img/icons/chevron.js +2 -2
  15. package/dist/src/assets/img/icons/contract.d.ts +2 -2
  16. package/dist/src/assets/img/icons/contract.js +2 -2
  17. package/dist/src/assets/img/icons/empty-query.d.ts +2 -2
  18. package/dist/src/assets/img/icons/empty-query.js +2 -2
  19. package/dist/src/assets/img/icons/expand.d.ts +2 -2
  20. package/dist/src/assets/img/icons/expand.js +2 -2
  21. package/dist/src/assets/img/icons/eye-closed.d.ts +2 -2
  22. package/dist/src/assets/img/icons/eye-closed.js +2 -2
  23. package/dist/src/assets/img/icons/eye.d.ts +2 -2
  24. package/dist/src/assets/img/icons/eye.js +2 -2
  25. package/dist/src/assets/img/icons/favorite-filled.d.ts +1 -1
  26. package/dist/src/assets/img/icons/favorite-filled.js +2 -2
  27. package/dist/src/assets/img/icons/favorite-unfilled.d.ts +1 -1
  28. package/dist/src/assets/img/icons/favorite-unfilled.js +2 -2
  29. package/dist/src/assets/img/icons/login-required.d.ts +1 -1
  30. package/dist/src/assets/img/icons/login-required.js +2 -2
  31. package/dist/src/assets/img/icons/mediatype/account.d.ts +1 -1
  32. package/dist/src/assets/img/icons/mediatype/account.js +2 -2
  33. package/dist/src/assets/img/icons/mediatype/audio.d.ts +1 -1
  34. package/dist/src/assets/img/icons/mediatype/audio.js +2 -2
  35. package/dist/src/assets/img/icons/mediatype/collection.d.ts +1 -1
  36. package/dist/src/assets/img/icons/mediatype/collection.js +2 -2
  37. package/dist/src/assets/img/icons/mediatype/data.d.ts +1 -1
  38. package/dist/src/assets/img/icons/mediatype/data.js +2 -2
  39. package/dist/src/assets/img/icons/mediatype/etree.d.ts +1 -1
  40. package/dist/src/assets/img/icons/mediatype/etree.js +2 -2
  41. package/dist/src/assets/img/icons/mediatype/film.d.ts +1 -1
  42. package/dist/src/assets/img/icons/mediatype/film.js +2 -2
  43. package/dist/src/assets/img/icons/mediatype/images.d.ts +1 -1
  44. package/dist/src/assets/img/icons/mediatype/images.js +2 -2
  45. package/dist/src/assets/img/icons/mediatype/radio.d.ts +1 -1
  46. package/dist/src/assets/img/icons/mediatype/radio.js +2 -2
  47. package/dist/src/assets/img/icons/mediatype/search.d.ts +1 -1
  48. package/dist/src/assets/img/icons/mediatype/search.js +2 -2
  49. package/dist/src/assets/img/icons/mediatype/software.d.ts +1 -1
  50. package/dist/src/assets/img/icons/mediatype/software.js +2 -2
  51. package/dist/src/assets/img/icons/mediatype/texts.d.ts +1 -1
  52. package/dist/src/assets/img/icons/mediatype/texts.js +2 -2
  53. package/dist/src/assets/img/icons/mediatype/tv.d.ts +1 -1
  54. package/dist/src/assets/img/icons/mediatype/tv.js +2 -2
  55. package/dist/src/assets/img/icons/mediatype/video.d.ts +1 -1
  56. package/dist/src/assets/img/icons/mediatype/video.js +2 -2
  57. package/dist/src/assets/img/icons/mediatype/web.d.ts +1 -1
  58. package/dist/src/assets/img/icons/mediatype/web.js +2 -2
  59. package/dist/src/assets/img/icons/null-result.d.ts +2 -2
  60. package/dist/src/assets/img/icons/null-result.js +2 -2
  61. package/dist/src/assets/img/icons/restricted.d.ts +1 -1
  62. package/dist/src/assets/img/icons/restricted.js +2 -2
  63. package/dist/src/assets/img/icons/reviews.d.ts +1 -1
  64. package/dist/src/assets/img/icons/reviews.js +2 -2
  65. package/dist/src/assets/img/icons/upload.d.ts +1 -1
  66. package/dist/src/assets/img/icons/upload.js +2 -2
  67. package/dist/src/assets/img/icons/views.d.ts +1 -1
  68. package/dist/src/assets/img/icons/views.js +2 -2
  69. package/dist/src/circular-activity-indicator.d.ts +5 -5
  70. package/dist/src/circular-activity-indicator.js +17 -17
  71. package/dist/src/collection-browser.d.ts +564 -564
  72. package/dist/src/collection-browser.js +1579 -1569
  73. package/dist/src/collection-browser.js.map +1 -1
  74. package/dist/src/collection-facets/facet-row.d.ts +30 -30
  75. package/dist/src/collection-facets/facet-row.js +120 -117
  76. package/dist/src/collection-facets/facet-row.js.map +1 -1
  77. package/dist/src/collection-facets/facet-tombstone-row.d.ts +5 -5
  78. package/dist/src/collection-facets/facet-tombstone-row.js +15 -15
  79. package/dist/src/collection-facets/facets-template.d.ts +13 -13
  80. package/dist/src/collection-facets/facets-template.js +45 -43
  81. package/dist/src/collection-facets/facets-template.js.map +1 -1
  82. package/dist/src/collection-facets/more-facets-content.d.ts +106 -106
  83. package/dist/src/collection-facets/more-facets-content.js +407 -407
  84. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -36
  85. package/dist/src/collection-facets/more-facets-pagination.js +196 -196
  86. package/dist/src/collection-facets/toggle-switch.d.ts +41 -41
  87. package/dist/src/collection-facets/toggle-switch.js +94 -94
  88. package/dist/src/collection-facets.d.ts +103 -103
  89. package/dist/src/collection-facets.js +534 -516
  90. package/dist/src/collection-facets.js.map +1 -1
  91. package/dist/src/data-source/collection-browser-data-source-interface.d.ts +241 -241
  92. package/dist/src/data-source/collection-browser-data-source-interface.js +1 -1
  93. package/dist/src/data-source/collection-browser-data-source.d.ts +378 -378
  94. package/dist/src/data-source/collection-browser-data-source.js +984 -985
  95. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  96. package/dist/src/data-source/collection-browser-query-state.d.ts +43 -43
  97. package/dist/src/data-source/collection-browser-query-state.js +1 -1
  98. package/dist/src/data-source/models.d.ts +28 -28
  99. package/dist/src/data-source/models.js +8 -8
  100. package/dist/src/empty-placeholder.d.ts +23 -23
  101. package/dist/src/empty-placeholder.js +92 -79
  102. package/dist/src/empty-placeholder.js.map +1 -1
  103. package/dist/src/expanded-date-picker.d.ts +43 -43
  104. package/dist/src/expanded-date-picker.js +109 -109
  105. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  106. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  107. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  108. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  109. package/dist/src/manage/manage-bar.d.ts +30 -30
  110. package/dist/src/manage/manage-bar.js +61 -61
  111. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  112. package/dist/src/mediatype/mediatype-config.js +91 -91
  113. package/dist/src/models.d.ts +211 -209
  114. package/dist/src/models.js +381 -381
  115. package/dist/src/models.js.map +1 -1
  116. package/dist/src/restoration-state-handler.d.ts +70 -70
  117. package/dist/src/restoration-state-handler.js +357 -357
  118. package/dist/src/sort-filter-bar/alpha-bar-tooltip.d.ts +6 -6
  119. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js +24 -24
  120. package/dist/src/sort-filter-bar/alpha-bar.d.ts +21 -21
  121. package/dist/src/sort-filter-bar/alpha-bar.js +128 -128
  122. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  123. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  124. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  125. package/dist/src/sort-filter-bar/img/list.js +2 -2
  126. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.d.ts +1 -1
  127. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js +2 -2
  128. package/dist/src/sort-filter-bar/img/sort-toggle-down.d.ts +1 -1
  129. package/dist/src/sort-filter-bar/img/sort-toggle-down.js +2 -2
  130. package/dist/src/sort-filter-bar/img/sort-toggle-up.d.ts +1 -1
  131. package/dist/src/sort-filter-bar/img/sort-toggle-up.js +2 -2
  132. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  133. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  134. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  135. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  136. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +223 -222
  137. package/dist/src/sort-filter-bar/sort-filter-bar.js +700 -696
  138. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  139. package/dist/src/styles/ia-button.d.ts +2 -2
  140. package/dist/src/styles/ia-button.js +16 -16
  141. package/dist/src/styles/item-image-styles.d.ts +8 -8
  142. package/dist/src/styles/item-image-styles.js +9 -9
  143. package/dist/src/styles/sr-only.d.ts +1 -1
  144. package/dist/src/styles/sr-only.js +2 -2
  145. package/dist/src/tiles/base-tile-component.d.ts +19 -19
  146. package/dist/src/tiles/base-tile-component.js +63 -63
  147. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  148. package/dist/src/tiles/collection-browser-loading-tile.js +15 -15
  149. package/dist/src/tiles/grid/account-tile.d.ts +18 -18
  150. package/dist/src/tiles/grid/account-tile.js +72 -72
  151. package/dist/src/tiles/grid/collection-tile.d.ts +15 -15
  152. package/dist/src/tiles/grid/collection-tile.js +80 -80
  153. package/dist/src/tiles/grid/item-tile.d.ts +30 -30
  154. package/dist/src/tiles/grid/item-tile.js +149 -149
  155. package/dist/src/tiles/grid/search-tile.d.ts +10 -10
  156. package/dist/src/tiles/grid/search-tile.js +51 -51
  157. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.d.ts +1 -1
  158. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +8 -8
  159. package/dist/src/tiles/grid/tile-stats.d.ts +11 -11
  160. package/dist/src/tiles/grid/tile-stats.js +53 -53
  161. package/dist/src/tiles/hover/hover-pane-controller.d.ts +219 -219
  162. package/dist/src/tiles/hover/hover-pane-controller.js +352 -352
  163. package/dist/src/tiles/hover/tile-hover-pane.d.ts +18 -18
  164. package/dist/src/tiles/hover/tile-hover-pane.js +69 -69
  165. package/dist/src/tiles/image-block.d.ts +17 -17
  166. package/dist/src/tiles/image-block.js +73 -73
  167. package/dist/src/tiles/item-image.d.ts +39 -39
  168. package/dist/src/tiles/item-image.js +154 -154
  169. package/dist/src/tiles/list/tile-list-compact-header.d.ts +6 -6
  170. package/dist/src/tiles/list/tile-list-compact-header.js +38 -38
  171. package/dist/src/tiles/list/tile-list-compact.d.ts +15 -15
  172. package/dist/src/tiles/list/tile-list-compact.js +114 -114
  173. package/dist/src/tiles/list/tile-list.d.ts +50 -50
  174. package/dist/src/tiles/list/tile-list.js +315 -315
  175. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  176. package/dist/src/tiles/mediatype-icon.js +47 -47
  177. package/dist/src/tiles/overlay/icon-overlay.d.ts +10 -10
  178. package/dist/src/tiles/overlay/icon-overlay.js +40 -40
  179. package/dist/src/tiles/overlay/icon-text-overlay.d.ts +9 -9
  180. package/dist/src/tiles/overlay/icon-text-overlay.js +38 -38
  181. package/dist/src/tiles/overlay/text-overlay.d.ts +10 -10
  182. package/dist/src/tiles/overlay/text-overlay.js +42 -42
  183. package/dist/src/tiles/review-block.d.ts +12 -12
  184. package/dist/src/tiles/review-block.js +56 -56
  185. package/dist/src/tiles/text-snippet-block.d.ts +27 -27
  186. package/dist/src/tiles/text-snippet-block.js +73 -73
  187. package/dist/src/tiles/tile-dispatcher.d.ts +64 -64
  188. package/dist/src/tiles/tile-dispatcher.js +229 -229
  189. package/dist/src/tiles/tile-display-value-provider.d.ts +47 -47
  190. package/dist/src/tiles/tile-display-value-provider.js +94 -94
  191. package/dist/src/utils/analytics-events.d.ts +28 -28
  192. package/dist/src/utils/analytics-events.js +30 -30
  193. package/dist/src/utils/array-equals.d.ts +4 -4
  194. package/dist/src/utils/array-equals.js +10 -10
  195. package/dist/src/utils/collapse-repeated-quotes.d.ts +11 -11
  196. package/dist/src/utils/collapse-repeated-quotes.js +13 -13
  197. package/dist/src/utils/facet-utils.d.ts +83 -83
  198. package/dist/src/utils/facet-utils.js +145 -145
  199. package/dist/src/utils/format-count.d.ts +7 -7
  200. package/dist/src/utils/format-count.js +76 -76
  201. package/dist/src/utils/format-date.d.ts +2 -2
  202. package/dist/src/utils/format-date.js +25 -25
  203. package/dist/src/utils/format-unit-size.d.ts +2 -2
  204. package/dist/src/utils/format-unit-size.js +33 -33
  205. package/dist/src/utils/local-date-from-utc.d.ts +9 -9
  206. package/dist/src/utils/local-date-from-utc.js +15 -15
  207. package/dist/src/utils/log.d.ts +7 -7
  208. package/dist/src/utils/log.js +15 -15
  209. package/dist/src/utils/resolve-mediatype.d.ts +8 -8
  210. package/dist/src/utils/resolve-mediatype.js +23 -23
  211. package/dist/src/utils/sha1.d.ts +2 -2
  212. package/dist/src/utils/sha1.js +8 -8
  213. package/dist/test/collection-browser.test.d.ts +1 -1
  214. package/dist/test/collection-browser.test.js +1294 -1294
  215. package/dist/test/collection-facets/facet-row.test.d.ts +1 -1
  216. package/dist/test/collection-facets/facet-row.test.js +227 -227
  217. package/dist/test/collection-facets/facets-template.test.d.ts +1 -1
  218. package/dist/test/collection-facets/facets-template.test.js +91 -91
  219. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -1
  220. package/dist/test/collection-facets/more-facets-content.test.js +141 -141
  221. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -1
  222. package/dist/test/collection-facets/more-facets-pagination.test.js +117 -117
  223. package/dist/test/collection-facets/toggle-switch.test.d.ts +1 -1
  224. package/dist/test/collection-facets/toggle-switch.test.js +73 -73
  225. package/dist/test/collection-facets.test.d.ts +2 -2
  226. package/dist/test/collection-facets.test.js +652 -652
  227. package/dist/test/data-source/collection-browser-data-source.test.d.ts +1 -1
  228. package/dist/test/data-source/collection-browser-data-source.test.js +89 -89
  229. package/dist/test/empty-placeholder.test.d.ts +1 -1
  230. package/dist/test/empty-placeholder.test.js +63 -63
  231. package/dist/test/expanded-date-picker.test.d.ts +1 -1
  232. package/dist/test/expanded-date-picker.test.js +95 -95
  233. package/dist/test/icon-overlay.test.d.ts +1 -1
  234. package/dist/test/icon-overlay.test.js +24 -24
  235. package/dist/test/image-block.test.d.ts +1 -1
  236. package/dist/test/image-block.test.js +48 -48
  237. package/dist/test/item-image.test.d.ts +1 -1
  238. package/dist/test/item-image.test.js +85 -85
  239. package/dist/test/manage/manage-bar.test.d.ts +1 -1
  240. package/dist/test/manage/manage-bar.test.js +81 -81
  241. package/dist/test/mediatype-config.test.d.ts +1 -1
  242. package/dist/test/mediatype-config.test.js +16 -16
  243. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  244. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  245. package/dist/test/mocks/mock-search-responses.d.ts +25 -25
  246. package/dist/test/mocks/mock-search-responses.js +942 -942
  247. package/dist/test/mocks/mock-search-service.d.ts +15 -15
  248. package/dist/test/mocks/mock-search-service.js +54 -54
  249. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  250. package/dist/test/restoration-state-handler.test.js +270 -270
  251. package/dist/test/review-block.test.d.ts +1 -1
  252. package/dist/test/review-block.test.js +44 -44
  253. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.d.ts +1 -1
  254. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +12 -12
  255. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +1 -1
  256. package/dist/test/sort-filter-bar/alpha-bar.test.js +73 -73
  257. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -1
  258. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +426 -426
  259. package/dist/test/text-overlay.test.d.ts +1 -1
  260. package/dist/test/text-overlay.test.js +48 -48
  261. package/dist/test/text-snippet-block.test.d.ts +1 -1
  262. package/dist/test/text-snippet-block.test.js +57 -57
  263. package/dist/test/tile-stats.test.d.ts +1 -1
  264. package/dist/test/tile-stats.test.js +81 -81
  265. package/dist/test/tiles/grid/account-tile.test.d.ts +1 -1
  266. package/dist/test/tiles/grid/account-tile.test.js +76 -76
  267. package/dist/test/tiles/grid/collection-tile.test.d.ts +1 -1
  268. package/dist/test/tiles/grid/collection-tile.test.js +73 -73
  269. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -1
  270. package/dist/test/tiles/grid/item-tile.test.js +312 -312
  271. package/dist/test/tiles/grid/search-tile.test.d.ts +1 -1
  272. package/dist/test/tiles/grid/search-tile.test.js +51 -51
  273. package/dist/test/tiles/hover/hover-pane-controller.test.d.ts +1 -1
  274. package/dist/test/tiles/hover/hover-pane-controller.test.js +259 -259
  275. package/dist/test/tiles/hover/tile-hover-pane.test.d.ts +1 -1
  276. package/dist/test/tiles/hover/tile-hover-pane.test.js +56 -56
  277. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -1
  278. package/dist/test/tiles/list/tile-list-compact.test.js +143 -143
  279. package/dist/test/tiles/list/tile-list.test.d.ts +1 -1
  280. package/dist/test/tiles/list/tile-list.test.js +297 -297
  281. package/dist/test/tiles/tile-dispatcher.test.d.ts +1 -1
  282. package/dist/test/tiles/tile-dispatcher.test.js +100 -100
  283. package/dist/test/tiles/tile-display-value-provider.test.d.ts +1 -1
  284. package/dist/test/tiles/tile-display-value-provider.test.js +141 -141
  285. package/dist/test/utils/array-equals.test.d.ts +1 -1
  286. package/dist/test/utils/array-equals.test.js +26 -26
  287. package/dist/test/utils/format-count.test.d.ts +1 -1
  288. package/dist/test/utils/format-count.test.js +23 -23
  289. package/dist/test/utils/format-date.test.d.ts +1 -1
  290. package/dist/test/utils/format-date.test.js +17 -17
  291. package/dist/test/utils/format-unit-size.test.d.ts +1 -1
  292. package/dist/test/utils/format-unit-size.test.js +17 -17
  293. package/dist/test/utils/local-date-from-utc.test.d.ts +1 -1
  294. package/dist/test/utils/local-date-from-utc.test.js +26 -26
  295. package/local.archive.org.cert +86 -86
  296. package/local.archive.org.key +27 -27
  297. package/package.json +1 -1
  298. package/renovate.json +6 -6
  299. package/src/collection-browser.ts +26 -10
  300. package/src/collection-facets/facet-row.ts +3 -0
  301. package/src/collection-facets/facets-template.ts +3 -1
  302. package/src/collection-facets.ts +20 -2
  303. package/src/data-source/collection-browser-data-source.ts +1 -5
  304. package/src/empty-placeholder.ts +18 -5
  305. package/src/models.ts +8 -1
  306. package/src/sort-filter-bar/sort-filter-bar.ts +4 -0
  307. package/web-dev-server.config.mjs +30 -30
  308. package/web-test-runner.config.mjs +41 -41
@@ -1,373 +1,373 @@
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 { msg } from '@lit/localize';
7
- import { SearchType, } from '@internetarchive/search-service';
8
- import '@internetarchive/infinite-scroller';
9
- import { SortField, getDefaultSelectedFacets, sortOptionFromAPIString, SORT_OPTIONS, defaultProfileElementSorts, } from './models';
10
- import { RestorationStateHandler, } from './restoration-state-handler';
11
- import { CollectionBrowserDataSource } from './data-source/collection-browser-data-source';
12
- import { FACETLESS_PAGE_ELEMENTS } from './data-source/models';
13
- import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
14
- import chevronIcon from './assets/img/icons/chevron';
15
- import { srOnlyStyle } from './styles/sr-only';
16
- import { sha1 } from './utils/sha1';
17
- import { formatDate } from './utils/format-date';
18
- import { log } from './utils/log';
19
- import './empty-placeholder';
20
- import './tiles/tile-dispatcher';
21
- import './tiles/collection-browser-loading-tile';
22
- import './sort-filter-bar/sort-filter-bar';
23
- import './manage/manage-bar';
24
- import './collection-facets';
25
- import './circular-activity-indicator';
26
- let CollectionBrowser = class CollectionBrowser extends LitElement {
27
- constructor() {
28
- super();
29
- this.baseImageUrl = 'https://archive.org';
30
- /**
31
- * Which backend should be targeted by searches (e.g., metadata or FTS)
32
- */
33
- this.searchType = SearchType.METADATA;
34
- this.defaultSortParam = null;
35
- this.selectedSort = SortField.default;
36
- this.selectedTitleFilter = null;
37
- this.selectedCreatorFilter = null;
38
- this.sortDirection = null;
39
- this.pageSize = 50;
40
- /**
41
- * Whether to show the date picker (above the facets)
42
- */
43
- this.showHistogramDatePicker = false;
44
- /**
45
- * Whether placeholder views should be suppressed. If true, searches that produce an
46
- * error or empty result set will simply show a blank results view instead of a placeholder.
47
- */
48
- this.suppressPlaceholders = false;
49
- /**
50
- * Whether the result count text should be suppressed.
51
- * If true, no "X Results" message will be shown.
52
- */
53
- this.suppressResultCount = false;
54
- /**
55
- * Whether the scrolling result view should be suppressed entirely.
56
- * If true, no infinite scroller (and thus no result tiles) will be rendered.
57
- */
58
- this.suppressResultTiles = false;
59
- /**
60
- * Whether to suppress persistence of the query to the URL.
61
- * If true, the `query` param will not be added to the URL or updated on query changes.
62
- */
63
- this.suppressURLQuery = false;
64
- /**
65
- * Whether to suppress display of the sort bar.
66
- * If true, the entire sort bar (incl. display modes) will be omitted from rendering.
67
- */
68
- this.suppressSortBar = false;
69
- /**
70
- * Whether to suppress showing the display mode options in the sort bar.
71
- * If true, those options will be omitted (though the rest of the sort bar may still render).
72
- */
73
- this.suppressDisplayModes = false;
74
- /**
75
- * What strategy to use for when/whether to load facet data for a search.
76
- *
77
- * Defaults to `eager`, always loading facets immediately alongside search results.
78
- *
79
- * To eliminate facets that are never seen, this can be reduced to `lazy-mobile`, which
80
- * will delay loading facets in the mobile view until the "Filters" accordion is opened.
81
- * Facets are still loaded eagerly when viewing the desktop layout.
82
- *
83
- * To further reduce facet requests for patrons who do not need to use them, this can be
84
- * again reduced to `opt-in`, which will also require desktop users to explicitly request
85
- * that they be loaded (in addition to the lazy mobile behavior described above).
86
- *
87
- * To entirely suppress facets from being loaded, this may be set to `off`.
88
- */
89
- this.facetLoadStrategy = 'eager';
90
- this.clearResultsOnEmptyQuery = false;
91
- this.collectionPagePath = '/details/';
92
- /** describes where this component is being used */
93
- this.searchContext = analyticsCategories.default;
94
- this.pageContext = 'search';
95
- this.restorationStateHandler = new RestorationStateHandler({
96
- context: this.pageContext,
97
- });
98
- this.mobileBreakpoint = 600;
99
- this.loggedIn = false;
100
- this.modalManager = undefined;
101
- /**
102
- * If item management UI active
103
- */
104
- this.isManageView = false;
105
- this.manageViewLabel = 'Select items to remove';
106
- /** Whether to replace the default sort options with a slot for customization (default: false) */
107
- this.enableSortOptionsSlot = false;
108
- /**
109
- * The results per page so we can paginate.
110
- *
111
- * This allows us to start in the middle of the search results and
112
- * fetch data before or after the current page. If we don't have a key
113
- * for the previous/next page, we'll fetch the next/previous page to populate it
114
- */
115
- this.dataSource = new CollectionBrowserDataSource(this, this.pageSize);
116
- /**
117
- * The page that the consumer wants to load.
118
- */
119
- this.initialPageNumber = 1;
120
- /**
121
- * This the the number of pages that we want to show.
122
- *
123
- * The data isn't necessarily loaded for all of the pages, but this lets us
124
- * know how many cells we should render.
125
- */
126
- this.pagesToRender = this.initialPageNumber;
127
- /**
128
- * Whether the initial page fetch for a new query is currently in progress.
129
- */
130
- this.searchResultsLoading = false;
131
- this.facetsLoading = false;
132
- this.mobileView = false;
133
- this.collapsibleFacetsVisible = false;
134
- this.defaultSortField = SortField.relevance;
135
- this.defaultSortDirection = null;
136
- this.placeholderType = null;
137
- /** Whether layout size analytics have been sent already. */
138
- this.layoutSizeAnalyticsSent = false;
139
- /**
140
- * When we're animated scrolling to the page, we don't want to fetch
141
- * all of the pages as it scrolls so this lets us know if we're scrolling
142
- */
143
- this.isScrollingToCell = false;
144
- /**
145
- * When page width resizes from desktop to mobile, set true to
146
- * disable expand/collapse transition when loading.
147
- */
148
- this.isResizeToMobile = false;
149
- /**
150
- * Flag indicating that a new data source is currently being installed.
151
- * During the install, any URL persistence operation should replace the current entry
152
- * instead of creating a new one.
153
- */
154
- this.dataSourceInstallInProgress = false;
155
- this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
156
- /**
157
- * Updates the height of the left column according to its position on the page.
158
- * Arrow function ensures proper `this` binding.
159
- */
160
- this.updateLeftColumnHeight = () => {
161
- var _a, _b, _c, _d, _e;
162
- if (this.mobileView) {
163
- (_b = (_a = this.leftColumn) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b.removeProperty('height');
164
- }
165
- else {
166
- const clientTop = (_c = this.leftColumn) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect().top;
167
- (_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`);
168
- }
169
- };
170
- /**
171
- * Toggles whether the fade-out is visible at the bottom of the facets.
172
- * It should only be visible if the facets are not scrolled to the bottom.
173
- * Arrow function ensures proper `this` binding.
174
- */
175
- this.updateFacetFadeOut = (entries) => {
176
- var _a, _b;
177
- const fadeElmt = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('facets-bottom-fade');
178
- 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);
179
- };
180
- // we only want to scroll on the very first query change
181
- // so this keeps track of whether we've already set the initial query
182
- this.initialQueryChangeHappened = false;
183
- this.historyPopOccurred = false;
184
- this.addController(this.dataSource);
185
- }
186
- tileModelAtCellIndex(index) {
187
- const model = this.dataSource.getTileModelAt(index);
188
- /**
189
- * If we encounter a model we don't have yet and we're not in the middle of an
190
- * automated scroll, fetch the page and just return undefined.
191
- * The datasource will be updated once the page is loaded and the cell will be rendered.
192
- *
193
- * We disable it during the automated scroll since we don't want to fetch pages for intervening cells the
194
- * user may never see.
195
- */
196
- if (!model && !this.isScrollingToCell && this.dataSource.queryInitialized) {
197
- const pageNumber = Math.floor(index / this.pageSize) + 1;
198
- this.dataSource.fetchPage(pageNumber);
199
- }
200
- return model;
201
- }
202
- // this is the total number of tiles we expect if
203
- // the data returned is a full page worth
204
- // this is useful for putting in placeholders for the expected number of tiles
205
- get estimatedTileCount() {
206
- return this.pagesToRender * this.pageSize;
207
- }
208
- /**
209
- * Returns a promise resolving to a unique string that persists for the current browser session.
210
- * Used in generating unique IDs for search requests, so that multiple requests coming from the
211
- * same browser session can be identified.
212
- */
213
- async getSessionId() {
214
- try {
215
- const storedSessionId = sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.getItem('cb-session');
216
- if (storedSessionId) {
217
- return storedSessionId;
218
- }
219
- // If we enter this method a second time while a first session ID is already being generated,
220
- // ensure we produce the same ID from both calls instead of generating another one.
221
- if (this.sessionIdGenPromise) {
222
- return this.sessionIdGenPromise;
223
- }
224
- this.sessionIdGenPromise = sha1(Math.random().toString());
225
- const newSessionId = await this.sessionIdGenPromise;
226
- sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.setItem('cb-session', newSessionId);
227
- return newSessionId;
228
- }
229
- catch (err) {
230
- // Either we can't generate the hash or we're restricted from accessing sessionStorage
231
- return '';
232
- }
233
- }
234
- /**
235
- * Go to the given page of results
236
- *
237
- * @param pageNumber
238
- */
239
- goToPage(pageNumber) {
240
- this.initialPageNumber = pageNumber;
241
- this.pagesToRender = pageNumber;
242
- return this.scrollToPage(pageNumber);
243
- }
244
- /**
245
- * Sets the state for whether the initial set of search results is loading in.
246
- */
247
- setSearchResultsLoading(loading) {
248
- this.searchResultsLoading = loading;
249
- }
250
- /**
251
- * Sets the state for whether facet data is loading in
252
- */
253
- setFacetsLoading(loading) {
254
- this.facetsLoading = loading;
255
- }
256
- /**
257
- * Sets the total number of results to be displayed for the current search
258
- */
259
- setTotalResultCount(totalResults) {
260
- this.totalResults = totalResults;
261
- }
262
- /**
263
- * Clears all selected/negated facets, date ranges, and letter filters.
264
- *
265
- * By default, the current sort field/direction are not cleared,
266
- * but this can be overridden by setting the `sort` option to `true`.
267
- *
268
- * Similarly, it is possible to finely control what is cleared by
269
- * setting any of the `facets`, `dateRange`, or `letterFilters` flags
270
- * in the options object.
271
- */
272
- clearFilters({ facets = true, dateRange = true, letterFilters = true, sort = false, } = {}) {
273
- // Don't bother clearing facets if none are checked, so that we don't
274
- // trigger unnecessary update cycles.
275
- if (facets && this.hasCheckedFacets) {
276
- this.selectedFacets = getDefaultSelectedFacets();
277
- }
278
- if (dateRange) {
279
- this.minSelectedDate = undefined;
280
- this.maxSelectedDate = undefined;
281
- }
282
- if (letterFilters) {
283
- this.selectedTitleFilter = null;
284
- this.selectedCreatorFilter = null;
285
- }
286
- if (sort) {
287
- this.sortDirection = null;
288
- this.selectedSort = SortField.default;
289
- }
290
- }
291
- /**
292
- * Returns true if the current value of `this.selectedFacets` contains
293
- * any facet buckets than have been selected or negated, or false otherwise.
294
- */
295
- get hasCheckedFacets() {
296
- if (!this.selectedFacets)
297
- return false;
298
- for (const facetGroup of Object.values(this.selectedFacets)) {
299
- for (const bucket of Object.values(facetGroup)) {
300
- if (bucket.state !== 'none')
301
- return true;
302
- }
303
- }
304
- return false;
305
- }
306
- /**
307
- * Returns true if there are any currently selected/negated facet buckets,
308
- * any selected date range, or any selected letter filters. False otherwise.
309
- *
310
- * Ignores sorting options.
311
- */
312
- get hasActiveFilters() {
313
- return !!(this.hasCheckedFacets ||
314
- this.minSelectedDate ||
315
- this.maxSelectedDate ||
316
- this.selectedTitleFilter ||
317
- this.selectedCreatorFilter);
318
- }
319
- willUpdate() {
320
- this.setPlaceholderType();
321
- }
322
- render() {
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 { msg } from '@lit/localize';
7
+ import { SearchType, } from '@internetarchive/search-service';
8
+ import '@internetarchive/infinite-scroller';
9
+ import { SortField, getDefaultSelectedFacets, sortOptionFromAPIString, SORT_OPTIONS, defaultProfileElementSorts, } from './models';
10
+ import { RestorationStateHandler, } from './restoration-state-handler';
11
+ import { CollectionBrowserDataSource } from './data-source/collection-browser-data-source';
12
+ import { FACETLESS_PAGE_ELEMENTS } from './data-source/models';
13
+ import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
14
+ import chevronIcon from './assets/img/icons/chevron';
15
+ import { srOnlyStyle } from './styles/sr-only';
16
+ import { sha1 } from './utils/sha1';
17
+ import { formatDate } from './utils/format-date';
18
+ import { log } from './utils/log';
19
+ import './empty-placeholder';
20
+ import './tiles/tile-dispatcher';
21
+ import './tiles/collection-browser-loading-tile';
22
+ import './sort-filter-bar/sort-filter-bar';
23
+ import './manage/manage-bar';
24
+ import './collection-facets';
25
+ import './circular-activity-indicator';
26
+ let CollectionBrowser = class CollectionBrowser extends LitElement {
27
+ constructor() {
28
+ super();
29
+ this.baseImageUrl = 'https://archive.org';
30
+ /**
31
+ * Which backend should be targeted by searches (e.g., metadata or FTS)
32
+ */
33
+ this.searchType = SearchType.METADATA;
34
+ this.defaultSortParam = null;
35
+ this.selectedSort = SortField.default;
36
+ this.selectedTitleFilter = null;
37
+ this.selectedCreatorFilter = null;
38
+ this.sortDirection = null;
39
+ this.pageSize = 50;
40
+ /**
41
+ * Whether to show the date picker (above the facets)
42
+ */
43
+ this.showHistogramDatePicker = false;
44
+ /**
45
+ * Whether placeholder views should be suppressed. If true, searches that produce an
46
+ * error or empty result set will simply show a blank results view instead of a placeholder.
47
+ */
48
+ this.suppressPlaceholders = false;
49
+ /**
50
+ * Whether the result count text should be suppressed.
51
+ * If true, no "X Results" message will be shown.
52
+ */
53
+ this.suppressResultCount = false;
54
+ /**
55
+ * Whether the scrolling result view should be suppressed entirely.
56
+ * If true, no infinite scroller (and thus no result tiles) will be rendered.
57
+ */
58
+ this.suppressResultTiles = false;
59
+ /**
60
+ * Whether to suppress persistence of the query to the URL.
61
+ * If true, the `query` param will not be added to the URL or updated on query changes.
62
+ */
63
+ this.suppressURLQuery = false;
64
+ /**
65
+ * Whether to suppress display of the sort bar.
66
+ * If true, the entire sort bar (incl. display modes) will be omitted from rendering.
67
+ */
68
+ this.suppressSortBar = false;
69
+ /**
70
+ * Whether to suppress showing the display mode options in the sort bar.
71
+ * If true, those options will be omitted (though the rest of the sort bar may still render).
72
+ */
73
+ this.suppressDisplayModes = false;
74
+ /**
75
+ * What strategy to use for when/whether to load facet data for a search.
76
+ *
77
+ * Defaults to `eager`, always loading facets immediately alongside search results.
78
+ *
79
+ * To eliminate facets that are never seen, this can be reduced to `lazy-mobile`, which
80
+ * will delay loading facets in the mobile view until the "Filters" accordion is opened.
81
+ * Facets are still loaded eagerly when viewing the desktop layout.
82
+ *
83
+ * To further reduce facet requests for patrons who do not need to use them, this can be
84
+ * again reduced to `opt-in`, which will also require desktop users to explicitly request
85
+ * that they be loaded (in addition to the lazy mobile behavior described above).
86
+ *
87
+ * To entirely suppress facets from being loaded, this may be set to `off`.
88
+ */
89
+ this.facetLoadStrategy = 'eager';
90
+ this.clearResultsOnEmptyQuery = false;
91
+ this.collectionPagePath = '/details/';
92
+ /** describes where this component is being used */
93
+ this.searchContext = analyticsCategories.default;
94
+ this.pageContext = 'search';
95
+ this.restorationStateHandler = new RestorationStateHandler({
96
+ context: this.pageContext,
97
+ });
98
+ this.mobileBreakpoint = 600;
99
+ this.loggedIn = false;
100
+ this.modalManager = undefined;
101
+ /**
102
+ * If item management UI active
103
+ */
104
+ this.isManageView = false;
105
+ this.manageViewLabel = 'Select items to remove';
106
+ /** Whether to replace the default sort options with a slot for customization (default: false) */
107
+ this.enableSortOptionsSlot = false;
108
+ /**
109
+ * The results per page so we can paginate.
110
+ *
111
+ * This allows us to start in the middle of the search results and
112
+ * fetch data before or after the current page. If we don't have a key
113
+ * for the previous/next page, we'll fetch the next/previous page to populate it
114
+ */
115
+ this.dataSource = new CollectionBrowserDataSource(this, this.pageSize);
116
+ /**
117
+ * The page that the consumer wants to load.
118
+ */
119
+ this.initialPageNumber = 1;
120
+ /**
121
+ * This the the number of pages that we want to show.
122
+ *
123
+ * The data isn't necessarily loaded for all of the pages, but this lets us
124
+ * know how many cells we should render.
125
+ */
126
+ this.pagesToRender = this.initialPageNumber;
127
+ /**
128
+ * Whether the initial page fetch for a new query is currently in progress.
129
+ */
130
+ this.searchResultsLoading = false;
131
+ this.facetsLoading = false;
132
+ this.mobileView = false;
133
+ this.collapsibleFacetsVisible = false;
134
+ this.defaultSortField = SortField.relevance;
135
+ this.defaultSortDirection = null;
136
+ this.placeholderType = null;
137
+ /** Whether layout size analytics have been sent already. */
138
+ this.layoutSizeAnalyticsSent = false;
139
+ /**
140
+ * When we're animated scrolling to the page, we don't want to fetch
141
+ * all of the pages as it scrolls so this lets us know if we're scrolling
142
+ */
143
+ this.isScrollingToCell = false;
144
+ /**
145
+ * When page width resizes from desktop to mobile, set true to
146
+ * disable expand/collapse transition when loading.
147
+ */
148
+ this.isResizeToMobile = false;
149
+ /**
150
+ * Flag indicating that a new data source is currently being installed.
151
+ * During the install, any URL persistence operation should replace the current entry
152
+ * instead of creating a new one.
153
+ */
154
+ this.dataSourceInstallInProgress = false;
155
+ this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
156
+ /**
157
+ * Updates the height of the left column according to its position on the page.
158
+ * Arrow function ensures proper `this` binding.
159
+ */
160
+ this.updateLeftColumnHeight = () => {
161
+ var _a, _b, _c, _d, _e;
162
+ if (this.mobileView) {
163
+ (_b = (_a = this.leftColumn) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b.removeProperty('height');
164
+ }
165
+ else {
166
+ const clientTop = (_c = this.leftColumn) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect().top;
167
+ (_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`);
168
+ }
169
+ };
170
+ /**
171
+ * Toggles whether the fade-out is visible at the bottom of the facets.
172
+ * It should only be visible if the facets are not scrolled to the bottom.
173
+ * Arrow function ensures proper `this` binding.
174
+ */
175
+ this.updateFacetFadeOut = (entries) => {
176
+ var _a, _b;
177
+ const fadeElmt = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.getElementById('facets-bottom-fade');
178
+ 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);
179
+ };
180
+ // we only want to scroll on the very first query change
181
+ // so this keeps track of whether we've already set the initial query
182
+ this.initialQueryChangeHappened = false;
183
+ this.historyPopOccurred = false;
184
+ this.addController(this.dataSource);
185
+ }
186
+ tileModelAtCellIndex(index) {
187
+ const model = this.dataSource.getTileModelAt(index);
188
+ /**
189
+ * If we encounter a model we don't have yet and we're not in the middle of an
190
+ * automated scroll, fetch the page and just return undefined.
191
+ * The datasource will be updated once the page is loaded and the cell will be rendered.
192
+ *
193
+ * We disable it during the automated scroll since we don't want to fetch pages for intervening cells the
194
+ * user may never see.
195
+ */
196
+ if (!model && !this.isScrollingToCell && this.dataSource.queryInitialized) {
197
+ const pageNumber = Math.floor(index / this.pageSize) + 1;
198
+ this.dataSource.fetchPage(pageNumber);
199
+ }
200
+ return model;
201
+ }
202
+ // this is the total number of tiles we expect if
203
+ // the data returned is a full page worth
204
+ // this is useful for putting in placeholders for the expected number of tiles
205
+ get estimatedTileCount() {
206
+ return this.pagesToRender * this.pageSize;
207
+ }
208
+ /**
209
+ * Returns a promise resolving to a unique string that persists for the current browser session.
210
+ * Used in generating unique IDs for search requests, so that multiple requests coming from the
211
+ * same browser session can be identified.
212
+ */
213
+ async getSessionId() {
214
+ try {
215
+ const storedSessionId = sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.getItem('cb-session');
216
+ if (storedSessionId) {
217
+ return storedSessionId;
218
+ }
219
+ // If we enter this method a second time while a first session ID is already being generated,
220
+ // ensure we produce the same ID from both calls instead of generating another one.
221
+ if (this.sessionIdGenPromise) {
222
+ return this.sessionIdGenPromise;
223
+ }
224
+ this.sessionIdGenPromise = sha1(Math.random().toString());
225
+ const newSessionId = await this.sessionIdGenPromise;
226
+ sessionStorage === null || sessionStorage === void 0 ? void 0 : sessionStorage.setItem('cb-session', newSessionId);
227
+ return newSessionId;
228
+ }
229
+ catch (err) {
230
+ // Either we can't generate the hash or we're restricted from accessing sessionStorage
231
+ return '';
232
+ }
233
+ }
234
+ /**
235
+ * Go to the given page of results
236
+ *
237
+ * @param pageNumber
238
+ */
239
+ goToPage(pageNumber) {
240
+ this.initialPageNumber = pageNumber;
241
+ this.pagesToRender = pageNumber;
242
+ return this.scrollToPage(pageNumber);
243
+ }
244
+ /**
245
+ * Sets the state for whether the initial set of search results is loading in.
246
+ */
247
+ setSearchResultsLoading(loading) {
248
+ this.searchResultsLoading = loading;
249
+ }
250
+ /**
251
+ * Sets the state for whether facet data is loading in
252
+ */
253
+ setFacetsLoading(loading) {
254
+ this.facetsLoading = loading;
255
+ }
256
+ /**
257
+ * Sets the total number of results to be displayed for the current search
258
+ */
259
+ setTotalResultCount(totalResults) {
260
+ this.totalResults = totalResults;
261
+ }
262
+ /**
263
+ * Clears all selected/negated facets, date ranges, and letter filters.
264
+ *
265
+ * By default, the current sort field/direction are not cleared,
266
+ * but this can be overridden by setting the `sort` option to `true`.
267
+ *
268
+ * Similarly, it is possible to finely control what is cleared by
269
+ * setting any of the `facets`, `dateRange`, or `letterFilters` flags
270
+ * in the options object.
271
+ */
272
+ clearFilters({ facets = true, dateRange = true, letterFilters = true, sort = false, } = {}) {
273
+ // Don't bother clearing facets if none are checked, so that we don't
274
+ // trigger unnecessary update cycles.
275
+ if (facets && this.hasCheckedFacets) {
276
+ this.selectedFacets = getDefaultSelectedFacets();
277
+ }
278
+ if (dateRange) {
279
+ this.minSelectedDate = undefined;
280
+ this.maxSelectedDate = undefined;
281
+ }
282
+ if (letterFilters) {
283
+ this.selectedTitleFilter = null;
284
+ this.selectedCreatorFilter = null;
285
+ }
286
+ if (sort) {
287
+ this.sortDirection = null;
288
+ this.selectedSort = SortField.default;
289
+ }
290
+ }
291
+ /**
292
+ * Returns true if the current value of `this.selectedFacets` contains
293
+ * any facet buckets than have been selected or negated, or false otherwise.
294
+ */
295
+ get hasCheckedFacets() {
296
+ if (!this.selectedFacets)
297
+ return false;
298
+ for (const facetGroup of Object.values(this.selectedFacets)) {
299
+ for (const bucket of Object.values(facetGroup)) {
300
+ if (bucket.state !== 'none')
301
+ return true;
302
+ }
303
+ }
304
+ return false;
305
+ }
306
+ /**
307
+ * Returns true if there are any currently selected/negated facet buckets,
308
+ * any selected date range, or any selected letter filters. False otherwise.
309
+ *
310
+ * Ignores sorting options.
311
+ */
312
+ get hasActiveFilters() {
313
+ return !!(this.hasCheckedFacets ||
314
+ this.minSelectedDate ||
315
+ this.maxSelectedDate ||
316
+ this.selectedTitleFilter ||
317
+ this.selectedCreatorFilter);
318
+ }
319
+ willUpdate() {
320
+ this.setPlaceholderType();
321
+ }
322
+ render() {
323
323
  return html `
324
324
  <div
325
325
  id="content-container"
326
326
  class=${this.mobileView ? 'mobile' : 'desktop'}
327
327
  >
328
- ${this.placeholderType
329
- ? this.emptyPlaceholderTemplate
328
+ ${this.placeholderType
329
+ ? this.emptyPlaceholderTemplate
330
330
  : this.collectionBrowserTemplate}
331
331
  </div>
332
- `;
333
- }
334
- /**
335
- * Determines what type of placeholder content should be shown instead of result tiles, if applicable.
336
- * The placeholders indicate states where we have no results to show, which could be the result of:
337
- * - No query is set (on the search page)
338
- * - No results were returned for the most recent search
339
- * - The collection being searched within has no viewable items
340
- * - An error occurred on the most recent search attempt
341
- */
342
- setPlaceholderType() {
343
- var _a;
344
- const hasQuery = !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
345
- const isCollection = !!this.withinCollection;
346
- const isProfile = !!this.withinProfile;
347
- const noResults = !this.searchResultsLoading &&
348
- (this.dataSource.size === 0 || !this.searchService);
349
- this.placeholderType = null;
350
- if (this.suppressPlaceholders)
351
- return;
352
- if (!hasQuery && !isCollection && !isProfile) {
353
- this.placeholderType = 'empty-query';
354
- }
355
- else if (noResults) {
356
- // Within a collection, no query + no results means the collection simply has no viewable items.
357
- // Otherwise, we must have a user query that produced 0 results.
358
- this.placeholderType =
359
- !hasQuery && isCollection ? 'empty-collection' : 'no-results';
360
- }
361
- if (this.dataSource.queryErrorMessage) {
362
- this.placeholderType =
363
- !hasQuery && isCollection ? 'collection-error' : 'query-error';
364
- }
365
- }
366
- /**
367
- * Template for the placeholder content to show when no results are available.
368
- */
369
- get emptyPlaceholderTemplate() {
370
- var _a;
332
+ `;
333
+ }
334
+ /**
335
+ * Determines what type of placeholder content should be shown instead of result tiles, if applicable.
336
+ * The placeholders indicate states where we have no results to show, which could be the result of:
337
+ * - No query is set (on the search page)
338
+ * - No results were returned for the most recent search
339
+ * - The collection being searched within has no viewable items
340
+ * - An error occurred on the most recent search attempt
341
+ */
342
+ setPlaceholderType() {
343
+ var _a;
344
+ const hasQuery = !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
345
+ const isCollection = !!this.withinCollection;
346
+ const isProfile = !!this.withinProfile;
347
+ const noResults = !this.searchResultsLoading &&
348
+ (this.dataSource.size === 0 || !this.searchService);
349
+ this.placeholderType = null;
350
+ if (this.suppressPlaceholders)
351
+ return;
352
+ if (!hasQuery && !isCollection && !isProfile) {
353
+ this.placeholderType = 'empty-query';
354
+ }
355
+ else if (noResults) {
356
+ // Within a collection, no query + no results means the collection simply has no viewable items.
357
+ // Otherwise, we must have a user query that produced 0 results.
358
+ this.placeholderType =
359
+ !hasQuery && isCollection ? 'empty-collection' : 'no-results';
360
+ }
361
+ if (this.dataSource.queryErrorMessage) {
362
+ this.placeholderType =
363
+ !hasQuery && isCollection ? 'collection-error' : 'query-error';
364
+ }
365
+ }
366
+ /**
367
+ * Template for the placeholder content to show when no results are available.
368
+ */
369
+ get emptyPlaceholderTemplate() {
370
+ var _a;
371
371
  return html `
372
372
  <empty-placeholder
373
373
  .placeholderType=${this.placeholderType}
@@ -376,33 +376,33 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
376
376
  .detailMessage=${(_a = this.dataSource.queryErrorMessage) !== null && _a !== void 0 ? _a : ''}
377
377
  .baseNavigationUrl=${this.baseNavigationUrl}
378
378
  ></empty-placeholder>
379
- `;
380
- }
381
- /**
382
- * Top-level template for rendering the left (facets) and right (results) columns.
383
- */
384
- get collectionBrowserTemplate() {
379
+ `;
380
+ }
381
+ /**
382
+ * Top-level template for rendering the left (facets) and right (results) columns.
383
+ */
384
+ get collectionBrowserTemplate() {
385
385
  return html `
386
386
  <div id="left-column-scroll-sentinel"></div>
387
387
  ${this.leftColumnTemplate} ${this.rightColumnTemplate}
388
- `;
389
- }
390
- /**
391
- * Template for either the mobile or desktop version of the left column, depending
392
- * on current component state.
393
- */
394
- get leftColumnTemplate() {
395
- if (this.mobileView) {
396
- return this.mobileLeftColumnTemplate;
397
- }
398
- return this.desktopLeftColumnTemplate;
399
- }
400
- /**
401
- * Template for the mobile version of the "left column" (which in this case, appears
402
- * *above* the search results rather than beside them), for rendering the
403
- * accordion-style facets.
404
- */
405
- get mobileLeftColumnTemplate() {
388
+ `;
389
+ }
390
+ /**
391
+ * Template for either the mobile or desktop version of the left column, depending
392
+ * on current component state.
393
+ */
394
+ get leftColumnTemplate() {
395
+ if (this.mobileView) {
396
+ return this.mobileLeftColumnTemplate;
397
+ }
398
+ return this.desktopLeftColumnTemplate;
399
+ }
400
+ /**
401
+ * Template for the mobile version of the "left column" (which in this case, appears
402
+ * *above* the search results rather than beside them), for rendering the
403
+ * accordion-style facets.
404
+ */
405
+ get mobileLeftColumnTemplate() {
406
406
  return html `
407
407
  <div
408
408
  id="left-column"
@@ -411,12 +411,12 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
411
411
  ${this.facetTopViewSlot} ${this.resultsCountTemplate}
412
412
  <div id="facets-header-container">${this.mobileFacetsTemplate}</div>
413
413
  </div>
414
- `;
415
- }
416
- /**
417
- * Template for the desktop version of the left column, displaying the facets sidebar.
418
- */
419
- get desktopLeftColumnTemplate() {
414
+ `;
415
+ }
416
+ /**
417
+ * Template for the desktop version of the left column, displaying the facets sidebar.
418
+ */
419
+ get desktopLeftColumnTemplate() {
420
420
  return html `
421
421
  <div id="left-column" class="column">
422
422
  ${this.facetTopViewSlot}
@@ -430,30 +430,31 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
430
430
  </div>
431
431
  <div id="facets-bottom-fade"></div>
432
432
  </div>
433
- `;
434
- }
435
- /**
436
- * Slot which is placed at top of the facets area for user-profile page
437
- * - mainly used to render userlists
438
- */
439
- get facetTopViewSlot() {
433
+ `;
434
+ }
435
+ /**
436
+ * Slot which is placed at top of the facets area for user-profile page
437
+ * - mainly used to render userlists
438
+ */
439
+ get facetTopViewSlot() {
440
440
  return html `<div id="facet-top-view">
441
441
  <slot name="facet-top-slot"></slot>
442
- </div>`;
443
- }
444
- /**
445
- * Template for the "X Results" count at the top of the search results.
446
- * Changes to the "Searching..." label if the search results are still loading.
447
- */
448
- get resultsCountTemplate() {
449
- var _a;
450
- if (this.suppressResultCount)
451
- return nothing;
452
- const shouldShowSearching = this.searchResultsLoading || this.totalResults === undefined;
453
- const resultsCount = (_a = this.totalResults) === null || _a === void 0 ? void 0 : _a.toLocaleString();
454
- const resultsLabel = this.totalResults === 1 ? 'Result' : 'Results';
442
+ </div>`;
443
+ }
444
+ /**
445
+ * Template for the "X Results" count at the top of the search results.
446
+ * Changes to the "Searching..." label if the search results are still loading.
447
+ */
448
+ get resultsCountTemplate() {
449
+ var _a;
450
+ if (this.suppressResultCount)
451
+ return nothing;
452
+ const shouldShowSearching = this.searchResultsLoading || this.totalResults === undefined;
453
+ const resultsCount = (_a = this.totalResults) === null || _a === void 0 ? void 0 : _a.toLocaleString();
454
+ const resultsLabel = this.totalResults === 1 ? 'Result' : 'Results';
455
+ // Added data-testid for Playwright testing
455
456
  return html `
456
- <div id="results-total">
457
+ <div id="results-total" data-testid="results-total">
457
458
  <span id="big-results-count">
458
459
  ${shouldShowSearching ? html `Searching&hellip;` : resultsCount}
459
460
  </span>
@@ -461,33 +462,33 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
461
462
  ${shouldShowSearching ? nothing : resultsLabel}
462
463
  </span>
463
464
  </div>
464
- `;
465
- }
466
- /**
467
- * Template for the right column of the collection browser, where the result
468
- * tiles and sort/filter bar are shown.
469
- */
470
- get rightColumnTemplate() {
465
+ `;
466
+ }
467
+ /**
468
+ * Template for the right column of the collection browser, where the result
469
+ * tiles and sort/filter bar are shown.
470
+ */
471
+ get rightColumnTemplate() {
471
472
  return html `
472
473
  <div id="right-column" class="column">
473
474
  <div id="cb-top-view">
474
475
  <slot name="cb-top-slot"></slot>
475
476
  </div>
476
- ${this.isManageView
477
- ? this.manageBarTemplate
477
+ ${this.isManageView
478
+ ? this.manageBarTemplate
478
479
  : this.sortFilterBarTemplate}
479
480
  <slot name="cb-results"></slot>
480
- ${this.displayMode === `list-compact` && this.totalResults
481
- ? this.listHeaderTemplate
481
+ ${this.displayMode === `list-compact` && this.totalResults
482
+ ? this.listHeaderTemplate
482
483
  : nothing}
483
484
  ${this.suppressResultTiles ? nothing : this.infiniteScrollerTemplate}
484
485
  </div>
485
- `;
486
- }
487
- /**
488
- * Template for the infinite scroller widget that contains the result tiles.
489
- */
490
- get infiniteScrollerTemplate() {
486
+ `;
487
+ }
488
+ /**
489
+ * Template for the infinite scroller widget that contains the result tiles.
490
+ */
491
+ get infiniteScrollerTemplate() {
491
492
  return html `<infinite-scroller
492
493
  class=${this.infiniteScrollerClasses}
493
494
  itemCount=${this.placeholderType ? 0 : nothing}
@@ -496,29 +497,29 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
496
497
  .placeholderCellTemplate=${this.placeholderCellTemplate}
497
498
  @scrollThresholdReached=${this.scrollThresholdReached}
498
499
  @visibleCellsChanged=${this.visibleCellsChanged}
499
- >${this.displayMode === 'grid'
500
- ? html `<slot name="result-last-tile" slot="result-last-tile"></slot>`
500
+ >${this.displayMode === 'grid'
501
+ ? html `<slot name="result-last-tile" slot="result-last-tile"></slot>`
501
502
  : nothing}
502
- </infinite-scroller>`;
503
- }
504
- /**
505
- * Produces a `classMap` indicating which classes the infinite scroller should have
506
- * given the current display mode & placeholder case.
507
- */
508
- get infiniteScrollerClasses() {
509
- var _a;
510
- return classMap({
511
- [(_a = this.displayMode) !== null && _a !== void 0 ? _a : '']: !!this.displayMode,
512
- hidden: !!this.placeholderType,
513
- });
514
- }
515
- /**
516
- * Template for the sort & filtering bar that appears atop the search results.
517
- */
518
- get sortFilterBarTemplate() {
519
- var _a;
520
- if (this.suppressSortBar)
521
- return nothing;
503
+ </infinite-scroller>`;
504
+ }
505
+ /**
506
+ * Produces a `classMap` indicating which classes the infinite scroller should have
507
+ * given the current display mode & placeholder case.
508
+ */
509
+ get infiniteScrollerClasses() {
510
+ var _a;
511
+ return classMap({
512
+ [(_a = this.displayMode) !== null && _a !== void 0 ? _a : '']: !!this.displayMode,
513
+ hidden: !!this.placeholderType,
514
+ });
515
+ }
516
+ /**
517
+ * Template for the sort & filtering bar that appears atop the search results.
518
+ */
519
+ get sortFilterBarTemplate() {
520
+ var _a;
521
+ if (this.suppressSortBar)
522
+ return nothing;
522
523
  return html `
523
524
  <sort-filter-bar
524
525
  .defaultSortField=${this.defaultSortField}
@@ -543,13 +544,13 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
543
544
  <slot name="sort-options" slot="sort-options"></slot>
544
545
  <slot name="sort-options-right" slot="sort-options-right"></slot>
545
546
  </sort-filter-bar>
546
- `;
547
- }
548
- /**
549
- * Template for the manage bar UI that appears atop the search results when we are
550
- * showing the management view. This generally replaces the sort bar when present.
551
- */
552
- get manageBarTemplate() {
547
+ `;
548
+ }
549
+ /**
550
+ * Template for the manage bar UI that appears atop the search results when we are
551
+ * showing the management view. This generally replaces the sort bar when present.
552
+ */
553
+ get manageBarTemplate() {
553
554
  return html `
554
555
  <manage-bar
555
556
  .label=${this.manageViewLabel}
@@ -559,189 +560,189 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
559
560
  @removeItems=${this.handleRemoveItems}
560
561
  @selectAll=${() => this.dataSource.checkAllTiles()}
561
562
  @unselectAll=${() => this.dataSource.uncheckAllTiles()}
562
- @cancel=${() => {
563
- this.isManageView = false;
564
- this.dataSource.uncheckAllTiles();
563
+ @cancel=${() => {
564
+ this.isManageView = false;
565
+ this.dataSource.uncheckAllTiles();
565
566
  }}
566
567
  ></manage-bar>
567
- `;
568
- }
569
- /**
570
- * Handler for when the user requests to remove all checked items via the manage bar.
571
- * Emits an `itemRemovalRequested` event with all checked tile models.
572
- */
573
- handleRemoveItems() {
574
- this.dispatchEvent(new CustomEvent('itemRemovalRequested', {
575
- detail: {
576
- items: this.dataSource.checkedTileModels.map(model => {
577
- const cloned = model.clone();
578
- cloned.dateStr = formatDate(model.datePublished, 'long');
579
- return cloned;
580
- }),
581
- },
582
- }));
583
- }
584
- /**
585
- * Removes all tile models that are currently checked & adjusts the paging
586
- * of the data source to account for any new gaps in the data.
587
- */
588
- removeCheckedTiles() {
589
- this.dataSource.removeCheckedTiles();
590
- }
591
- /**
592
- * Handler for when the user changes the selected sort option or direction.
593
- */
594
- userChangedSort(e) {
595
- var _a;
596
- const { selectedSort, sortDirection } = e.detail;
597
- this.selectedSort = selectedSort;
598
- this.sortDirection = sortDirection;
599
- if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
600
- this.goToPage(1);
601
- }
602
- this.currentPage = 1;
603
- }
604
- /**
605
- * Fires an analytics event for sorting changes.
606
- * @param prevSortDirection Which sort direction was previously set.
607
- */
608
- sendSortByAnalytics(prevSortDirection) {
609
- var _a;
610
- const directionCleared = prevSortDirection && !this.sortDirection;
611
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
612
- category: this.searchContext,
613
- action: analyticsActions.sortBy,
614
- label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
615
- });
616
- }
617
- /**
618
- * Handler for when the selected sort option is updated, whether by the user
619
- * themselves or programmatically.
620
- */
621
- selectedSortChanged() {
622
- // Lazy-load the alphabet counts for title/creator sort bar as needed
623
- this.dataSource.updatePrefixFiltersForCurrentSort();
624
- }
625
- /**
626
- * An object representing the current sort field & direction.
627
- */
628
- get sortParam() {
629
- var _a;
630
- const sortOption = SORT_OPTIONS[this.selectedSort];
631
- if (!(sortOption === null || sortOption === void 0 ? void 0 : sortOption.handledBySearchService)) {
632
- return null;
633
- }
634
- // If the sort option specified in the URL is unrecognized, we just use it as-is
635
- const urlSortParam = new URL(window.location.href).searchParams.get('sort');
636
- const sortField = (_a = sortOption.searchServiceKey) !== null && _a !== void 0 ? _a : urlSortParam === null || urlSortParam === void 0 ? void 0 : urlSortParam.replace(/^-/, '');
637
- // If the sort direction is still null at this point, then we assume ascending
638
- // (i.e., it was unrecognized and had no directional flag)
639
- if (!this.sortDirection)
640
- this.sortDirection = 'asc';
641
- if (!sortField)
642
- return null;
643
- return { field: sortField, direction: this.sortDirection };
644
- }
645
- /**
646
- * Handler for when the display mode option is changed (grid/list/compact-list views).
647
- */
648
- displayModeChanged(e) {
649
- var _a;
650
- this.displayMode = e.detail.displayMode;
651
- if (this.displayMode) {
652
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
653
- category: this.searchContext,
654
- action: analyticsActions.displayMode,
655
- label: this.displayMode,
656
- });
657
- }
658
- }
659
- /**
660
- * Returns a query clause identifying the currently selected title filter,
661
- * e.g., `firstTitle:X`.
662
- */
663
- get titleQuery() {
664
- return this.selectedTitleFilter
665
- ? `firstTitle:${this.selectedTitleFilter}`
666
- : undefined;
667
- }
668
- /**
669
- * Returns a query clause identifying the currently selected creator filter,
670
- * e.g., `firstCreator:X`.
671
- */
672
- get creatorQuery() {
673
- return this.selectedCreatorFilter
674
- ? `firstCreator:${this.selectedCreatorFilter}`
675
- : undefined;
676
- }
677
- /**
678
- * Send Analytics when sorting by title's first letter
679
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
680
- */
681
- sendFilterByTitleAnalytics(prevSelectedLetter) {
682
- var _a;
683
- if (!prevSelectedLetter && !this.selectedTitleFilter) {
684
- return;
685
- }
686
- const cleared = prevSelectedLetter && !this.selectedTitleFilter;
687
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
688
- category: this.searchContext,
689
- action: analyticsActions.filterByTitle,
690
- label: cleared
691
- ? `clear-${prevSelectedLetter}`
692
- : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
693
- });
694
- }
695
- /**
696
- * Send Analytics when filtering by creator's first letter
697
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
698
- */
699
- sendFilterByCreatorAnalytics(prevSelectedLetter) {
700
- var _a;
701
- if (!prevSelectedLetter && !this.selectedCreatorFilter) {
702
- return;
703
- }
704
- const cleared = prevSelectedLetter && !this.selectedCreatorFilter;
705
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
706
- category: this.searchContext,
707
- action: analyticsActions.filterByCreator,
708
- label: cleared
709
- ? `clear-${prevSelectedLetter}`
710
- : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
711
- });
712
- }
713
- /**
714
- * Handler for changes to which letter is selected in the title alphabet bar.
715
- */
716
- titleLetterSelected(e) {
717
- this.selectedCreatorFilter = null;
718
- this.selectedTitleFilter = e.detail.selectedLetter;
719
- }
720
- /**
721
- * Handler for changes to which letter is selected in the creator alphabet bar.
722
- */
723
- creatorLetterSelected(e) {
724
- this.selectedTitleFilter = null;
725
- this.selectedCreatorFilter = e.detail.selectedLetter;
726
- }
727
- /**
728
- * The full template for how the facets should be structured in mobile view,
729
- * including the collapsible container (with header) and the facets themselves.
730
- */
731
- get mobileFacetsTemplate() {
732
- if (FACETLESS_PAGE_ELEMENTS.includes(this.profileElement))
733
- return nothing;
734
- const toggleFacetsVisible = (e) => {
735
- var _a;
736
- const target = e.target;
737
- this.isResizeToMobile = false;
738
- this.collapsibleFacetsVisible = target.open;
739
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
740
- category: this.searchContext,
741
- action: analyticsActions.mobileFacetsToggled,
742
- label: target.open ? 'open' : 'closed',
743
- });
744
- };
568
+ `;
569
+ }
570
+ /**
571
+ * Handler for when the user requests to remove all checked items via the manage bar.
572
+ * Emits an `itemRemovalRequested` event with all checked tile models.
573
+ */
574
+ handleRemoveItems() {
575
+ this.dispatchEvent(new CustomEvent('itemRemovalRequested', {
576
+ detail: {
577
+ items: this.dataSource.checkedTileModels.map(model => {
578
+ const cloned = model.clone();
579
+ cloned.dateStr = formatDate(model.datePublished, 'long');
580
+ return cloned;
581
+ }),
582
+ },
583
+ }));
584
+ }
585
+ /**
586
+ * Removes all tile models that are currently checked & adjusts the paging
587
+ * of the data source to account for any new gaps in the data.
588
+ */
589
+ removeCheckedTiles() {
590
+ this.dataSource.removeCheckedTiles();
591
+ }
592
+ /**
593
+ * Handler for when the user changes the selected sort option or direction.
594
+ */
595
+ userChangedSort(e) {
596
+ var _a;
597
+ const { selectedSort, sortDirection } = e.detail;
598
+ this.selectedSort = selectedSort;
599
+ this.sortDirection = sortDirection;
600
+ if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
601
+ this.goToPage(1);
602
+ }
603
+ this.currentPage = 1;
604
+ }
605
+ /**
606
+ * Fires an analytics event for sorting changes.
607
+ * @param prevSortDirection Which sort direction was previously set.
608
+ */
609
+ sendSortByAnalytics(prevSortDirection) {
610
+ var _a;
611
+ const directionCleared = prevSortDirection && !this.sortDirection;
612
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
613
+ category: this.searchContext,
614
+ action: analyticsActions.sortBy,
615
+ label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
616
+ });
617
+ }
618
+ /**
619
+ * Handler for when the selected sort option is updated, whether by the user
620
+ * themselves or programmatically.
621
+ */
622
+ selectedSortChanged() {
623
+ // Lazy-load the alphabet counts for title/creator sort bar as needed
624
+ this.dataSource.updatePrefixFiltersForCurrentSort();
625
+ }
626
+ /**
627
+ * An object representing the current sort field & direction.
628
+ */
629
+ get sortParam() {
630
+ var _a;
631
+ const sortOption = SORT_OPTIONS[this.selectedSort];
632
+ if (!(sortOption === null || sortOption === void 0 ? void 0 : sortOption.handledBySearchService)) {
633
+ return null;
634
+ }
635
+ // If the sort option specified in the URL is unrecognized, we just use it as-is
636
+ const urlSortParam = new URL(window.location.href).searchParams.get('sort');
637
+ const sortField = (_a = sortOption.searchServiceKey) !== null && _a !== void 0 ? _a : urlSortParam === null || urlSortParam === void 0 ? void 0 : urlSortParam.replace(/^-/, '');
638
+ // If the sort direction is still null at this point, then we assume ascending
639
+ // (i.e., it was unrecognized and had no directional flag)
640
+ if (!this.sortDirection)
641
+ this.sortDirection = 'asc';
642
+ if (!sortField)
643
+ return null;
644
+ return { field: sortField, direction: this.sortDirection };
645
+ }
646
+ /**
647
+ * Handler for when the display mode option is changed (grid/list/compact-list views).
648
+ */
649
+ displayModeChanged(e) {
650
+ var _a;
651
+ this.displayMode = e.detail.displayMode;
652
+ if (this.displayMode) {
653
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
654
+ category: this.searchContext,
655
+ action: analyticsActions.displayMode,
656
+ label: this.displayMode,
657
+ });
658
+ }
659
+ }
660
+ /**
661
+ * Returns a query clause identifying the currently selected title filter,
662
+ * e.g., `firstTitle:X`.
663
+ */
664
+ get titleQuery() {
665
+ return this.selectedTitleFilter
666
+ ? `firstTitle:${this.selectedTitleFilter}`
667
+ : undefined;
668
+ }
669
+ /**
670
+ * Returns a query clause identifying the currently selected creator filter,
671
+ * e.g., `firstCreator:X`.
672
+ */
673
+ get creatorQuery() {
674
+ return this.selectedCreatorFilter
675
+ ? `firstCreator:${this.selectedCreatorFilter}`
676
+ : undefined;
677
+ }
678
+ /**
679
+ * Send Analytics when sorting by title's first letter
680
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
681
+ */
682
+ sendFilterByTitleAnalytics(prevSelectedLetter) {
683
+ var _a;
684
+ if (!prevSelectedLetter && !this.selectedTitleFilter) {
685
+ return;
686
+ }
687
+ const cleared = prevSelectedLetter && !this.selectedTitleFilter;
688
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
689
+ category: this.searchContext,
690
+ action: analyticsActions.filterByTitle,
691
+ label: cleared
692
+ ? `clear-${prevSelectedLetter}`
693
+ : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
694
+ });
695
+ }
696
+ /**
697
+ * Send Analytics when filtering by creator's first letter
698
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
699
+ */
700
+ sendFilterByCreatorAnalytics(prevSelectedLetter) {
701
+ var _a;
702
+ if (!prevSelectedLetter && !this.selectedCreatorFilter) {
703
+ return;
704
+ }
705
+ const cleared = prevSelectedLetter && !this.selectedCreatorFilter;
706
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
707
+ category: this.searchContext,
708
+ action: analyticsActions.filterByCreator,
709
+ label: cleared
710
+ ? `clear-${prevSelectedLetter}`
711
+ : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
712
+ });
713
+ }
714
+ /**
715
+ * Handler for changes to which letter is selected in the title alphabet bar.
716
+ */
717
+ titleLetterSelected(e) {
718
+ this.selectedCreatorFilter = null;
719
+ this.selectedTitleFilter = e.detail.selectedLetter;
720
+ }
721
+ /**
722
+ * Handler for changes to which letter is selected in the creator alphabet bar.
723
+ */
724
+ creatorLetterSelected(e) {
725
+ this.selectedTitleFilter = null;
726
+ this.selectedCreatorFilter = e.detail.selectedLetter;
727
+ }
728
+ /**
729
+ * The full template for how the facets should be structured in mobile view,
730
+ * including the collapsible container (with header) and the facets themselves.
731
+ */
732
+ get mobileFacetsTemplate() {
733
+ if (FACETLESS_PAGE_ELEMENTS.includes(this.profileElement))
734
+ return nothing;
735
+ const toggleFacetsVisible = (e) => {
736
+ var _a;
737
+ const target = e.target;
738
+ this.isResizeToMobile = false;
739
+ this.collapsibleFacetsVisible = target.open;
740
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
741
+ category: this.searchContext,
742
+ action: analyticsActions.mobileFacetsToggled,
743
+ label: target.open ? 'open' : 'closed',
744
+ });
745
+ };
745
746
  return html `
746
747
  <details id="mobile-filter-collapse" @toggle=${toggleFacetsVisible}>
747
748
  <summary>
@@ -751,21 +752,21 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
751
752
  </summary>
752
753
  ${this.facetsTemplate}
753
754
  </details>
754
- `;
755
- }
756
- /**
757
- * The template for the facets component alone, without any surrounding wrappers.
758
- */
759
- get facetsTemplate() {
760
- if (FACETLESS_PAGE_ELEMENTS.includes(this.profileElement))
761
- return nothing;
762
- if (this.facetLoadStrategy === 'off') {
755
+ `;
756
+ }
757
+ /**
758
+ * The template for the facets component alone, without any surrounding wrappers.
759
+ */
760
+ get facetsTemplate() {
761
+ if (FACETLESS_PAGE_ELEMENTS.includes(this.profileElement))
762
+ return nothing;
763
+ if (this.facetLoadStrategy === 'off') {
763
764
  return html `
764
765
  <p class="facets-message">
765
766
  ${msg('Facets are temporarily unavailable.')}
766
767
  </p>
767
- `;
768
- }
768
+ `;
769
+ }
769
770
  const facets = html `
770
771
  <collection-facets
771
772
  @facetsChanged=${this.facetsChanged}
@@ -779,7 +780,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
779
780
  .resizeObserver=${this.resizeObserver}
780
781
  .searchType=${this.searchType}
781
782
  .aggregations=${this.dataSource.aggregations}
782
- .fullYearsHistogramAggregation=${this.dataSource
783
+ .fullYearsHistogramAggregation=${this.dataSource
783
784
  .yearHistogramAggregation}
784
785
  .minSelectedDate=${this.minSelectedDate}
785
786
  .maxSelectedDate=${this.maxSelectedDate}
@@ -800,16 +801,19 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
800
801
  .analyticsHandler=${this.analyticsHandler}
801
802
  >
802
803
  </collection-facets>
803
- `;
804
- // In the desktop facets opt-in case, wrap the facet sidebar in a <details> widget
805
- // that can be opened and closed as needed.
806
- if (this.facetLoadStrategy === 'opt-in' && !this.mobileView) {
804
+ `;
805
+ // If we are using one of the opt-in facet load strategies, we may need to wrap the
806
+ // desktop view facets in a <details> widget so that patrons can opt into loading them.
807
+ // In the `opt-in-or-login` case, we only do this if they are not logged in.
808
+ const showDesktopOptInWidget = this.facetLoadStrategy === 'opt-in' ||
809
+ (this.facetLoadStrategy === 'opt-in-or-login' && !this.loggedIn);
810
+ if (showDesktopOptInWidget && !this.mobileView) {
807
811
  return html `
808
812
  <details
809
813
  class="desktop-facets-dropdown"
810
- @toggle=${(e) => {
811
- const target = e.target;
812
- this.collapsibleFacetsVisible = target.open;
814
+ @toggle=${(e) => {
815
+ const target = e.target;
816
+ this.collapsibleFacetsVisible = target.open;
813
817
  }}
814
818
  >
815
819
  <summary>
@@ -818,40 +822,40 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
818
822
  </summary>
819
823
  ${facets}
820
824
  </button>
821
- `;
822
- }
823
- // Otherwise, just render the facets component bare
824
- return facets;
825
- }
826
- /**
827
- * The HTML template for the "Clear all filters" button, or `nothing` if no
828
- * filters are currently active.
829
- *
830
- * @param mobile Whether to style/shorten the button for mobile view
831
- */
832
- clearFiltersBtnTemplate(mobile) {
833
- if (!this.hasActiveFilters)
834
- return nothing;
835
- const buttonClasses = classMap({
836
- 'clear-filters-btn': true,
837
- mobile,
838
- });
839
- const buttonText = mobile ? 'Clear all' : 'Clear all filters';
825
+ `;
826
+ }
827
+ // Otherwise, just render the facets component bare
828
+ return facets;
829
+ }
830
+ /**
831
+ * The HTML template for the "Clear all filters" button, or `nothing` if no
832
+ * filters are currently active.
833
+ *
834
+ * @param mobile Whether to style/shorten the button for mobile view
835
+ */
836
+ clearFiltersBtnTemplate(mobile) {
837
+ if (!this.hasActiveFilters)
838
+ return nothing;
839
+ const buttonClasses = classMap({
840
+ 'clear-filters-btn': true,
841
+ mobile,
842
+ });
843
+ const buttonText = mobile ? 'Clear all' : 'Clear all filters';
840
844
  return html `
841
845
  <div class="clear-filters-btn-row">
842
- ${mobile
843
- ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
846
+ ${mobile
847
+ ? html `<span class="clear-filters-btn-separator">&nbsp;</span>`
844
848
  : nothing}
845
849
  <button class=${buttonClasses} @click=${this.clearFilters}>
846
850
  ${buttonText}
847
851
  </button>
848
852
  </div>
849
- `;
850
- }
851
- /**
852
- * Template for the table header content that appears atop the compact list view.
853
- */
854
- get listHeaderTemplate() {
853
+ `;
854
+ }
855
+ /**
856
+ * Template for the table header content that appears atop the compact list view.
857
+ */
858
+ get listHeaderTemplate() {
855
859
  return html `
856
860
  <div id="list-header">
857
861
  <tile-dispatcher
@@ -864,694 +868,700 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
864
868
  >
865
869
  </tile-dispatcher>
866
870
  </div>
867
- `;
868
- }
869
- /**
870
- * Handler for when the date picker's date range is changed.
871
- */
872
- histogramDateRangeUpdated(e) {
873
- var _a;
874
- const { minDate, maxDate } = e.detail;
875
- [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
876
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
877
- category: this.searchContext,
878
- action: analyticsActions.histogramChanged,
879
- label: this.dateRangeQueryClause,
880
- });
881
- }
882
- /**
883
- * The Lucene query corresponding to the current date range.
884
- */
885
- get dateRangeQueryClause() {
886
- if (!this.minSelectedDate || !this.maxSelectedDate) {
887
- return undefined;
888
- }
889
- return `year:[${this.minSelectedDate} TO ${this.maxSelectedDate}]`;
890
- }
891
- /**
892
- * Emits an event indicating a change in whether the manage mode is shown.
893
- */
894
- emitManageModeChangedEvent() {
895
- this.dispatchEvent(new CustomEvent('manageModeChanged', {
896
- detail: this.isManageView,
897
- }));
898
- }
899
- /**
900
- * Installs a new data source component and associated query state parameters into
901
- * this component, causing it to efficiently update its views to represent the
902
- * newly-provided data. In this way, one can reuse a single instance of
903
- * <collection-browser> to handle multiple different sets of search results on
904
- * a single page, each set of results being loaded & updated by its own data
905
- * source.
906
- *
907
- * @param dataSource The data source component containing (or prepared to fetch)
908
- * the tile data to be displayed.
909
- * @param queryState The new query-related state that this component should
910
- * represent, such as the search query, sort option, and any filters applied.
911
- */
912
- async installDataSourceAndQueryState(dataSource, queryState) {
913
- var _a, _b;
914
- log('Installing data source & query state in CB:', dataSource, queryState);
915
- if (this.dataSource)
916
- this.removeController(this.dataSource);
917
- this.dataSource = dataSource;
918
- this.addController(this.dataSource);
919
- this.baseQuery = queryState.baseQuery;
920
- this.profileElement = queryState.profileElement;
921
- this.searchType = queryState.searchType;
922
- this.selectedFacets =
923
- (_a = queryState.selectedFacets) !== null && _a !== void 0 ? _a : getDefaultSelectedFacets();
924
- this.minSelectedDate = queryState.minSelectedDate;
925
- this.maxSelectedDate = queryState.maxSelectedDate;
926
- this.selectedSort = (_b = queryState.selectedSort) !== null && _b !== void 0 ? _b : SortField.default;
927
- this.sortDirection = queryState.sortDirection;
928
- this.selectedTitleFilter = queryState.selectedTitleFilter;
929
- this.selectedCreatorFilter = queryState.selectedCreatorFilter;
930
- // We set this flag during the update to prevent the URL state persistence
931
- // from creating an unwanted extra history entry.
932
- this.dataSourceInstallInProgress = true;
933
- this.requestUpdate();
934
- await this.updateComplete;
935
- this.dataSourceInstallInProgress = false;
936
- if (!this.searchResultsLoading) {
937
- this.setTotalResultCount(this.dataSource.totalResults);
938
- this.setTileCount(this.dataSource.size);
939
- }
940
- this.refreshVisibleResults();
941
- }
942
- firstUpdated() {
943
- this.restoreState();
944
- this.setInitialSize();
945
- }
946
- /**
947
- * Determines the initial size of the content container and whether or not
948
- * the mobile layout should be used.
949
- */
950
- setInitialSize() {
951
- this.contentWidth = this.contentContainer.getBoundingClientRect().width;
952
- this.mobileView =
953
- this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
954
- this.sendLayoutSizeAnalytics();
955
- }
956
- /**
957
- * Fires an analytics event indicating which type of layout was rendered:
958
- * mobile or desktop.
959
- */
960
- sendLayoutSizeAnalytics() {
961
- if (this.analyticsHandler) {
962
- this.layoutSizeAnalyticsSent = true;
963
- this.analyticsHandler.sendEvent({
964
- category: this.searchContext,
965
- action: this.mobileView
966
- ? analyticsActions.loadMobileView
967
- : analyticsActions.loadDesktopView,
968
- });
969
- }
970
- }
971
- updated(changed) {
972
- var _a, _b;
973
- if (changed.has('placeholderType') && this.placeholderType === null) {
974
- if (!this.leftColIntersectionObserver) {
975
- this.setupLeftColumnScrollListeners();
976
- }
977
- if (!this.facetsIntersectionObserver) {
978
- this.setupFacetsScrollListeners();
979
- }
980
- this.updateLeftColumnHeight();
981
- }
982
- if (changed.has('analyticsHandler') && !this.layoutSizeAnalyticsSent) {
983
- this.sendLayoutSizeAnalytics();
984
- }
985
- if (changed.has('displayMode') ||
986
- changed.has('baseNavigationUrl') ||
987
- changed.has('baseImageUrl') ||
988
- changed.has('loggedIn')) {
989
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
990
- }
991
- if (changed.has('baseQuery') ||
992
- changed.has('searchType') ||
993
- changed.has('withinCollection')) {
994
- // Unless this query/search type update is from the initial page load or the
995
- // result of hitting the back button,
996
- // we need to clear any existing filters since they may no longer be valid for
997
- // the new set of search results.
998
- if (!this.historyPopOccurred && this.initialQueryChangeHappened) {
999
- // Ordinarily, we leave the sort param unchanged between searches.
1000
- // However, if we are changing the target collection itself, we want the sort cleared too,
1001
- // since different collections may have different sorting options available.
1002
- const shouldClearSort = changed.has('withinCollection') &&
1003
- !changed.has('selectedSort') &&
1004
- !changed.has('sortDirection');
1005
- // Otherwise, only clear filters that haven't been simultaneously applied in this update
1006
- this.clearFilters({
1007
- sort: shouldClearSort,
1008
- facets: !changed.has('selectedFacets'),
1009
- dateRange: !(changed.has('minSelectedDate') || changed.has('maxSelectedDate')),
1010
- letterFilters: !(changed.has('selectedTitleFilter') ||
1011
- changed.has('selectedCreatorFilter')),
1012
- });
1013
- }
1014
- }
1015
- if (changed.has('profileElement')) {
1016
- this.applyDefaultProfileSort();
1017
- }
1018
- if (changed.has('baseQuery')) {
1019
- this.emitBaseQueryChanged();
1020
- }
1021
- if (changed.has('searchType')) {
1022
- this.emitSearchTypeChanged();
1023
- }
1024
- if (changed.has('currentPage') || changed.has('displayMode')) {
1025
- this.persistState();
1026
- }
1027
- if (changed.has('baseQuery') ||
1028
- changed.has('minSelectedDate') ||
1029
- changed.has('maxSelectedDate') ||
1030
- changed.has('selectedFacets') ||
1031
- changed.has('searchService') ||
1032
- changed.has('withinCollection') ||
1033
- changed.has('withinProfile') ||
1034
- changed.has('profileElement')) {
1035
- this.dataSource.refreshLetterCounts();
1036
- }
1037
- if (changed.has('selectedSort') || changed.has('sortDirection')) {
1038
- const prevSortDirection = changed.get('sortDirection');
1039
- this.sendSortByAnalytics(prevSortDirection);
1040
- this.selectedSortChanged();
1041
- }
1042
- if (changed.has('selectedTitleFilter')) {
1043
- this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
1044
- }
1045
- if (changed.has('selectedCreatorFilter')) {
1046
- this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
1047
- }
1048
- this.updateFacetReadiness();
1049
- if (changed.has('baseQuery') ||
1050
- changed.has('searchType') ||
1051
- changed.has('selectedTitleFilter') ||
1052
- changed.has('selectedCreatorFilter') ||
1053
- changed.has('minSelectedDate') ||
1054
- changed.has('maxSelectedDate') ||
1055
- changed.has('selectedSort') ||
1056
- changed.has('sortDirection') ||
1057
- changed.has('selectedFacets') ||
1058
- changed.has('searchService') ||
1059
- changed.has('withinCollection') ||
1060
- changed.has('withinProfile') ||
1061
- changed.has('profileElement')) {
1062
- this.handleQueryChange();
1063
- }
1064
- if (changed.has('searchResultsLoading')) {
1065
- this.emitSearchResultsLoadingChanged();
1066
- }
1067
- if (changed.has('facetsLoading') &&
1068
- this.facetsLoading &&
1069
- this.collectionFacets) {
1070
- this.collectionFacets.moreLinksVisible =
1071
- this.searchType !== SearchType.FULLTEXT;
1072
- }
1073
- if (changed.has('pagesToRender')) {
1074
- if (!this.dataSource.endOfDataReached && this.infiniteScroller) {
1075
- this.infiniteScroller.itemCount = this.estimatedTileCount;
1076
- }
1077
- }
1078
- if (changed.has('isManageView')) {
1079
- if (this.isManageView)
1080
- this.displayMode = 'grid';
1081
- (_b = this.infiniteScroller) === null || _b === void 0 ? void 0 : _b.refreshAllVisibleCells();
1082
- this.emitManageModeChangedEvent();
1083
- }
1084
- if (changed.has('resizeObserver')) {
1085
- const oldObserver = changed.get('resizeObserver');
1086
- if (oldObserver)
1087
- this.disconnectResizeObserver(oldObserver);
1088
- this.setupResizeObserver();
1089
- }
1090
- }
1091
- connectedCallback() {
1092
- var _a;
1093
- (_a = super.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
1094
- this.setupStateRestorationObserver();
1095
- this.setupResizeObserver();
1096
- }
1097
- disconnectedCallback() {
1098
- var _a, _b;
1099
- if (this.resizeObserver) {
1100
- this.disconnectResizeObserver(this.resizeObserver);
1101
- }
1102
- if (this.boundNavigationHandler) {
1103
- window.removeEventListener('popstate', this.boundNavigationHandler);
1104
- }
1105
- (_a = this.leftColIntersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
1106
- (_b = this.facetsIntersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
1107
- window.removeEventListener('resize', this.updateLeftColumnHeight);
1108
- }
1109
- handleResize(entry) {
1110
- const previousView = this.mobileView;
1111
- if (entry.target === this.contentContainer) {
1112
- this.contentWidth = entry.contentRect.width;
1113
- this.mobileView =
1114
- this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
1115
- // If changing from desktop to mobile disable transition
1116
- if (this.mobileView && !previousView) {
1117
- this.isResizeToMobile = true;
1118
- }
1119
- }
1120
- // Ensure the facet sidebar remains sized correctly
1121
- this.updateLeftColumnHeight();
1122
- }
1123
- /**
1124
- * Updates the data source with the current state of facet readiness for loading,
1125
- * so that they will begin to load in at the appropriate time according to the
1126
- * current facet loading strategy.
1127
- */
1128
- updateFacetReadiness() {
1129
- // In desktop view, we are always ready to load facets *unless* we are
1130
- // using the `opt-in` strategy and the facets dropdown is not open.
1131
- const desktopFacetsReady = !this.mobileView &&
1132
- (this.facetLoadStrategy !== 'opt-in' || this.collapsibleFacetsVisible);
1133
- // In mobile view, facets are considered ready provided they are currently visible (their dropdown is opened).
1134
- const mobileFacetsReady = this.mobileView && this.collapsibleFacetsVisible;
1135
- this.dataSource.handleFacetReadinessChange(desktopFacetsReady || mobileFacetsReady);
1136
- }
1137
- /**
1138
- * Sets up listeners for events that may require updating the left column height.
1139
- */
1140
- setupLeftColumnScrollListeners() {
1141
- var _a;
1142
- // We observe intersections between the left column's scroll sentinel and
1143
- // the viewport, so that we can ensure the left column is always sized to
1144
- // match the _available_ viewport height. This should generally be more
1145
- // performant than listening to scroll events on the page or column.
1146
- const leftColumnSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#left-column-scroll-sentinel');
1147
- if (leftColumnSentinel) {
1148
- this.leftColIntersectionObserver = new IntersectionObserver(this.updateLeftColumnHeight, {
1149
- threshold: [...Array(101).keys()].map(n => n / 100), // Threshold every 1%
1150
- });
1151
- this.leftColIntersectionObserver.observe(leftColumnSentinel);
1152
- }
1153
- // We also listen for window resize events, as they are not always captured
1154
- // by the resize observer and can affect the desired height of the left column.
1155
- window.addEventListener('resize', this.updateLeftColumnHeight);
1156
- }
1157
- /**
1158
- * Sets up listeners to control whether the facet sidebar shows its bottom fade-out.
1159
- * Note this uses a separate IntersectionObserver from the left column, because we
1160
- * don't need granular intersection thresholds for this.
1161
- */
1162
- setupFacetsScrollListeners() {
1163
- var _a;
1164
- const facetsSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#facets-scroll-sentinel');
1165
- if (facetsSentinel) {
1166
- this.facetsIntersectionObserver = new IntersectionObserver(this.updateFacetFadeOut);
1167
- this.facetsIntersectionObserver.observe(facetsSentinel);
1168
- }
1169
- }
1170
- /**
1171
- * Emits a `baseQueryChanged` event indicating an update to the search query.
1172
- */
1173
- emitBaseQueryChanged() {
1174
- this.dispatchEvent(new CustomEvent('baseQueryChanged', {
1175
- detail: {
1176
- baseQuery: this.baseQuery,
1177
- },
1178
- }));
1179
- }
1180
- /**
1181
- * Emits a `searchTypeChanged` event indicating an update to the search type
1182
- * (e.g., metadata vs. full-text).
1183
- */
1184
- emitSearchTypeChanged() {
1185
- this.dispatchEvent(new CustomEvent('searchTypeChanged', {
1186
- detail: this.searchType,
1187
- }));
1188
- }
1189
- /**
1190
- * Emits a `queryStateChanged` event indicating that one or more of this component's
1191
- * properties have changed in a way that could affect the set of search results.
1192
- */
1193
- emitQueryStateChanged() {
1194
- this.dispatchEvent(new CustomEvent('queryStateChanged', {
1195
- detail: {
1196
- baseQuery: this.baseQuery,
1197
- withinCollection: this.withinCollection,
1198
- withinProfile: this.withinProfile,
1199
- profileElement: this.profileElement,
1200
- searchType: this.searchType,
1201
- selectedFacets: this.selectedFacets,
1202
- minSelectedDate: this.minSelectedDate,
1203
- maxSelectedDate: this.maxSelectedDate,
1204
- selectedSort: this.selectedSort,
1205
- sortDirection: this.sortDirection,
1206
- selectedTitleFilter: this.selectedTitleFilter,
1207
- selectedCreatorFilter: this.selectedCreatorFilter,
1208
- },
1209
- }));
1210
- }
1211
- /**
1212
- * Emits an `emptyResults` event indicating that we have received an empty result set
1213
- * for the most recent query.
1214
- */
1215
- emitEmptyResults() {
1216
- this.dispatchEvent(new Event('emptyResults'));
1217
- }
1218
- disconnectResizeObserver(resizeObserver) {
1219
- resizeObserver.removeObserver({
1220
- target: this.contentContainer,
1221
- handler: this,
1222
- });
1223
- }
1224
- setupResizeObserver() {
1225
- if (!this.resizeObserver || !this.contentContainer)
1226
- return;
1227
- this.resizeObserver.addObserver({
1228
- target: this.contentContainer,
1229
- handler: this,
1230
- });
1231
- }
1232
- /**
1233
- * When the visible cells change from the infinite scroller, we want to emit
1234
- * which page is currently visible so the consumer can update its UI or the URL
1235
- *
1236
- * @param e
1237
- * @returns
1238
- */
1239
- visibleCellsChanged(e) {
1240
- if (this.isScrollingToCell)
1241
- return;
1242
- const { visibleCellIndices } = e.detail;
1243
- if (visibleCellIndices.length === 0)
1244
- return;
1245
- // For page determination, do not count more than a single page of visible cells,
1246
- // since otherwise patrons using very tall screens will be treated as one page
1247
- // further than they actually are.
1248
- const lastIndexWithinCurrentPage = Math.min(this.pageSize, visibleCellIndices.length) - 1;
1249
- const lastVisibleCellIndex = visibleCellIndices[lastIndexWithinCurrentPage];
1250
- const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
1251
- if (this.currentPage !== lastVisibleCellPage) {
1252
- this.currentPage = lastVisibleCellPage;
1253
- }
1254
- const event = new CustomEvent('visiblePageChanged', {
1255
- detail: {
1256
- pageNumber: lastVisibleCellPage,
1257
- },
1258
- });
1259
- this.dispatchEvent(event);
1260
- }
1261
- /**
1262
- * A Promise which, after each query change, resolves once the fetches for the initial
1263
- * search have completed. Waits for *both* the hits and aggregations fetches to finish.
1264
- *
1265
- * Ensure you await this component's `updateComplete` promise before awaiting this
1266
- * one, to ensure you do not await an obsolete promise from the previous update.
1267
- */
1268
- get initialSearchComplete() {
1269
- return this.dataSource.initialSearchComplete;
1270
- }
1271
- /**
1272
- * Handler for whenever the component's properties change in a way that may require
1273
- * fetching new results.
1274
- */
1275
- async handleQueryChange() {
1276
- var _a;
1277
- // only reset if the query has actually changed
1278
- if (!this.searchService ||
1279
- this.dataSource.pageFetchQueryKey === this.previousQueryKey)
1280
- return;
1281
- // If the new state prevents us from updating the search results, don't reset
1282
- if (!this.dataSource.canPerformSearch &&
1283
- !(this.clearResultsOnEmptyQuery && this.baseQuery === ''))
1284
- return;
1285
- this.previousQueryKey = this.dataSource.pageFetchQueryKey;
1286
- this.totalResults = undefined;
1287
- this.pagesToRender =
1288
- this.initialPageNumber === 1
1289
- ? 2 // First two pages are batched into one request when starting from page 1
1290
- : this.initialPageNumber;
1291
- // Reset the infinite scroller's item count, so that it
1292
- // shows tile placeholders until the new query's results load in
1293
- if (this.infiniteScroller) {
1294
- this.infiniteScroller.itemCount = this.estimatedTileCount;
1295
- this.infiniteScroller.reload();
1296
- }
1297
- if (this.withinCollection && ((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
1298
- this.defaultSortField = SortField.relevance;
1299
- this.defaultSortDirection = null;
1300
- }
1301
- if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
1302
- this.scrollToPage(this.initialPageNumber);
1303
- }
1304
- this.initialQueryChangeHappened = true;
1305
- // if the query changed as part of a window.history pop event, we don't want to
1306
- // persist the state because it overwrites the forward history
1307
- if (!this.historyPopOccurred) {
1308
- this.persistState();
1309
- }
1310
- this.historyPopOccurred = false;
1311
- }
1312
- setupStateRestorationObserver() {
1313
- if (!this.boundNavigationHandler) {
1314
- this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
1315
- }
1316
- // when the user navigates back, we want to update the UI to match the URL
1317
- window.addEventListener('popstate', this.boundNavigationHandler);
1318
- }
1319
- historyNavigationHandler() {
1320
- this.historyPopOccurred = true;
1321
- this.restoreState();
1322
- }
1323
- restoreState() {
1324
- var _a, _b, _c, _d, _e;
1325
- const restorationState = this.restorationStateHandler.getRestorationState();
1326
- this.displayMode = restorationState.displayMode;
1327
- if (restorationState.searchType != null)
1328
- this.searchType = restorationState.searchType;
1329
- this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.default;
1330
- this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
1331
- this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
1332
- this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
1333
- this.selectedFacets = restorationState.selectedFacets;
1334
- if (!this.suppressURLQuery)
1335
- this.baseQuery = restorationState.baseQuery;
1336
- this.currentPage = (_e = restorationState.currentPage) !== null && _e !== void 0 ? _e : 1;
1337
- this.minSelectedDate = restorationState.minSelectedDate;
1338
- this.maxSelectedDate = restorationState.maxSelectedDate;
1339
- if (this.currentPage > 1) {
1340
- this.goToPage(this.currentPage);
1341
- }
1342
- }
1343
- persistState() {
1344
- var _a, _b, _c, _d;
1345
- const restorationState = {
1346
- displayMode: this.displayMode,
1347
- searchType: this.searchType,
1348
- selectedSort: this.selectedSort,
1349
- sortDirection: (_a = this.sortDirection) !== null && _a !== void 0 ? _a : undefined,
1350
- selectedFacets: (_b = this.selectedFacets) !== null && _b !== void 0 ? _b : getDefaultSelectedFacets(),
1351
- baseQuery: this.suppressURLQuery ? undefined : this.baseQuery,
1352
- currentPage: this.currentPage,
1353
- titleQuery: this.titleQuery,
1354
- creatorQuery: this.creatorQuery,
1355
- minSelectedDate: this.minSelectedDate,
1356
- maxSelectedDate: this.maxSelectedDate,
1357
- selectedTitleFilter: (_c = this.selectedTitleFilter) !== null && _c !== void 0 ? _c : undefined,
1358
- selectedCreatorFilter: (_d = this.selectedCreatorFilter) !== null && _d !== void 0 ? _d : undefined,
1359
- };
1360
- this.restorationStateHandler.persistState(restorationState, this.dataSourceInstallInProgress);
1361
- }
1362
- /**
1363
- * Emits a `searchResultsLoadingChanged` event indicating that our loading state has
1364
- * changed (either we have started loading new results, or we have finished loading them).
1365
- */
1366
- emitSearchResultsLoadingChanged() {
1367
- this.dispatchEvent(new CustomEvent('searchResultsLoadingChanged', {
1368
- detail: {
1369
- loading: this.searchResultsLoading,
1370
- },
1371
- }));
1372
- }
1373
- /**
1374
- * Handler for when the set of selected facets changes.
1375
- */
1376
- facetsChanged(e) {
1377
- this.selectedFacets = e.detail;
1378
- }
1379
- /**
1380
- * Handler for when any facet is selected/unselected/hidden/unhidden.
1381
- * Fires analytics indicating the type of facet event that took place.
1382
- */
1383
- facetClickHandler({ detail: { facetType, bucket, negative }, }) {
1384
- var _a;
1385
- let action;
1386
- if (negative) {
1387
- action =
1388
- bucket.state !== 'none'
1389
- ? analyticsActions.facetNegativeSelected
1390
- : analyticsActions.facetNegativeDeselected;
1391
- }
1392
- else {
1393
- action =
1394
- bucket.state !== 'none'
1395
- ? analyticsActions.facetSelected
1396
- : analyticsActions.facetDeselected;
1397
- }
1398
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1399
- category: this.searchContext,
1400
- action,
1401
- label: facetType,
1402
- });
1403
- }
1404
- scrollToPage(pageNumber) {
1405
- return new Promise(resolve => {
1406
- const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
1407
- // without this setTimeout, Safari just pauses until the `fetchPage` is complete
1408
- // then scrolls to the cell
1409
- setTimeout(() => {
1410
- var _a;
1411
- this.isScrollingToCell = true;
1412
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.scrollToCell(cellIndexToScrollTo, true);
1413
- // This timeout is to give the scroll animation time to finish
1414
- // then updating the infinite scroller once we're done scrolling
1415
- // There's no scroll animation completion callback so we're
1416
- // giving it 0.5s to finish.
1417
- setTimeout(() => {
1418
- var _a;
1419
- this.isScrollingToCell = false;
1420
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1421
- resolve();
1422
- }, 500);
1423
- }, 0);
1424
- });
1425
- }
1426
- /**
1427
- * Whether sorting by relevance makes sense for the current state.
1428
- * Currently equivalent to having a non-empty query.
1429
- */
1430
- get isRelevanceSortAvailable() {
1431
- var _a;
1432
- return !!((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim());
1433
- }
1434
- /**
1435
- * Sets the total number of tiles displayed in the infinite scroller.
1436
- */
1437
- setTileCount(count) {
1438
- if (this.infiniteScroller) {
1439
- this.infiniteScroller.itemCount = count;
1440
- }
1441
- }
1442
- /**
1443
- * Applies any default sort option for the current collection, by checking
1444
- * for one in the collection's metadata. If none is found, defaults to sorting
1445
- * descending by:
1446
- * - Date Favorited for fav-* collections
1447
- * - Weekly views for all other collections
1448
- */
1449
- applyDefaultCollectionSort(collectionInfo) {
1450
- var _a, _b, _c;
1451
- if (this.baseQuery) {
1452
- // If there's a query set, then we default to relevance sorting regardless of
1453
- // the collection metadata-specified sort.
1454
- this.defaultSortField = SortField.relevance;
1455
- this.defaultSortDirection = null;
1456
- return;
1457
- }
1458
- // Favorite collections sort on Date Favorited by default.
1459
- // Other collections fall back to sorting on weekly views.
1460
- 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-'))
1461
- ? '-favoritedate'
1462
- : '-week';
1463
- // The collection metadata may override the default sorting with something else
1464
- const metadataSort = (_c = collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.public_metadata) === null || _c === void 0 ? void 0 : _c['sort-by'];
1465
- // Prefer the metadata-specified sort if one exists
1466
- const defaultSortToApply = metadataSort !== null && metadataSort !== void 0 ? metadataSort : baseDefaultSort;
1467
- // Account for both -field and field:dir formats
1468
- let [field, dir] = defaultSortToApply.split(':');
1469
- if (field.startsWith('-')) {
1470
- field = field.slice(1);
1471
- dir = 'desc';
1472
- }
1473
- else if (!['asc', 'desc'].includes(dir)) {
1474
- dir = 'asc';
1475
- }
1476
- const sortOption = sortOptionFromAPIString(field);
1477
- const sortField = sortOption.field;
1478
- if (sortField && sortField !== SortField.default) {
1479
- this.defaultSortField = sortField;
1480
- this.defaultSortDirection = dir;
1481
- this.defaultSortParam = {
1482
- field: this.defaultSortField,
1483
- direction: this.defaultSortDirection,
1484
- };
1485
- }
1486
- }
1487
- /**
1488
- * Applies the default sort option for the current profile element
1489
- */
1490
- applyDefaultProfileSort() {
1491
- if (this.profileElement) {
1492
- const defaultSortField = defaultProfileElementSorts[this.profileElement];
1493
- this.defaultSortField = defaultSortField !== null && defaultSortField !== void 0 ? defaultSortField : SortField.weeklyview;
1494
- }
1495
- else {
1496
- this.defaultSortField = SortField.weeklyview;
1497
- }
1498
- this.defaultSortDirection = 'desc';
1499
- this.defaultSortParam = {
1500
- field: this.defaultSortField,
1501
- direction: this.defaultSortDirection,
1502
- };
1503
- }
1504
- /**
1505
- * This is useful for determining whether we need to reload the scroller.
1506
- *
1507
- * When the fetch completes, we need to reload the scroller if the cells for that
1508
- * page are visible, but if the page is not currenlty visible, we don't need to reload
1509
- */
1510
- get currentVisiblePageNumbers() {
1511
- var _a, _b;
1512
- const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
1513
- const visiblePages = new Set();
1514
- visibleCells.forEach(cellIndex => {
1515
- const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1516
- visiblePages.add(visiblePage);
1517
- });
1518
- return Array.from(visiblePages);
1519
- }
1520
- /**
1521
- * Refreshes all visible result cells in the infinite scroller.
1522
- */
1523
- refreshVisibleResults() {
1524
- var _a;
1525
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1526
- }
1527
- /**
1528
- * Callback when a result is selected
1529
- */
1530
- resultSelected(event) {
1531
- var _a, _b, _c;
1532
- if (this.isManageView) {
1533
- // Checked/unchecked state change -- rerender to ensure it propagates
1534
- // this.mapDataSource(model => ({ ...model }));
1535
- const cellIndex = this.dataSource.indexOf(event.detail);
1536
- if (cellIndex >= 0)
1537
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshCell(cellIndex);
1538
- this.requestUpdate();
1539
- }
1540
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1541
- category: this.searchContext,
1542
- action: analyticsActions.resultSelected,
1543
- label: event.detail.mediatype,
1544
- });
1545
- (_c = this.analyticsHandler) === null || _c === void 0 ? void 0 : _c.sendEvent({
1546
- category: this.searchContext,
1547
- action: analyticsActions.resultSelected,
1548
- label: `page-${this.currentPage}`,
1549
- });
1550
- }
1551
- cellForIndex(index) {
1552
- const model = this.tileModelAtCellIndex(index);
1553
- if (!model)
1554
- return undefined;
871
+ `;
872
+ }
873
+ /**
874
+ * Handler for when the date picker's date range is changed.
875
+ */
876
+ histogramDateRangeUpdated(e) {
877
+ var _a;
878
+ const { minDate, maxDate } = e.detail;
879
+ [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
880
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
881
+ category: this.searchContext,
882
+ action: analyticsActions.histogramChanged,
883
+ label: this.dateRangeQueryClause,
884
+ });
885
+ }
886
+ /**
887
+ * The Lucene query corresponding to the current date range.
888
+ */
889
+ get dateRangeQueryClause() {
890
+ if (!this.minSelectedDate || !this.maxSelectedDate) {
891
+ return undefined;
892
+ }
893
+ return `year:[${this.minSelectedDate} TO ${this.maxSelectedDate}]`;
894
+ }
895
+ /**
896
+ * Emits an event indicating a change in whether the manage mode is shown.
897
+ */
898
+ emitManageModeChangedEvent() {
899
+ this.dispatchEvent(new CustomEvent('manageModeChanged', {
900
+ detail: this.isManageView,
901
+ }));
902
+ }
903
+ /**
904
+ * Installs a new data source component and associated query state parameters into
905
+ * this component, causing it to efficiently update its views to represent the
906
+ * newly-provided data. In this way, one can reuse a single instance of
907
+ * <collection-browser> to handle multiple different sets of search results on
908
+ * a single page, each set of results being loaded & updated by its own data
909
+ * source.
910
+ *
911
+ * @param dataSource The data source component containing (or prepared to fetch)
912
+ * the tile data to be displayed.
913
+ * @param queryState The new query-related state that this component should
914
+ * represent, such as the search query, sort option, and any filters applied.
915
+ */
916
+ async installDataSourceAndQueryState(dataSource, queryState) {
917
+ var _a, _b;
918
+ log('Installing data source & query state in CB:', dataSource, queryState);
919
+ if (this.dataSource)
920
+ this.removeController(this.dataSource);
921
+ this.dataSource = dataSource;
922
+ this.addController(this.dataSource);
923
+ this.baseQuery = queryState.baseQuery;
924
+ this.profileElement = queryState.profileElement;
925
+ this.searchType = queryState.searchType;
926
+ this.selectedFacets =
927
+ (_a = queryState.selectedFacets) !== null && _a !== void 0 ? _a : getDefaultSelectedFacets();
928
+ this.minSelectedDate = queryState.minSelectedDate;
929
+ this.maxSelectedDate = queryState.maxSelectedDate;
930
+ this.selectedSort = (_b = queryState.selectedSort) !== null && _b !== void 0 ? _b : SortField.default;
931
+ this.sortDirection = queryState.sortDirection;
932
+ this.selectedTitleFilter = queryState.selectedTitleFilter;
933
+ this.selectedCreatorFilter = queryState.selectedCreatorFilter;
934
+ // We set this flag during the update to prevent the URL state persistence
935
+ // from creating an unwanted extra history entry.
936
+ this.dataSourceInstallInProgress = true;
937
+ this.requestUpdate();
938
+ await this.updateComplete;
939
+ this.dataSourceInstallInProgress = false;
940
+ if (!this.searchResultsLoading) {
941
+ this.setTotalResultCount(this.dataSource.totalResults);
942
+ this.setTileCount(this.dataSource.size);
943
+ }
944
+ this.refreshVisibleResults();
945
+ }
946
+ firstUpdated() {
947
+ this.restoreState();
948
+ this.setInitialSize();
949
+ }
950
+ /**
951
+ * Determines the initial size of the content container and whether or not
952
+ * the mobile layout should be used.
953
+ */
954
+ setInitialSize() {
955
+ this.contentWidth = this.contentContainer.getBoundingClientRect().width;
956
+ this.mobileView =
957
+ this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
958
+ this.sendLayoutSizeAnalytics();
959
+ }
960
+ /**
961
+ * Fires an analytics event indicating which type of layout was rendered:
962
+ * mobile or desktop.
963
+ */
964
+ sendLayoutSizeAnalytics() {
965
+ if (this.analyticsHandler) {
966
+ this.layoutSizeAnalyticsSent = true;
967
+ this.analyticsHandler.sendEvent({
968
+ category: this.searchContext,
969
+ action: this.mobileView
970
+ ? analyticsActions.loadMobileView
971
+ : analyticsActions.loadDesktopView,
972
+ });
973
+ }
974
+ }
975
+ updated(changed) {
976
+ var _a, _b;
977
+ if (changed.has('placeholderType') && this.placeholderType === null) {
978
+ if (!this.leftColIntersectionObserver) {
979
+ this.setupLeftColumnScrollListeners();
980
+ }
981
+ if (!this.facetsIntersectionObserver) {
982
+ this.setupFacetsScrollListeners();
983
+ }
984
+ this.updateLeftColumnHeight();
985
+ }
986
+ if (changed.has('analyticsHandler') && !this.layoutSizeAnalyticsSent) {
987
+ this.sendLayoutSizeAnalytics();
988
+ }
989
+ if (changed.has('displayMode') ||
990
+ changed.has('baseNavigationUrl') ||
991
+ changed.has('baseImageUrl') ||
992
+ changed.has('loggedIn')) {
993
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
994
+ }
995
+ if (changed.has('baseQuery') ||
996
+ changed.has('searchType') ||
997
+ changed.has('withinCollection')) {
998
+ // Unless this query/search type update is from the initial page load or the
999
+ // result of hitting the back button,
1000
+ // we need to clear any existing filters since they may no longer be valid for
1001
+ // the new set of search results.
1002
+ if (!this.historyPopOccurred && this.initialQueryChangeHappened) {
1003
+ // Ordinarily, we leave the sort param unchanged between searches.
1004
+ // However, if we are changing the target collection itself, we want the sort cleared too,
1005
+ // since different collections may have different sorting options available.
1006
+ const shouldClearSort = changed.has('withinCollection') &&
1007
+ !changed.has('selectedSort') &&
1008
+ !changed.has('sortDirection');
1009
+ // Otherwise, only clear filters that haven't been simultaneously applied in this update
1010
+ this.clearFilters({
1011
+ sort: shouldClearSort,
1012
+ facets: !changed.has('selectedFacets'),
1013
+ dateRange: !(changed.has('minSelectedDate') || changed.has('maxSelectedDate')),
1014
+ letterFilters: !(changed.has('selectedTitleFilter') ||
1015
+ changed.has('selectedCreatorFilter')),
1016
+ });
1017
+ }
1018
+ }
1019
+ if (changed.has('profileElement')) {
1020
+ this.applyDefaultProfileSort();
1021
+ }
1022
+ if (changed.has('baseQuery')) {
1023
+ this.emitBaseQueryChanged();
1024
+ }
1025
+ if (changed.has('searchType')) {
1026
+ this.emitSearchTypeChanged();
1027
+ }
1028
+ if (changed.has('currentPage') || changed.has('displayMode')) {
1029
+ this.persistState();
1030
+ }
1031
+ if (changed.has('baseQuery') ||
1032
+ changed.has('minSelectedDate') ||
1033
+ changed.has('maxSelectedDate') ||
1034
+ changed.has('selectedFacets') ||
1035
+ changed.has('searchService') ||
1036
+ changed.has('withinCollection') ||
1037
+ changed.has('withinProfile') ||
1038
+ changed.has('profileElement')) {
1039
+ this.dataSource.refreshLetterCounts();
1040
+ }
1041
+ if (changed.has('selectedSort') || changed.has('sortDirection')) {
1042
+ const prevSortDirection = changed.get('sortDirection');
1043
+ this.sendSortByAnalytics(prevSortDirection);
1044
+ this.selectedSortChanged();
1045
+ }
1046
+ if (changed.has('selectedTitleFilter')) {
1047
+ this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
1048
+ }
1049
+ if (changed.has('selectedCreatorFilter')) {
1050
+ this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
1051
+ }
1052
+ this.updateFacetReadiness();
1053
+ if (changed.has('baseQuery') ||
1054
+ changed.has('searchType') ||
1055
+ changed.has('selectedTitleFilter') ||
1056
+ changed.has('selectedCreatorFilter') ||
1057
+ changed.has('minSelectedDate') ||
1058
+ changed.has('maxSelectedDate') ||
1059
+ changed.has('selectedSort') ||
1060
+ changed.has('sortDirection') ||
1061
+ changed.has('selectedFacets') ||
1062
+ changed.has('searchService') ||
1063
+ changed.has('withinCollection') ||
1064
+ changed.has('withinProfile') ||
1065
+ changed.has('profileElement')) {
1066
+ this.handleQueryChange();
1067
+ }
1068
+ if (changed.has('searchResultsLoading')) {
1069
+ this.emitSearchResultsLoadingChanged();
1070
+ }
1071
+ if (changed.has('facetsLoading') &&
1072
+ this.facetsLoading &&
1073
+ this.collectionFacets) {
1074
+ this.collectionFacets.moreLinksVisible =
1075
+ this.searchType !== SearchType.FULLTEXT;
1076
+ }
1077
+ if (changed.has('pagesToRender')) {
1078
+ if (!this.dataSource.endOfDataReached && this.infiniteScroller) {
1079
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
1080
+ }
1081
+ }
1082
+ if (changed.has('isManageView')) {
1083
+ if (this.isManageView)
1084
+ this.displayMode = 'grid';
1085
+ (_b = this.infiniteScroller) === null || _b === void 0 ? void 0 : _b.refreshAllVisibleCells();
1086
+ this.emitManageModeChangedEvent();
1087
+ }
1088
+ if (changed.has('resizeObserver')) {
1089
+ const oldObserver = changed.get('resizeObserver');
1090
+ if (oldObserver)
1091
+ this.disconnectResizeObserver(oldObserver);
1092
+ this.setupResizeObserver();
1093
+ }
1094
+ }
1095
+ connectedCallback() {
1096
+ var _a;
1097
+ (_a = super.connectedCallback) === null || _a === void 0 ? void 0 : _a.call(this);
1098
+ this.setupStateRestorationObserver();
1099
+ this.setupResizeObserver();
1100
+ }
1101
+ disconnectedCallback() {
1102
+ var _a, _b;
1103
+ if (this.resizeObserver) {
1104
+ this.disconnectResizeObserver(this.resizeObserver);
1105
+ }
1106
+ if (this.boundNavigationHandler) {
1107
+ window.removeEventListener('popstate', this.boundNavigationHandler);
1108
+ }
1109
+ (_a = this.leftColIntersectionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
1110
+ (_b = this.facetsIntersectionObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
1111
+ window.removeEventListener('resize', this.updateLeftColumnHeight);
1112
+ }
1113
+ handleResize(entry) {
1114
+ const previousView = this.mobileView;
1115
+ if (entry.target === this.contentContainer) {
1116
+ this.contentWidth = entry.contentRect.width;
1117
+ this.mobileView =
1118
+ this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
1119
+ // If changing from desktop to mobile disable transition
1120
+ if (this.mobileView && !previousView) {
1121
+ this.isResizeToMobile = true;
1122
+ }
1123
+ }
1124
+ // Ensure the facet sidebar remains sized correctly
1125
+ this.updateLeftColumnHeight();
1126
+ }
1127
+ /**
1128
+ * Updates the data source with the current state of facet readiness for loading,
1129
+ * so that they will begin to load in at the appropriate time according to the
1130
+ * current facet loading strategy.
1131
+ */
1132
+ updateFacetReadiness() {
1133
+ // There are two ways to opt into facet production:
1134
+ // (1) have the facets dropdown open, or
1135
+ // (2) if using the `opt-in-or-login` strategy, be logged into an account
1136
+ const optedIn = this.collapsibleFacetsVisible ||
1137
+ (this.facetLoadStrategy === 'opt-in-or-login' && this.loggedIn);
1138
+ // In desktop view, we are always ready to load facets *unless* we are using one of the
1139
+ // `opt-in` strategies and have not opted in (whether by login or UI interaction).
1140
+ const usingOptInStrategy = ['opt-in', 'opt-in-or-login'].includes(this.facetLoadStrategy);
1141
+ const desktopFacetsReady = !this.mobileView && (!usingOptInStrategy || optedIn);
1142
+ // In the mobile view, facets are considered ready provided we have opted in (whether by
1143
+ // login or UI interaction).
1144
+ const mobileFacetsReady = this.mobileView && optedIn;
1145
+ this.dataSource.handleFacetReadinessChange(desktopFacetsReady || mobileFacetsReady);
1146
+ }
1147
+ /**
1148
+ * Sets up listeners for events that may require updating the left column height.
1149
+ */
1150
+ setupLeftColumnScrollListeners() {
1151
+ var _a;
1152
+ // We observe intersections between the left column's scroll sentinel and
1153
+ // the viewport, so that we can ensure the left column is always sized to
1154
+ // match the _available_ viewport height. This should generally be more
1155
+ // performant than listening to scroll events on the page or column.
1156
+ const leftColumnSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#left-column-scroll-sentinel');
1157
+ if (leftColumnSentinel) {
1158
+ this.leftColIntersectionObserver = new IntersectionObserver(this.updateLeftColumnHeight, {
1159
+ threshold: [...Array(101).keys()].map(n => n / 100), // Threshold every 1%
1160
+ });
1161
+ this.leftColIntersectionObserver.observe(leftColumnSentinel);
1162
+ }
1163
+ // We also listen for window resize events, as they are not always captured
1164
+ // by the resize observer and can affect the desired height of the left column.
1165
+ window.addEventListener('resize', this.updateLeftColumnHeight);
1166
+ }
1167
+ /**
1168
+ * Sets up listeners to control whether the facet sidebar shows its bottom fade-out.
1169
+ * Note this uses a separate IntersectionObserver from the left column, because we
1170
+ * don't need granular intersection thresholds for this.
1171
+ */
1172
+ setupFacetsScrollListeners() {
1173
+ var _a;
1174
+ const facetsSentinel = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#facets-scroll-sentinel');
1175
+ if (facetsSentinel) {
1176
+ this.facetsIntersectionObserver = new IntersectionObserver(this.updateFacetFadeOut);
1177
+ this.facetsIntersectionObserver.observe(facetsSentinel);
1178
+ }
1179
+ }
1180
+ /**
1181
+ * Emits a `baseQueryChanged` event indicating an update to the search query.
1182
+ */
1183
+ emitBaseQueryChanged() {
1184
+ this.dispatchEvent(new CustomEvent('baseQueryChanged', {
1185
+ detail: {
1186
+ baseQuery: this.baseQuery,
1187
+ },
1188
+ }));
1189
+ }
1190
+ /**
1191
+ * Emits a `searchTypeChanged` event indicating an update to the search type
1192
+ * (e.g., metadata vs. full-text).
1193
+ */
1194
+ emitSearchTypeChanged() {
1195
+ this.dispatchEvent(new CustomEvent('searchTypeChanged', {
1196
+ detail: this.searchType,
1197
+ }));
1198
+ }
1199
+ /**
1200
+ * Emits a `queryStateChanged` event indicating that one or more of this component's
1201
+ * properties have changed in a way that could affect the set of search results.
1202
+ */
1203
+ emitQueryStateChanged() {
1204
+ this.dispatchEvent(new CustomEvent('queryStateChanged', {
1205
+ detail: {
1206
+ baseQuery: this.baseQuery,
1207
+ withinCollection: this.withinCollection,
1208
+ withinProfile: this.withinProfile,
1209
+ profileElement: this.profileElement,
1210
+ searchType: this.searchType,
1211
+ selectedFacets: this.selectedFacets,
1212
+ minSelectedDate: this.minSelectedDate,
1213
+ maxSelectedDate: this.maxSelectedDate,
1214
+ selectedSort: this.selectedSort,
1215
+ sortDirection: this.sortDirection,
1216
+ selectedTitleFilter: this.selectedTitleFilter,
1217
+ selectedCreatorFilter: this.selectedCreatorFilter,
1218
+ },
1219
+ }));
1220
+ }
1221
+ /**
1222
+ * Emits an `emptyResults` event indicating that we have received an empty result set
1223
+ * for the most recent query.
1224
+ */
1225
+ emitEmptyResults() {
1226
+ this.dispatchEvent(new Event('emptyResults'));
1227
+ }
1228
+ disconnectResizeObserver(resizeObserver) {
1229
+ resizeObserver.removeObserver({
1230
+ target: this.contentContainer,
1231
+ handler: this,
1232
+ });
1233
+ }
1234
+ setupResizeObserver() {
1235
+ if (!this.resizeObserver || !this.contentContainer)
1236
+ return;
1237
+ this.resizeObserver.addObserver({
1238
+ target: this.contentContainer,
1239
+ handler: this,
1240
+ });
1241
+ }
1242
+ /**
1243
+ * When the visible cells change from the infinite scroller, we want to emit
1244
+ * which page is currently visible so the consumer can update its UI or the URL
1245
+ *
1246
+ * @param e
1247
+ * @returns
1248
+ */
1249
+ visibleCellsChanged(e) {
1250
+ if (this.isScrollingToCell)
1251
+ return;
1252
+ const { visibleCellIndices } = e.detail;
1253
+ if (visibleCellIndices.length === 0)
1254
+ return;
1255
+ // For page determination, do not count more than a single page of visible cells,
1256
+ // since otherwise patrons using very tall screens will be treated as one page
1257
+ // further than they actually are.
1258
+ const lastIndexWithinCurrentPage = Math.min(this.pageSize, visibleCellIndices.length) - 1;
1259
+ const lastVisibleCellIndex = visibleCellIndices[lastIndexWithinCurrentPage];
1260
+ const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
1261
+ if (this.currentPage !== lastVisibleCellPage) {
1262
+ this.currentPage = lastVisibleCellPage;
1263
+ }
1264
+ const event = new CustomEvent('visiblePageChanged', {
1265
+ detail: {
1266
+ pageNumber: lastVisibleCellPage,
1267
+ },
1268
+ });
1269
+ this.dispatchEvent(event);
1270
+ }
1271
+ /**
1272
+ * A Promise which, after each query change, resolves once the fetches for the initial
1273
+ * search have completed. Waits for *both* the hits and aggregations fetches to finish.
1274
+ *
1275
+ * Ensure you await this component's `updateComplete` promise before awaiting this
1276
+ * one, to ensure you do not await an obsolete promise from the previous update.
1277
+ */
1278
+ get initialSearchComplete() {
1279
+ return this.dataSource.initialSearchComplete;
1280
+ }
1281
+ /**
1282
+ * Handler for whenever the component's properties change in a way that may require
1283
+ * fetching new results.
1284
+ */
1285
+ async handleQueryChange() {
1286
+ var _a;
1287
+ // only reset if the query has actually changed
1288
+ if (!this.searchService ||
1289
+ this.dataSource.pageFetchQueryKey === this.previousQueryKey)
1290
+ return;
1291
+ // If the new state prevents us from updating the search results, don't reset
1292
+ if (!this.dataSource.canPerformSearch &&
1293
+ !(this.clearResultsOnEmptyQuery && this.baseQuery === ''))
1294
+ return;
1295
+ this.previousQueryKey = this.dataSource.pageFetchQueryKey;
1296
+ this.totalResults = undefined;
1297
+ this.pagesToRender =
1298
+ this.initialPageNumber === 1
1299
+ ? 2 // First two pages are batched into one request when starting from page 1
1300
+ : this.initialPageNumber;
1301
+ // Reset the infinite scroller's item count, so that it
1302
+ // shows tile placeholders until the new query's results load in
1303
+ if (this.infiniteScroller) {
1304
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
1305
+ this.infiniteScroller.reload();
1306
+ }
1307
+ if (this.withinCollection && ((_a = this.baseQuery) === null || _a === void 0 ? void 0 : _a.trim())) {
1308
+ this.defaultSortField = SortField.relevance;
1309
+ this.defaultSortDirection = null;
1310
+ }
1311
+ if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
1312
+ this.scrollToPage(this.initialPageNumber);
1313
+ }
1314
+ this.initialQueryChangeHappened = true;
1315
+ // if the query changed as part of a window.history pop event, we don't want to
1316
+ // persist the state because it overwrites the forward history
1317
+ if (!this.historyPopOccurred) {
1318
+ this.persistState();
1319
+ }
1320
+ this.historyPopOccurred = false;
1321
+ }
1322
+ setupStateRestorationObserver() {
1323
+ if (!this.boundNavigationHandler) {
1324
+ this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
1325
+ }
1326
+ // when the user navigates back, we want to update the UI to match the URL
1327
+ window.addEventListener('popstate', this.boundNavigationHandler);
1328
+ }
1329
+ historyNavigationHandler() {
1330
+ this.historyPopOccurred = true;
1331
+ this.restoreState();
1332
+ }
1333
+ restoreState() {
1334
+ var _a, _b, _c, _d, _e;
1335
+ const restorationState = this.restorationStateHandler.getRestorationState();
1336
+ this.displayMode = restorationState.displayMode;
1337
+ if (restorationState.searchType != null)
1338
+ this.searchType = restorationState.searchType;
1339
+ this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.default;
1340
+ this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
1341
+ this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
1342
+ this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
1343
+ this.selectedFacets = restorationState.selectedFacets;
1344
+ if (!this.suppressURLQuery)
1345
+ this.baseQuery = restorationState.baseQuery;
1346
+ this.currentPage = (_e = restorationState.currentPage) !== null && _e !== void 0 ? _e : 1;
1347
+ this.minSelectedDate = restorationState.minSelectedDate;
1348
+ this.maxSelectedDate = restorationState.maxSelectedDate;
1349
+ if (this.currentPage > 1) {
1350
+ this.goToPage(this.currentPage);
1351
+ }
1352
+ }
1353
+ persistState() {
1354
+ var _a, _b, _c, _d;
1355
+ const restorationState = {
1356
+ displayMode: this.displayMode,
1357
+ searchType: this.searchType,
1358
+ selectedSort: this.selectedSort,
1359
+ sortDirection: (_a = this.sortDirection) !== null && _a !== void 0 ? _a : undefined,
1360
+ selectedFacets: (_b = this.selectedFacets) !== null && _b !== void 0 ? _b : getDefaultSelectedFacets(),
1361
+ baseQuery: this.suppressURLQuery ? undefined : this.baseQuery,
1362
+ currentPage: this.currentPage,
1363
+ titleQuery: this.titleQuery,
1364
+ creatorQuery: this.creatorQuery,
1365
+ minSelectedDate: this.minSelectedDate,
1366
+ maxSelectedDate: this.maxSelectedDate,
1367
+ selectedTitleFilter: (_c = this.selectedTitleFilter) !== null && _c !== void 0 ? _c : undefined,
1368
+ selectedCreatorFilter: (_d = this.selectedCreatorFilter) !== null && _d !== void 0 ? _d : undefined,
1369
+ };
1370
+ this.restorationStateHandler.persistState(restorationState, this.dataSourceInstallInProgress);
1371
+ }
1372
+ /**
1373
+ * Emits a `searchResultsLoadingChanged` event indicating that our loading state has
1374
+ * changed (either we have started loading new results, or we have finished loading them).
1375
+ */
1376
+ emitSearchResultsLoadingChanged() {
1377
+ this.dispatchEvent(new CustomEvent('searchResultsLoadingChanged', {
1378
+ detail: {
1379
+ loading: this.searchResultsLoading,
1380
+ },
1381
+ }));
1382
+ }
1383
+ /**
1384
+ * Handler for when the set of selected facets changes.
1385
+ */
1386
+ facetsChanged(e) {
1387
+ this.selectedFacets = e.detail;
1388
+ }
1389
+ /**
1390
+ * Handler for when any facet is selected/unselected/hidden/unhidden.
1391
+ * Fires analytics indicating the type of facet event that took place.
1392
+ */
1393
+ facetClickHandler({ detail: { facetType, bucket, negative }, }) {
1394
+ var _a;
1395
+ let action;
1396
+ if (negative) {
1397
+ action =
1398
+ bucket.state !== 'none'
1399
+ ? analyticsActions.facetNegativeSelected
1400
+ : analyticsActions.facetNegativeDeselected;
1401
+ }
1402
+ else {
1403
+ action =
1404
+ bucket.state !== 'none'
1405
+ ? analyticsActions.facetSelected
1406
+ : analyticsActions.facetDeselected;
1407
+ }
1408
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1409
+ category: this.searchContext,
1410
+ action,
1411
+ label: facetType,
1412
+ });
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
+ * Sets the total number of tiles displayed in the infinite scroller.
1446
+ */
1447
+ setTileCount(count) {
1448
+ if (this.infiniteScroller) {
1449
+ this.infiniteScroller.itemCount = count;
1450
+ }
1451
+ }
1452
+ /**
1453
+ * Applies any default sort option for the current collection, by checking
1454
+ * for one in the collection's metadata. If none is found, defaults to sorting
1455
+ * descending by:
1456
+ * - Date Favorited for fav-* collections
1457
+ * - Weekly views for all other collections
1458
+ */
1459
+ applyDefaultCollectionSort(collectionInfo) {
1460
+ var _a, _b, _c;
1461
+ if (this.baseQuery) {
1462
+ // If there's a query set, then we default to relevance sorting regardless of
1463
+ // the collection metadata-specified sort.
1464
+ this.defaultSortField = SortField.relevance;
1465
+ this.defaultSortDirection = null;
1466
+ return;
1467
+ }
1468
+ // Favorite collections sort on Date Favorited by default.
1469
+ // Other collections fall back to sorting on weekly views.
1470
+ 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-'))
1471
+ ? '-favoritedate'
1472
+ : '-week';
1473
+ // The collection metadata may override the default sorting with something else
1474
+ const metadataSort = (_c = collectionInfo === null || collectionInfo === void 0 ? void 0 : collectionInfo.public_metadata) === null || _c === void 0 ? void 0 : _c['sort-by'];
1475
+ // Prefer the metadata-specified sort if one exists
1476
+ const defaultSortToApply = metadataSort !== null && metadataSort !== void 0 ? metadataSort : baseDefaultSort;
1477
+ // Account for both -field and field:dir formats
1478
+ let [field, dir] = defaultSortToApply.split(':');
1479
+ if (field.startsWith('-')) {
1480
+ field = field.slice(1);
1481
+ dir = 'desc';
1482
+ }
1483
+ else if (!['asc', 'desc'].includes(dir)) {
1484
+ dir = 'asc';
1485
+ }
1486
+ const sortOption = sortOptionFromAPIString(field);
1487
+ const sortField = sortOption.field;
1488
+ if (sortField && sortField !== SortField.default) {
1489
+ this.defaultSortField = sortField;
1490
+ this.defaultSortDirection = dir;
1491
+ this.defaultSortParam = {
1492
+ field: this.defaultSortField,
1493
+ direction: this.defaultSortDirection,
1494
+ };
1495
+ }
1496
+ }
1497
+ /**
1498
+ * Applies the default sort option for the current profile element
1499
+ */
1500
+ applyDefaultProfileSort() {
1501
+ if (this.profileElement) {
1502
+ const defaultSortField = defaultProfileElementSorts[this.profileElement];
1503
+ this.defaultSortField = defaultSortField !== null && defaultSortField !== void 0 ? defaultSortField : SortField.weeklyview;
1504
+ }
1505
+ else {
1506
+ this.defaultSortField = SortField.weeklyview;
1507
+ }
1508
+ this.defaultSortDirection = 'desc';
1509
+ this.defaultSortParam = {
1510
+ field: this.defaultSortField,
1511
+ direction: this.defaultSortDirection,
1512
+ };
1513
+ }
1514
+ /**
1515
+ * This is useful for determining whether we need to reload the scroller.
1516
+ *
1517
+ * When the fetch completes, we need to reload the scroller if the cells for that
1518
+ * page are visible, but if the page is not currenlty visible, we don't need to reload
1519
+ */
1520
+ get currentVisiblePageNumbers() {
1521
+ var _a, _b;
1522
+ const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
1523
+ const visiblePages = new Set();
1524
+ visibleCells.forEach(cellIndex => {
1525
+ const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1526
+ visiblePages.add(visiblePage);
1527
+ });
1528
+ return Array.from(visiblePages);
1529
+ }
1530
+ /**
1531
+ * Refreshes all visible result cells in the infinite scroller.
1532
+ */
1533
+ refreshVisibleResults() {
1534
+ var _a;
1535
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshAllVisibleCells();
1536
+ }
1537
+ /**
1538
+ * Callback when a result is selected
1539
+ */
1540
+ resultSelected(event) {
1541
+ var _a, _b, _c;
1542
+ if (this.isManageView) {
1543
+ // Checked/unchecked state change -- rerender to ensure it propagates
1544
+ // this.mapDataSource(model => ({ ...model }));
1545
+ const cellIndex = this.dataSource.indexOf(event.detail);
1546
+ if (cellIndex >= 0)
1547
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.refreshCell(cellIndex);
1548
+ this.requestUpdate();
1549
+ }
1550
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1551
+ category: this.searchContext,
1552
+ action: analyticsActions.resultSelected,
1553
+ label: event.detail.mediatype,
1554
+ });
1555
+ (_c = this.analyticsHandler) === null || _c === void 0 ? void 0 : _c.sendEvent({
1556
+ category: this.searchContext,
1557
+ action: analyticsActions.resultSelected,
1558
+ label: `page-${this.currentPage}`,
1559
+ });
1560
+ }
1561
+ cellForIndex(index) {
1562
+ const model = this.tileModelAtCellIndex(index);
1563
+ if (!model)
1564
+ return undefined;
1555
1565
  return html `
1556
1566
  <tile-dispatcher
1557
1567
  .collectionPagePath=${this.collectionPagePath}
@@ -1571,21 +1581,21 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1571
1581
  @resultSelected=${(e) => this.resultSelected(e)}
1572
1582
  >
1573
1583
  </tile-dispatcher>
1574
- `;
1575
- }
1576
- /**
1577
- * When the user scrolls near to the bottom of the page, fetch the next page
1578
- * increase the number of pages to render and start fetching data for the new page
1579
- */
1580
- scrollThresholdReached() {
1581
- if (!this.dataSource.endOfDataReached && this.dataSource.queryInitialized) {
1582
- this.pagesToRender += 1;
1583
- this.dataSource.fetchPage(this.pagesToRender);
1584
- }
1585
- }
1586
- static get styles() {
1587
- return [
1588
- srOnlyStyle,
1584
+ `;
1585
+ }
1586
+ /**
1587
+ * When the user scrolls near to the bottom of the page, fetch the next page
1588
+ * increase the number of pages to render and start fetching data for the new page
1589
+ */
1590
+ scrollThresholdReached() {
1591
+ if (!this.dataSource.endOfDataReached && this.dataSource.queryInitialized) {
1592
+ this.pagesToRender += 1;
1593
+ this.dataSource.fetchPage(this.pagesToRender);
1594
+ }
1595
+ }
1596
+ static get styles() {
1597
+ return [
1598
+ srOnlyStyle,
1589
1599
  css `
1590
1600
  :host {
1591
1601
  display: block;
@@ -1983,183 +1993,183 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1983
1993
  infinite-scroller.hidden {
1984
1994
  display: none;
1985
1995
  }
1986
- `,
1987
- ];
1988
- }
1989
- };
1990
- __decorate([
1991
- property({ type: String })
1992
- ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
1993
- __decorate([
1994
- property({ type: String })
1995
- ], CollectionBrowser.prototype, "baseImageUrl", void 0);
1996
- __decorate([
1997
- property({ type: Object })
1998
- ], CollectionBrowser.prototype, "searchService", void 0);
1999
- __decorate([
2000
- property({ type: String })
2001
- ], CollectionBrowser.prototype, "searchType", void 0);
2002
- __decorate([
2003
- property({ type: String })
2004
- ], CollectionBrowser.prototype, "withinCollection", void 0);
2005
- __decorate([
2006
- property({ type: String })
2007
- ], CollectionBrowser.prototype, "withinProfile", void 0);
2008
- __decorate([
2009
- property({ type: String })
2010
- ], CollectionBrowser.prototype, "profileElement", void 0);
2011
- __decorate([
2012
- property({ type: String })
2013
- ], CollectionBrowser.prototype, "baseQuery", void 0);
2014
- __decorate([
2015
- property({ type: String })
2016
- ], CollectionBrowser.prototype, "displayMode", void 0);
2017
- __decorate([
2018
- property({ type: Object })
2019
- ], CollectionBrowser.prototype, "defaultSortParam", void 0);
2020
- __decorate([
2021
- property({ type: String })
2022
- ], CollectionBrowser.prototype, "selectedSort", void 0);
2023
- __decorate([
2024
- property({ type: String })
2025
- ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
2026
- __decorate([
2027
- property({ type: String })
2028
- ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
2029
- __decorate([
2030
- property({ type: String })
2031
- ], CollectionBrowser.prototype, "sortDirection", void 0);
2032
- __decorate([
2033
- property({ type: Number })
2034
- ], CollectionBrowser.prototype, "pageSize", void 0);
2035
- __decorate([
2036
- property({ type: Number })
2037
- ], CollectionBrowser.prototype, "currentPage", void 0);
2038
- __decorate([
2039
- property({ type: String })
2040
- ], CollectionBrowser.prototype, "minSelectedDate", void 0);
2041
- __decorate([
2042
- property({ type: String })
2043
- ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
2044
- __decorate([
2045
- property({ type: Object })
2046
- ], CollectionBrowser.prototype, "selectedFacets", void 0);
2047
- __decorate([
2048
- property({ type: Boolean })
2049
- ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
2050
- __decorate([
2051
- property({ type: Boolean })
2052
- ], CollectionBrowser.prototype, "suppressPlaceholders", void 0);
2053
- __decorate([
2054
- property({ type: Boolean })
2055
- ], CollectionBrowser.prototype, "suppressResultCount", void 0);
2056
- __decorate([
2057
- property({ type: Boolean })
2058
- ], CollectionBrowser.prototype, "suppressResultTiles", void 0);
2059
- __decorate([
2060
- property({ type: Boolean })
2061
- ], CollectionBrowser.prototype, "suppressURLQuery", void 0);
2062
- __decorate([
2063
- property({ type: Boolean })
2064
- ], CollectionBrowser.prototype, "suppressSortBar", void 0);
2065
- __decorate([
2066
- property({ type: Boolean })
2067
- ], CollectionBrowser.prototype, "suppressDisplayModes", void 0);
2068
- __decorate([
2069
- property({ type: String })
2070
- ], CollectionBrowser.prototype, "facetLoadStrategy", void 0);
2071
- __decorate([
2072
- property({ type: Boolean })
2073
- ], CollectionBrowser.prototype, "clearResultsOnEmptyQuery", void 0);
2074
- __decorate([
2075
- property({ type: String })
2076
- ], CollectionBrowser.prototype, "collectionPagePath", void 0);
2077
- __decorate([
2078
- property({ type: String, reflect: true })
2079
- ], CollectionBrowser.prototype, "searchContext", void 0);
2080
- __decorate([
2081
- property({ type: String })
2082
- ], CollectionBrowser.prototype, "pageContext", void 0);
2083
- __decorate([
2084
- property({ type: Object })
2085
- ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
2086
- __decorate([
2087
- property({ type: Number })
2088
- ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
2089
- __decorate([
2090
- property({ type: Boolean })
2091
- ], CollectionBrowser.prototype, "loggedIn", void 0);
2092
- __decorate([
2093
- property({ type: Object })
2094
- ], CollectionBrowser.prototype, "resizeObserver", void 0);
2095
- __decorate([
2096
- property({ type: Object })
2097
- ], CollectionBrowser.prototype, "modalManager", void 0);
2098
- __decorate([
2099
- property({ type: Object })
2100
- ], CollectionBrowser.prototype, "featureFeedbackService", void 0);
2101
- __decorate([
2102
- property({ type: Object })
2103
- ], CollectionBrowser.prototype, "recaptchaManager", void 0);
2104
- __decorate([
2105
- property({ type: Boolean })
2106
- ], CollectionBrowser.prototype, "isManageView", void 0);
2107
- __decorate([
2108
- property({ type: String })
2109
- ], CollectionBrowser.prototype, "manageViewLabel", void 0);
2110
- __decorate([
2111
- property({ type: Boolean })
2112
- ], CollectionBrowser.prototype, "enableSortOptionsSlot", void 0);
2113
- __decorate([
2114
- property({ type: Object })
2115
- ], CollectionBrowser.prototype, "dataSource", void 0);
2116
- __decorate([
2117
- state()
2118
- ], CollectionBrowser.prototype, "pagesToRender", void 0);
2119
- __decorate([
2120
- state()
2121
- ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
2122
- __decorate([
2123
- state()
2124
- ], CollectionBrowser.prototype, "facetsLoading", void 0);
2125
- __decorate([
2126
- state()
2127
- ], CollectionBrowser.prototype, "totalResults", void 0);
2128
- __decorate([
2129
- state()
2130
- ], CollectionBrowser.prototype, "mobileView", void 0);
2131
- __decorate([
2132
- state()
2133
- ], CollectionBrowser.prototype, "collapsibleFacetsVisible", void 0);
2134
- __decorate([
2135
- state()
2136
- ], CollectionBrowser.prototype, "contentWidth", void 0);
2137
- __decorate([
2138
- state()
2139
- ], CollectionBrowser.prototype, "defaultSortField", void 0);
2140
- __decorate([
2141
- state()
2142
- ], CollectionBrowser.prototype, "defaultSortDirection", void 0);
2143
- __decorate([
2144
- state()
2145
- ], CollectionBrowser.prototype, "placeholderType", void 0);
2146
- __decorate([
2147
- query('#content-container')
2148
- ], CollectionBrowser.prototype, "contentContainer", void 0);
2149
- __decorate([
2150
- query('#left-column')
2151
- ], CollectionBrowser.prototype, "leftColumn", void 0);
2152
- __decorate([
2153
- query('collection-facets')
2154
- ], CollectionBrowser.prototype, "collectionFacets", void 0);
2155
- __decorate([
2156
- property({ type: Object, attribute: false })
2157
- ], CollectionBrowser.prototype, "analyticsHandler", void 0);
2158
- __decorate([
2159
- query('infinite-scroller')
2160
- ], CollectionBrowser.prototype, "infiniteScroller", void 0);
2161
- CollectionBrowser = __decorate([
2162
- customElement('collection-browser')
2163
- ], CollectionBrowser);
2164
- export { CollectionBrowser };
1996
+ `,
1997
+ ];
1998
+ }
1999
+ };
2000
+ __decorate([
2001
+ property({ type: String })
2002
+ ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
2003
+ __decorate([
2004
+ property({ type: String })
2005
+ ], CollectionBrowser.prototype, "baseImageUrl", void 0);
2006
+ __decorate([
2007
+ property({ type: Object })
2008
+ ], CollectionBrowser.prototype, "searchService", void 0);
2009
+ __decorate([
2010
+ property({ type: String })
2011
+ ], CollectionBrowser.prototype, "searchType", void 0);
2012
+ __decorate([
2013
+ property({ type: String })
2014
+ ], CollectionBrowser.prototype, "withinCollection", void 0);
2015
+ __decorate([
2016
+ property({ type: String })
2017
+ ], CollectionBrowser.prototype, "withinProfile", void 0);
2018
+ __decorate([
2019
+ property({ type: String })
2020
+ ], CollectionBrowser.prototype, "profileElement", void 0);
2021
+ __decorate([
2022
+ property({ type: String })
2023
+ ], CollectionBrowser.prototype, "baseQuery", void 0);
2024
+ __decorate([
2025
+ property({ type: String })
2026
+ ], CollectionBrowser.prototype, "displayMode", void 0);
2027
+ __decorate([
2028
+ property({ type: Object })
2029
+ ], CollectionBrowser.prototype, "defaultSortParam", void 0);
2030
+ __decorate([
2031
+ property({ type: String })
2032
+ ], CollectionBrowser.prototype, "selectedSort", void 0);
2033
+ __decorate([
2034
+ property({ type: String })
2035
+ ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
2036
+ __decorate([
2037
+ property({ type: String })
2038
+ ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
2039
+ __decorate([
2040
+ property({ type: String })
2041
+ ], CollectionBrowser.prototype, "sortDirection", void 0);
2042
+ __decorate([
2043
+ property({ type: Number })
2044
+ ], CollectionBrowser.prototype, "pageSize", void 0);
2045
+ __decorate([
2046
+ property({ type: Number })
2047
+ ], CollectionBrowser.prototype, "currentPage", void 0);
2048
+ __decorate([
2049
+ property({ type: String })
2050
+ ], CollectionBrowser.prototype, "minSelectedDate", void 0);
2051
+ __decorate([
2052
+ property({ type: String })
2053
+ ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
2054
+ __decorate([
2055
+ property({ type: Object })
2056
+ ], CollectionBrowser.prototype, "selectedFacets", void 0);
2057
+ __decorate([
2058
+ property({ type: Boolean })
2059
+ ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
2060
+ __decorate([
2061
+ property({ type: Boolean })
2062
+ ], CollectionBrowser.prototype, "suppressPlaceholders", void 0);
2063
+ __decorate([
2064
+ property({ type: Boolean })
2065
+ ], CollectionBrowser.prototype, "suppressResultCount", void 0);
2066
+ __decorate([
2067
+ property({ type: Boolean })
2068
+ ], CollectionBrowser.prototype, "suppressResultTiles", void 0);
2069
+ __decorate([
2070
+ property({ type: Boolean })
2071
+ ], CollectionBrowser.prototype, "suppressURLQuery", void 0);
2072
+ __decorate([
2073
+ property({ type: Boolean })
2074
+ ], CollectionBrowser.prototype, "suppressSortBar", void 0);
2075
+ __decorate([
2076
+ property({ type: Boolean })
2077
+ ], CollectionBrowser.prototype, "suppressDisplayModes", void 0);
2078
+ __decorate([
2079
+ property({ type: String })
2080
+ ], CollectionBrowser.prototype, "facetLoadStrategy", void 0);
2081
+ __decorate([
2082
+ property({ type: Boolean })
2083
+ ], CollectionBrowser.prototype, "clearResultsOnEmptyQuery", void 0);
2084
+ __decorate([
2085
+ property({ type: String })
2086
+ ], CollectionBrowser.prototype, "collectionPagePath", void 0);
2087
+ __decorate([
2088
+ property({ type: String, reflect: true })
2089
+ ], CollectionBrowser.prototype, "searchContext", void 0);
2090
+ __decorate([
2091
+ property({ type: String })
2092
+ ], CollectionBrowser.prototype, "pageContext", void 0);
2093
+ __decorate([
2094
+ property({ type: Object })
2095
+ ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
2096
+ __decorate([
2097
+ property({ type: Number })
2098
+ ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
2099
+ __decorate([
2100
+ property({ type: Boolean })
2101
+ ], CollectionBrowser.prototype, "loggedIn", void 0);
2102
+ __decorate([
2103
+ property({ type: Object })
2104
+ ], CollectionBrowser.prototype, "resizeObserver", void 0);
2105
+ __decorate([
2106
+ property({ type: Object })
2107
+ ], CollectionBrowser.prototype, "modalManager", void 0);
2108
+ __decorate([
2109
+ property({ type: Object })
2110
+ ], CollectionBrowser.prototype, "featureFeedbackService", void 0);
2111
+ __decorate([
2112
+ property({ type: Object })
2113
+ ], CollectionBrowser.prototype, "recaptchaManager", void 0);
2114
+ __decorate([
2115
+ property({ type: Boolean })
2116
+ ], CollectionBrowser.prototype, "isManageView", void 0);
2117
+ __decorate([
2118
+ property({ type: String })
2119
+ ], CollectionBrowser.prototype, "manageViewLabel", void 0);
2120
+ __decorate([
2121
+ property({ type: Boolean })
2122
+ ], CollectionBrowser.prototype, "enableSortOptionsSlot", void 0);
2123
+ __decorate([
2124
+ property({ type: Object })
2125
+ ], CollectionBrowser.prototype, "dataSource", void 0);
2126
+ __decorate([
2127
+ state()
2128
+ ], CollectionBrowser.prototype, "pagesToRender", void 0);
2129
+ __decorate([
2130
+ state()
2131
+ ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
2132
+ __decorate([
2133
+ state()
2134
+ ], CollectionBrowser.prototype, "facetsLoading", void 0);
2135
+ __decorate([
2136
+ state()
2137
+ ], CollectionBrowser.prototype, "totalResults", void 0);
2138
+ __decorate([
2139
+ state()
2140
+ ], CollectionBrowser.prototype, "mobileView", void 0);
2141
+ __decorate([
2142
+ state()
2143
+ ], CollectionBrowser.prototype, "collapsibleFacetsVisible", void 0);
2144
+ __decorate([
2145
+ state()
2146
+ ], CollectionBrowser.prototype, "contentWidth", void 0);
2147
+ __decorate([
2148
+ state()
2149
+ ], CollectionBrowser.prototype, "defaultSortField", void 0);
2150
+ __decorate([
2151
+ state()
2152
+ ], CollectionBrowser.prototype, "defaultSortDirection", void 0);
2153
+ __decorate([
2154
+ state()
2155
+ ], CollectionBrowser.prototype, "placeholderType", void 0);
2156
+ __decorate([
2157
+ query('#content-container')
2158
+ ], CollectionBrowser.prototype, "contentContainer", void 0);
2159
+ __decorate([
2160
+ query('#left-column')
2161
+ ], CollectionBrowser.prototype, "leftColumn", void 0);
2162
+ __decorate([
2163
+ query('collection-facets')
2164
+ ], CollectionBrowser.prototype, "collectionFacets", void 0);
2165
+ __decorate([
2166
+ property({ type: Object, attribute: false })
2167
+ ], CollectionBrowser.prototype, "analyticsHandler", void 0);
2168
+ __decorate([
2169
+ query('infinite-scroller')
2170
+ ], CollectionBrowser.prototype, "infiniteScroller", void 0);
2171
+ CollectionBrowser = __decorate([
2172
+ customElement('collection-browser')
2173
+ ], CollectionBrowser);
2174
+ export { CollectionBrowser };
2165
2175
  //# sourceMappingURL=collection-browser.js.map