@internetarchive/collection-browser 4.7.1-alpha-webdev9189.0 → 4.8.1-webdev-9227.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/README.md +33 -0
  2. package/dist/src/app-root.js +0 -2
  3. package/dist/src/app-root.js.map +1 -1
  4. package/dist/src/assets/img/icons/check.d.ts +2 -0
  5. package/dist/src/assets/img/icons/check.js +5 -0
  6. package/dist/src/assets/img/icons/check.js.map +1 -0
  7. package/dist/src/collection-browser.d.ts +2 -1
  8. package/dist/src/collection-browser.js +5 -27
  9. package/dist/src/collection-browser.js.map +1 -1
  10. package/dist/src/collection-facets/facet-row-template.d.ts +38 -0
  11. package/dist/src/collection-facets/facet-row-template.js +200 -0
  12. package/dist/src/collection-facets/facet-row-template.js.map +1 -0
  13. package/dist/src/collection-facets/facet-row.js +11 -186
  14. package/dist/src/collection-facets/facet-row.js.map +1 -1
  15. package/dist/src/collection-facets/models.d.ts +7 -2
  16. package/dist/src/collection-facets/models.js +7 -2
  17. package/dist/src/collection-facets/models.js.map +1 -1
  18. package/dist/src/collection-facets/more-facets-content.d.ts +87 -21
  19. package/dist/src/collection-facets/more-facets-content.js +479 -201
  20. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  21. package/dist/src/collection-facets/more-facets-scroller.d.ts +85 -0
  22. package/dist/src/collection-facets/more-facets-scroller.js +429 -0
  23. package/dist/src/collection-facets/more-facets-scroller.js.map +1 -0
  24. package/dist/src/collection-facets/page-window.d.ts +73 -0
  25. package/dist/src/collection-facets/page-window.js +202 -0
  26. package/dist/src/collection-facets/page-window.js.map +1 -0
  27. package/dist/src/collection-facets/toggle-switch.js +1 -0
  28. package/dist/src/collection-facets/toggle-switch.js.map +1 -1
  29. package/dist/src/collection-facets.js +3 -2
  30. package/dist/src/collection-facets.js.map +1 -1
  31. package/dist/src/empty-placeholder.d.ts +7 -7
  32. package/dist/src/empty-placeholder.js +29 -15
  33. package/dist/src/empty-placeholder.js.map +1 -1
  34. package/dist/src/expanded-date-picker.js +3 -2
  35. package/dist/src/expanded-date-picker.js.map +1 -1
  36. package/dist/src/locales/es.d.ts +94 -0
  37. package/dist/src/locales/es.js +109 -0
  38. package/dist/src/locales/es.js.map +1 -0
  39. package/dist/src/manage/manage-bar.d.ts +3 -2
  40. package/dist/src/manage/manage-bar.js +6 -7
  41. package/dist/src/manage/manage-bar.js.map +1 -1
  42. package/dist/src/manage/remove-items-modal-content.js +3 -2
  43. package/dist/src/manage/remove-items-modal-content.js.map +1 -1
  44. package/dist/src/models.d.ts +4 -0
  45. package/dist/src/models.js +22 -2
  46. package/dist/src/models.js.map +1 -1
  47. package/dist/src/sort-filter-bar/sort-filter-bar.js +3 -3
  48. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  49. package/dist/src/tiles/grid/account-tile.js +3 -2
  50. package/dist/src/tiles/grid/account-tile.js.map +1 -1
  51. package/dist/src/tiles/grid/collection-tile.js +3 -2
  52. package/dist/src/tiles/grid/collection-tile.js.map +1 -1
  53. package/dist/src/tiles/grid/item-tile.js +3 -2
  54. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  55. package/dist/src/tiles/grid/tile-stats.js +3 -2
  56. package/dist/src/tiles/grid/tile-stats.js.map +1 -1
  57. package/dist/src/tiles/list/tile-list-compact-header.js +3 -2
  58. package/dist/src/tiles/list/tile-list-compact-header.js.map +1 -1
  59. package/dist/src/tiles/list/tile-list-compact.js +3 -1
  60. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  61. package/dist/src/tiles/list/tile-list.js +3 -2
  62. package/dist/src/tiles/list/tile-list.js.map +1 -1
  63. package/dist/src/tiles/overlay/text-overlay.js +3 -1
  64. package/dist/src/tiles/overlay/text-overlay.js.map +1 -1
  65. package/dist/src/tiles/review-block.js +3 -2
  66. package/dist/src/tiles/review-block.js.map +1 -1
  67. package/dist/src/tiles/tile-dispatcher.d.ts +2 -1
  68. package/dist/src/tiles/tile-dispatcher.js +5 -4
  69. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  70. package/dist/src/utils/log.d.ts +1 -4
  71. package/dist/src/utils/normalize-filter-text.d.ts +28 -0
  72. package/dist/src/utils/normalize-filter-text.js +35 -0
  73. package/dist/src/utils/normalize-filter-text.js.map +1 -0
  74. package/locales/es.d.ts +1 -0
  75. package/locales/es.js +1 -0
  76. package/package.json +15 -1
  77. package/.editorconfig +0 -29
  78. package/.github/workflows/ci.yml +0 -29
  79. package/.github/workflows/gh-pages-main.yml +0 -41
  80. package/.github/workflows/npm-publish.yml +0 -42
  81. package/.github/workflows/pr-preview.yml +0 -40
  82. package/.husky/pre-commit +0 -1
  83. package/.prettierignore +0 -1
  84. package/dist/src/collection-facets/more-facets-pagination.d.ts +0 -36
  85. package/dist/src/collection-facets/more-facets-pagination.js +0 -260
  86. package/dist/src/collection-facets/more-facets-pagination.js.map +0 -1
  87. package/dist/test/collection-browser.test.d.ts +0 -1
  88. package/dist/test/collection-browser.test.js +0 -1849
  89. package/dist/test/collection-browser.test.js.map +0 -1
  90. package/dist/test/collection-facets/facet-row.test.d.ts +0 -1
  91. package/dist/test/collection-facets/facet-row.test.js +0 -291
  92. package/dist/test/collection-facets/facet-row.test.js.map +0 -1
  93. package/dist/test/collection-facets/facets-template.test.d.ts +0 -1
  94. package/dist/test/collection-facets/facets-template.test.js +0 -95
  95. package/dist/test/collection-facets/facets-template.test.js.map +0 -1
  96. package/dist/test/collection-facets/more-facets-content.test.d.ts +0 -1
  97. package/dist/test/collection-facets/more-facets-content.test.js +0 -159
  98. package/dist/test/collection-facets/more-facets-content.test.js.map +0 -1
  99. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +0 -1
  100. package/dist/test/collection-facets/more-facets-pagination.test.js +0 -126
  101. package/dist/test/collection-facets/more-facets-pagination.test.js.map +0 -1
  102. package/dist/test/collection-facets/toggle-switch.test.d.ts +0 -1
  103. package/dist/test/collection-facets/toggle-switch.test.js +0 -99
  104. package/dist/test/collection-facets/toggle-switch.test.js.map +0 -1
  105. package/dist/test/collection-facets.test.d.ts +0 -2
  106. package/dist/test/collection-facets.test.js +0 -728
  107. package/dist/test/collection-facets.test.js.map +0 -1
  108. package/dist/test/data-source/collection-browser-data-source.test.d.ts +0 -1
  109. package/dist/test/data-source/collection-browser-data-source.test.js +0 -154
  110. package/dist/test/data-source/collection-browser-data-source.test.js.map +0 -1
  111. package/dist/test/empty-placeholder.test.d.ts +0 -1
  112. package/dist/test/empty-placeholder.test.js +0 -57
  113. package/dist/test/empty-placeholder.test.js.map +0 -1
  114. package/dist/test/expanded-date-picker.test.d.ts +0 -1
  115. package/dist/test/expanded-date-picker.test.js +0 -124
  116. package/dist/test/expanded-date-picker.test.js.map +0 -1
  117. package/dist/test/icon-overlay.test.d.ts +0 -1
  118. package/dist/test/icon-overlay.test.js +0 -31
  119. package/dist/test/icon-overlay.test.js.map +0 -1
  120. package/dist/test/image-block.test.d.ts +0 -1
  121. package/dist/test/image-block.test.js +0 -208
  122. package/dist/test/image-block.test.js.map +0 -1
  123. package/dist/test/item-image.test.d.ts +0 -1
  124. package/dist/test/item-image.test.js +0 -187
  125. package/dist/test/item-image.test.js.map +0 -1
  126. package/dist/test/manage/manage-bar.test.d.ts +0 -3
  127. package/dist/test/manage/manage-bar.test.js +0 -216
  128. package/dist/test/manage/manage-bar.test.js.map +0 -1
  129. package/dist/test/manage/remove-items-modal-content.test.d.ts +0 -1
  130. package/dist/test/manage/remove-items-modal-content.test.js +0 -60
  131. package/dist/test/manage/remove-items-modal-content.test.js.map +0 -1
  132. package/dist/test/mediatype-config.test.d.ts +0 -1
  133. package/dist/test/mediatype-config.test.js +0 -11
  134. package/dist/test/mediatype-config.test.js.map +0 -1
  135. package/dist/test/mocks/mock-analytics-handler.d.ts +0 -10
  136. package/dist/test/mocks/mock-analytics-handler.js +0 -16
  137. package/dist/test/mocks/mock-analytics-handler.js.map +0 -1
  138. package/dist/test/mocks/mock-search-responses.d.ts +0 -31
  139. package/dist/test/mocks/mock-search-responses.js +0 -1241
  140. package/dist/test/mocks/mock-search-responses.js.map +0 -1
  141. package/dist/test/mocks/mock-search-service.d.ts +0 -16
  142. package/dist/test/mocks/mock-search-service.js +0 -64
  143. package/dist/test/mocks/mock-search-service.js.map +0 -1
  144. package/dist/test/restoration-state-handler.test.d.ts +0 -1
  145. package/dist/test/restoration-state-handler.test.js +0 -335
  146. package/dist/test/restoration-state-handler.test.js.map +0 -1
  147. package/dist/test/review-block.test.d.ts +0 -1
  148. package/dist/test/review-block.test.js +0 -46
  149. package/dist/test/review-block.test.js.map +0 -1
  150. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.d.ts +0 -1
  151. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +0 -12
  152. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js.map +0 -1
  153. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +0 -1
  154. package/dist/test/sort-filter-bar/alpha-bar.test.js +0 -68
  155. package/dist/test/sort-filter-bar/alpha-bar.test.js.map +0 -1
  156. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +0 -1
  157. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +0 -326
  158. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +0 -1
  159. package/dist/test/text-overlay.test.d.ts +0 -1
  160. package/dist/test/text-overlay.test.js +0 -43
  161. package/dist/test/text-overlay.test.js.map +0 -1
  162. package/dist/test/text-snippet-block.test.d.ts +0 -1
  163. package/dist/test/text-snippet-block.test.js +0 -58
  164. package/dist/test/text-snippet-block.test.js.map +0 -1
  165. package/dist/test/tile-stats.test.d.ts +0 -1
  166. package/dist/test/tile-stats.test.js +0 -167
  167. package/dist/test/tile-stats.test.js.map +0 -1
  168. package/dist/test/tiles/grid/account-tile.test.d.ts +0 -1
  169. package/dist/test/tiles/grid/account-tile.test.js +0 -96
  170. package/dist/test/tiles/grid/account-tile.test.js.map +0 -1
  171. package/dist/test/tiles/grid/collection-tile.test.d.ts +0 -1
  172. package/dist/test/tiles/grid/collection-tile.test.js +0 -90
  173. package/dist/test/tiles/grid/collection-tile.test.js.map +0 -1
  174. package/dist/test/tiles/grid/item-tile.test.d.ts +0 -1
  175. package/dist/test/tiles/grid/item-tile.test.js +0 -400
  176. package/dist/test/tiles/grid/item-tile.test.js.map +0 -1
  177. package/dist/test/tiles/grid/search-tile.test.d.ts +0 -1
  178. package/dist/test/tiles/grid/search-tile.test.js +0 -62
  179. package/dist/test/tiles/grid/search-tile.test.js.map +0 -1
  180. package/dist/test/tiles/hover/hover-pane-controller.test.d.ts +0 -1
  181. package/dist/test/tiles/hover/hover-pane-controller.test.js +0 -351
  182. package/dist/test/tiles/hover/hover-pane-controller.test.js.map +0 -1
  183. package/dist/test/tiles/hover/tile-hover-pane.test.d.ts +0 -1
  184. package/dist/test/tiles/hover/tile-hover-pane.test.js +0 -53
  185. package/dist/test/tiles/hover/tile-hover-pane.test.js.map +0 -1
  186. package/dist/test/tiles/list/tile-list-compact-header.test.d.ts +0 -1
  187. package/dist/test/tiles/list/tile-list-compact-header.test.js +0 -36
  188. package/dist/test/tiles/list/tile-list-compact-header.test.js.map +0 -1
  189. package/dist/test/tiles/list/tile-list-compact.test.d.ts +0 -1
  190. package/dist/test/tiles/list/tile-list-compact.test.js +0 -237
  191. package/dist/test/tiles/list/tile-list-compact.test.js.map +0 -1
  192. package/dist/test/tiles/list/tile-list.test.d.ts +0 -1
  193. package/dist/test/tiles/list/tile-list.test.js +0 -460
  194. package/dist/test/tiles/list/tile-list.test.js.map +0 -1
  195. package/dist/test/tiles/tile-dispatcher.test.d.ts +0 -1
  196. package/dist/test/tiles/tile-dispatcher.test.js +0 -246
  197. package/dist/test/tiles/tile-dispatcher.test.js.map +0 -1
  198. package/dist/test/tiles/tile-display-value-provider.test.d.ts +0 -1
  199. package/dist/test/tiles/tile-display-value-provider.test.js +0 -142
  200. package/dist/test/tiles/tile-display-value-provider.test.js.map +0 -1
  201. package/dist/test/tiles/tile-mediatype-icon.test.d.ts +0 -1
  202. package/dist/test/tiles/tile-mediatype-icon.test.js +0 -133
  203. package/dist/test/tiles/tile-mediatype-icon.test.js.map +0 -1
  204. package/dist/test/utils/array-equals.test.d.ts +0 -1
  205. package/dist/test/utils/array-equals.test.js +0 -27
  206. package/dist/test/utils/array-equals.test.js.map +0 -1
  207. package/dist/test/utils/format-count.test.d.ts +0 -1
  208. package/dist/test/utils/format-count.test.js +0 -24
  209. package/dist/test/utils/format-count.test.js.map +0 -1
  210. package/dist/test/utils/format-date.test.d.ts +0 -1
  211. package/dist/test/utils/format-date.test.js +0 -61
  212. package/dist/test/utils/format-date.test.js.map +0 -1
  213. package/dist/test/utils/format-unit-size.test.d.ts +0 -1
  214. package/dist/test/utils/format-unit-size.test.js +0 -18
  215. package/dist/test/utils/format-unit-size.test.js.map +0 -1
  216. package/dist/test/utils/local-date-from-utc.test.d.ts +0 -1
  217. package/dist/test/utils/local-date-from-utc.test.js +0 -27
  218. package/dist/test/utils/local-date-from-utc.test.js.map +0 -1
  219. package/eslint.config.mjs +0 -53
  220. package/index.html +0 -24
  221. package/index.ts +0 -29
  222. package/local.archive.org.cert +0 -86
  223. package/local.archive.org.key +0 -27
  224. package/pnpm-workspace.yaml +0 -30
  225. package/renovate.json +0 -6
  226. package/src/app-root.ts +0 -1284
  227. package/src/assets/img/icons/arrow-left.ts +0 -10
  228. package/src/assets/img/icons/arrow-right.ts +0 -10
  229. package/src/assets/img/icons/chevron.ts +0 -4
  230. package/src/assets/img/icons/close-circle-dark.ts +0 -5
  231. package/src/assets/img/icons/contract.ts +0 -9
  232. package/src/assets/img/icons/empty-query.ts +0 -5
  233. package/src/assets/img/icons/expand.ts +0 -9
  234. package/src/assets/img/icons/eye-closed.ts +0 -5
  235. package/src/assets/img/icons/eye.ts +0 -5
  236. package/src/assets/img/icons/favorite-filled.ts +0 -10
  237. package/src/assets/img/icons/favorite-unfilled.ts +0 -9
  238. package/src/assets/img/icons/filter.ts +0 -10
  239. package/src/assets/img/icons/login-required.ts +0 -18
  240. package/src/assets/img/icons/mediatype/account.ts +0 -14
  241. package/src/assets/img/icons/mediatype/audio.ts +0 -14
  242. package/src/assets/img/icons/mediatype/collection.ts +0 -12
  243. package/src/assets/img/icons/mediatype/data.ts +0 -15
  244. package/src/assets/img/icons/mediatype/etree.ts +0 -14
  245. package/src/assets/img/icons/mediatype/film.ts +0 -14
  246. package/src/assets/img/icons/mediatype/images.ts +0 -13
  247. package/src/assets/img/icons/mediatype/radio.ts +0 -15
  248. package/src/assets/img/icons/mediatype/search.ts +0 -14
  249. package/src/assets/img/icons/mediatype/software.ts +0 -13
  250. package/src/assets/img/icons/mediatype/texts.ts +0 -13
  251. package/src/assets/img/icons/mediatype/tv-commercial.ts +0 -12
  252. package/src/assets/img/icons/mediatype/tv-fact-check.ts +0 -12
  253. package/src/assets/img/icons/mediatype/tv-quote.ts +0 -12
  254. package/src/assets/img/icons/mediatype/tv.ts +0 -14
  255. package/src/assets/img/icons/mediatype/video.ts +0 -14
  256. package/src/assets/img/icons/mediatype/web.ts +0 -13
  257. package/src/assets/img/icons/null-result.ts +0 -5
  258. package/src/assets/img/icons/quote.ts +0 -7
  259. package/src/assets/img/icons/restricted.ts +0 -13
  260. package/src/assets/img/icons/reviews.ts +0 -11
  261. package/src/assets/img/icons/upload.ts +0 -12
  262. package/src/assets/img/icons/views.ts +0 -11
  263. package/src/circular-activity-indicator.ts +0 -64
  264. package/src/collection-browser.ts +0 -3187
  265. package/src/collection-facets/facet-row.ts +0 -309
  266. package/src/collection-facets/facet-tombstone-row.ts +0 -40
  267. package/src/collection-facets/facets-template.ts +0 -85
  268. package/src/collection-facets/models.ts +0 -10
  269. package/src/collection-facets/more-facets-content.ts +0 -644
  270. package/src/collection-facets/more-facets-pagination.ts +0 -294
  271. package/src/collection-facets/smart-facets/dedupe.ts +0 -44
  272. package/src/collection-facets/smart-facets/heuristics/browser-language/browser-language-heuristic.ts +0 -27
  273. package/src/collection-facets/smart-facets/heuristics/index.ts +0 -3
  274. package/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.ts +0 -17
  275. package/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.ts +0 -70
  276. package/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.ts +0 -79
  277. package/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.ts +0 -93
  278. package/src/collection-facets/smart-facets/models.ts +0 -36
  279. package/src/collection-facets/smart-facets/smart-facet-bar.ts +0 -437
  280. package/src/collection-facets/smart-facets/smart-facet-button.ts +0 -145
  281. package/src/collection-facets/smart-facets/smart-facet-dropdown.ts +0 -185
  282. package/src/collection-facets/smart-facets/smart-facet-equals.ts +0 -16
  283. package/src/collection-facets/smart-facets/smart-facet-heuristics.ts +0 -26
  284. package/src/collection-facets/toggle-switch.ts +0 -174
  285. package/src/collection-facets.ts +0 -1013
  286. package/src/data-source/collection-browser-data-source-interface.ts +0 -351
  287. package/src/data-source/collection-browser-data-source.ts +0 -1474
  288. package/src/data-source/collection-browser-query-state.ts +0 -60
  289. package/src/data-source/models.ts +0 -56
  290. package/src/empty-placeholder.ts +0 -192
  291. package/src/expanded-date-picker.ts +0 -191
  292. package/src/language-code-handler/language-code-handler.ts +0 -64
  293. package/src/language-code-handler/language-code-mapping.ts +0 -564
  294. package/src/manage/manage-bar.ts +0 -276
  295. package/src/manage/remove-items-modal-content.ts +0 -102
  296. package/src/mediatype/mediatype-config.ts +0 -146
  297. package/src/models.ts +0 -895
  298. package/src/restoration-state-handler.ts +0 -550
  299. package/src/sort-filter-bar/alpha-bar-tooltip.ts +0 -53
  300. package/src/sort-filter-bar/alpha-bar.ts +0 -252
  301. package/src/sort-filter-bar/img/compact.ts +0 -5
  302. package/src/sort-filter-bar/img/list.ts +0 -5
  303. package/src/sort-filter-bar/img/sort-toggle-disabled.ts +0 -15
  304. package/src/sort-filter-bar/img/sort-toggle-down.ts +0 -17
  305. package/src/sort-filter-bar/img/sort-toggle-up.ts +0 -17
  306. package/src/sort-filter-bar/img/sort-triangle.ts +0 -5
  307. package/src/sort-filter-bar/img/tile.ts +0 -5
  308. package/src/sort-filter-bar/sort-filter-bar.ts +0 -734
  309. package/src/styles/ia-button.ts +0 -139
  310. package/src/styles/item-image-styles.ts +0 -124
  311. package/src/styles/sr-only.ts +0 -18
  312. package/src/styles/tile-action-styles.ts +0 -59
  313. package/src/tiles/base-tile-component.ts +0 -124
  314. package/src/tiles/collection-browser-loading-tile.ts +0 -26
  315. package/src/tiles/grid/account-tile.ts +0 -113
  316. package/src/tiles/grid/collection-tile.ts +0 -184
  317. package/src/tiles/grid/item-tile.ts +0 -347
  318. package/src/tiles/grid/search-tile.ts +0 -90
  319. package/src/tiles/grid/styles/tile-grid-shared-styles.ts +0 -130
  320. package/src/tiles/grid/tile-stats.ts +0 -211
  321. package/src/tiles/hover/hover-pane-controller.ts +0 -638
  322. package/src/tiles/hover/tile-hover-pane.ts +0 -184
  323. package/src/tiles/image-block.ts +0 -162
  324. package/src/tiles/item-image.ts +0 -214
  325. package/src/tiles/list/tile-list-compact-header.ts +0 -112
  326. package/src/tiles/list/tile-list-compact.ts +0 -278
  327. package/src/tiles/list/tile-list.ts +0 -718
  328. package/src/tiles/models.ts +0 -21
  329. package/src/tiles/overlay/icon-overlay.ts +0 -57
  330. package/src/tiles/overlay/text-overlay.ts +0 -79
  331. package/src/tiles/review-block.ts +0 -130
  332. package/src/tiles/text-snippet-block.ts +0 -132
  333. package/src/tiles/tile-dispatcher.ts +0 -637
  334. package/src/tiles/tile-display-value-provider.ts +0 -133
  335. package/src/tiles/tile-mediatype-icon.ts +0 -133
  336. package/src/utils/analytics-events.ts +0 -29
  337. package/src/utils/array-equals.ts +0 -8
  338. package/src/utils/collapse-repeated-quotes.ts +0 -13
  339. package/src/utils/date-filter-field.ts +0 -11
  340. package/src/utils/facet-utils.ts +0 -183
  341. package/src/utils/format-count.ts +0 -95
  342. package/src/utils/format-date.ts +0 -62
  343. package/src/utils/format-unit-size.ts +0 -43
  344. package/src/utils/local-date-from-utc.ts +0 -15
  345. package/src/utils/log.ts +0 -14
  346. package/src/utils/resolve-mediatype.ts +0 -26
  347. package/src/utils/sha1.ts +0 -9
  348. package/test/collection-browser.test.ts +0 -2694
  349. package/test/collection-facets/facet-row.test.ts +0 -421
  350. package/test/collection-facets/facets-template.test.ts +0 -139
  351. package/test/collection-facets/more-facets-content.test.ts +0 -231
  352. package/test/collection-facets/more-facets-pagination.test.ts +0 -201
  353. package/test/collection-facets/toggle-switch.test.ts +0 -164
  354. package/test/collection-facets.test.ts +0 -928
  355. package/test/data-source/collection-browser-data-source.test.ts +0 -193
  356. package/test/empty-placeholder.test.ts +0 -88
  357. package/test/expanded-date-picker.test.ts +0 -201
  358. package/test/icon-overlay.test.ts +0 -38
  359. package/test/image-block.test.ts +0 -247
  360. package/test/item-image.test.ts +0 -220
  361. package/test/manage/manage-bar.test.ts +0 -347
  362. package/test/manage/remove-items-modal-content.test.ts +0 -81
  363. package/test/mediatype-config.test.ts +0 -11
  364. package/test/mocks/mock-analytics-handler.ts +0 -30
  365. package/test/mocks/mock-search-responses.ts +0 -1364
  366. package/test/mocks/mock-search-service.ts +0 -134
  367. package/test/restoration-state-handler.test.ts +0 -480
  368. package/test/review-block.test.ts +0 -62
  369. package/test/sort-filter-bar/alpha-bar-tooltip.test.ts +0 -17
  370. package/test/sort-filter-bar/alpha-bar.test.ts +0 -101
  371. package/test/sort-filter-bar/sort-filter-bar.test.ts +0 -472
  372. package/test/text-overlay.test.ts +0 -55
  373. package/test/text-snippet-block.test.ts +0 -85
  374. package/test/tile-stats.test.ts +0 -191
  375. package/test/tiles/grid/account-tile.test.ts +0 -121
  376. package/test/tiles/grid/collection-tile.test.ts +0 -114
  377. package/test/tiles/grid/item-tile.test.ts +0 -520
  378. package/test/tiles/grid/search-tile.test.ts +0 -75
  379. package/test/tiles/hover/hover-pane-controller.test.ts +0 -482
  380. package/test/tiles/hover/tile-hover-pane.test.ts +0 -80
  381. package/test/tiles/list/tile-list-compact-header.test.ts +0 -43
  382. package/test/tiles/list/tile-list-compact.test.ts +0 -282
  383. package/test/tiles/list/tile-list.test.ts +0 -576
  384. package/test/tiles/tile-dispatcher.test.ts +0 -320
  385. package/test/tiles/tile-display-value-provider.test.ts +0 -172
  386. package/test/tiles/tile-mediatype-icon.test.ts +0 -160
  387. package/test/utils/array-equals.test.ts +0 -31
  388. package/test/utils/format-count.test.ts +0 -32
  389. package/test/utils/format-date.test.ts +0 -89
  390. package/test/utils/format-unit-size.test.ts +0 -21
  391. package/test/utils/local-date-from-utc.test.ts +0 -37
  392. package/tsconfig.json +0 -25
  393. package/types/dompurify.d.ts +0 -1
  394. package/vite.config.ts +0 -29
  395. package/web-dev-server.config.mjs +0 -30
  396. package/web-test-runner.config.mjs +0 -52
@@ -1,3187 +0,0 @@
1
- import {
2
- html,
3
- css,
4
- LitElement,
5
- PropertyValues,
6
- TemplateResult,
7
- HTMLTemplateResult,
8
- nothing,
9
- } from 'lit';
10
- import { customElement, property, query, state } from 'lit/decorators.js';
11
- import { classMap } from 'lit/directives/class-map.js';
12
- import { msg } from '@lit/localize';
13
-
14
- import type { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
15
- import type {
16
- InfiniteScroller,
17
- InfiniteScrollerCellProviderInterface,
18
- } from '@internetarchive/infinite-scroller';
19
- import {
20
- CollectionExtraInfo,
21
- PageElementName,
22
- SearchServiceInterface,
23
- SearchType,
24
- SortDirection,
25
- SortParam,
26
- } from '@internetarchive/search-service';
27
- import type {
28
- SharedResizeObserverInterface,
29
- SharedResizeObserverResizeHandlerInterface,
30
- } from '@internetarchive/shared-resize-observer';
31
- import '@internetarchive/infinite-scroller';
32
- import type { ModalManagerInterface } from '@internetarchive/modal-manager';
33
- import type { FeatureFeedbackServiceInterface } from '@internetarchive/feature-feedback';
34
- import type { RecaptchaManagerInterface } from '@internetarchive/recaptcha-manager';
35
- import type { IAComboBox } from '@internetarchive/elements/ia-combo-box/ia-combo-box';
36
- import {
37
- SelectedFacets,
38
- SortField,
39
- CollectionBrowserContext,
40
- getDefaultSelectedFacets,
41
- TileModel,
42
- CollectionDisplayMode,
43
- FacetEventDetails,
44
- sortOptionFromAPIString,
45
- SORT_OPTIONS,
46
- defaultProfileElementSorts,
47
- FacetLoadStrategy,
48
- defaultFacetDisplayOrder,
49
- tvFacetDisplayOrder,
50
- TileBlurOverrideState,
51
- defaultSortAvailability,
52
- favoritesSortAvailability,
53
- tvSortAvailability,
54
- FacetBucket,
55
- } from './models';
56
- import {
57
- RestorationStateHandlerInterface,
58
- RestorationStateHandler,
59
- RestorationState,
60
- RestorationStatePersistOptions,
61
- } from './restoration-state-handler';
62
- import { CollectionBrowserDataSource } from './data-source/collection-browser-data-source';
63
- import type {
64
- CollectionBrowserQueryState,
65
- CollectionBrowserSearchInterface,
66
- } from './data-source/collection-browser-query-state';
67
- import { FACETLESS_PAGE_ELEMENTS } from './data-source/models';
68
- import type { CollectionFacets } from './collection-facets';
69
- import type { CollectionBrowserDataSourceInterface } from './data-source/collection-browser-data-source-interface';
70
- import {
71
- analyticsActions,
72
- analyticsCategories,
73
- } from './utils/analytics-events';
74
- import { updateSelectedFacetBucket } from './utils/facet-utils';
75
- import chevronIcon from './assets/img/icons/chevron';
76
- import { srOnlyStyle } from './styles/sr-only';
77
- import { sha1 } from './utils/sha1';
78
- import type { PlaceholderType } from './empty-placeholder';
79
- import type { ManageBar } from './manage/manage-bar';
80
- import type { SmartFacetBar } from './collection-facets/smart-facets/smart-facet-bar';
81
- import type { LayoutType, TileAction } from './tiles/models';
82
-
83
- import '@internetarchive/elements/ia-combo-box/ia-combo-box';
84
- import './empty-placeholder';
85
- import './tiles/tile-dispatcher';
86
- import './tiles/collection-browser-loading-tile';
87
- import './sort-filter-bar/sort-filter-bar';
88
- import './manage/manage-bar';
89
- import './collection-facets';
90
- import './circular-activity-indicator';
91
- import './collection-facets/smart-facets/smart-facet-bar';
92
-
93
- @customElement('collection-browser')
94
- export class CollectionBrowser
95
- extends LitElement
96
- implements
97
- InfiniteScrollerCellProviderInterface,
98
- SharedResizeObserverResizeHandlerInterface,
99
- CollectionBrowserSearchInterface
100
- {
101
- @property({ type: String }) baseNavigationUrl?: string;
102
-
103
- @property({ type: String }) baseImageUrl: string = 'https://archive.org';
104
-
105
- @property({ type: Object }) searchService?: SearchServiceInterface;
106
-
107
- /**
108
- * Which backend should be targeted by searches (e.g., metadata or FTS)
109
- */
110
- @property({ type: Number }) searchType: SearchType = SearchType.DEFAULT;
111
-
112
- /**
113
- * The identifier of the collection that searches should be performed within
114
- */
115
- @property({ type: String }) withinCollection?: string;
116
-
117
- /**
118
- * The identifier (e.g., @person) of the user whose profile is being searched within
119
- */
120
- @property({ type: String }) withinProfile?: string;
121
-
122
- /**
123
- * Which section of the profile page searches are for (e.g., uploads, reviews, ...)
124
- */
125
- @property({ type: String }) profileElement?: PageElementName;
126
-
127
- /**
128
- * The base query to use for all searches, updated to match the current user query.
129
- */
130
- @property({ type: String }) baseQuery?: string;
131
-
132
- /**
133
- * The base list of identifiers to fetch, if using the client_document_fetch feature
134
- * of the search service.
135
- *
136
- * This approach allows many more identifiers to be retrieved than a query like
137
- * `identifier:(foo OR bar OR ...)` would, but still may be more limited in what
138
- * content is returned by the backend
139
- */
140
- @property({ type: Array }) identifiers?: string[];
141
-
142
- /**
143
- * Which mode to display result tiles in (grid, extended list, or compact list)
144
- */
145
- @property({ type: String }) displayMode?: CollectionDisplayMode;
146
-
147
- @property({ type: String }) selectedSort: SortField = SortField.default;
148
-
149
- @property({ type: String }) selectedTitleFilter: string | null = null;
150
-
151
- @property({ type: String }) selectedCreatorFilter: string | null = null;
152
-
153
- @property({ type: String }) sortDirection: SortDirection | null = null;
154
-
155
- @property({ type: String }) defaultSortField: Exclude<
156
- SortField,
157
- SortField.default
158
- > = SortField.relevance;
159
-
160
- @property({ type: String }) defaultSortDirection: SortDirection | null = null;
161
-
162
- @property({ type: Number }) pageSize = 50;
163
-
164
- @property({ type: Number }) currentPage?: number;
165
-
166
- @property({ type: String }) minSelectedDate?: string;
167
-
168
- @property({ type: String }) maxSelectedDate?: string;
169
-
170
- @property({ type: Object }) selectedFacets?: SelectedFacets;
171
-
172
- /**
173
- * Set of filters to be applied internally to searches, but not included in URL params or
174
- * visibly selected facets. Use when this instance of collection browser is being shown
175
- * in a filtered context, such as a single-mediatype tab, but the corresponding filters
176
- * should not be exposed/changeable within that context.
177
- */
178
- @property({ type: Object }) internalFilters?: SelectedFacets;
179
-
180
- /**
181
- * Whether to show smart facets (bubbles) along the top of the component
182
- */
183
- @property({ type: Boolean }) showSmartFacetBar = false;
184
-
185
- /**
186
- * Sets the label that is shown in front of the smart facets, if present.
187
- */
188
- @property({ type: String }) smartFacetBarLabel?: string;
189
-
190
- /**
191
- * Whether to show the date picker (above the facets)
192
- */
193
- @property({ type: Boolean }) showHistogramDatePicker = false;
194
-
195
- /**
196
- * Whether placeholder views should be suppressed. If true, searches that produce an
197
- * error or empty result set will simply show a blank results view instead of a placeholder.
198
- */
199
- @property({ type: Boolean }) suppressPlaceholders = false;
200
-
201
- /**
202
- * Whether the result count text should be suppressed.
203
- * If true, no "X Results" message will be shown.
204
- */
205
- @property({ type: Boolean }) suppressResultCount = false;
206
-
207
- /**
208
- * Whether the scrolling result view should be suppressed entirely.
209
- * If true, no infinite scroller (and thus no result tiles) will be rendered.
210
- */
211
- @property({ type: Boolean }) suppressResultTiles = false;
212
-
213
- /**
214
- * Whether to suppress persistence of the query to the URL.
215
- * If true, the `query` param will not be added to the URL or updated on query changes.
216
- */
217
- @property({ type: Boolean }) suppressURLQuery = false;
218
-
219
- /**
220
- * Whether to suppress persistence of the `sin` search type param to the URL.
221
- * If true, the `sin` param will not be added to the URL or updated on query changes.
222
- */
223
- @property({ type: Boolean }) suppressURLSinParam = false;
224
-
225
- /**
226
- * Whether to suppress display of the sort bar.
227
- * If true, the entire sort bar (incl. display modes) will be omitted from rendering.
228
- */
229
- @property({ type: Boolean }) suppressSortBar = false;
230
-
231
- /**
232
- * Whether to suppress showing the display mode options in the sort bar.
233
- * If true, those options will be omitted (though the rest of the sort bar may still render).
234
- */
235
- @property({ type: Boolean }) suppressDisplayModes = false;
236
-
237
- /**
238
- * Whether to suppress the display of the `mediatype` facet group, e.g., because this instance
239
- * of collection browser is being shown in a filtered single-mediatype context.
240
- */
241
- @property({ type: Boolean }) suppressMediatypeFacets = false;
242
-
243
- /**
244
- * What strategy to use for when/whether to load facet data for a search.
245
- *
246
- * Defaults to `eager`, always loading facets immediately alongside search results.
247
- *
248
- * To eliminate facets that are never seen, this can be reduced to `lazy-mobile`, which
249
- * will delay loading facets in the mobile view until the "Filters" accordion is opened.
250
- * Facets are still loaded eagerly when viewing the desktop layout.
251
- *
252
- * To further reduce facet requests for patrons who do not need to use them, this can be
253
- * again reduced to `opt-in`, which will also require desktop users to explicitly request
254
- * that they be loaded (in addition to the lazy mobile behavior described above).
255
- *
256
- * To entirely suppress facets from being loaded, this may be set to `off`.
257
- */
258
- @property({ type: String }) facetLoadStrategy: FacetLoadStrategy = 'eager';
259
-
260
- @property({ type: Boolean, reflect: true }) facetPaneVisible = false;
261
-
262
- @property({ type: Boolean }) clearResultsOnEmptyQuery = false;
263
-
264
- @property({ type: String }) collectionPagePath: string = '/details/';
265
-
266
- /** describes where this component is being used */
267
- @property({ type: String, reflect: true }) searchContext: string =
268
- analyticsCategories.default;
269
-
270
- @property({ type: String }) pageContext: CollectionBrowserContext = 'search';
271
-
272
- @property({ type: Object })
273
- restorationStateHandler: RestorationStateHandlerInterface =
274
- new RestorationStateHandler({
275
- context: this.pageContext,
276
- });
277
-
278
- @property({ type: Number }) mobileBreakpoint = 600;
279
-
280
- @property({ type: Boolean }) loggedIn = false;
281
-
282
- @property({ type: Object }) resizeObserver?: SharedResizeObserverInterface;
283
-
284
- @property({ type: Object }) modalManager?: ModalManagerInterface = undefined;
285
-
286
- @property({ type: Object })
287
- featureFeedbackService?: FeatureFeedbackServiceInterface;
288
-
289
- @property({ type: Object }) recaptchaManager?: RecaptchaManagerInterface;
290
-
291
- /**
292
- * Whether we are representing a TV collection, needing slightly different tile handling.
293
- */
294
- @property({ type: Boolean }) isTVCollection = false;
295
-
296
- /**
297
- * If item management UI active
298
- */
299
- @property({ type: Boolean }) isManageView = false;
300
-
301
- /** Action buttons to display on each tile */
302
- @property({ type: Array }) tileActions: TileAction[] = [];
303
-
304
- /**
305
- * The simplified layout to apply to grid-mode tiles, if any. See
306
- * `LayoutType` for available options. Has no effect on list display modes.
307
- */
308
- @property({ type: String }) tileLayoutType: LayoutType = 'default';
309
-
310
- @property({ type: String }) manageViewLabel = 'Select items to remove';
311
-
312
- /** Whether to replace the default sort options with a slot for customization (default: false) */
313
- @property({ type: Boolean }) enableSortOptionsSlot = false;
314
-
315
- /** Whether to expose a slot for a smart results carousel above the full results */
316
- @property({ type: Boolean, reflect: true }) showSmartResults = false;
317
-
318
- /**
319
- * The maximum number of pages we will load when a privileged user clicks
320
- * the "Manage" button on the search page. Limited to 15 pages.
321
- */
322
- @property({ type: Number }) maxPagesToManage = 15;
323
-
324
- /**
325
- * The results per page so we can paginate.
326
- *
327
- * This allows us to start in the middle of the search results and
328
- * fetch data before or after the current page. If we don't have a key
329
- * for the previous/next page, we'll fetch the next/previous page to populate it
330
- */
331
- @property({ type: Object }) dataSource: CollectionBrowserDataSourceInterface =
332
- new CollectionBrowserDataSource(this, this.pageSize);
333
-
334
- /**
335
- * The page that the consumer wants to load.
336
- */
337
- initialPageNumber = 1;
338
-
339
- /**
340
- * This the the number of pages that we want to show.
341
- *
342
- * The data isn't necessarily loaded for all of the pages, but this lets us
343
- * know how many cells we should render.
344
- */
345
- @state() private pagesToRender = this.initialPageNumber;
346
-
347
- /**
348
- * Whether the initial page fetch for a new query is currently in progress.
349
- */
350
- @state() private searchResultsLoading = false;
351
-
352
- @state() private facetsLoading = false;
353
-
354
- @state() private totalResults?: number;
355
-
356
- @state() private mobileView = false;
357
-
358
- /**
359
- * Any temporarily overridden `on`/`off` state for the user's tile blurring preference if they
360
- * have chosen to override it, or `no-override` if they have not.
361
- */
362
- @state() private tileBlurOverrideState: TileBlurOverrideState = 'no-override';
363
-
364
- @state() private collapsibleFacetsVisible = false;
365
-
366
- @state() private contentWidth?: number;
367
-
368
- @state() private placeholderType: PlaceholderType = null;
369
-
370
- @state() private selectedTVNetwork?: string = undefined;
371
-
372
- @state() private selectedTVShow?: string = undefined;
373
-
374
- @state() private tvMapsPopulated: boolean = false;
375
-
376
- @state() private tvMapsLoading: boolean = false;
377
-
378
- @state() private tvMapsErrored: boolean = false;
379
-
380
- @query('#content-container') private contentContainer!: HTMLDivElement;
381
-
382
- @query('#left-column') private leftColumn?: HTMLDivElement;
383
-
384
- @query('collection-facets') private collectionFacets?: CollectionFacets;
385
-
386
- @query('manage-bar') private manageBar?: ManageBar;
387
-
388
- @query('smart-facet-bar') private smartFacetBar?: SmartFacetBar;
389
-
390
- @query('#tv-networks') private tvNetworksDropdown?: IAComboBox;
391
-
392
- @query('#tv-shows') private tvShowsDropdown?: IAComboBox;
393
-
394
- @property({ type: Object, attribute: false })
395
- analyticsHandler?: AnalyticsManagerInterface;
396
-
397
- /** Whether layout size analytics have been sent already. */
398
- private layoutSizeAnalyticsSent = false;
399
-
400
- /**
401
- * When we're animated scrolling to the page, we don't want to fetch
402
- * all of the pages as it scrolls so this lets us know if we're scrolling
403
- */
404
- private isScrollingToCell = false;
405
-
406
- /**
407
- * When page width resizes from desktop to mobile, set true to
408
- * disable expand/collapse transition when loading.
409
- */
410
- private isResizeToMobile = false;
411
-
412
- /**
413
- * Flag indicating that a new data source is currently being installed.
414
- * During the install, any URL persistence operation should replace the current entry
415
- * instead of creating a new one.
416
- */
417
- private dataSourceInstallInProgress = false;
418
-
419
- private leftColIntersectionObserver?: IntersectionObserver;
420
-
421
- private facetsIntersectionObserver?: IntersectionObserver;
422
-
423
- private placeholderCellTemplate = html`<collection-browser-loading-tile></collection-browser-loading-tile>`;
424
-
425
- constructor() {
426
- super();
427
- this.addController(this.dataSource);
428
- }
429
-
430
- private tileModelAtCellIndex(index: number): TileModel | undefined {
431
- const model = this.dataSource.getTileModelAt(index);
432
- /**
433
- * If we encounter a model we don't have yet and we're not in the middle of an
434
- * automated scroll, schedule a fetch for the missing page and return undefined.
435
- * The datasource will be updated once the page is loaded and the cell will be rendered.
436
- *
437
- * We disable it during the automated scroll since we don't want to fetch pages for intervening cells the
438
- * user may never see.
439
- */
440
- if (!model && !this.isScrollingToCell && this.dataSource.queryInitialized) {
441
- const pageNumber = Math.floor(index / this.pageSize) + 1;
442
- this.scheduleDeferredPageFetch(pageNumber);
443
- }
444
- return model;
445
- }
446
-
447
- /**
448
- * Debounce delay for page fetches initiated by new cells becoming visible.
449
- * Tuned so quick scrolling through unloaded regions doesn't send rapid-fire
450
- * search requests for every page we pass through, but to still feel responsive
451
- * when the scroll ends.
452
- */
453
- private static readonly DEFERRED_FETCH_DELAY_MS = 150;
454
-
455
- private deferredFetchTimer = 0;
456
-
457
- /**
458
- * Schedules a fetch for the given page, debounced to ensure we don't
459
- * rapid-fire fetches while scrolling through pages quickly.
460
- *
461
- * If there's no pending fetch timer yet, it will fire a fetch immediately.
462
- * Otherwise, it will reset any existing timer. In either case, a deferred
463
- * fetch for the visible pages is scheduled after a brief delay to account
464
- * for whatever pages we land on after scrolling.
465
- */
466
- private scheduleDeferredPageFetch(pageNumber: number): void {
467
- if (!this.deferredFetchTimer) {
468
- this.dataSource.fetchPage(pageNumber);
469
- } else {
470
- window.clearTimeout(this.deferredFetchTimer);
471
- }
472
-
473
- this.deferredFetchTimer = window.setTimeout(() => {
474
- this.deferredFetchTimer = 0;
475
- this.fetchVisiblePages();
476
- }, CollectionBrowser.DEFERRED_FETCH_DELAY_MS);
477
- }
478
-
479
- /**
480
- * Fetch each currently-visible page whose first cell still has no
481
- * loaded model.
482
- */
483
- private fetchVisiblePages(): void {
484
- const visibleIndices = this.infiniteScroller?.getVisibleCellIndices() ?? [];
485
- const visiblePages = new Set(
486
- visibleIndices.map(i => Math.floor(i / this.pageSize) + 1),
487
- );
488
-
489
- for (const page of visiblePages) {
490
- const firstCellOfPage = (page - 1) * this.pageSize;
491
- if (!this.dataSource.getTileModelAt(firstCellOfPage)) {
492
- this.dataSource.fetchPage(page);
493
- }
494
- }
495
- }
496
-
497
- // this is the total number of tiles we expect if
498
- // the data returned is a full page worth
499
- // this is useful for putting in placeholders for the expected number of tiles
500
- private get estimatedTileCount(): number {
501
- return this.pagesToRender * this.pageSize;
502
- }
503
-
504
- @query('infinite-scroller')
505
- private infiniteScroller?: InfiniteScroller;
506
-
507
- private sessionIdGenPromise?: Promise<string>;
508
-
509
- /**
510
- * Returns a promise resolving to a unique string that persists for the current browser session.
511
- * Used in generating unique IDs for search requests, so that multiple requests coming from the
512
- * same browser session can be identified.
513
- */
514
- async getSessionId(): Promise<string> {
515
- try {
516
- const storedSessionId = sessionStorage?.getItem('cb-session');
517
- if (storedSessionId) {
518
- return storedSessionId;
519
- }
520
-
521
- // If we enter this method a second time while a first session ID is already being generated,
522
- // ensure we produce the same ID from both calls instead of generating another one.
523
- if (this.sessionIdGenPromise) {
524
- return this.sessionIdGenPromise;
525
- }
526
-
527
- this.sessionIdGenPromise = sha1(Math.random().toString());
528
- const newSessionId = await this.sessionIdGenPromise;
529
-
530
- sessionStorage?.setItem('cb-session', newSessionId);
531
- return newSessionId;
532
- } catch {
533
- // Either we can't generate the hash or we're restricted from accessing sessionStorage
534
- return '';
535
- }
536
- }
537
-
538
- /**
539
- * Go to the given page of results
540
- *
541
- * @param pageNumber
542
- */
543
- goToPage(pageNumber: number) {
544
- this.initialPageNumber = pageNumber;
545
- this.pagesToRender = pageNumber;
546
- return this.scrollToPage(pageNumber);
547
- }
548
-
549
- /**
550
- * Sets the state for whether the initial set of search results is loading in.
551
- */
552
- setSearchResultsLoading(loading: boolean): void {
553
- this.searchResultsLoading = loading;
554
- }
555
-
556
- /**
557
- * Sets the state for whether facet data is loading in
558
- */
559
- setFacetsLoading(loading: boolean): void {
560
- this.facetsLoading = loading;
561
- }
562
-
563
- /**
564
- * Sets the total number of results to be displayed for the current search
565
- */
566
- setTotalResultCount(totalResults: number): void {
567
- this.totalResults = totalResults;
568
- }
569
-
570
- /**
571
- * Clears all selected/negated facets, date ranges, and letter filters.
572
- *
573
- * By default, the current sort field/direction are not cleared,
574
- * but this can be overridden by setting the `sort` option to `true`.
575
- *
576
- * Similarly, it is possible to finely control what is cleared by
577
- * setting any of the `facets`, `dateRange`, or `letterFilters` flags
578
- * in the options object.
579
- */
580
- clearFilters({
581
- facets = true,
582
- dateRange = true,
583
- letterFilters = true,
584
- sort = false,
585
- } = {}): void {
586
- // Don't bother clearing facets if none are checked, so that we don't
587
- // trigger unnecessary update cycles.
588
- if (facets && this.hasCheckedFacets) {
589
- this.selectedFacets = getDefaultSelectedFacets();
590
- }
591
-
592
- if (dateRange) {
593
- this.minSelectedDate = undefined;
594
- this.maxSelectedDate = undefined;
595
- }
596
-
597
- if (letterFilters) {
598
- this.selectedTitleFilter = null;
599
- this.selectedCreatorFilter = null;
600
- }
601
-
602
- if (sort) {
603
- this.sortDirection = null;
604
- this.selectedSort = SortField.default;
605
- }
606
-
607
- this.clearTVDropdowns();
608
-
609
- if (this.smartFacetBar) {
610
- this.smartFacetBar.deselectAll();
611
- }
612
- }
613
-
614
- /**
615
- * Resets any selected TV network/show dropdowns to their default state
616
- */
617
- private clearTVDropdowns(): void {
618
- this.selectedTVNetwork = undefined;
619
- this.selectedTVShow = undefined;
620
-
621
- if (this.tvNetworksDropdown) {
622
- this.tvNetworksDropdown.clearSelectedOption();
623
- }
624
-
625
- if (this.tvShowsDropdown) {
626
- this.tvShowsDropdown.clearSelectedOption();
627
- }
628
- }
629
-
630
- /**
631
- * Returns true if the current value of `this.selectedFacets` contains
632
- * any facet buckets than have been selected or negated, or false otherwise.
633
- */
634
- private get hasCheckedFacets(): boolean {
635
- if (!this.selectedFacets) return false;
636
-
637
- for (const facetGroup of Object.values(this.selectedFacets)) {
638
- for (const bucket of Object.values(facetGroup)) {
639
- if (bucket.state !== 'none') return true;
640
- }
641
- }
642
-
643
- return false;
644
- }
645
-
646
- /**
647
- * Returns true if there are any currently selected/negated facet buckets,
648
- * any selected date range, or any selected letter filters. False otherwise.
649
- *
650
- * Ignores sorting options.
651
- */
652
- private get hasActiveFilters(): boolean {
653
- return !!(
654
- this.hasCheckedFacets ||
655
- this.minSelectedDate ||
656
- this.maxSelectedDate ||
657
- this.selectedTitleFilter ||
658
- this.selectedCreatorFilter
659
- );
660
- }
661
-
662
- willUpdate(changed: PropertyValues): void {
663
- this.setPlaceholderType();
664
-
665
- if (changed.has('searchType') && this.searchType === SearchType.TV) {
666
- this.applyDefaultTVSearchSort();
667
- }
668
-
669
- // If we need to clear filters due to a query change or other reset, we do so *before* any
670
- // updates happen, to prevent unnecessary update cycles and ensure there's a clean slate
671
- // for any search requests that fire.
672
- if (
673
- changed.has('baseQuery') ||
674
- changed.has('identifiers') ||
675
- changed.has('searchType') ||
676
- changed.has('withinCollection')
677
- ) {
678
- // Unless this query/search type update is from the initial page load or the
679
- // result of hitting the back button,
680
- // we need to clear any existing filters since they may no longer be valid for
681
- // the new set of search results.
682
- if (!this.historyPopOccurred && this.initialQueryChangeHappened) {
683
- // Ordinarily, we leave the sort param unchanged between searches.
684
- // However, if we are changing the target collection itself, we want the sort cleared too,
685
- // since different collections may have different sorting options available.
686
- const shouldClearSort =
687
- changed.has('withinCollection') &&
688
- !changed.has('selectedSort') &&
689
- !changed.has('sortDirection');
690
-
691
- // Otherwise, only clear filters that haven't been simultaneously applied in this update
692
- this.clearFilters({
693
- sort: shouldClearSort,
694
- facets: !changed.has('selectedFacets'),
695
- dateRange: !(
696
- changed.has('minSelectedDate') || changed.has('maxSelectedDate')
697
- ),
698
- letterFilters: !(
699
- changed.has('selectedTitleFilter') ||
700
- changed.has('selectedCreatorFilter')
701
- ),
702
- });
703
- }
704
- }
705
- }
706
-
707
- render() {
708
- return html`
709
- ${this.showSmartFacetBar && this.placeholderType === null
710
- ? html`<smart-facet-bar
711
- .query=${this.baseQuery}
712
- .aggregations=${this.dataSource.aggregations}
713
- .selectedFacets=${this.selectedFacets}
714
- .collectionTitles=${this.dataSource.collectionTitles}
715
- .filterToggleShown=${!this.mobileView}
716
- .filterToggleActive=${this.facetPaneVisible}
717
- .label=${this.smartFacetBarLabel}
718
- @facetsChanged=${this.facetsChanged}
719
- @filtersToggled=${() => {
720
- this.facetPaneVisible = !this.facetPaneVisible;
721
- this.emitFacetPaneVisibilityChanged();
722
- }}
723
- ></smart-facet-bar>`
724
- : nothing}
725
-
726
- <div
727
- id="content-container"
728
- class=${this.mobileView ? 'mobile' : 'desktop'}
729
- >
730
- ${this.placeholderType
731
- ? this.emptyPlaceholderTemplate
732
- : this.collectionBrowserTemplate}
733
- </div>
734
- `;
735
- }
736
-
737
- /**
738
- * Determines what type of placeholder content should be shown instead of result tiles, if applicable.
739
- * The placeholders indicate states where we have no results to show, which could be the result of:
740
- * - No query is set (on the search page)
741
- * - No results were returned for the most recent search
742
- * - The collection being searched within has no viewable items
743
- * - An error occurred on the most recent search attempt
744
- */
745
- private setPlaceholderType() {
746
- const isInitialized = this.dataSource.queryInitialized;
747
- const hasQuery = !!this.baseQuery?.trim();
748
- const hasIdentifiers = !!this.identifiers?.length;
749
- const isCollection = !!this.withinCollection;
750
- const isProfile = !!this.withinProfile;
751
- const isSearchResults = !isCollection && !isProfile;
752
- const noResults =
753
- !this.searchResultsLoading &&
754
- (this.dataSource.size === 0 || !this.searchService);
755
-
756
- this.placeholderType = null;
757
- if (this.suppressPlaceholders) return;
758
-
759
- if (!isInitialized) {
760
- this.placeholderType = 'empty-query';
761
- } else if (isSearchResults && !hasQuery && !hasIdentifiers) {
762
- this.placeholderType = 'empty-query';
763
- } else if (noResults) {
764
- // Within a collection, no query + no results means the collection simply has no viewable items.
765
- // Otherwise, we must have a user query that produced 0 results.
766
- this.placeholderType =
767
- !hasQuery && isCollection ? 'empty-collection' : 'no-results';
768
- }
769
-
770
- if (this.dataSource.queryErrorMessage) {
771
- this.placeholderType =
772
- !hasQuery && isCollection ? 'collection-error' : 'query-error';
773
- }
774
- }
775
-
776
- /**
777
- * Template for the placeholder content to show when no results are available.
778
- */
779
- private get emptyPlaceholderTemplate() {
780
- return html`
781
- <empty-placeholder
782
- .placeholderType=${this.placeholderType}
783
- ?isMobileView=${this.mobileView}
784
- ?isCollection=${!!this.withinCollection}
785
- .detailMessage=${this.dataSource.queryErrorMessage ?? ''}
786
- .baseNavigationUrl=${this.baseNavigationUrl}
787
- ></empty-placeholder>
788
- `;
789
- }
790
-
791
- /**
792
- * Top-level template for rendering the left (facets) and right (results) columns.
793
- */
794
- private get collectionBrowserTemplate() {
795
- return html`
796
- <div id="left-column-scroll-sentinel"></div>
797
- ${this.leftColumnTemplate} ${this.rightColumnTemplate}
798
- `;
799
- }
800
-
801
- /**
802
- * Template for either the mobile or desktop version of the left column, depending
803
- * on current component state.
804
- */
805
- private get leftColumnTemplate(): TemplateResult {
806
- if (this.mobileView) {
807
- return this.mobileLeftColumnTemplate;
808
- }
809
- return this.desktopLeftColumnTemplate;
810
- }
811
-
812
- /**
813
- * Template for the mobile version of the "left column" (which in this case, appears
814
- * *above* the search results rather than beside them), for rendering the
815
- * accordion-style facets.
816
- */
817
- private get mobileLeftColumnTemplate(): TemplateResult {
818
- return html`
819
- <div
820
- id="left-column"
821
- class="column${this.isResizeToMobile ? ' preload' : ''}"
822
- >
823
- ${this.facetTopViewSlot} ${this.resultsCountTemplate}
824
- <div id="facets-header-container">${this.mobileFacetsTemplate}</div>
825
- </div>
826
- `;
827
- }
828
-
829
- /**
830
- * Template for the desktop version of the left column, displaying the facets sidebar.
831
- */
832
- private get desktopLeftColumnTemplate(): TemplateResult {
833
- return html`
834
- <div id="left-column" class="column" ?hidden=${!this.facetPaneVisible}>
835
- ${this.facetTopViewSlot}
836
- <div id="facets-header-container">
837
- <h2 id="facets-header" class="sr-only">${msg('Filters')}</h2>
838
- ${this.resultsCountTemplate} ${this.clearFiltersBtnTemplate(false)}
839
- </div>
840
- <div id="facets-container" aria-labelledby="facets-header">
841
- ${this.facetsTemplate}
842
- <div id="facets-scroll-sentinel"></div>
843
- </div>
844
- <div id="facets-bottom-fade"></div>
845
- </div>
846
- `;
847
- }
848
-
849
- /**
850
- * Slot which is placed at top of the facets area for user-profile page
851
- * - mainly used to render userlists
852
- */
853
- private get facetTopViewSlot(): TemplateResult {
854
- return html`<div id="facet-top-view">
855
- <slot name="facet-top-slot"></slot>
856
- </div>`;
857
- }
858
-
859
- /**
860
- * Template for the "X Results" count at the top of the search results.
861
- * Changes to the "Searching..." label if the search results are still loading.
862
- */
863
- private get resultsCountTemplate(): TemplateResult | typeof nothing {
864
- if (this.suppressResultCount) return nothing;
865
-
866
- const shouldShowSearching =
867
- this.searchResultsLoading || this.totalResults === undefined;
868
- const classes = classMap({ filtered: this.hasActiveFilters });
869
- const resultsCount = this.totalResults?.toLocaleString();
870
- const resultsLabel = this.totalResults === 1 ? 'Result' : 'Results';
871
-
872
- // Added data-testid for Playwright testing
873
- return html`
874
- <div id="results-total" class=${classes} data-testid="results-total">
875
- <span id="big-results-count">
876
- ${shouldShowSearching ? html`Searching&hellip;` : resultsCount}
877
- </span>
878
- <span id="big-results-label">
879
- ${shouldShowSearching ? nothing : resultsLabel}
880
- </span>
881
- </div>
882
- `;
883
- }
884
-
885
- /**
886
- * Template for the right column of the collection browser, where the result
887
- * tiles and sort/filter bar are shown.
888
- */
889
- private get rightColumnTemplate(): TemplateResult {
890
- const rightColumnClasses = classMap({
891
- column: true,
892
- 'full-width': !this.facetPaneVisible,
893
- 'smart-results-spacing': !!this.showSmartResults,
894
- });
895
-
896
- return html`
897
- <div id="right-column" class=${rightColumnClasses}>
898
- ${this.showSmartResults
899
- ? html`<slot name="smart-results"></slot>`
900
- : nothing}
901
- <section id="results">
902
- <h2 class="results-section-heading">
903
- <slot name="results-heading"></slot>
904
- </h2>
905
- <div id="cb-top-view">
906
- <slot name="cb-top-slot"></slot>
907
- </div>
908
- ${this.isManageView
909
- ? this.manageBarTemplate
910
- : this.sortFilterBarTemplate}
911
- <slot name="cb-results"></slot>
912
- <div id="results-body">
913
- <div id="results-main">
914
- ${this.displayMode === `list-compact` && this.totalResults
915
- ? this.listHeaderTemplate
916
- : nothing}
917
- ${this.suppressResultTiles
918
- ? nothing
919
- : this.infiniteScrollerTemplate}
920
- </div>
921
- <slot name="results-aside"></slot>
922
- </div>
923
- </section>
924
- </div>
925
- `;
926
- }
927
-
928
- /**
929
- * Template for the infinite scroller widget that contains the result tiles.
930
- */
931
- private get infiniteScrollerTemplate() {
932
- return html`<infinite-scroller
933
- class=${this.infiniteScrollerClasses}
934
- itemCount=${this.placeholderType ? 0 : nothing}
935
- ariaLandmarkLabel="Search results"
936
- .estimatedCellHeight=${this.estimatedTileHeight}
937
- .minBufferMarginCells=${this.pageSize}
938
- .cellProvider=${this}
939
- .placeholderCellTemplate=${this.placeholderCellTemplate}
940
- @scrollThresholdReached=${this.scrollThresholdReached}
941
- @visibleCellsChanged=${this.visibleCellsChanged}
942
- >${this.displayMode === 'grid'
943
- ? html`<slot name="result-last-tile" slot="result-last-tile"></slot>`
944
- : nothing}
945
- </infinite-scroller>`;
946
- }
947
-
948
- /**
949
- * Produces a `classMap` indicating which classes the infinite scroller should have
950
- * given the current display mode & placeholder case.
951
- */
952
- private get infiniteScrollerClasses() {
953
- return classMap({
954
- [this.displayMode ?? '']: !!this.displayMode,
955
- hidden: !!this.placeholderType,
956
- });
957
- }
958
-
959
- /**
960
- * Best-effort hint of how tall a single rendered tile is, by display mode.
961
- * The scroller uses this to better estimate the size its initial scroll
962
- * spacer and buffer position before real cell heights are measured.
963
- * Should roughly match the placeholder heights since the initial render
964
- * of a new page generally shows placeholders only anyway.
965
- */
966
- private get estimatedTileHeight(): number {
967
- switch (this.displayMode) {
968
- case 'list-detail':
969
- return 80;
970
- case 'list-compact':
971
- return 45;
972
- case 'grid':
973
- default:
974
- return 225;
975
- }
976
- }
977
-
978
- /**
979
- * Template for the sort & filtering bar that appears atop the search results.
980
- */
981
- private get sortFilterBarTemplate(): TemplateResult | typeof nothing {
982
- if (this.suppressSortBar) return nothing;
983
-
984
- // Determine the set of sortable fields that should be shown in the sort bar
985
- let sortFieldAvailability = defaultSortAvailability;
986
-
987
- // We adjust the available sort options for a couple of special cases...
988
- if (
989
- this.withinCollection?.startsWith('fav-') ||
990
- this.profileElement === 'favorites'
991
- ) {
992
- // When viewing a fav- collection or the favorites profile tab,
993
- // we include the Date Favorited option as the default
994
- sortFieldAvailability = favoritesSortAvailability;
995
- } else if (!this.withinCollection && this.searchType === SearchType.TV) {
996
- // When viewing TV search results, we exclude several of the usual date sort options.
997
- sortFieldAvailability = tvSortAvailability;
998
- }
999
-
1000
- // We only show relevance sort if a search query is currently defined
1001
- sortFieldAvailability.relevance = this.isRelevanceSortAvailable;
1002
-
1003
- return html`
1004
- <sort-filter-bar
1005
- .defaultSortField=${this.defaultSortField}
1006
- .defaultSortDirection=${this.defaultSortDirection}
1007
- .selectedSort=${this.selectedSort}
1008
- .sortDirection=${this.sortDirection}
1009
- .sortFieldAvailability=${sortFieldAvailability}
1010
- .displayMode=${this.displayMode}
1011
- .selectedTitleFilter=${this.selectedTitleFilter}
1012
- .selectedCreatorFilter=${this.selectedCreatorFilter}
1013
- .prefixFilterCountMap=${this.dataSource.prefixFilterCountMap}
1014
- .enableSortOptionsSlot=${this.enableSortOptionsSlot}
1015
- .suppressDisplayModes=${this.suppressDisplayModes}
1016
- @sortChanged=${this.userChangedSort}
1017
- @displayModeChanged=${this.displayModeChanged}
1018
- @titleLetterChanged=${this.titleLetterSelected}
1019
- @creatorLetterChanged=${this.creatorLetterSelected}
1020
- >
1021
- ${this.tileBlurCheckboxTemplate}
1022
- <slot name="sort-options-left" slot="sort-options-left"></slot>
1023
- <slot name="sort-options" slot="sort-options"></slot>
1024
- <slot name="sort-options-right" slot="sort-options-right"></slot>
1025
- <slot name="sort-bar-end" slot="sort-bar-end"></slot>
1026
- </sort-filter-bar>
1027
- `;
1028
- }
1029
-
1030
- /**
1031
- * Template for the Blurring toggle for admins to enable/disable blurring of
1032
- * sensitive content in result tiles.
1033
- */
1034
- private get tileBlurCheckboxTemplate(): TemplateResult | typeof nothing {
1035
- // Only show the checkbox for @archive.org users
1036
- if (!this.dataSource.sessionContext?.is_archive_user) return nothing;
1037
-
1038
- return html`
1039
- <label
1040
- id="tile-blur-label"
1041
- for="tile-blur-check"
1042
- slot="sort-options-right"
1043
- >
1044
- ${msg('Blurring')}
1045
- <input
1046
- id="tile-blur-check"
1047
- type="checkbox"
1048
- ?checked=${!this.shouldSuppressTileBlurring}
1049
- @change=${this.tileBlurCheckboxChanged}
1050
- />
1051
- </label>
1052
- `;
1053
- }
1054
-
1055
- /**
1056
- * Template for the manage bar UI that appears atop the search results when we are
1057
- * showing the management view. This generally replaces the sort bar when present.
1058
- */
1059
- private get manageBarTemplate(): TemplateResult {
1060
- return html`
1061
- <manage-bar
1062
- .label=${this.manageViewLabel}
1063
- .modalManager=${this.modalManager}
1064
- .selectedItems=${this.dataSource.checkedTileModels}
1065
- .profileElement=${this.profileElement}
1066
- showSelectAll
1067
- showUnselectAll
1068
- ?showItemManageButton=${this.pageContext === 'search'}
1069
- ?removeAllowed=${this.dataSource.checkedTileModels.length !== 0}
1070
- @removeItems=${this.handleRemoveItems}
1071
- @manageItems=${this.handleManageItems}
1072
- @selectAll=${() => this.dataSource.checkAllTiles()}
1073
- @unselectAll=${() => this.dataSource.uncheckAllTiles()}
1074
- @cancel=${() => {
1075
- this.isManageView = false;
1076
- this.dataSource.uncheckAllTiles();
1077
- if (this.searchResultsLoading) this.dataSource.resetPages();
1078
- }}
1079
- ></manage-bar>
1080
- `;
1081
- }
1082
-
1083
- /**
1084
- * Handler for when the user requests to remove all checked items via the manage bar.
1085
- * Emits an `itemRemovalRequested` event with all checked tile models.
1086
- */
1087
- private handleRemoveItems(): void {
1088
- this.dispatchEvent(
1089
- new CustomEvent<{ items: string[] }>('itemRemovalRequested', {
1090
- detail: {
1091
- items: this.dataSource.checkedTileModels.map(model => {
1092
- // For favorited searches, we attach a search: prefix to differentiate it from an item
1093
- const searchPrefix = model?.mediatype === 'search' ? 'search:' : '';
1094
- const identifier = model?.identifier ?? '';
1095
- return `${searchPrefix}${identifier}`;
1096
- }),
1097
- },
1098
- }),
1099
- );
1100
- }
1101
-
1102
- /**
1103
- * Handler when user request to bulk edit from /search/ page
1104
- */
1105
- private handleManageItems(): void {
1106
- this.dispatchEvent(
1107
- new CustomEvent<{ items: string[] }>('itemManagerRequested', {
1108
- detail: {
1109
- items: this.dataSource.checkedTileModels.map(model =>
1110
- model?.identifier ? model.identifier : '',
1111
- ),
1112
- },
1113
- }),
1114
- );
1115
- }
1116
-
1117
- refreshSmartFacets(): void {
1118
- this.smartFacetBar?.refresh();
1119
- }
1120
-
1121
- /**
1122
- * Handler to show processing modal while removing item
1123
- */
1124
- showRemoveItemsProcessingModal(): void {
1125
- this.manageBar?.showRemoveItemsProcessingModal();
1126
- }
1127
-
1128
- /**
1129
- * Handler to show error modal when item removal failed
1130
- */
1131
- showRemoveItemsErrorModal(): void {
1132
- this.manageBar?.showRemoveItemsErrorModal();
1133
- }
1134
-
1135
- /**
1136
- * Removes all tile models that are currently checked & adjusts the paging
1137
- * of the data source to account for any new gaps in the data.
1138
- */
1139
- removeCheckedTiles(): void {
1140
- this.dataSource.removeCheckedTiles();
1141
- }
1142
-
1143
- /**
1144
- * Handler for when the tile blurring checkbox state is toggled
1145
- */
1146
- private tileBlurCheckboxChanged(e: Event): void {
1147
- const { checked } = e.target as HTMLInputElement;
1148
- this.tileBlurOverrideState = checked ? 'on' : 'off';
1149
- this.infiniteScroller?.refreshAllVisibleCells();
1150
- }
1151
-
1152
- /**
1153
- * Whether result tiles should have the default blurring of sensitive content suppressed.
1154
- * First considers any override specified by the user, falling back to the setting in
1155
- * user preferences if not overridden.
1156
- */
1157
- private get shouldSuppressTileBlurring(): boolean {
1158
- if (this.tileBlurOverrideState !== 'no-override') {
1159
- // User wants to override their preference.
1160
- // Return true if they want blurring turned off, or false otherwise.
1161
- return this.tileBlurOverrideState === 'off';
1162
- }
1163
-
1164
- // Not overriding, so use the preference from session context
1165
- const { sessionContext } = this.dataSource;
1166
- const userPrefs = sessionContext?.pps_relevant_user_preferences;
1167
- const blurringPref = userPrefs?.display__blur_moderated_content;
1168
-
1169
- // Only suppress blurring if the preference is disabled.
1170
- // If enabled or missing, tile blurring remains on.
1171
- return blurringPref === 'off';
1172
- }
1173
-
1174
- /**
1175
- * Handler for when the user changes the selected sort option or direction.
1176
- */
1177
- private userChangedSort(
1178
- e: CustomEvent<{
1179
- selectedSort: SortField;
1180
- sortDirection: SortDirection | null;
1181
- }>,
1182
- ) {
1183
- const { selectedSort, sortDirection } = e.detail;
1184
- this.selectedSort = selectedSort;
1185
- this.sortDirection = sortDirection;
1186
-
1187
- if ((this.currentPage ?? 1) > 1) {
1188
- this.goToPage(1);
1189
- }
1190
- this.setCurrentPage(1);
1191
- }
1192
-
1193
- /**
1194
- * Fires an analytics event for sorting changes.
1195
- * @param prevSortDirection Which sort direction was previously set.
1196
- */
1197
- private sendSortByAnalytics(prevSortDirection: SortDirection | null): void {
1198
- const directionCleared = prevSortDirection && !this.sortDirection;
1199
-
1200
- this.analyticsHandler?.sendEvent({
1201
- category: this.searchContext,
1202
- action: analyticsActions.sortBy,
1203
- label: `${this.selectedSort}${
1204
- this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''
1205
- }`,
1206
- });
1207
- }
1208
-
1209
- /**
1210
- * Handler for when the selected sort option is updated, whether by the user
1211
- * themselves or programmatically.
1212
- */
1213
- private selectedSortChanged(): void {
1214
- // Lazy-load the alphabet counts for title/creator sort bar as needed
1215
- this.dataSource.updatePrefixFiltersForCurrentSort();
1216
- }
1217
-
1218
- /**
1219
- * An object representing the current sort field & direction.
1220
- */
1221
- get sortParam(): SortParam | null {
1222
- const sortOption = SORT_OPTIONS[this.selectedSort];
1223
- if (!sortOption?.handledBySearchService) {
1224
- return null;
1225
- }
1226
-
1227
- // If the sort option specified in the URL is unrecognized, we just use it as-is
1228
- const urlSortParam = new URL(window.location.href).searchParams.get('sort');
1229
- const sortField =
1230
- sortOption.searchServiceKey ?? urlSortParam?.replace(/^-/, '');
1231
-
1232
- // If the sort direction is still null at this point, then we assume ascending
1233
- // (i.e., it was unrecognized and had no directional flag)
1234
- if (!this.sortDirection) this.sortDirection = 'asc';
1235
-
1236
- if (!sortField) return null;
1237
- return { field: sortField, direction: this.sortDirection };
1238
- }
1239
-
1240
- /**
1241
- * An object representing the default sort field & direction, if none are explicitly set.
1242
- */
1243
- get defaultSortParam(): SortParam | null {
1244
- const direction = this.defaultSortDirection ?? 'asc';
1245
- const field = SORT_OPTIONS[this.defaultSortField].searchServiceKey;
1246
- if (!field) return null;
1247
-
1248
- return { field, direction };
1249
- }
1250
-
1251
- /**
1252
- * Handler for when the display mode option is changed (grid/list/compact-list views).
1253
- */
1254
- private displayModeChanged(
1255
- e: CustomEvent<{ displayMode?: CollectionDisplayMode }>,
1256
- ): void {
1257
- this.displayMode = e.detail.displayMode;
1258
-
1259
- if (this.displayMode) {
1260
- this.analyticsHandler?.sendEvent({
1261
- category: this.searchContext,
1262
- action: analyticsActions.displayMode,
1263
- label: this.displayMode,
1264
- });
1265
- }
1266
- }
1267
-
1268
- /**
1269
- * Returns a query clause identifying the currently selected title filter,
1270
- * e.g., `firstTitle:X`.
1271
- */
1272
- private get titleQuery(): string | undefined {
1273
- return this.selectedTitleFilter
1274
- ? `firstTitle:${this.selectedTitleFilter}`
1275
- : undefined;
1276
- }
1277
-
1278
- /**
1279
- * Returns a query clause identifying the currently selected creator filter,
1280
- * e.g., `firstCreator:X`.
1281
- */
1282
- private get creatorQuery(): string | undefined {
1283
- return this.selectedCreatorFilter
1284
- ? `firstCreator:${this.selectedCreatorFilter}`
1285
- : undefined;
1286
- }
1287
-
1288
- /**
1289
- * Send Analytics when sorting by title's first letter
1290
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
1291
- */
1292
- private sendFilterByTitleAnalytics(prevSelectedLetter: string | null): void {
1293
- if (!prevSelectedLetter && !this.selectedTitleFilter) {
1294
- return;
1295
- }
1296
- const cleared = prevSelectedLetter && !this.selectedTitleFilter;
1297
-
1298
- this.analyticsHandler?.sendEvent({
1299
- category: this.searchContext,
1300
- action: analyticsActions.filterByTitle,
1301
- label: cleared
1302
- ? `clear-${prevSelectedLetter}`
1303
- : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
1304
- });
1305
- }
1306
-
1307
- /**
1308
- * Send Analytics when filtering by creator's first letter
1309
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
1310
- */
1311
- private sendFilterByCreatorAnalytics(
1312
- prevSelectedLetter: string | null,
1313
- ): void {
1314
- if (!prevSelectedLetter && !this.selectedCreatorFilter) {
1315
- return;
1316
- }
1317
- const cleared = prevSelectedLetter && !this.selectedCreatorFilter;
1318
-
1319
- this.analyticsHandler?.sendEvent({
1320
- category: this.searchContext,
1321
- action: analyticsActions.filterByCreator,
1322
- label: cleared
1323
- ? `clear-${prevSelectedLetter}`
1324
- : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
1325
- });
1326
- }
1327
-
1328
- /**
1329
- * Handler for changes to which letter is selected in the title alphabet bar.
1330
- */
1331
- private titleLetterSelected(
1332
- e: CustomEvent<{ selectedLetter: string | null }>,
1333
- ): void {
1334
- this.selectedCreatorFilter = null;
1335
- this.selectedTitleFilter = e.detail.selectedLetter;
1336
- }
1337
-
1338
- /**
1339
- * Handler for changes to which letter is selected in the creator alphabet bar.
1340
- */
1341
- private creatorLetterSelected(
1342
- e: CustomEvent<{ selectedLetter: string | null }>,
1343
- ): void {
1344
- this.selectedTitleFilter = null;
1345
- this.selectedCreatorFilter = e.detail.selectedLetter;
1346
- }
1347
-
1348
- /**
1349
- * The full template for how the facets should be structured in mobile view,
1350
- * including the collapsible container (with header) and the facets themselves.
1351
- */
1352
- private get mobileFacetsTemplate(): TemplateResult | typeof nothing {
1353
- if (FACETLESS_PAGE_ELEMENTS.includes(this.profileElement!)) return nothing;
1354
-
1355
- const toggleFacetsVisible = (e: Event) => {
1356
- const target = e.target as HTMLDetailsElement;
1357
- this.isResizeToMobile = false;
1358
- this.collapsibleFacetsVisible = target.open;
1359
-
1360
- this.analyticsHandler?.sendEvent({
1361
- category: this.searchContext,
1362
- action: analyticsActions.mobileFacetsToggled,
1363
- label: target.open ? 'open' : 'closed',
1364
- });
1365
- };
1366
-
1367
- return html`
1368
- <details id="mobile-filter-collapse" @toggle=${toggleFacetsVisible}>
1369
- <summary>
1370
- <span class="collapser-icon">${chevronIcon}</span>
1371
- <h2>${msg('Filters')}</h2>
1372
- ${this.clearFiltersBtnTemplate(true)}
1373
- </summary>
1374
- ${this.facetsTemplate}
1375
- </details>
1376
- `;
1377
- }
1378
-
1379
- /**
1380
- * Handler for when either of the TV dropdown filters are toggled, loading their
1381
- * contents if necessary.
1382
- */
1383
- private async tvDropdownToggled(e: CustomEvent<boolean>): Promise<void> {
1384
- if (!e.detail) return; // Only run when toggled open
1385
- if (this.tvMapsPopulated) return;
1386
-
1387
- this.tvMapsLoading = true;
1388
- this.tvMapsErrored = false;
1389
- try {
1390
- await this.dataSource.populateTVChannelMaps();
1391
- this.tvMapsPopulated = true;
1392
- } catch (err) {
1393
- this.tvMapsErrored = true;
1394
- }
1395
-
1396
- this.tvMapsLoading = false;
1397
- }
1398
-
1399
- private async networksDropdownChanged(): Promise<void> {
1400
- const previousNetwork = this.selectedTVNetwork;
1401
- const newNetwork = this.tvNetworksDropdown!.selectedOption?.text;
1402
- this.selectedTVNetwork = newNetwork ?? undefined;
1403
-
1404
- const entries = this.dataSource.tvChannelMaps.channelToNetwork!.entries();
1405
- for (const [channel, network] of entries) {
1406
- if (network === previousNetwork) {
1407
- // Remove any previously-applied network filter
1408
- const removedBucket: FacetBucket = {
1409
- key: channel.toLowerCase(),
1410
- count: 0,
1411
- state: 'none',
1412
- };
1413
- this.selectedFacets = updateSelectedFacetBucket(
1414
- this.selectedFacets,
1415
- 'creator',
1416
- removedBucket,
1417
- true,
1418
- );
1419
- } else if (network === this.selectedTVNetwork) {
1420
- const newBucket: FacetBucket = {
1421
- key: channel.toLowerCase(),
1422
- count: 0,
1423
- state: 'selected',
1424
- };
1425
- this.selectedFacets = updateSelectedFacetBucket(
1426
- this.selectedFacets,
1427
- 'creator',
1428
- newBucket,
1429
- );
1430
- }
1431
- }
1432
- }
1433
-
1434
- private async showsDropdownChanged(): Promise<void> {
1435
- const previousShow = this.selectedTVShow;
1436
- const newShow = this.tvShowsDropdown!.selectedOption?.text;
1437
- this.selectedTVShow = newShow ?? undefined;
1438
-
1439
- // Remove any previously-applied shows filter
1440
- if (previousShow !== undefined) {
1441
- const removedBucket: FacetBucket = {
1442
- key: previousShow,
1443
- count: 0,
1444
- state: 'none',
1445
- };
1446
- this.selectedFacets = updateSelectedFacetBucket(
1447
- this.selectedFacets,
1448
- 'program',
1449
- removedBucket,
1450
- true,
1451
- );
1452
- }
1453
-
1454
- if (this.selectedTVShow) {
1455
- const newBucket: FacetBucket = {
1456
- key: this.selectedTVShow,
1457
- count: 0,
1458
- state: 'selected',
1459
- };
1460
- this.selectedFacets = updateSelectedFacetBucket(
1461
- this.selectedFacets,
1462
- 'program',
1463
- newBucket,
1464
- );
1465
- }
1466
- }
1467
-
1468
- private get tvDropdownFiltersTemplate(): TemplateResult | typeof nothing {
1469
- if (this.searchType !== SearchType.TV) return nothing;
1470
-
1471
- const { channelToNetwork, programToChannels } =
1472
- this.dataSource.tvChannelMaps;
1473
- const networks = channelToNetwork
1474
- ? [...new Set(channelToNetwork.values())]
1475
- : [];
1476
-
1477
- let showEntries = programToChannels ? [...programToChannels.entries()] : [];
1478
-
1479
- if (channelToNetwork && this.selectedTVNetwork) {
1480
- showEntries = showEntries.filter(([, channels]) =>
1481
- Object.keys(channels).some(
1482
- c => channelToNetwork.get(c) === this.selectedTVNetwork,
1483
- ),
1484
- );
1485
- }
1486
-
1487
- const filterByNetworkLabel = msg('Filter by Network');
1488
- const filterByShowLabel = msg('Filter by Show');
1489
- const shows = showEntries.map(([show]) => show);
1490
- const loadingIndicator = html`
1491
- <span slot="empty-options">
1492
- <img src="https://archive.org/images/loading.gif" />
1493
- </span>
1494
- `;
1495
- const errorMessage = html`
1496
- <span slot="empty-options">
1497
- ${msg('Unable to fetch options, try again later')}
1498
- </span>
1499
- `;
1500
-
1501
- return html`
1502
- <div id="tv-filters" slot="facets-top">
1503
- <ia-combo-box
1504
- id="tv-networks"
1505
- class="tv-filter-dropdown"
1506
- placeholder=${filterByNetworkLabel}
1507
- clearable
1508
- wrap-arrow-keys
1509
- sort
1510
- .options=${networks.map((n, i) => ({ id: `network-${i}`, text: n }))}
1511
- @toggle=${this.tvDropdownToggled}
1512
- @change=${this.networksDropdownChanged}
1513
- >
1514
- <span slot="label" class="sr-only">${filterByNetworkLabel}</span>
1515
- ${this.tvMapsLoading ? loadingIndicator : nothing}
1516
- ${this.tvMapsErrored ? errorMessage : nothing}
1517
- </ia-combo-box>
1518
- <ia-combo-box
1519
- id="tv-shows"
1520
- class="tv-filter-dropdown"
1521
- placeholder=${filterByShowLabel}
1522
- max-autocomplete-entries="500"
1523
- clearable
1524
- wrap-arrow-keys
1525
- sort
1526
- .options=${shows.map((s, i) => ({ id: `show-${i}`, text: s }))}
1527
- @toggle=${this.tvDropdownToggled}
1528
- @change=${this.showsDropdownChanged}
1529
- >
1530
- <span slot="label" class="sr-only">${filterByShowLabel}</span>
1531
- ${this.tvMapsLoading ? loadingIndicator : nothing}
1532
- ${this.tvMapsErrored ? errorMessage : nothing}
1533
- </ia-combo-box>
1534
- </div>
1535
- `;
1536
- }
1537
-
1538
- /**
1539
- * The template for the facets component alone, without any surrounding wrappers.
1540
- */
1541
- private get facetsTemplate() {
1542
- if (FACETLESS_PAGE_ELEMENTS.includes(this.profileElement!)) return nothing;
1543
- if (this.facetLoadStrategy === 'off') {
1544
- return html`
1545
- <p class="facets-message">
1546
- ${msg('Facets are temporarily unavailable.')}
1547
- </p>
1548
- `;
1549
- }
1550
-
1551
- // We switch to TV facet ordering & date picker if we are in a TV collection or showing TV search results
1552
- const shouldUseTvInterface =
1553
- this.isTVCollection ||
1554
- (!this.withinCollection && this.searchType === SearchType.TV);
1555
- const facetDisplayOrder = shouldUseTvInterface
1556
- ? tvFacetDisplayOrder
1557
- : defaultFacetDisplayOrder;
1558
-
1559
- const facets = html`
1560
- <collection-facets
1561
- .collectionPagePath=${this.collectionPagePath}
1562
- .parentCollections=${this.dataSource.parentCollections}
1563
- .pageSpecifierParams=${this.dataSource.pageSpecifierParams}
1564
- .searchService=${this.searchService}
1565
- .featureFeedbackService=${this.featureFeedbackService}
1566
- .recaptchaManager=${this.recaptchaManager}
1567
- .resizeObserver=${this.resizeObserver}
1568
- .searchType=${this.searchType}
1569
- .aggregations=${this.dataSource.aggregations}
1570
- .histogramAggregation=${this.dataSource.histogramAggregation}
1571
- .minSelectedDate=${this.minSelectedDate}
1572
- .maxSelectedDate=${this.maxSelectedDate}
1573
- .selectedFacets=${this.selectedFacets}
1574
- .baseNavigationUrl=${this.baseNavigationUrl}
1575
- .collectionTitles=${this.dataSource.collectionTitles}
1576
- .tvChannelAliases=${this.dataSource.tvChannelAliases}
1577
- .showHistogramDatePicker=${this.showHistogramDatePicker}
1578
- .allowExpandingDatePicker=${!this.mobileView}
1579
- .allowDatePickerMonths=${shouldUseTvInterface}
1580
- .contentWidth=${this.contentWidth}
1581
- .query=${this.baseQuery}
1582
- .identifiers=${this.identifiers}
1583
- .filterMap=${this.dataSource.filterMap}
1584
- .isManageView=${this.isManageView}
1585
- .modalManager=${this.modalManager}
1586
- .analyticsHandler=${this.analyticsHandler}
1587
- .facetDisplayOrder=${facetDisplayOrder}
1588
- .isTvSearch=${shouldUseTvInterface}
1589
- ?collapsableFacets=${this.mobileView}
1590
- ?facetsLoading=${this.facetsLoading}
1591
- ?histogramAggregationLoading=${this.facetsLoading}
1592
- ?suppressMediatypeFacets=${this.suppressMediatypeFacets}
1593
- @facetClick=${this.facetClickHandler}
1594
- @facetsChanged=${this.facetsChanged}
1595
- @histogramDateRangeUpdated=${this.histogramDateRangeUpdated}
1596
- >
1597
- ${this.tvDropdownFiltersTemplate}
1598
- </collection-facets>
1599
- `;
1600
-
1601
- // If we are using one of the opt-in facet load strategies, we may need to wrap the
1602
- // desktop view facets in a <details> widget so that patrons can opt into loading them.
1603
- // In the `opt-in-or-login` case, we only do this if they are not logged in.
1604
- const showDesktopOptInWidget =
1605
- this.facetLoadStrategy === 'opt-in' ||
1606
- (this.facetLoadStrategy === 'opt-in-or-login' && !this.loggedIn);
1607
-
1608
- if (showDesktopOptInWidget && !this.mobileView) {
1609
- return html`
1610
- <details
1611
- class="desktop-facets-dropdown"
1612
- @toggle=${(e: Event) => {
1613
- const target = e.target as HTMLDetailsElement;
1614
- this.collapsibleFacetsVisible = target.open;
1615
- }}
1616
- >
1617
- <summary>
1618
- <span class="collapser-icon">${chevronIcon}</span>
1619
- <h2>${msg('Filters')}</h2>
1620
- </summary>
1621
- ${facets}
1622
- </details>
1623
- `;
1624
- }
1625
- // Otherwise, just render the facets component bare
1626
- return facets;
1627
- }
1628
-
1629
- /**
1630
- * The HTML template for the "Clear all filters" button, or `nothing` if no
1631
- * filters are currently active.
1632
- *
1633
- * @param mobile Whether to style/shorten the button for mobile view
1634
- */
1635
- private clearFiltersBtnTemplate(
1636
- mobile: boolean,
1637
- ): TemplateResult | typeof nothing {
1638
- if (!this.hasActiveFilters) return nothing;
1639
-
1640
- const buttonClasses = classMap({
1641
- 'clear-filters-btn': true,
1642
- mobile,
1643
- });
1644
-
1645
- const buttonText = mobile ? 'Clear all' : 'Clear all filters';
1646
-
1647
- return html`
1648
- <div class="clear-filters-btn-row">
1649
- ${mobile
1650
- ? html`<span class="clear-filters-btn-separator">&nbsp;</span>`
1651
- : nothing}
1652
- <button class=${buttonClasses} @click=${this.clearFilters}>
1653
- ${buttonText}
1654
- </button>
1655
- </div>
1656
- `;
1657
- }
1658
-
1659
- /**
1660
- * Template for the table header content that appears atop the compact list view.
1661
- */
1662
- private get listHeaderTemplate() {
1663
- return html`
1664
- <div id="list-header">
1665
- <tile-dispatcher
1666
- .tileDisplayMode=${'list-header'}
1667
- .resizeObserver=${this.resizeObserver}
1668
- .sortParam=${this.sortParam}
1669
- .defaultSortParam=${this.defaultSortParam}
1670
- .mobileBreakpoint=${this.mobileBreakpoint}
1671
- .loggedIn=${this.loggedIn}
1672
- .suppressBlurring=${this.shouldSuppressTileBlurring}
1673
- .tileActions=${this.tileActions}
1674
- >
1675
- </tile-dispatcher>
1676
- </div>
1677
- `;
1678
- }
1679
-
1680
- /**
1681
- * Handler for when the date picker's date range is changed.
1682
- */
1683
- private histogramDateRangeUpdated(
1684
- e: CustomEvent<{
1685
- minDate: string;
1686
- maxDate: string;
1687
- }>,
1688
- ) {
1689
- const { minDate, maxDate } = e.detail;
1690
- [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
1691
-
1692
- this.analyticsHandler?.sendEvent({
1693
- category: this.searchContext,
1694
- action: analyticsActions.histogramChanged,
1695
- label: this.dataSource.dateRangeQueryClause,
1696
- });
1697
- }
1698
-
1699
- /**
1700
- * Emits an event indicating a change in whether the manage mode is shown.
1701
- */
1702
- private emitManageModeChangedEvent(): void {
1703
- this.dispatchEvent(
1704
- new CustomEvent<boolean>('manageModeChanged', {
1705
- detail: this.isManageView,
1706
- }),
1707
- );
1708
- }
1709
-
1710
- /**
1711
- * Installs a new data source component and associated query state parameters into
1712
- * this component, causing it to efficiently update its views to represent the
1713
- * newly-provided data. In this way, one can reuse a single instance of
1714
- * <collection-browser> to handle multiple different sets of search results on
1715
- * a single page, each set of results being loaded & updated by its own data
1716
- * source.
1717
- *
1718
- * @param dataSource The data source component containing (or prepared to fetch)
1719
- * the tile data to be displayed.
1720
- * @param queryState The new query-related state that this component should
1721
- * represent, such as the search query, sort option, and any filters applied.
1722
- */
1723
- async installDataSourceAndQueryState(
1724
- dataSource: CollectionBrowserDataSourceInterface,
1725
- queryState: CollectionBrowserQueryState,
1726
- ): Promise<void> {
1727
- if (this.dataSource) this.removeController(this.dataSource);
1728
- this.dataSource = dataSource;
1729
- this.addController(this.dataSource);
1730
-
1731
- this.baseQuery = queryState.baseQuery;
1732
- this.profileElement = queryState.profileElement;
1733
- this.searchType = queryState.searchType;
1734
- this.selectedFacets =
1735
- queryState.selectedFacets ?? getDefaultSelectedFacets();
1736
- this.internalFilters = queryState.internalFilters;
1737
- this.minSelectedDate = queryState.minSelectedDate;
1738
- this.maxSelectedDate = queryState.maxSelectedDate;
1739
- this.selectedSort = queryState.selectedSort ?? SortField.default;
1740
- this.sortDirection = queryState.sortDirection;
1741
- this.selectedTitleFilter = queryState.selectedTitleFilter;
1742
- this.selectedCreatorFilter = queryState.selectedCreatorFilter;
1743
-
1744
- this.pagesToRender = this.initialPageNumber;
1745
-
1746
- // We set this flag during the update to prevent the URL state persistence
1747
- // from creating an unwanted extra history entry.
1748
- this.dataSourceInstallInProgress = true;
1749
- this.requestUpdate();
1750
- await this.updateComplete;
1751
- this.dataSourceInstallInProgress = false;
1752
-
1753
- if (!this.searchResultsLoading) {
1754
- this.setTotalResultCount(this.dataSource.totalResults);
1755
- this.setTileCount(this.dataSource.size);
1756
- }
1757
-
1758
- this.refreshVisibleResults();
1759
- }
1760
-
1761
- firstUpdated(): void {
1762
- this.restoreState();
1763
- this.setInitialSize();
1764
- }
1765
-
1766
- /**
1767
- * Determines the initial size of the content container and whether or not
1768
- * the mobile layout should be used.
1769
- */
1770
- setInitialSize(): void {
1771
- this.contentWidth = this.contentContainer.getBoundingClientRect().width;
1772
- this.mobileView =
1773
- this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
1774
- this.sendLayoutSizeAnalytics();
1775
- }
1776
-
1777
- /**
1778
- * Fires an analytics event indicating which type of layout was rendered:
1779
- * mobile or desktop.
1780
- */
1781
- private sendLayoutSizeAnalytics(): void {
1782
- if (this.analyticsHandler) {
1783
- this.layoutSizeAnalyticsSent = true;
1784
- this.analyticsHandler.sendEvent({
1785
- category: this.searchContext,
1786
- action: this.mobileView
1787
- ? analyticsActions.loadMobileView
1788
- : analyticsActions.loadDesktopView,
1789
- });
1790
- }
1791
- }
1792
-
1793
- updated(changed: PropertyValues) {
1794
- if (changed.has('placeholderType') && this.placeholderType === null) {
1795
- if (!this.leftColIntersectionObserver) {
1796
- this.setupLeftColumnScrollListeners();
1797
- }
1798
- if (!this.facetsIntersectionObserver) {
1799
- this.setupFacetsScrollListeners();
1800
- }
1801
- this.updateLeftColumnHeight();
1802
- }
1803
-
1804
- if (changed.has('analyticsHandler') && !this.layoutSizeAnalyticsSent) {
1805
- this.sendLayoutSizeAnalytics();
1806
- }
1807
-
1808
- if (
1809
- changed.has('displayMode') ||
1810
- changed.has('baseNavigationUrl') ||
1811
- changed.has('baseImageUrl') ||
1812
- changed.has('loggedIn') ||
1813
- changed.has('tileActions') ||
1814
- changed.has('tileLayoutType')
1815
- ) {
1816
- this.infiniteScroller?.reload();
1817
- }
1818
-
1819
- if (changed.has('profileElement')) {
1820
- this.applyDefaultProfileSort();
1821
- }
1822
-
1823
- if (changed.has('withinCollection') && this.withinCollection) {
1824
- // Set a sensible default collection sort while we load results, which we will later
1825
- // adjust based on any sort-by metadata once the response arrives.
1826
- if (!this.baseQuery) {
1827
- this.defaultSortField = this.withinCollection.startsWith('fav-')
1828
- ? SortField.datefavorited
1829
- : SortField.weeklyview;
1830
- this.defaultSortDirection = 'desc';
1831
- }
1832
- }
1833
-
1834
- if (changed.has('baseQuery')) {
1835
- this.emitBaseQueryChanged();
1836
- }
1837
- if (changed.has('searchType')) {
1838
- this.emitSearchTypeChanged();
1839
- }
1840
-
1841
- if (changed.has('currentPage') || changed.has('displayMode')) {
1842
- this.persistState();
1843
- }
1844
-
1845
- if (
1846
- changed.has('baseQuery') ||
1847
- changed.has('identifiers') ||
1848
- changed.has('minSelectedDate') ||
1849
- changed.has('maxSelectedDate') ||
1850
- changed.has('selectedFacets') ||
1851
- changed.has('searchService') ||
1852
- changed.has('withinCollection') ||
1853
- changed.has('withinProfile') ||
1854
- changed.has('profileElement')
1855
- ) {
1856
- this.dataSource.refreshLetterCounts();
1857
- }
1858
-
1859
- if (changed.has('selectedSort') || changed.has('sortDirection')) {
1860
- const prevSortDirection = changed.get('sortDirection') as SortDirection;
1861
- this.sendSortByAnalytics(prevSortDirection);
1862
- this.selectedSortChanged();
1863
- }
1864
-
1865
- if (changed.has('selectedTitleFilter')) {
1866
- this.sendFilterByTitleAnalytics(
1867
- changed.get('selectedTitleFilter') as string,
1868
- );
1869
- }
1870
- if (changed.has('selectedCreatorFilter')) {
1871
- this.sendFilterByCreatorAnalytics(
1872
- changed.get('selectedCreatorFilter') as string,
1873
- );
1874
- }
1875
-
1876
- this.updateFacetReadiness();
1877
-
1878
- if (
1879
- changed.has('baseQuery') ||
1880
- changed.has('identifiers') ||
1881
- changed.has('searchType') ||
1882
- changed.has('selectedTitleFilter') ||
1883
- changed.has('selectedCreatorFilter') ||
1884
- changed.has('minSelectedDate') ||
1885
- changed.has('maxSelectedDate') ||
1886
- changed.has('selectedSort') ||
1887
- changed.has('sortDirection') ||
1888
- changed.has('selectedFacets') ||
1889
- changed.has('searchService') ||
1890
- changed.has('withinCollection') ||
1891
- changed.has('withinProfile') ||
1892
- changed.has('profileElement')
1893
- ) {
1894
- this.handleQueryChange();
1895
- }
1896
-
1897
- if (changed.has('searchResultsLoading')) {
1898
- this.emitSearchResultsLoadingChanged();
1899
- }
1900
-
1901
- if (
1902
- changed.has('facetsLoading') &&
1903
- this.facetsLoading &&
1904
- this.collectionFacets
1905
- ) {
1906
- this.collectionFacets.moreLinksVisible =
1907
- this.searchType !== SearchType.FULLTEXT;
1908
- }
1909
-
1910
- if (changed.has('pagesToRender')) {
1911
- if (!this.dataSource.endOfDataReached && this.infiniteScroller) {
1912
- this.infiniteScroller.itemCount = this.estimatedTileCount;
1913
- }
1914
- }
1915
-
1916
- if (changed.has('isManageView')) {
1917
- if (this.isManageView) {
1918
- this.displayMode = 'grid';
1919
- this.fetchManageableSearchResults();
1920
- } else if (this.pageContext === 'search') this.infiniteScroller?.reload();
1921
-
1922
- this.infiniteScroller?.refreshAllVisibleCells();
1923
-
1924
- // Only emit change event if changing b/w true & false, not on initial value set.
1925
- if (changed.get('isManageView') !== undefined) {
1926
- this.emitManageModeChangedEvent();
1927
- }
1928
- }
1929
-
1930
- if (changed.has('resizeObserver')) {
1931
- const oldObserver = changed.get(
1932
- 'resizeObserver',
1933
- ) as SharedResizeObserverInterface;
1934
- if (oldObserver) this.disconnectResizeObserver(oldObserver);
1935
- this.setupResizeObserver();
1936
- }
1937
-
1938
- this.ensureAvailableTilesDisplayed();
1939
- }
1940
-
1941
- connectedCallback(): void {
1942
- super.connectedCallback?.();
1943
- this.setupStateRestorationObserver();
1944
- this.setupResizeObserver();
1945
- }
1946
-
1947
- disconnectedCallback(): void {
1948
- if (this.resizeObserver) {
1949
- this.disconnectResizeObserver(this.resizeObserver);
1950
- }
1951
- if (this.boundNavigationHandler) {
1952
- window.removeEventListener('popstate', this.boundNavigationHandler);
1953
- }
1954
-
1955
- if (this.deferredFetchTimer) {
1956
- window.clearTimeout(this.deferredFetchTimer);
1957
- this.deferredFetchTimer = 0;
1958
- }
1959
-
1960
- this.leftColIntersectionObserver?.disconnect();
1961
- this.facetsIntersectionObserver?.disconnect();
1962
- window.removeEventListener('resize', this.updateLeftColumnHeight);
1963
- }
1964
-
1965
- handleResize(entry: ResizeObserverEntry): void {
1966
- const previousView = this.mobileView;
1967
- if (entry.target === this.contentContainer) {
1968
- this.contentWidth = entry.contentRect.width;
1969
- this.mobileView =
1970
- this.contentWidth > 0 && this.contentWidth < this.mobileBreakpoint;
1971
- // If changing from desktop to mobile disable transition
1972
- if (this.mobileView && !previousView) {
1973
- this.isResizeToMobile = true;
1974
- }
1975
- }
1976
-
1977
- // Ensure the facet sidebar remains sized correctly
1978
- this.updateLeftColumnHeight();
1979
- }
1980
-
1981
- /**
1982
- * Ensures that if we have new results from the data source that are not yet
1983
- * displayed in the infinite scroller, that they are immediately reflected
1984
- * in the tile count.
1985
- */
1986
- private ensureAvailableTilesDisplayed(): void {
1987
- if (
1988
- this.infiniteScroller &&
1989
- this.infiniteScroller.itemCount < this.dataSource.size
1990
- ) {
1991
- this.setTileCount(
1992
- this.dataSource.endOfDataReached
1993
- ? this.dataSource.size
1994
- : this.estimatedTileCount,
1995
- );
1996
- }
1997
- }
1998
-
1999
- /**
2000
- * Updates the data source with the current state of facet readiness for loading,
2001
- * so that they will begin to load in at the appropriate time according to the
2002
- * current facet loading strategy.
2003
- */
2004
- private updateFacetReadiness(): void {
2005
- // There are two ways to opt into facet production:
2006
- // (1) have the facets dropdown open, or
2007
- // (2) if using the `opt-in-or-login` strategy, be logged into an account
2008
- const optedIn =
2009
- this.collapsibleFacetsVisible ||
2010
- (this.facetLoadStrategy === 'opt-in-or-login' && this.loggedIn);
2011
-
2012
- // In desktop view, we are always ready to load facets *unless* we are using one of the
2013
- // `opt-in` strategies and have not opted in (whether by login or UI interaction).
2014
- const usingOptInStrategy = ['opt-in', 'opt-in-or-login'].includes(
2015
- this.facetLoadStrategy,
2016
- );
2017
- const desktopFacetsReady =
2018
- !this.mobileView && (!usingOptInStrategy || optedIn);
2019
-
2020
- // In the mobile view, facets are considered ready provided we have opted in (whether by
2021
- // login or UI interaction).
2022
- const mobileFacetsReady = this.mobileView && optedIn;
2023
-
2024
- this.dataSource.handleFacetReadinessChange(
2025
- desktopFacetsReady || mobileFacetsReady,
2026
- );
2027
- }
2028
-
2029
- /**
2030
- * Sets up listeners for events that may require updating the left column height.
2031
- */
2032
- private setupLeftColumnScrollListeners(): void {
2033
- // We observe intersections between the left column's scroll sentinel and
2034
- // the viewport, so that we can ensure the left column is always sized to
2035
- // match the _available_ viewport height. This should generally be more
2036
- // performant than listening to scroll events on the page or column.
2037
- const leftColumnSentinel = this.shadowRoot?.querySelector(
2038
- '#left-column-scroll-sentinel',
2039
- );
2040
- if (leftColumnSentinel) {
2041
- this.leftColIntersectionObserver = new IntersectionObserver(
2042
- this.updateLeftColumnHeight,
2043
- {
2044
- threshold: [...Array(201).keys()].map(n => n / 200), // Threshold every 0.5%
2045
- },
2046
- );
2047
- this.leftColIntersectionObserver.observe(leftColumnSentinel);
2048
- }
2049
-
2050
- // We also listen for window resize events, as they are not always captured
2051
- // by the resize observer and can affect the desired height of the left column.
2052
- window.addEventListener('resize', this.updateLeftColumnHeight);
2053
- }
2054
-
2055
- /**
2056
- * Sets up listeners to control whether the facet sidebar shows its bottom fade-out.
2057
- * Note this uses a separate IntersectionObserver from the left column, because we
2058
- * don't need granular intersection thresholds for this.
2059
- */
2060
- private setupFacetsScrollListeners(): void {
2061
- const facetsSentinel = this.shadowRoot?.querySelector(
2062
- '#facets-scroll-sentinel',
2063
- );
2064
- if (facetsSentinel) {
2065
- this.facetsIntersectionObserver = new IntersectionObserver(
2066
- this.updateFacetFadeOut,
2067
- );
2068
- this.facetsIntersectionObserver.observe(facetsSentinel);
2069
- }
2070
- }
2071
-
2072
- /**
2073
- * Updates the height of the left column according to its position on the page.
2074
- * Arrow function ensures proper `this` binding.
2075
- */
2076
- private updateLeftColumnHeight = (): void => {
2077
- if (this.mobileView) {
2078
- this.leftColumn?.style?.removeProperty('height');
2079
- } else {
2080
- const clientTop = this.leftColumn?.getBoundingClientRect().top;
2081
- const columnHeight = window.innerHeight - (clientTop ?? 0);
2082
- const cssHeightValue =
2083
- clientTop === 0
2084
- ? null
2085
- : // Subtract off the column's top padding so that it doesn't overflow
2086
- `calc(${columnHeight}px - var(--leftColumnPaddingTop, 2rem))`;
2087
-
2088
- this.leftColumn?.style?.setProperty('height', cssHeightValue);
2089
- }
2090
- };
2091
-
2092
- /**
2093
- * Toggles whether the fade-out is visible at the bottom of the facets.
2094
- * It should only be visible if the facets are not scrolled to the bottom.
2095
- * Arrow function ensures proper `this` binding.
2096
- */
2097
- private updateFacetFadeOut = (entries: IntersectionObserverEntry[]): void => {
2098
- const fadeElmt = this.shadowRoot?.getElementById('facets-bottom-fade');
2099
- fadeElmt?.classList.toggle('hidden', entries?.[0]?.isIntersecting);
2100
- };
2101
-
2102
- /**
2103
- * Emits a `baseQueryChanged` event indicating an update to the search query.
2104
- */
2105
- private emitBaseQueryChanged() {
2106
- this.dispatchEvent(
2107
- new CustomEvent<{ baseQuery?: string }>('baseQueryChanged', {
2108
- detail: {
2109
- baseQuery: this.baseQuery,
2110
- },
2111
- }),
2112
- );
2113
- }
2114
-
2115
- /**
2116
- * Emits a `searchTypeChanged` event indicating an update to the search type
2117
- * (e.g., metadata vs. full-text).
2118
- */
2119
- private emitSearchTypeChanged() {
2120
- this.dispatchEvent(
2121
- new CustomEvent<SearchType>('searchTypeChanged', {
2122
- detail: this.searchType,
2123
- }),
2124
- );
2125
- }
2126
-
2127
- /**
2128
- * Emits a `facetPaneVisibilityChanged` event indicating that the facet pane has
2129
- * been toggled open or closed.
2130
- */
2131
- private emitFacetPaneVisibilityChanged(): void {
2132
- this.dispatchEvent(
2133
- new CustomEvent<boolean>('facetPaneVisibilityChanged', {
2134
- detail: this.facetPaneVisible,
2135
- }),
2136
- );
2137
- }
2138
-
2139
- /**
2140
- * Emits a `searchError` event indicating that the most recent search has encountered
2141
- * an error from the backend.
2142
- */
2143
- emitSearchError(): void {
2144
- this.dispatchEvent(
2145
- new CustomEvent<string>('searchError', {
2146
- detail: this.dataSource.queryErrorMessage,
2147
- }),
2148
- );
2149
- }
2150
-
2151
- /**
2152
- * Emits a `queryStateChanged` event indicating that one or more of this component's
2153
- * properties have changed in a way that could affect the set of search results.
2154
- */
2155
- emitQueryStateChanged() {
2156
- this.dispatchEvent(
2157
- new CustomEvent<CollectionBrowserQueryState>('queryStateChanged', {
2158
- detail: {
2159
- baseQuery: this.baseQuery,
2160
- withinCollection: this.withinCollection,
2161
- withinProfile: this.withinProfile,
2162
- profileElement: this.profileElement,
2163
- searchType: this.searchType,
2164
- selectedFacets: this.selectedFacets,
2165
- internalFilters: this.internalFilters,
2166
- minSelectedDate: this.minSelectedDate,
2167
- maxSelectedDate: this.maxSelectedDate,
2168
- selectedSort: this.selectedSort,
2169
- sortDirection: this.sortDirection,
2170
- selectedTitleFilter: this.selectedTitleFilter,
2171
- selectedCreatorFilter: this.selectedCreatorFilter,
2172
- },
2173
- }),
2174
- );
2175
- }
2176
-
2177
- /**
2178
- * Emits an `emptyResults` event indicating that we have received an empty result set
2179
- * for the most recent query.
2180
- */
2181
- emitEmptyResults() {
2182
- this.dispatchEvent(new Event('emptyResults'));
2183
- }
2184
-
2185
- private disconnectResizeObserver(
2186
- resizeObserver: SharedResizeObserverInterface,
2187
- ) {
2188
- resizeObserver.removeObserver({
2189
- target: this.contentContainer,
2190
- handler: this,
2191
- });
2192
- }
2193
-
2194
- private setupResizeObserver() {
2195
- if (!this.resizeObserver || !this.contentContainer) return;
2196
- this.resizeObserver.addObserver({
2197
- target: this.contentContainer,
2198
- handler: this,
2199
- });
2200
- }
2201
-
2202
- /**
2203
- * When the visible cells change from the infinite scroller, we want to emit
2204
- * which page is currently visible so the consumer can update its UI or the URL
2205
- *
2206
- * @param e
2207
- * @returns
2208
- */
2209
- private visibleCellsChanged(
2210
- e: CustomEvent<{ visibleCellIndices: number[] }>,
2211
- ) {
2212
- this.updateVisiblePage(e.detail.visibleCellIndices);
2213
- }
2214
-
2215
- /**
2216
- * Recomputes the current page from the given set of visible cell indices
2217
- * and emits `visiblePageChanged` if the page actually changed.
2218
- */
2219
- private updateVisiblePage(visibleCellIndices: number[]): void {
2220
- if (this.isScrollingToCell) return;
2221
- if (visibleCellIndices.length === 0) return;
2222
-
2223
- // The indices aren't necessarily sorted, so sort them here to ensure our
2224
- // calculations below find the right cell/page.
2225
- const sorted = [...visibleCellIndices].sort((a, b) => a - b);
2226
-
2227
- // For page determination, do not count more than a single page of visible cells,
2228
- // since otherwise patrons using very tall screens will be treated as one page
2229
- // further than they actually are.
2230
- const lastIndexWithinCurrentPage =
2231
- Math.min(this.pageSize, sorted.length) - 1;
2232
- const lastVisibleCellIndex = sorted[lastIndexWithinCurrentPage];
2233
- const lastVisibleCellPage =
2234
- Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
2235
-
2236
- this.setCurrentPage(lastVisibleCellPage);
2237
- }
2238
-
2239
- /**
2240
- * Sets the current page number and emits a `visiblePageChanged`
2241
- * event if the new page differs from the previous one.
2242
- */
2243
- private setCurrentPage(pageNumber: number): void {
2244
- if (this.currentPage === pageNumber) return;
2245
- this.currentPage = pageNumber;
2246
- this.dispatchEvent(
2247
- new CustomEvent('visiblePageChanged', {
2248
- detail: { pageNumber },
2249
- }),
2250
- );
2251
- }
2252
-
2253
- // we only want to scroll on the very first query change
2254
- // so this keeps track of whether we've already set the initial query
2255
- private initialQueryChangeHappened = false;
2256
-
2257
- private historyPopOccurred = false;
2258
-
2259
- // this lets us store the query key so we know if it's actually changed or not
2260
- private previousQueryKey?: string;
2261
-
2262
- /**
2263
- * A Promise which, after each query change, resolves once the fetches for the initial
2264
- * search have completed. Waits for *both* the hits and aggregations fetches to finish.
2265
- *
2266
- * Ensure you await this component's `updateComplete` promise before awaiting this
2267
- * one, to ensure you do not await an obsolete promise from the previous update.
2268
- */
2269
- get initialSearchComplete(): Promise<boolean> {
2270
- return this.dataSource.initialSearchComplete;
2271
- }
2272
-
2273
- /**
2274
- * Handler for whenever the component's properties change in a way that may require
2275
- * fetching new results.
2276
- */
2277
- private async handleQueryChange() {
2278
- // only reset if the query has actually changed
2279
- if (
2280
- !this.searchService ||
2281
- this.dataSource.pageFetchQueryKey === this.previousQueryKey
2282
- ) {
2283
- return;
2284
- }
2285
-
2286
- // If the new state prevents us from updating the search results, don't reset
2287
- if (this.baseQuery && !this.dataSource.canPerformSearch) {
2288
- return;
2289
- }
2290
-
2291
- this.previousQueryKey = this.dataSource.pageFetchQueryKey;
2292
-
2293
- this.totalResults = undefined;
2294
- this.pagesToRender =
2295
- this.initialPageNumber === 1
2296
- ? 2 // First two pages are batched into one request when starting from page 1
2297
- : this.initialPageNumber;
2298
-
2299
- // Reset the infinite scroller's item count, so that it
2300
- // shows tile placeholders until the new query's results load in
2301
- if (this.infiniteScroller) {
2302
- this.infiniteScroller.itemCount = this.estimatedTileCount;
2303
- this.infiniteScroller.reload();
2304
- }
2305
-
2306
- if (this.withinCollection && this.baseQuery?.trim()) {
2307
- this.defaultSortField = SortField.relevance;
2308
- this.defaultSortDirection = null;
2309
- }
2310
-
2311
- if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
2312
- this.scrollToPage(this.initialPageNumber);
2313
- }
2314
- this.initialQueryChangeHappened = true;
2315
-
2316
- // if the query changed as part of a window.history pop event, we don't want to
2317
- // persist the state because it overwrites the forward history
2318
- if (!this.historyPopOccurred) {
2319
- this.persistState();
2320
- }
2321
- this.historyPopOccurred = false;
2322
- }
2323
-
2324
- private setupStateRestorationObserver() {
2325
- if (!this.boundNavigationHandler) {
2326
- this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
2327
- }
2328
- // when the user navigates back, we want to update the UI to match the URL
2329
- window.addEventListener('popstate', this.boundNavigationHandler);
2330
- }
2331
-
2332
- private boundNavigationHandler?: () => void;
2333
-
2334
- private historyNavigationHandler() {
2335
- this.historyPopOccurred = true;
2336
- this.restoreState();
2337
- }
2338
-
2339
- private restoreState() {
2340
- const restorationState = this.restorationStateHandler.getRestorationState();
2341
- this.displayMode = restorationState.displayMode;
2342
- if (!this.suppressURLSinParam && restorationState.searchType != null)
2343
- this.searchType = restorationState.searchType;
2344
- this.selectedSort = restorationState.selectedSort ?? SortField.default;
2345
- this.sortDirection = restorationState.sortDirection ?? null;
2346
- this.selectedTitleFilter = restorationState.selectedTitleFilter ?? null;
2347
- this.selectedCreatorFilter = restorationState.selectedCreatorFilter ?? null;
2348
- this.selectedFacets = restorationState.selectedFacets;
2349
- if (!this.suppressURLQuery) this.baseQuery = restorationState.baseQuery;
2350
- this.setCurrentPage(restorationState.currentPage ?? 1);
2351
- this.minSelectedDate = restorationState.minSelectedDate;
2352
- this.maxSelectedDate = restorationState.maxSelectedDate;
2353
- if (this.currentPage && this.currentPage > 1) {
2354
- this.goToPage(this.currentPage);
2355
- }
2356
- }
2357
-
2358
- private persistState() {
2359
- const isDefaultSort = this.selectedSort === this.defaultSortField;
2360
- const restorationState: RestorationState = {
2361
- displayMode: this.displayMode,
2362
- searchType: this.suppressURLSinParam ? undefined : this.searchType,
2363
- selectedSort: isDefaultSort ? SortField.default : this.selectedSort,
2364
- sortDirection: this.sortDirection ?? undefined,
2365
- selectedFacets: this.selectedFacets ?? getDefaultSelectedFacets(),
2366
- baseQuery: this.suppressURLQuery ? undefined : this.baseQuery,
2367
- currentPage: this.currentPage,
2368
- titleQuery: this.titleQuery,
2369
- creatorQuery: this.creatorQuery,
2370
- minSelectedDate: this.minSelectedDate,
2371
- maxSelectedDate: this.maxSelectedDate,
2372
- selectedTitleFilter: this.selectedTitleFilter ?? undefined,
2373
- selectedCreatorFilter: this.selectedCreatorFilter ?? undefined,
2374
- };
2375
- const persistOptions: RestorationStatePersistOptions = {
2376
- forceReplace: this.dataSourceInstallInProgress,
2377
- persistMetadataSearchType: this.isTVCollection,
2378
- };
2379
- this.restorationStateHandler.persistState(restorationState, persistOptions);
2380
- }
2381
-
2382
- /**
2383
- * Emits a `searchResultsLoadingChanged` event indicating that our loading state has
2384
- * changed (either we have started loading new results, or we have finished loading them).
2385
- */
2386
- private emitSearchResultsLoadingChanged(): void {
2387
- this.dispatchEvent(
2388
- new CustomEvent<{ loading: boolean }>('searchResultsLoadingChanged', {
2389
- detail: {
2390
- loading: this.searchResultsLoading,
2391
- },
2392
- }),
2393
- );
2394
- }
2395
-
2396
- /**
2397
- * Handler for when the set of selected facets changes.
2398
- */
2399
- facetsChanged(e: CustomEvent<SelectedFacets>) {
2400
- this.selectedFacets = e.detail;
2401
- }
2402
-
2403
- /**
2404
- * Handler for when any facet is selected/unselected/hidden/unhidden.
2405
- * Fires analytics indicating the type of facet event that took place.
2406
- */
2407
- facetClickHandler({
2408
- detail: { facetType, bucket, negative },
2409
- }: CustomEvent<FacetEventDetails>): void {
2410
- let action: analyticsActions;
2411
- if (negative) {
2412
- action =
2413
- bucket.state !== 'none'
2414
- ? analyticsActions.facetNegativeSelected
2415
- : analyticsActions.facetNegativeDeselected;
2416
- } else {
2417
- action =
2418
- bucket.state !== 'none'
2419
- ? analyticsActions.facetSelected
2420
- : analyticsActions.facetDeselected;
2421
- }
2422
-
2423
- this.analyticsHandler?.sendEvent({
2424
- category: this.searchContext,
2425
- action,
2426
- label: facetType,
2427
- });
2428
- }
2429
-
2430
- private async scrollToPage(pageNumber: number): Promise<void> {
2431
- const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
2432
-
2433
- // Wait for the infinite scroller be rendered before proceeding
2434
- let waitAttempts = 0;
2435
- while (!this.infiniteScroller && waitAttempts < 20) {
2436
- await this.updateComplete;
2437
- waitAttempts++;
2438
- }
2439
- if (!this.infiniteScroller) return;
2440
-
2441
- // The scroller have its default `itemCount=0`, so propagate our estimated
2442
- // tile count before jumping to the desired page.
2443
- if (this.infiniteScroller.itemCount < this.estimatedTileCount) {
2444
- this.infiniteScroller.itemCount = this.estimatedTileCount;
2445
- await this.updateComplete;
2446
- }
2447
-
2448
- // Without this setTimeout(0), Safari just pauses until the `fetchPage`
2449
- // is complete then scrolls to the cell.
2450
- await new Promise<void>(resolve => {
2451
- setTimeout(resolve, 0);
2452
- });
2453
-
2454
- this.isScrollingToCell = true;
2455
- const scrolled = await this.infiniteScroller.scrollToCell(
2456
- cellIndexToScrollTo,
2457
- true,
2458
- );
2459
- this.isScrollingToCell = false;
2460
- this.infiniteScroller.refreshAllVisibleCells();
2461
-
2462
- // After we finish scrolling, recompute the visible page from the new state
2463
- // so that it doesn't fall out of sync.
2464
- if (scrolled) {
2465
- this.updateVisiblePage(this.infiniteScroller.getVisibleCellIndices());
2466
- }
2467
- }
2468
-
2469
- /**
2470
- * Whether sorting by relevance makes sense for the current state.
2471
- * Currently equivalent to having a non-empty query.
2472
- */
2473
- private get isRelevanceSortAvailable(): boolean {
2474
- return !!this.baseQuery?.trim();
2475
- }
2476
-
2477
- /**
2478
- * Sets the total number of tiles displayed in the infinite scroller.
2479
- */
2480
- setTileCount(count: number): void {
2481
- if (this.infiniteScroller) {
2482
- this.infiniteScroller.itemCount = count;
2483
- }
2484
- }
2485
-
2486
- /**
2487
- * Applies the default sort options for the TV search results page
2488
- */
2489
- applyDefaultTVSearchSort(): void {
2490
- this.defaultSortField = SortField.datearchived;
2491
- this.defaultSortDirection = 'desc';
2492
- }
2493
-
2494
- /**
2495
- * Applies any default sort option for the current collection, by checking
2496
- * for one in the collection's metadata. If none is found, defaults to sorting
2497
- * descending by:
2498
- * - Date Favorited for fav-* collections
2499
- * - Weekly views for all other collections
2500
- */
2501
- applyDefaultCollectionSort(collectionInfo?: CollectionExtraInfo): void {
2502
- if (this.baseQuery) {
2503
- // If there's a query set, then we default to relevance sorting regardless of
2504
- // the collection metadata-specified sort.
2505
- this.defaultSortField = SortField.relevance;
2506
- this.defaultSortDirection = null;
2507
- return;
2508
- }
2509
-
2510
- // Favorite collections sort on Date Favorited by default.
2511
- // Other collections fall back to sorting on weekly views.
2512
- const baseDefaultSort: string =
2513
- collectionInfo?.public_metadata?.identifier?.startsWith('fav-')
2514
- ? '-favoritedate'
2515
- : '-week';
2516
-
2517
- // The collection metadata may override the default sorting with something else
2518
- const metadataSort: string | undefined =
2519
- collectionInfo?.public_metadata?.['sort-by'];
2520
-
2521
- // Prefer the metadata-specified sort if one exists
2522
- const defaultSortToApply = metadataSort ?? baseDefaultSort;
2523
-
2524
- // Account for both -field and field:dir formats
2525
- let [field, dir] = defaultSortToApply.split(':');
2526
- if (field.startsWith('-')) {
2527
- field = field.slice(1);
2528
- dir = 'desc';
2529
- } else if (!['asc', 'desc'].includes(dir)) {
2530
- dir = 'asc';
2531
- }
2532
-
2533
- const sortOption = sortOptionFromAPIString(field);
2534
- const sortField = sortOption.field;
2535
- if (sortField && sortField !== SortField.default) {
2536
- this.defaultSortField = sortField;
2537
- this.defaultSortDirection = dir as SortDirection;
2538
- }
2539
- }
2540
-
2541
- /**
2542
- * Applies the default sort option for the current profile element
2543
- */
2544
- applyDefaultProfileSort(): void {
2545
- if (this.profileElement) {
2546
- const defaultSortField = defaultProfileElementSorts[this.profileElement];
2547
- this.defaultSortField = defaultSortField ?? SortField.weeklyview;
2548
- } else {
2549
- this.defaultSortField = SortField.weeklyview;
2550
- }
2551
-
2552
- this.defaultSortDirection = 'desc';
2553
- }
2554
-
2555
- /**
2556
- * This is useful for determining whether we need to reload the scroller.
2557
- *
2558
- * When the fetch completes, we need to reload the scroller if the cells for that
2559
- * page are visible, but if the page is not currenlty visible, we don't need to reload
2560
- */
2561
- get currentVisiblePageNumbers(): number[] {
2562
- const visibleCells = this.infiniteScroller?.getVisibleCellIndices() ?? [];
2563
- const visiblePages = new Set<number>();
2564
- visibleCells.forEach(cellIndex => {
2565
- const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
2566
- visiblePages.add(visiblePage);
2567
- });
2568
- return Array.from(visiblePages);
2569
- }
2570
-
2571
- /**
2572
- * Whether we are currently displaying results for a radio collection
2573
- */
2574
- private get isRadioCollection(): boolean {
2575
- const { withinCollection } = this;
2576
- const topCollections = ['radio'];
2577
- const isTopCollection = topCollections.includes(withinCollection as string);
2578
- const isSubCollection = topCollections.some(topCollxn =>
2579
- this.dataSource.parentCollections?.includes(topCollxn),
2580
- );
2581
- return isTopCollection || isSubCollection;
2582
- }
2583
-
2584
- /**
2585
- * Refreshes all visible result cells in the infinite scroller.
2586
- */
2587
- refreshVisibleResults(): void {
2588
- this.infiniteScroller?.refreshAllVisibleCells();
2589
- }
2590
-
2591
- /**
2592
- * Callback when a result is selected
2593
- */
2594
- resultSelected(event: CustomEvent<TileModel>): void {
2595
- if (this.isManageView) {
2596
- // Checked/unchecked state change -- rerender to ensure it propagates
2597
- // this.mapDataSource(model => ({ ...model }));
2598
- const cellIndex = this.dataSource.indexOf(event.detail);
2599
- if (cellIndex >= 0) this.infiniteScroller?.refreshCell(cellIndex);
2600
-
2601
- this.requestUpdate();
2602
- }
2603
-
2604
- this.analyticsHandler?.sendEvent({
2605
- category: this.searchContext,
2606
- action: analyticsActions.resultSelected,
2607
- label: event.detail.mediatype,
2608
- });
2609
-
2610
- this.analyticsHandler?.sendEvent({
2611
- category: this.searchContext,
2612
- action: analyticsActions.resultSelected,
2613
- label: `page-${this.currentPage}`,
2614
- });
2615
- }
2616
-
2617
- cellForIndex(index: number): HTMLTemplateResult | undefined {
2618
- const model = this.tileModelAtCellIndex(index);
2619
- if (!model) return undefined;
2620
-
2621
- // Tiles show dates in UTC by default.
2622
- // But for certain types of time-based media, we want them to use local time instead.
2623
- // Those local-time cases are:
2624
- // - TV or Radio search results
2625
- // - TV or Radio collection results
2626
- const isTVSearch = this.searchType === SearchType.TV;
2627
- const isRadioSearch = this.searchType === SearchType.RADIO;
2628
- const { isTVCollection, isRadioCollection } = this;
2629
- const shouldUseLocalTime =
2630
- isTVSearch || isRadioSearch || isTVCollection || isRadioCollection;
2631
-
2632
- return html`
2633
- <tile-dispatcher
2634
- .collectionPagePath=${this.collectionPagePath}
2635
- .baseNavigationUrl=${this.baseNavigationUrl}
2636
- .baseImageUrl=${this.baseImageUrl}
2637
- .model=${model}
2638
- .tileDisplayMode=${this.displayMode}
2639
- .resizeObserver=${this.resizeObserver}
2640
- .collectionTitles=${this.dataSource.collectionTitles}
2641
- .sortParam=${this.sortParam}
2642
- .defaultSortParam=${this.defaultSortParam}
2643
- .creatorFilter=${this.selectedCreatorFilter}
2644
- .mobileBreakpoint=${this.mobileBreakpoint}
2645
- .loggedIn=${this.loggedIn}
2646
- .suppressBlurring=${this.shouldSuppressTileBlurring}
2647
- .isManageView=${this.isManageView}
2648
- .tileActions=${this.tileActions}
2649
- .layoutType=${this.tileLayoutType}
2650
- ?showTvClips=${isTVSearch || isTVCollection}
2651
- ?enableHoverPane=${true}
2652
- ?useLocalTime=${shouldUseLocalTime}
2653
- @resultSelected=${(e: CustomEvent) => this.resultSelected(e)}
2654
- >
2655
- </tile-dispatcher>
2656
- `;
2657
- }
2658
-
2659
- /**
2660
- * When the user scrolls near to the bottom of the page, fetch the next page
2661
- * increase the number of pages to render and start fetching data for the new page
2662
- */
2663
- private scrollThresholdReached() {
2664
- if (!this.dataSource.endOfDataReached && this.dataSource.queryInitialized) {
2665
- this.pagesToRender += 1;
2666
- this.dataSource.fetchPage(this.pagesToRender);
2667
- }
2668
- }
2669
-
2670
- /**
2671
- * Fetches search results for privileged users when in manage view.
2672
- *
2673
- * This method:
2674
- * 1. Checks if we're in search context and either haven't loaded results yet, or have already finished loading with > 100 total results
2675
- * 2. Resets the datasource pagination state
2676
- * 3. Fetches first page with limit based on maxPagesToManage threshold
2677
- * 4. Reloads the infinite scroller to display new results
2678
- */
2679
- private fetchManageableSearchResults(): void {
2680
- const hasNotLoadedInitialResults = !this.dataSource.totalResults;
2681
- const hasLoadedWithMoreResultsAvailable =
2682
- !this.searchResultsLoading && this.dataSource.totalResults > 100;
2683
-
2684
- if (
2685
- this.pageContext === 'search' &&
2686
- (hasNotLoadedInitialResults || hasLoadedWithMoreResultsAvailable)
2687
- ) {
2688
- this.dataSource.resetPages();
2689
- this.dataSource.fetchPage(1, this.maxPagesToManage);
2690
- this.infiniteScroller?.reload();
2691
- }
2692
- }
2693
-
2694
- static get styles() {
2695
- return [
2696
- srOnlyStyle,
2697
- css`
2698
- :host {
2699
- display: block;
2700
- --leftColumnWidth: 18rem;
2701
- --leftColumnPaddingTop: 2rem;
2702
- --leftColumnPaddingRight: 2.5rem;
2703
- }
2704
-
2705
- #facet-top-view {
2706
- display: flex;
2707
- }
2708
-
2709
- /**
2710
- * When page width resizes from desktop to mobile, use this class to
2711
- * disable expand/collapse transition when loading.
2712
- */
2713
- .preload * {
2714
- transition: none !important;
2715
- -webkit-transition: none !important;
2716
- -moz-transition: none !important;
2717
- -ms-transition: none !important;
2718
- -o-transition: none !important;
2719
- }
2720
-
2721
- #content-container {
2722
- display: flex;
2723
- }
2724
-
2725
- empty-placeholder {
2726
- margin-top: var(--placeholderMarginTop, 0);
2727
- }
2728
-
2729
- .collapser-icon {
2730
- display: inline-block;
2731
- }
2732
-
2733
- .collapser-icon svg {
2734
- display: inline-block;
2735
- width: 12px;
2736
- height: 12px;
2737
- transition: transform 0.2s ease-out;
2738
- }
2739
-
2740
- #mobile-filter-collapse {
2741
- width: 100%;
2742
- }
2743
-
2744
- #mobile-filter-collapse > summary {
2745
- cursor: pointer;
2746
- list-style: none;
2747
- }
2748
-
2749
- #mobile-filter-collapse[open] > summary {
2750
- margin-bottom: 10px;
2751
- }
2752
-
2753
- #mobile-filter-collapse h2 {
2754
- display: inline-block;
2755
- margin: 0;
2756
- font-size: 2rem;
2757
- }
2758
-
2759
- #mobile-filter-collapse[open] svg {
2760
- transform: rotate(90deg);
2761
- }
2762
-
2763
- #content-container.mobile {
2764
- display: block;
2765
- }
2766
-
2767
- #right-column {
2768
- flex: 1;
2769
- position: relative;
2770
- min-height: 90vh;
2771
- border-right: 1px solid rgb(232, 232, 232);
2772
- margin-top: var(--rightColumnMarginTop, 0);
2773
- padding-top: var(--rightColumnPaddingTop, 2rem);
2774
- background: #fff;
2775
- }
2776
-
2777
- #left-column:not([hidden]) + #right-column {
2778
- border-left: 1px solid rgb(232, 232, 232);
2779
- }
2780
-
2781
- #right-column.smart-results-spacing {
2782
- padding-top: 0.5rem;
2783
- border-right: none;
2784
- background: transparent;
2785
- min-width: 0;
2786
- }
2787
-
2788
- #results {
2789
- background: #fff;
2790
- padding-left: 1rem;
2791
- padding-right: 1rem;
2792
- }
2793
-
2794
- #right-column.smart-results-spacing #results {
2795
- border-radius: 10px 10px 0px 0px;
2796
- padding-top: 0.5rem;
2797
- margin-top: 1rem;
2798
- }
2799
-
2800
- .mobile #right-column {
2801
- border-left: none;
2802
- }
2803
-
2804
- .mobile #results {
2805
- padding: 5px 5px 0;
2806
- }
2807
-
2808
- /*
2809
- * The results sit in a row with the optional results-aside slot, which
2810
- * lays out beside them as a flex item and takes its own width and spacing
2811
- */
2812
- #results-body {
2813
- display: flex;
2814
- align-items: flex-start;
2815
- }
2816
-
2817
- #results-main {
2818
- flex: 1;
2819
- min-width: 0;
2820
- }
2821
-
2822
- #left-column {
2823
- width: var(--leftColumnWidth, 18rem);
2824
- /* Prevents Safari from shrinking col at first draw */
2825
- min-width: var(--leftColumnWidth, 18rem);
2826
- padding-top: var(--leftColumnPaddingTop, 2rem);
2827
- /* Reduced padding by 0.2rem to add the invisible border in the rule below */
2828
- padding-right: calc(var(--leftColumnPaddingRight, 2.5rem) - 0.2rem);
2829
- border-right: 0.2rem solid transparent; /* Pads to the right of the scrollbar a bit */
2830
- z-index: 1;
2831
- }
2832
-
2833
- .desktop #left-column {
2834
- top: 0;
2835
- position: sticky;
2836
- height: calc(100vh - 2rem);
2837
- max-height: calc(100vh - 2rem);
2838
- overflow-x: hidden;
2839
- overflow-y: scroll;
2840
-
2841
- /*
2842
- * Firefox doesn't support any of the -webkit-scrollbar stuff below, but
2843
- * does at least give us a tiny bit of control over width & color.
2844
- */
2845
- scrollbar-width: thin;
2846
- scrollbar-color: transparent transparent;
2847
- }
2848
- .desktop #left-column:hover {
2849
- scrollbar-color: auto;
2850
- }
2851
- .desktop #left-column::-webkit-scrollbar {
2852
- appearance: none;
2853
- width: 6px;
2854
- }
2855
- .desktop #left-column::-webkit-scrollbar-button {
2856
- height: 3px;
2857
- background: transparent;
2858
- }
2859
- .desktop #left-column::-webkit-scrollbar-corner {
2860
- background: transparent;
2861
- }
2862
- .desktop #left-column::-webkit-scrollbar-thumb {
2863
- border-radius: 4px;
2864
- }
2865
- .desktop #left-column:hover::-webkit-scrollbar-thumb {
2866
- background: rgba(0, 0, 0, 0.15);
2867
- }
2868
- .desktop #left-column:hover::-webkit-scrollbar-thumb:hover {
2869
- background: rgba(0, 0, 0, 0.2);
2870
- }
2871
- .desktop #left-column:hover::-webkit-scrollbar-thumb:active {
2872
- background: rgba(0, 0, 0, 0.3);
2873
- }
2874
-
2875
- #facets-bottom-fade {
2876
- background: linear-gradient(
2877
- to bottom,
2878
- #fbfbfd00 0%,
2879
- #fbfbfdc0 50%,
2880
- #fbfbfd 80%,
2881
- #fbfbfd 100%
2882
- );
2883
- position: fixed;
2884
- bottom: 0;
2885
- height: 50px;
2886
- /* Wide enough to cover the content, but leave the scrollbar uncovered */
2887
- width: calc(
2888
- var(--leftColumnWidth) + var(--leftColumnPaddingRight) - 10px
2889
- );
2890
- z-index: 2;
2891
- pointer-events: none;
2892
- transition: height 0.1s ease;
2893
- }
2894
- #facets-bottom-fade.hidden {
2895
- height: 0;
2896
- }
2897
-
2898
- .facets-message {
2899
- font-size: 1.4rem;
2900
- }
2901
-
2902
- .desktop-facets-dropdown > summary {
2903
- cursor: pointer;
2904
- list-style: none;
2905
- }
2906
-
2907
- .desktop-facets-dropdown h2 {
2908
- display: inline-block;
2909
- margin: 0;
2910
- font-size: 1.6rem;
2911
- }
2912
-
2913
- .desktop-facets-dropdown[open] > summary {
2914
- margin-bottom: 10px;
2915
- }
2916
-
2917
- .desktop-facets-dropdown[open] svg {
2918
- transform: rotate(90deg);
2919
- }
2920
-
2921
- .desktop #left-column-scroll-sentinel {
2922
- width: 1px;
2923
- height: 100vh;
2924
- background: transparent;
2925
- }
2926
-
2927
- .desktop #facets-scroll-sentinel {
2928
- width: 1px;
2929
- height: 1px;
2930
- background: transparent;
2931
- }
2932
-
2933
- #facets-header-container {
2934
- display: flex;
2935
- justify-content: space-between;
2936
- align-items: flex-start;
2937
- clear: both;
2938
- }
2939
-
2940
- .desktop #facets-header-container {
2941
- flex-wrap: wrap;
2942
- }
2943
-
2944
- .mobile #left-column {
2945
- width: 100%;
2946
- min-width: 0;
2947
- padding: 5px 0;
2948
- border: 0;
2949
- }
2950
-
2951
- .clear-filters-btn-row {
2952
- display: inline-block;
2953
- }
2954
-
2955
- .desktop .clear-filters-btn-row {
2956
- width: 100%;
2957
- }
2958
-
2959
- .clear-filters-btn {
2960
- display: inline-block;
2961
- appearance: none;
2962
- margin: 0;
2963
- padding: 0;
2964
- border: 0;
2965
- background: none;
2966
- color: var(--ia-theme-link-color);
2967
- font-size: 1.4rem;
2968
- font-family: inherit;
2969
- cursor: pointer;
2970
- }
2971
-
2972
- .clear-filters-btn:hover {
2973
- text-decoration: underline;
2974
- }
2975
-
2976
- .clear-filters-btn-separator {
2977
- display: inline-block;
2978
- margin-left: 5px;
2979
- border-left: 1px solid #2c2c2c;
2980
- font-size: 1.4rem;
2981
- line-height: 1.3rem;
2982
- }
2983
-
2984
- #tv-filters {
2985
- margin-bottom: 15px;
2986
- }
2987
-
2988
- #tv-shows {
2989
- --comboBoxListWidth: 300px;
2990
- }
2991
-
2992
- .tv-filter-dropdown {
2993
- display: block;
2994
- font-size: 14px;
2995
- margin-left: 1px;
2996
- margin-bottom: 5px;
2997
- }
2998
-
2999
- .tv-filter-dropdown::part(combo-box) {
3000
- outline-offset: 1px;
3001
- }
3002
-
3003
- .tv-filter-dropdown::part(option) {
3004
- line-height: 1.1;
3005
- padding: 7px;
3006
- }
3007
-
3008
- .tv-filter-dropdown::part(clear-button) {
3009
- flex: 0 0 26px;
3010
- --combo-box-clear-icon-size: 14px;
3011
- }
3012
-
3013
- .tv-filter-dropdown::part(icon) {
3014
- width: 1.4rem;
3015
- height: 1.4rem;
3016
- }
3017
-
3018
- #facets-container {
3019
- position: relative;
3020
- max-height: 0;
3021
- transition: max-height 0.2s ease-in-out;
3022
- z-index: 1;
3023
- margin-top: var(--facetsContainerMarginTop, 3rem);
3024
- padding-bottom: 2rem;
3025
- }
3026
-
3027
- .desktop #facets-container {
3028
- width: 18rem;
3029
- }
3030
-
3031
- .mobile #facets-container {
3032
- overflow: hidden;
3033
- padding-bottom: 0;
3034
- padding-left: 10px;
3035
- padding-right: 10px;
3036
- }
3037
-
3038
- #facets-container.expanded {
3039
- max-height: 2000px;
3040
- }
3041
-
3042
- .results-section-heading {
3043
- margin: 0.5rem 0.3rem;
3044
- font-size: 2rem;
3045
- line-height: 25px;
3046
- }
3047
-
3048
- #results-total {
3049
- display: flex;
3050
- align-items: baseline;
3051
- }
3052
-
3053
- #results-total:not(.filtered) {
3054
- padding-bottom: 2rem;
3055
- }
3056
-
3057
- .mobile #results-total {
3058
- position: absolute;
3059
- right: 10px;
3060
- }
3061
-
3062
- #big-results-count {
3063
- font-size: 2.4rem;
3064
- font-weight: 500;
3065
- margin-right: 5px;
3066
- }
3067
-
3068
- .mobile #big-results-count {
3069
- font-size: 2rem;
3070
- }
3071
-
3072
- #big-results-label {
3073
- font-size: 1.4rem;
3074
- font-weight: 200;
3075
- }
3076
-
3077
- #list-header {
3078
- max-height: 4.2rem;
3079
- }
3080
-
3081
- .loading-cover {
3082
- position: absolute;
3083
- top: 0;
3084
- left: 0;
3085
- width: 100%;
3086
- height: 100%;
3087
- display: flex;
3088
- justify-content: center;
3089
- z-index: 1;
3090
- padding-top: 50px;
3091
- }
3092
-
3093
- #tile-blur-label {
3094
- display: flex;
3095
- align-items: center;
3096
- column-gap: 5px;
3097
- }
3098
-
3099
- #tile-blur-check {
3100
- margin: 0 5px 0 0;
3101
- width: 15px;
3102
- }
3103
-
3104
- circular-activity-indicator {
3105
- width: 30px;
3106
- height: 30px;
3107
- }
3108
-
3109
- sort-filter-bar {
3110
- display: block;
3111
- margin-bottom: 4rem;
3112
- }
3113
-
3114
- infinite-scroller {
3115
- display: block;
3116
- --infiniteScrollerRowGap: var(--collectionBrowserRowGap, 1.7rem);
3117
- --infiniteScrollerColGap: var(--collectionBrowserColGap, 1.7rem);
3118
- }
3119
-
3120
- infinite-scroller.list-compact {
3121
- --infiniteScrollerCellMinWidth: var(
3122
- --collectionBrowserCellMinWidth,
3123
- 100%
3124
- );
3125
- --infiniteScrollerCellMinHeight: 45px; /* override infinite scroller component */
3126
- --infiniteScrollerCellMaxHeight: 56px;
3127
- --infiniteScrollerRowGap: 10px;
3128
- }
3129
-
3130
- infinite-scroller.list-detail {
3131
- --infiniteScrollerCellMinWidth: var(
3132
- --collectionBrowserCellMinWidth,
3133
- 100%
3134
- );
3135
- --infiniteScrollerCellMinHeight: var(
3136
- --collectionBrowserCellMinHeight,
3137
- 5rem
3138
- );
3139
- /*
3140
- 30px in spec, compensating for a -4px margin
3141
- to align title with top of item image
3142
- src/tiles/list/tile-list.ts
3143
- */
3144
- --infiniteScrollerRowGap: 34px;
3145
- }
3146
-
3147
- .mobile infinite-scroller.list-detail {
3148
- --infiniteScrollerRowGap: 24px;
3149
- }
3150
-
3151
- infinite-scroller.grid {
3152
- --infiniteScrollerCellMinWidth: var(
3153
- --collectionBrowserCellMinWidth,
3154
- 17rem
3155
- );
3156
- --infiniteScrollerCellMaxWidth: var(
3157
- --collectionBrowserCellMaxWidth,
3158
- 1fr
3159
- );
3160
- }
3161
-
3162
- /* Allow tiles to shrink a bit further at smaller viewport widths */
3163
- @media screen and (max-width: 880px) {
3164
- infinite-scroller.grid {
3165
- --infiniteScrollerCellMinWidth: var(
3166
- --collectionBrowserCellMinWidth,
3167
- 15rem
3168
- );
3169
- }
3170
- }
3171
- /* At very small widths, maintain a 2-tile layout as far as it can reasonably go */
3172
- @media screen and (max-width: 360px) {
3173
- infinite-scroller.grid {
3174
- --infiniteScrollerCellMinWidth: var(
3175
- --collectionBrowserCellMinWidth,
3176
- 12rem
3177
- );
3178
- }
3179
- }
3180
-
3181
- infinite-scroller.hidden {
3182
- display: none;
3183
- }
3184
- `,
3185
- ];
3186
- }
3187
- }