@internetarchive/collection-browser 2.6.6-alpha.0 → 2.6.6

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