@internetarchive/collection-browser 3.3.2 → 3.3.4-alpha-webdev7761.0

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 (543) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +27 -27
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +4 -4
  7. package/.prettierignore +1 -1
  8. package/LICENSE +661 -661
  9. package/README.md +83 -83
  10. package/dist/index.d.ts +16 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/src/app-root.d.ts +105 -0
  13. package/dist/src/app-root.js +1076 -0
  14. package/dist/src/app-root.js.map +1 -0
  15. package/dist/src/assets/img/icons/arrow-left.d.ts +2 -0
  16. package/dist/src/assets/img/icons/arrow-left.js +10 -0
  17. package/dist/src/assets/img/icons/arrow-left.js.map +1 -0
  18. package/dist/src/assets/img/icons/arrow-right.d.ts +2 -0
  19. package/dist/src/assets/img/icons/arrow-right.js +10 -0
  20. package/dist/src/assets/img/icons/arrow-right.js.map +1 -0
  21. package/dist/src/assets/img/icons/chevron.d.ts +2 -0
  22. package/dist/src/assets/img/icons/chevron.js +4 -0
  23. package/dist/src/assets/img/icons/chevron.js.map +1 -0
  24. package/dist/src/assets/img/icons/close-circle-dark.d.ts +2 -0
  25. package/dist/src/assets/img/icons/close-circle-dark.js +5 -0
  26. package/dist/src/assets/img/icons/close-circle-dark.js.map +1 -0
  27. package/dist/src/assets/img/icons/contract.d.ts +2 -0
  28. package/dist/src/assets/img/icons/contract.js +9 -0
  29. package/dist/src/assets/img/icons/contract.js.map +1 -0
  30. package/dist/src/assets/img/icons/empty-query.d.ts +2 -0
  31. package/dist/src/assets/img/icons/empty-query.js +5 -0
  32. package/dist/src/assets/img/icons/empty-query.js.map +1 -0
  33. package/dist/src/assets/img/icons/expand.d.ts +2 -0
  34. package/dist/src/assets/img/icons/expand.js +9 -0
  35. package/dist/src/assets/img/icons/expand.js.map +1 -0
  36. package/dist/src/assets/img/icons/eye-closed.d.ts +2 -0
  37. package/dist/src/assets/img/icons/eye-closed.js +5 -0
  38. package/dist/src/assets/img/icons/eye-closed.js.map +1 -0
  39. package/dist/src/assets/img/icons/eye.d.ts +2 -0
  40. package/dist/src/assets/img/icons/eye.js +5 -0
  41. package/dist/src/assets/img/icons/eye.js.map +1 -0
  42. package/dist/src/assets/img/icons/favorite-filled.d.ts +1 -0
  43. package/dist/src/assets/img/icons/favorite-filled.js +10 -0
  44. package/dist/src/assets/img/icons/favorite-filled.js.map +1 -0
  45. package/dist/src/assets/img/icons/favorite-unfilled.d.ts +1 -0
  46. package/dist/src/assets/img/icons/favorite-unfilled.js +9 -0
  47. package/dist/src/assets/img/icons/favorite-unfilled.js.map +1 -0
  48. package/dist/src/assets/img/icons/filter.d.ts +2 -0
  49. package/dist/src/assets/img/icons/filter.js +10 -0
  50. package/dist/src/assets/img/icons/filter.js.map +1 -0
  51. package/dist/src/assets/img/icons/login-required.d.ts +1 -0
  52. package/dist/src/assets/img/icons/login-required.js +18 -0
  53. package/dist/src/assets/img/icons/login-required.js.map +1 -0
  54. package/dist/src/assets/img/icons/mediatype/account.d.ts +1 -0
  55. package/dist/src/assets/img/icons/mediatype/account.js +14 -0
  56. package/dist/src/assets/img/icons/mediatype/account.js.map +1 -0
  57. package/dist/src/assets/img/icons/mediatype/audio.d.ts +1 -0
  58. package/dist/src/assets/img/icons/mediatype/audio.js +14 -0
  59. package/dist/src/assets/img/icons/mediatype/audio.js.map +1 -0
  60. package/dist/src/assets/img/icons/mediatype/collection.d.ts +1 -0
  61. package/dist/src/assets/img/icons/mediatype/collection.js +12 -0
  62. package/dist/src/assets/img/icons/mediatype/collection.js.map +1 -0
  63. package/dist/src/assets/img/icons/mediatype/data.d.ts +1 -0
  64. package/dist/src/assets/img/icons/mediatype/data.js +15 -0
  65. package/dist/src/assets/img/icons/mediatype/data.js.map +1 -0
  66. package/dist/src/assets/img/icons/mediatype/etree.d.ts +1 -0
  67. package/dist/src/assets/img/icons/mediatype/etree.js +14 -0
  68. package/dist/src/assets/img/icons/mediatype/etree.js.map +1 -0
  69. package/dist/src/assets/img/icons/mediatype/film.d.ts +1 -0
  70. package/dist/src/assets/img/icons/mediatype/film.js +14 -0
  71. package/dist/src/assets/img/icons/mediatype/film.js.map +1 -0
  72. package/dist/src/assets/img/icons/mediatype/images.d.ts +1 -0
  73. package/dist/src/assets/img/icons/mediatype/images.js +13 -0
  74. package/dist/src/assets/img/icons/mediatype/images.js.map +1 -0
  75. package/dist/src/assets/img/icons/mediatype/radio.d.ts +1 -0
  76. package/dist/src/assets/img/icons/mediatype/radio.js +15 -0
  77. package/dist/src/assets/img/icons/mediatype/radio.js.map +1 -0
  78. package/dist/src/assets/img/icons/mediatype/search.d.ts +1 -0
  79. package/dist/src/assets/img/icons/mediatype/search.js +14 -0
  80. package/dist/src/assets/img/icons/mediatype/search.js.map +1 -0
  81. package/dist/src/assets/img/icons/mediatype/software.d.ts +1 -0
  82. package/dist/src/assets/img/icons/mediatype/software.js +13 -0
  83. package/dist/src/assets/img/icons/mediatype/software.js.map +1 -0
  84. package/dist/src/assets/img/icons/mediatype/texts.d.ts +1 -0
  85. package/dist/src/assets/img/icons/mediatype/texts.js +13 -0
  86. package/dist/src/assets/img/icons/mediatype/texts.js.map +1 -0
  87. package/dist/src/assets/img/icons/mediatype/tv-commercial.d.ts +1 -0
  88. package/dist/src/assets/img/icons/mediatype/tv-commercial.js +12 -0
  89. package/dist/src/assets/img/icons/mediatype/tv-commercial.js.map +1 -0
  90. package/dist/src/assets/img/icons/mediatype/tv-fact-check.d.ts +1 -0
  91. package/dist/src/assets/img/icons/mediatype/tv-fact-check.js +12 -0
  92. package/dist/src/assets/img/icons/mediatype/tv-fact-check.js.map +1 -0
  93. package/dist/src/assets/img/icons/mediatype/tv-quote.d.ts +1 -0
  94. package/dist/src/assets/img/icons/mediatype/tv-quote.js +12 -0
  95. package/dist/src/assets/img/icons/mediatype/tv-quote.js.map +1 -0
  96. package/dist/src/assets/img/icons/mediatype/tv.d.ts +1 -0
  97. package/dist/src/assets/img/icons/mediatype/tv.js +14 -0
  98. package/dist/src/assets/img/icons/mediatype/tv.js.map +1 -0
  99. package/dist/src/assets/img/icons/mediatype/video.d.ts +1 -0
  100. package/dist/src/assets/img/icons/mediatype/video.js +14 -0
  101. package/dist/src/assets/img/icons/mediatype/video.js.map +1 -0
  102. package/dist/src/assets/img/icons/mediatype/web.d.ts +1 -0
  103. package/dist/src/assets/img/icons/mediatype/web.js +13 -0
  104. package/dist/src/assets/img/icons/mediatype/web.js.map +1 -0
  105. package/dist/src/assets/img/icons/null-result.d.ts +2 -0
  106. package/dist/src/assets/img/icons/null-result.js +5 -0
  107. package/dist/src/assets/img/icons/null-result.js.map +1 -0
  108. package/dist/src/assets/img/icons/quote.d.ts +1 -0
  109. package/dist/src/assets/img/icons/quote.js +7 -0
  110. package/dist/src/assets/img/icons/quote.js.map +1 -0
  111. package/dist/src/assets/img/icons/restricted.d.ts +1 -0
  112. package/dist/src/assets/img/icons/restricted.js +13 -0
  113. package/dist/src/assets/img/icons/restricted.js.map +1 -0
  114. package/dist/src/assets/img/icons/reviews.d.ts +1 -0
  115. package/dist/src/assets/img/icons/reviews.js +11 -0
  116. package/dist/src/assets/img/icons/reviews.js.map +1 -0
  117. package/dist/src/assets/img/icons/upload.d.ts +1 -0
  118. package/dist/src/assets/img/icons/upload.js +12 -0
  119. package/dist/src/assets/img/icons/upload.js.map +1 -0
  120. package/dist/src/assets/img/icons/views.d.ts +1 -0
  121. package/dist/src/assets/img/icons/views.js +11 -0
  122. package/dist/src/assets/img/icons/views.js.map +1 -0
  123. package/dist/src/circular-activity-indicator.d.ts +5 -0
  124. package/dist/src/circular-activity-indicator.js +66 -0
  125. package/dist/src/circular-activity-indicator.js.map +1 -0
  126. package/dist/src/collection-browser.d.ts +692 -0
  127. package/dist/src/collection-browser.js +2669 -0
  128. package/dist/src/collection-browser.js.map +1 -0
  129. package/dist/src/collection-facets/facet-row.d.ts +30 -0
  130. package/dist/src/collection-facets/facet-row.js +266 -0
  131. package/dist/src/collection-facets/facet-row.js.map +1 -0
  132. package/dist/src/collection-facets/facet-tombstone-row.d.ts +5 -0
  133. package/dist/src/collection-facets/facet-tombstone-row.js +43 -0
  134. package/dist/src/collection-facets/facet-tombstone-row.js.map +1 -0
  135. package/dist/src/collection-facets/facets-template.d.ts +13 -0
  136. package/dist/src/collection-facets/facets-template.js +68 -0
  137. package/dist/src/collection-facets/facets-template.js.map +1 -0
  138. package/dist/src/collection-facets/models.d.ts +9 -0
  139. package/dist/src/collection-facets/models.js +10 -0
  140. package/dist/src/collection-facets/models.js.map +1 -0
  141. package/dist/src/collection-facets/more-facets-content.d.ts +109 -0
  142. package/dist/src/collection-facets/more-facets-content.js +547 -0
  143. package/dist/src/collection-facets/more-facets-content.js.map +1 -0
  144. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -0
  145. package/dist/src/collection-facets/more-facets-pagination.js +264 -0
  146. package/dist/src/collection-facets/more-facets-pagination.js.map +1 -0
  147. package/dist/src/collection-facets/smart-facets/dedupe.d.ts +10 -0
  148. package/dist/src/collection-facets/smart-facets/dedupe.js +35 -0
  149. package/dist/src/collection-facets/smart-facets/dedupe.js.map +1 -0
  150. package/dist/src/collection-facets/smart-facets/heuristics/browser-language/browser-language-heuristic.d.ts +5 -0
  151. package/dist/src/collection-facets/smart-facets/heuristics/browser-language/browser-language-heuristic.js +24 -0
  152. package/dist/src/collection-facets/smart-facets/heuristics/browser-language/browser-language-heuristic.js.map +1 -0
  153. package/dist/src/collection-facets/smart-facets/heuristics/index.d.ts +3 -0
  154. package/dist/src/collection-facets/smart-facets/heuristics/index.js +4 -0
  155. package/dist/src/collection-facets/smart-facets/heuristics/index.js.map +1 -0
  156. package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.d.ts +4 -0
  157. package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.js +14 -0
  158. package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.js.map +1 -0
  159. package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.d.ts +6 -0
  160. package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.js +68 -0
  161. package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.js.map +1 -0
  162. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.d.ts +9 -0
  163. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.js +69 -0
  164. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.js.map +1 -0
  165. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.d.ts +21 -0
  166. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js +76 -0
  167. package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js.map +1 -0
  168. package/dist/src/collection-facets/smart-facets/models.d.ts +30 -0
  169. package/dist/src/collection-facets/smart-facets/models.js +2 -0
  170. package/dist/src/collection-facets/smart-facets/models.js.map +1 -0
  171. package/dist/src/collection-facets/smart-facets/smart-facet-bar.d.ts +54 -0
  172. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js +383 -0
  173. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js.map +1 -0
  174. package/dist/src/collection-facets/smart-facets/smart-facet-button.d.ts +11 -0
  175. package/dist/src/collection-facets/smart-facets/smart-facet-button.js +133 -0
  176. package/dist/src/collection-facets/smart-facets/smart-facet-button.js.map +1 -0
  177. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.d.ts +28 -0
  178. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js +172 -0
  179. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js.map +1 -0
  180. package/dist/src/collection-facets/smart-facets/smart-facet-equals.d.ts +2 -0
  181. package/dist/src/collection-facets/smart-facets/smart-facet-equals.js +13 -0
  182. package/dist/src/collection-facets/smart-facets/smart-facet-equals.js.map +1 -0
  183. package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.d.ts +5 -0
  184. package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.js +18 -0
  185. package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.js.map +1 -0
  186. package/dist/src/collection-facets/toggle-switch.d.ts +41 -0
  187. package/dist/src/collection-facets/toggle-switch.js +174 -0
  188. package/dist/src/collection-facets/toggle-switch.js.map +1 -0
  189. package/dist/src/collection-facets.d.ts +113 -0
  190. package/dist/src/collection-facets.js +884 -0
  191. package/dist/src/collection-facets.js.map +1 -0
  192. package/dist/src/data-source/collection-browser-data-source-interface.d.ts +270 -0
  193. package/dist/src/data-source/collection-browser-data-source-interface.js +2 -0
  194. package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -0
  195. package/dist/src/data-source/collection-browser-data-source.d.ts +418 -0
  196. package/dist/src/data-source/collection-browser-data-source.js +1121 -0
  197. package/dist/src/data-source/collection-browser-data-source.js.map +1 -0
  198. package/dist/src/data-source/collection-browser-query-state.d.ts +48 -0
  199. package/dist/src/data-source/collection-browser-query-state.js +2 -0
  200. package/dist/src/data-source/collection-browser-query-state.js.map +1 -0
  201. package/dist/src/data-source/models.d.ts +43 -0
  202. package/dist/src/data-source/models.js +9 -0
  203. package/dist/src/data-source/models.js.map +1 -0
  204. package/dist/src/empty-placeholder.d.ts +23 -0
  205. package/dist/src/empty-placeholder.js +165 -0
  206. package/dist/src/empty-placeholder.js.map +1 -0
  207. package/dist/src/expanded-date-picker.d.ts +50 -0
  208. package/dist/src/expanded-date-picker.js +182 -0
  209. package/dist/src/expanded-date-picker.js.map +1 -0
  210. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -0
  211. package/dist/src/language-code-handler/language-code-handler.js +27 -0
  212. package/dist/src/language-code-handler/language-code-handler.js.map +1 -0
  213. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -0
  214. package/dist/src/language-code-handler/language-code-mapping.js +563 -0
  215. package/dist/src/language-code-handler/language-code-mapping.js.map +1 -0
  216. package/dist/src/manage/manage-bar.d.ts +58 -0
  217. package/dist/src/manage/manage-bar.js +237 -0
  218. package/dist/src/manage/manage-bar.js.map +1 -0
  219. package/dist/src/manage/remove-items-modal-content.d.ts +9 -0
  220. package/dist/src/manage/remove-items-modal-content.js +104 -0
  221. package/dist/src/manage/remove-items-modal-content.js.map +1 -0
  222. package/dist/src/mediatype/mediatype-config.d.ts +11 -0
  223. package/dist/src/mediatype/mediatype-config.js +116 -0
  224. package/dist/src/mediatype/mediatype-config.js.map +1 -0
  225. package/dist/src/models.d.ts +298 -0
  226. package/dist/src/models.js +507 -0
  227. package/dist/src/models.js.map +1 -0
  228. package/dist/src/restoration-state-handler.d.ts +74 -0
  229. package/dist/src/restoration-state-handler.js +397 -0
  230. package/dist/src/restoration-state-handler.js.map +1 -0
  231. package/dist/src/sort-filter-bar/alpha-bar-tooltip.d.ts +6 -0
  232. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js +60 -0
  233. package/dist/src/sort-filter-bar/alpha-bar-tooltip.js.map +1 -0
  234. package/dist/src/sort-filter-bar/alpha-bar.d.ts +21 -0
  235. package/dist/src/sort-filter-bar/alpha-bar.js +241 -0
  236. package/dist/src/sort-filter-bar/alpha-bar.js.map +1 -0
  237. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -0
  238. package/dist/src/sort-filter-bar/img/compact.js +5 -0
  239. package/dist/src/sort-filter-bar/img/compact.js.map +1 -0
  240. package/dist/src/sort-filter-bar/img/list.d.ts +1 -0
  241. package/dist/src/sort-filter-bar/img/list.js +5 -0
  242. package/dist/src/sort-filter-bar/img/list.js.map +1 -0
  243. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.d.ts +1 -0
  244. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js +15 -0
  245. package/dist/src/sort-filter-bar/img/sort-toggle-disabled.js.map +1 -0
  246. package/dist/src/sort-filter-bar/img/sort-toggle-down.d.ts +1 -0
  247. package/dist/src/sort-filter-bar/img/sort-toggle-down.js +17 -0
  248. package/dist/src/sort-filter-bar/img/sort-toggle-down.js.map +1 -0
  249. package/dist/src/sort-filter-bar/img/sort-toggle-up.d.ts +1 -0
  250. package/dist/src/sort-filter-bar/img/sort-toggle-up.js +17 -0
  251. package/dist/src/sort-filter-bar/img/sort-toggle-up.js.map +1 -0
  252. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -0
  253. package/dist/src/sort-filter-bar/img/sort-triangle.js +5 -0
  254. package/dist/src/sort-filter-bar/img/sort-triangle.js.map +1 -0
  255. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -0
  256. package/dist/src/sort-filter-bar/img/tile.js +5 -0
  257. package/dist/src/sort-filter-bar/img/tile.js.map +1 -0
  258. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +278 -0
  259. package/dist/src/sort-filter-bar/sort-filter-bar.js +1161 -0
  260. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -0
  261. package/dist/src/styles/ia-button.d.ts +2 -0
  262. package/dist/src/styles/ia-button.js +134 -0
  263. package/dist/src/styles/ia-button.js.map +1 -0
  264. package/dist/src/styles/item-image-styles.d.ts +8 -0
  265. package/dist/src/styles/item-image-styles.js +123 -0
  266. package/dist/src/styles/item-image-styles.js.map +1 -0
  267. package/dist/src/styles/sr-only.d.ts +1 -0
  268. package/dist/src/styles/sr-only.js +18 -0
  269. package/dist/src/styles/sr-only.js.map +1 -0
  270. package/dist/src/tiles/base-tile-component.d.ts +27 -0
  271. package/dist/src/tiles/base-tile-component.js +82 -0
  272. package/dist/src/tiles/base-tile-component.js.map +1 -0
  273. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -0
  274. package/dist/src/tiles/collection-browser-loading-tile.js +29 -0
  275. package/dist/src/tiles/collection-browser-loading-tile.js.map +1 -0
  276. package/dist/src/tiles/grid/account-tile.d.ts +18 -0
  277. package/dist/src/tiles/grid/account-tile.js +111 -0
  278. package/dist/src/tiles/grid/account-tile.js.map +1 -0
  279. package/dist/src/tiles/grid/collection-tile.d.ts +15 -0
  280. package/dist/src/tiles/grid/collection-tile.js +160 -0
  281. package/dist/src/tiles/grid/collection-tile.js.map +1 -0
  282. package/dist/src/tiles/grid/item-tile.d.ts +41 -0
  283. package/dist/src/tiles/grid/item-tile.js +321 -0
  284. package/dist/src/tiles/grid/item-tile.js.map +1 -0
  285. package/dist/src/tiles/grid/search-tile.d.ts +10 -0
  286. package/dist/src/tiles/grid/search-tile.js +95 -0
  287. package/dist/src/tiles/grid/search-tile.js.map +1 -0
  288. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.d.ts +1 -0
  289. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +128 -0
  290. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js.map +1 -0
  291. package/dist/src/tiles/grid/tile-stats.d.ts +58 -0
  292. package/dist/src/tiles/grid/tile-stats.js +204 -0
  293. package/dist/src/tiles/grid/tile-stats.js.map +1 -0
  294. package/dist/src/tiles/hover/hover-pane-controller.d.ts +228 -0
  295. package/dist/src/tiles/hover/hover-pane-controller.js +446 -0
  296. package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -0
  297. package/dist/src/tiles/hover/tile-hover-pane.d.ts +20 -0
  298. package/dist/src/tiles/hover/tile-hover-pane.js +185 -0
  299. package/dist/src/tiles/hover/tile-hover-pane.js.map +1 -0
  300. package/dist/src/tiles/image-block.d.ts +19 -0
  301. package/dist/src/tiles/image-block.js +175 -0
  302. package/dist/src/tiles/image-block.js.map +1 -0
  303. package/dist/src/tiles/item-image.d.ts +40 -0
  304. package/dist/src/tiles/item-image.js +191 -0
  305. package/dist/src/tiles/item-image.js.map +1 -0
  306. package/dist/src/tiles/list/tile-list-compact-header.d.ts +6 -0
  307. package/dist/src/tiles/list/tile-list-compact-header.js +85 -0
  308. package/dist/src/tiles/list/tile-list-compact-header.js.map +1 -0
  309. package/dist/src/tiles/list/tile-list-compact.d.ts +19 -0
  310. package/dist/src/tiles/list/tile-list-compact.js +223 -0
  311. package/dist/src/tiles/list/tile-list-compact.js.map +1 -0
  312. package/dist/src/tiles/list/tile-list.d.ts +54 -0
  313. package/dist/src/tiles/list/tile-list.js +621 -0
  314. package/dist/src/tiles/list/tile-list.js.map +1 -0
  315. package/dist/src/tiles/models.d.ts +1 -0
  316. package/dist/src/tiles/models.js +2 -0
  317. package/dist/src/tiles/models.js.map +1 -0
  318. package/dist/src/tiles/overlay/icon-overlay.d.ts +8 -0
  319. package/dist/src/tiles/overlay/icon-overlay.js +55 -0
  320. package/dist/src/tiles/overlay/icon-overlay.js.map +1 -0
  321. package/dist/src/tiles/overlay/text-overlay.d.ts +9 -0
  322. package/dist/src/tiles/overlay/text-overlay.js +74 -0
  323. package/dist/src/tiles/overlay/text-overlay.js.map +1 -0
  324. package/dist/src/tiles/review-block.d.ts +12 -0
  325. package/dist/src/tiles/review-block.js +134 -0
  326. package/dist/src/tiles/review-block.js.map +1 -0
  327. package/dist/src/tiles/text-snippet-block.d.ts +27 -0
  328. package/dist/src/tiles/text-snippet-block.js +132 -0
  329. package/dist/src/tiles/text-snippet-block.js.map +1 -0
  330. package/dist/src/tiles/tile-dispatcher.d.ts +71 -0
  331. package/dist/src/tiles/tile-dispatcher.js +472 -0
  332. package/dist/src/tiles/tile-dispatcher.js.map +1 -0
  333. package/dist/src/tiles/tile-display-value-provider.d.ts +47 -0
  334. package/dist/src/tiles/tile-display-value-provider.js +95 -0
  335. package/dist/src/tiles/tile-display-value-provider.js.map +1 -0
  336. package/dist/src/tiles/tile-mediatype-icon.d.ts +27 -0
  337. package/dist/src/tiles/tile-mediatype-icon.js +130 -0
  338. package/dist/src/tiles/tile-mediatype-icon.js.map +1 -0
  339. package/dist/src/utils/analytics-events.d.ts +28 -0
  340. package/dist/src/utils/analytics-events.js +31 -0
  341. package/dist/src/utils/analytics-events.js.map +1 -0
  342. package/dist/src/utils/array-equals.d.ts +4 -0
  343. package/dist/src/utils/array-equals.js +11 -0
  344. package/dist/src/utils/array-equals.js.map +1 -0
  345. package/dist/src/utils/collapse-repeated-quotes.d.ts +11 -0
  346. package/dist/src/utils/collapse-repeated-quotes.js +14 -0
  347. package/dist/src/utils/collapse-repeated-quotes.js.map +1 -0
  348. package/dist/src/utils/facet-utils.d.ts +83 -0
  349. package/dist/src/utils/facet-utils.js +152 -0
  350. package/dist/src/utils/facet-utils.js.map +1 -0
  351. package/dist/src/utils/format-count.d.ts +7 -0
  352. package/dist/src/utils/format-count.js +76 -0
  353. package/dist/src/utils/format-count.js.map +1 -0
  354. package/dist/src/utils/format-date.d.ts +16 -0
  355. package/dist/src/utils/format-date.js +33 -0
  356. package/dist/src/utils/format-date.js.map +1 -0
  357. package/dist/src/utils/format-unit-size.d.ts +2 -0
  358. package/dist/src/utils/format-unit-size.js +34 -0
  359. package/dist/src/utils/format-unit-size.js.map +1 -0
  360. package/dist/src/utils/local-date-from-utc.d.ts +9 -0
  361. package/dist/src/utils/local-date-from-utc.js +16 -0
  362. package/dist/src/utils/local-date-from-utc.js.map +1 -0
  363. package/dist/src/utils/log.d.ts +7 -0
  364. package/dist/src/utils/log.js +14 -0
  365. package/dist/src/utils/log.js.map +1 -0
  366. package/dist/src/utils/resolve-mediatype.d.ts +8 -0
  367. package/dist/src/utils/resolve-mediatype.js +24 -0
  368. package/dist/src/utils/resolve-mediatype.js.map +1 -0
  369. package/dist/src/utils/sha1.d.ts +2 -0
  370. package/dist/src/utils/sha1.js +9 -0
  371. package/dist/src/utils/sha1.js.map +1 -0
  372. package/dist/test/collection-browser.test.d.ts +1 -0
  373. package/dist/test/collection-browser.test.js +1721 -0
  374. package/dist/test/collection-browser.test.js.map +1 -0
  375. package/dist/test/collection-facets/facet-row.test.d.ts +1 -0
  376. package/dist/test/collection-facets/facet-row.test.js +274 -0
  377. package/dist/test/collection-facets/facet-row.test.js.map +1 -0
  378. package/dist/test/collection-facets/facets-template.test.d.ts +1 -0
  379. package/dist/test/collection-facets/facets-template.test.js +101 -0
  380. package/dist/test/collection-facets/facets-template.test.js.map +1 -0
  381. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -0
  382. package/dist/test/collection-facets/more-facets-content.test.js +169 -0
  383. package/dist/test/collection-facets/more-facets-content.test.js.map +1 -0
  384. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -0
  385. package/dist/test/collection-facets/more-facets-pagination.test.js +132 -0
  386. package/dist/test/collection-facets/more-facets-pagination.test.js.map +1 -0
  387. package/dist/test/collection-facets/toggle-switch.test.d.ts +1 -0
  388. package/dist/test/collection-facets/toggle-switch.test.js +96 -0
  389. package/dist/test/collection-facets/toggle-switch.test.js.map +1 -0
  390. package/dist/test/collection-facets.test.d.ts +2 -0
  391. package/dist/test/collection-facets.test.js +745 -0
  392. package/dist/test/collection-facets.test.js.map +1 -0
  393. package/dist/test/data-source/collection-browser-data-source.test.d.ts +1 -0
  394. package/dist/test/data-source/collection-browser-data-source.test.js +102 -0
  395. package/dist/test/data-source/collection-browser-data-source.test.js.map +1 -0
  396. package/dist/test/empty-placeholder.test.d.ts +1 -0
  397. package/dist/test/empty-placeholder.test.js +63 -0
  398. package/dist/test/empty-placeholder.test.js.map +1 -0
  399. package/dist/test/expanded-date-picker.test.d.ts +1 -0
  400. package/dist/test/expanded-date-picker.test.js +130 -0
  401. package/dist/test/expanded-date-picker.test.js.map +1 -0
  402. package/dist/test/icon-overlay.test.d.ts +1 -0
  403. package/dist/test/icon-overlay.test.js +30 -0
  404. package/dist/test/icon-overlay.test.js.map +1 -0
  405. package/dist/test/image-block.test.d.ts +1 -0
  406. package/dist/test/image-block.test.js +218 -0
  407. package/dist/test/image-block.test.js.map +1 -0
  408. package/dist/test/item-image.test.d.ts +1 -0
  409. package/dist/test/item-image.test.js +196 -0
  410. package/dist/test/item-image.test.js.map +1 -0
  411. package/dist/test/manage/manage-bar.test.d.ts +2 -0
  412. package/dist/test/manage/manage-bar.test.js +106 -0
  413. package/dist/test/manage/manage-bar.test.js.map +1 -0
  414. package/dist/test/manage/remove-items-modal-content.test.d.ts +1 -0
  415. package/dist/test/manage/remove-items-modal-content.test.js +65 -0
  416. package/dist/test/manage/remove-items-modal-content.test.js.map +1 -0
  417. package/dist/test/mediatype-config.test.d.ts +1 -0
  418. package/dist/test/mediatype-config.test.js +11 -0
  419. package/dist/test/mediatype-config.test.js.map +1 -0
  420. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -0
  421. package/dist/test/mocks/mock-analytics-handler.js +16 -0
  422. package/dist/test/mocks/mock-analytics-handler.js.map +1 -0
  423. package/dist/test/mocks/mock-search-responses.d.ts +31 -0
  424. package/dist/test/mocks/mock-search-responses.js +1241 -0
  425. package/dist/test/mocks/mock-search-responses.js.map +1 -0
  426. package/dist/test/mocks/mock-search-service.d.ts +16 -0
  427. package/dist/test/mocks/mock-search-service.js +65 -0
  428. package/dist/test/mocks/mock-search-service.js.map +1 -0
  429. package/dist/test/restoration-state-handler.test.d.ts +1 -0
  430. package/dist/test/restoration-state-handler.test.js +343 -0
  431. package/dist/test/restoration-state-handler.test.js.map +1 -0
  432. package/dist/test/review-block.test.d.ts +1 -0
  433. package/dist/test/review-block.test.js +48 -0
  434. package/dist/test/review-block.test.js.map +1 -0
  435. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.d.ts +1 -0
  436. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js +13 -0
  437. package/dist/test/sort-filter-bar/alpha-bar-tooltip.test.js.map +1 -0
  438. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +1 -0
  439. package/dist/test/sort-filter-bar/alpha-bar.test.js +74 -0
  440. package/dist/test/sort-filter-bar/alpha-bar.test.js.map +1 -0
  441. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -0
  442. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +609 -0
  443. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -0
  444. package/dist/test/text-overlay.test.d.ts +1 -0
  445. package/dist/test/text-overlay.test.js +42 -0
  446. package/dist/test/text-overlay.test.js.map +1 -0
  447. package/dist/test/text-snippet-block.test.d.ts +1 -0
  448. package/dist/test/text-snippet-block.test.js +63 -0
  449. package/dist/test/text-snippet-block.test.js.map +1 -0
  450. package/dist/test/tile-stats.test.d.ts +1 -0
  451. package/dist/test/tile-stats.test.js +128 -0
  452. package/dist/test/tile-stats.test.js.map +1 -0
  453. package/dist/test/tiles/grid/account-tile.test.d.ts +1 -0
  454. package/dist/test/tiles/grid/account-tile.test.js +96 -0
  455. package/dist/test/tiles/grid/account-tile.test.js.map +1 -0
  456. package/dist/test/tiles/grid/collection-tile.test.d.ts +1 -0
  457. package/dist/test/tiles/grid/collection-tile.test.js +96 -0
  458. package/dist/test/tiles/grid/collection-tile.test.js.map +1 -0
  459. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -0
  460. package/dist/test/tiles/grid/item-tile.test.js +427 -0
  461. package/dist/test/tiles/grid/item-tile.test.js.map +1 -0
  462. package/dist/test/tiles/grid/search-tile.test.d.ts +1 -0
  463. package/dist/test/tiles/grid/search-tile.test.js +66 -0
  464. package/dist/test/tiles/grid/search-tile.test.js.map +1 -0
  465. package/dist/test/tiles/hover/hover-pane-controller.test.d.ts +1 -0
  466. package/dist/test/tiles/hover/hover-pane-controller.test.js +329 -0
  467. package/dist/test/tiles/hover/hover-pane-controller.test.js.map +1 -0
  468. package/dist/test/tiles/hover/tile-hover-pane.test.d.ts +1 -0
  469. package/dist/test/tiles/hover/tile-hover-pane.test.js +57 -0
  470. package/dist/test/tiles/hover/tile-hover-pane.test.js.map +1 -0
  471. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -0
  472. package/dist/test/tiles/list/tile-list-compact.test.js +251 -0
  473. package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -0
  474. package/dist/test/tiles/list/tile-list.test.d.ts +1 -0
  475. package/dist/test/tiles/list/tile-list.test.js +469 -0
  476. package/dist/test/tiles/list/tile-list.test.js.map +1 -0
  477. package/dist/test/tiles/tile-dispatcher.test.d.ts +1 -0
  478. package/dist/test/tiles/tile-dispatcher.test.js +231 -0
  479. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -0
  480. package/dist/test/tiles/tile-display-value-provider.test.d.ts +1 -0
  481. package/dist/test/tiles/tile-display-value-provider.test.js +142 -0
  482. package/dist/test/tiles/tile-display-value-provider.test.js.map +1 -0
  483. package/dist/test/tiles/tile-mediatype-icon.test.d.ts +1 -0
  484. package/dist/test/tiles/tile-mediatype-icon.test.js +145 -0
  485. package/dist/test/tiles/tile-mediatype-icon.test.js.map +1 -0
  486. package/dist/test/utils/array-equals.test.d.ts +1 -0
  487. package/dist/test/utils/array-equals.test.js +27 -0
  488. package/dist/test/utils/array-equals.test.js.map +1 -0
  489. package/dist/test/utils/format-count.test.d.ts +1 -0
  490. package/dist/test/utils/format-count.test.js +24 -0
  491. package/dist/test/utils/format-count.test.js.map +1 -0
  492. package/dist/test/utils/format-date.test.d.ts +1 -0
  493. package/dist/test/utils/format-date.test.js +61 -0
  494. package/dist/test/utils/format-date.test.js.map +1 -0
  495. package/dist/test/utils/format-unit-size.test.d.ts +1 -0
  496. package/dist/test/utils/format-unit-size.test.js +18 -0
  497. package/dist/test/utils/format-unit-size.test.js.map +1 -0
  498. package/dist/test/utils/local-date-from-utc.test.d.ts +1 -0
  499. package/dist/test/utils/local-date-from-utc.test.js +27 -0
  500. package/dist/test/utils/local-date-from-utc.test.js.map +1 -0
  501. package/eslint.config.mjs +53 -53
  502. package/index.html +24 -24
  503. package/local.archive.org.cert +86 -86
  504. package/local.archive.org.key +27 -27
  505. package/package.json +118 -117
  506. package/renovate.json +6 -6
  507. package/src/collection-browser.ts +2954 -2829
  508. package/src/collection-facets/facet-row.ts +299 -296
  509. package/src/collection-facets/models.ts +10 -10
  510. package/src/collection-facets/more-facets-content.ts +639 -639
  511. package/src/collection-facets.ts +1005 -995
  512. package/src/data-source/collection-browser-data-source-interface.ts +345 -333
  513. package/src/data-source/collection-browser-data-source.ts +1441 -1401
  514. package/src/data-source/collection-browser-query-state.ts +59 -65
  515. package/src/data-source/models.ts +56 -43
  516. package/src/manage/manage-bar.ts +247 -247
  517. package/src/models.ts +866 -870
  518. package/src/restoration-state-handler.ts +542 -544
  519. package/src/tiles/base-tile-component.ts +65 -65
  520. package/src/tiles/grid/account-tile.ts +113 -113
  521. package/src/tiles/grid/collection-tile.ts +163 -163
  522. package/src/tiles/grid/item-tile.ts +340 -340
  523. package/src/tiles/grid/search-tile.ts +90 -90
  524. package/src/tiles/grid/styles/tile-grid-shared-styles.ts +130 -130
  525. package/src/tiles/hover/hover-pane-controller.ts +613 -517
  526. package/src/tiles/hover/tile-hover-pane.ts +184 -180
  527. package/src/tiles/list/tile-list-compact.ts +239 -239
  528. package/src/tiles/list/tile-list.ts +700 -700
  529. package/src/tiles/tile-dispatcher.ts +517 -490
  530. package/src/utils/format-date.ts +62 -62
  531. package/test/collection-browser.test.ts +2413 -2403
  532. package/test/collection-facets/facet-row.test.ts +375 -375
  533. package/test/collection-facets.test.ts +928 -928
  534. package/test/restoration-state-handler.test.ts +480 -510
  535. package/test/tiles/grid/item-tile.test.ts +520 -520
  536. package/test/tiles/hover/hover-pane-controller.test.ts +418 -353
  537. package/test/tiles/list/tile-list-compact.test.ts +282 -282
  538. package/test/tiles/list/tile-list.test.ts +552 -552
  539. package/test/tiles/tile-dispatcher.test.ts +283 -187
  540. package/test/utils/format-date.test.ts +89 -89
  541. package/tsconfig.json +20 -20
  542. package/web-dev-server.config.mjs +30 -30
  543. package/web-test-runner.config.mjs +41 -41
@@ -0,0 +1,1121 @@
1
+ import { FilterConstraint, FilterMapBuilder, SearchType, } from '@internetarchive/search-service';
2
+ import { prefixFilterAggregationKeys, TileModel, SortField, SORT_OPTIONS, } from '../models';
3
+ import { FACETLESS_PAGE_ELEMENTS, } from './models';
4
+ import { sha1 } from '../utils/sha1';
5
+ import { log } from '../utils/log';
6
+ import { mergeSelectedFacets } from '../utils/facet-utils';
7
+ export class CollectionBrowserDataSource {
8
+ /**
9
+ * @inheritdoc
10
+ */
11
+ get initialSearchComplete() {
12
+ return this._initialSearchCompletePromise;
13
+ }
14
+ constructor(
15
+ /** The host element to which this controller should attach listeners */
16
+ host,
17
+ /** Default size of result pages */
18
+ pageSize = 50) {
19
+ this.host = host;
20
+ this.pageSize = pageSize;
21
+ /**
22
+ * All pages of tile models that have been fetched so far, indexed by their page
23
+ * number (with the first being page 1).
24
+ */
25
+ this.pages = {};
26
+ /**
27
+ * Tile offset to apply when looking up tiles in the pages, in order to maintain
28
+ * page alignment after tiles are removed.
29
+ */
30
+ this.offset = 0;
31
+ /**
32
+ * Total number of tile models stored in this data source's pages
33
+ */
34
+ this.numTileModels = 0;
35
+ /**
36
+ * How many consecutive pages should be batched together on the initial page fetch.
37
+ * Defaults to 2 pages.
38
+ */
39
+ this.numInitialPages = 2;
40
+ /**
41
+ * A set of fetch IDs that are valid for the current query state
42
+ */
43
+ this.fetchesInProgress = new Set();
44
+ /**
45
+ * A record of the query key used for the last search.
46
+ * If this changes, we need to load new results.
47
+ */
48
+ this.previousQueryKey = '';
49
+ /**
50
+ * Whether the initial page of search results for the current query state
51
+ * is presently being fetched.
52
+ */
53
+ this.searchResultsLoading = false;
54
+ /**
55
+ * Whether the facets (aggregations) for the current query state are
56
+ * presently being fetched.
57
+ */
58
+ this.facetsLoading = false;
59
+ /**
60
+ * Whether the facets are actually visible -- if not, then we can delay any facet
61
+ * fetches until they become visible.
62
+ */
63
+ this.facetsReadyToLoad = false;
64
+ /**
65
+ * Whether further query changes should be ignored and not trigger fetches
66
+ */
67
+ this.suppressFetches = false;
68
+ /**
69
+ * @inheritdoc
70
+ */
71
+ this.totalResults = 0;
72
+ /**
73
+ * @inheritdoc
74
+ */
75
+ this.endOfDataReached = false;
76
+ /**
77
+ * @inheritdoc
78
+ */
79
+ this.queryInitialized = false;
80
+ /**
81
+ * @inheritdoc
82
+ */
83
+ this.collectionTitles = new Map();
84
+ /**
85
+ * @inheritdoc
86
+ */
87
+ this.tvChannelMaps = {};
88
+ /**
89
+ * @inheritdoc
90
+ */
91
+ this.tvChannelAliases = new Map();
92
+ /**
93
+ * @inheritdoc
94
+ */
95
+ this.parentCollections = [];
96
+ /**
97
+ * @inheritdoc
98
+ */
99
+ this.prefixFilterCountMap = {};
100
+ /**
101
+ * Internal property to store the private value backing the `initialSearchComplete` getter.
102
+ */
103
+ this._initialSearchCompletePromise = Promise.resolve(true);
104
+ /**
105
+ * @inheritdoc
106
+ */
107
+ this.checkAllTiles = () => {
108
+ this.map(model => {
109
+ const cloned = model.clone();
110
+ cloned.checked = true;
111
+ return cloned;
112
+ });
113
+ };
114
+ /**
115
+ * @inheritdoc
116
+ */
117
+ this.uncheckAllTiles = () => {
118
+ this.map(model => {
119
+ const cloned = model.clone();
120
+ cloned.checked = false;
121
+ return cloned;
122
+ });
123
+ };
124
+ /**
125
+ * @inheritdoc
126
+ */
127
+ this.removeCheckedTiles = () => {
128
+ // To make sure our data source remains page-aligned, we will offset our data source by
129
+ // the number of removed tiles, so that we can just add the offset when the infinite
130
+ // scroller queries for cell contents.
131
+ // This only matters while we're still viewing the same set of results. If the user changes
132
+ // their query/filters/sort, then the data source is overwritten and the offset cleared.
133
+ const { checkedTileModels, uncheckedTileModels } = this;
134
+ const numChecked = checkedTileModels.length;
135
+ if (numChecked === 0)
136
+ return;
137
+ this.offset += numChecked;
138
+ const newPages = {};
139
+ // Which page the remaining tile models start on, post-offset
140
+ let offsetPageNumber = Math.floor(this.offset / this.pageSize) + 1;
141
+ let indexOnPage = this.offset % this.pageSize;
142
+ // Fill the pages up to that point with empty models
143
+ for (let page = 1; page <= offsetPageNumber; page += 1) {
144
+ const remainingHidden = this.offset - this.pageSize * (page - 1);
145
+ const offsetCellsOnPage = Math.min(this.pageSize, remainingHidden);
146
+ newPages[page] = Array(offsetCellsOnPage).fill(undefined);
147
+ }
148
+ // Shift all the remaining tiles into their new positions in the data source
149
+ for (const model of uncheckedTileModels) {
150
+ if (!newPages[offsetPageNumber])
151
+ newPages[offsetPageNumber] = [];
152
+ newPages[offsetPageNumber].push(model);
153
+ indexOnPage += 1;
154
+ if (indexOnPage >= this.pageSize) {
155
+ offsetPageNumber += 1;
156
+ indexOnPage = 0;
157
+ }
158
+ }
159
+ // Swap in the new pages
160
+ this.pages = newPages;
161
+ this.numTileModels -= numChecked;
162
+ this.totalResults -= numChecked;
163
+ this.host.setTileCount(this.size);
164
+ this.host.setTotalResultCount(this.totalResults);
165
+ this.requestHostUpdate();
166
+ this.refreshVisibleResults();
167
+ };
168
+ // Just setting some property values
169
+ }
170
+ hostConnected() {
171
+ this.setSearchResultsLoading(this.searchResultsLoading);
172
+ this.setFacetsLoading(this.facetsLoading);
173
+ }
174
+ hostUpdate() {
175
+ // This reactive controller hook is run whenever the host component (collection-browser) performs an update.
176
+ // We check whether the host's state has changed in a way which should trigger a reset & new results fetch.
177
+ // Only the currently-installed data source should react to the update
178
+ if (!this.activeOnHost)
179
+ return;
180
+ // Copy loading states onto the host
181
+ this.setSearchResultsLoading(this.searchResultsLoading);
182
+ this.setFacetsLoading(this.facetsLoading);
183
+ // Can't perform searches without a search service
184
+ if (!this.host.searchService)
185
+ return;
186
+ // We should only reset if part of the full query state has changed
187
+ const queryKeyChanged = this.pageFetchQueryKey !== this.previousQueryKey;
188
+ if (!queryKeyChanged)
189
+ return;
190
+ // We should only reset if either:
191
+ // (a) our state permits a valid search, or
192
+ // (b) we have a blank query that we're showing a placeholder/message for
193
+ const queryIsEmpty = !this.host.baseQuery;
194
+ if (!(this.canPerformSearch || queryIsEmpty))
195
+ return;
196
+ if (this.activeOnHost)
197
+ this.host.emitQueryStateChanged();
198
+ this.handleQueryChange();
199
+ }
200
+ /**
201
+ * Returns whether this data source is the one currently installed on the host component.
202
+ */
203
+ get activeOnHost() {
204
+ return this.host.dataSource === this;
205
+ }
206
+ /**
207
+ * @inheritdoc
208
+ */
209
+ get size() {
210
+ return this.numTileModels;
211
+ }
212
+ /**
213
+ * @inheritdoc
214
+ */
215
+ reset() {
216
+ log('Resetting CB data source');
217
+ this.pages = {};
218
+ this.aggregations = {};
219
+ this.histogramAggregation = undefined;
220
+ this.pageElements = undefined;
221
+ this.parentCollections = [];
222
+ this.previousQueryKey = '';
223
+ this.queryErrorMessage = undefined;
224
+ this.offset = 0;
225
+ this.numTileModels = 0;
226
+ this.endOfDataReached = false;
227
+ this.queryInitialized = false;
228
+ this.facetsLoading = false;
229
+ // Invalidate any fetches in progress
230
+ this.fetchesInProgress.clear();
231
+ this.setTotalResultCount(0);
232
+ this.requestHostUpdate();
233
+ }
234
+ /**
235
+ * @inheritdoc
236
+ */
237
+ resetPages() {
238
+ if (Object.keys(this.pages).length < this.host.maxPagesToManage) {
239
+ this.pages = {};
240
+ // Invalidate any page fetches in progress (keep facet fetches)
241
+ this.fetchesInProgress.forEach(key => {
242
+ if (!key.startsWith('facets-'))
243
+ this.fetchesInProgress.delete(key);
244
+ });
245
+ this.requestHostUpdate();
246
+ }
247
+ }
248
+ /**
249
+ * @inheritdoc
250
+ */
251
+ addPage(pageNum, pageTiles) {
252
+ this.pages[pageNum] = pageTiles;
253
+ this.numTileModels += pageTiles.length;
254
+ this.requestHostUpdate();
255
+ }
256
+ /**
257
+ * @inheritdoc
258
+ */
259
+ addMultiplePages(firstPageNum, tiles) {
260
+ const numPages = Math.ceil(tiles.length / this.pageSize);
261
+ for (let i = 0; i < numPages; i += 1) {
262
+ const pageStartIndex = this.pageSize * i;
263
+ this.addPage(firstPageNum + i, tiles.slice(pageStartIndex, pageStartIndex + this.pageSize));
264
+ }
265
+ const visiblePages = this.host.currentVisiblePageNumbers;
266
+ const needsReload = visiblePages.some(page => page >= firstPageNum && page <= firstPageNum + numPages);
267
+ if (needsReload) {
268
+ this.refreshVisibleResults();
269
+ }
270
+ }
271
+ /**
272
+ * @inheritdoc
273
+ */
274
+ getPage(pageNum) {
275
+ return this.pages[pageNum];
276
+ }
277
+ /**
278
+ * @inheritdoc
279
+ */
280
+ getAllPages() {
281
+ return this.pages;
282
+ }
283
+ /**
284
+ * @inheritdoc
285
+ */
286
+ hasPage(pageNum) {
287
+ return !!this.pages[pageNum];
288
+ }
289
+ /**
290
+ * @inheritdoc
291
+ */
292
+ getTileModelAt(index) {
293
+ var _a, _b;
294
+ const offsetIndex = index + this.offset;
295
+ const expectedPageNum = Math.floor(offsetIndex / this.pageSize) + 1;
296
+ const expectedIndexOnPage = offsetIndex % this.pageSize;
297
+ let page = 1;
298
+ let tilesSeen = 0;
299
+ while (tilesSeen <= offsetIndex) {
300
+ if (!this.pages[page]) {
301
+ // If we encounter a missing page, either we're past all the results or the page data is sparse.
302
+ // So just return the tile at the expected position if it exists.
303
+ return (_a = this.pages[expectedPageNum]) === null || _a === void 0 ? void 0 : _a[expectedIndexOnPage];
304
+ }
305
+ if (tilesSeen + this.pages[page].length > offsetIndex) {
306
+ return this.pages[page][offsetIndex - tilesSeen];
307
+ }
308
+ tilesSeen += this.pages[page].length;
309
+ page += 1;
310
+ }
311
+ return (_b = this.pages[expectedPageNum]) === null || _b === void 0 ? void 0 : _b[expectedIndexOnPage];
312
+ }
313
+ /**
314
+ * @inheritdoc
315
+ */
316
+ indexOf(tile) {
317
+ return Object.values(this.pages).flat().indexOf(tile) - this.offset;
318
+ }
319
+ /**
320
+ * @inheritdoc
321
+ */
322
+ getPageSize() {
323
+ return this.pageSize;
324
+ }
325
+ /**
326
+ * @inheritdoc
327
+ */
328
+ setPageSize(pageSize) {
329
+ this.reset();
330
+ this.pageSize = pageSize;
331
+ }
332
+ /**
333
+ * @inheritdoc
334
+ */
335
+ setNumInitialPages(numPages) {
336
+ this.numInitialPages = numPages;
337
+ }
338
+ /**
339
+ * @inheritdoc
340
+ */
341
+ setTotalResultCount(count) {
342
+ this.totalResults = count;
343
+ if (this.activeOnHost) {
344
+ this.host.setTotalResultCount(count);
345
+ }
346
+ }
347
+ /**
348
+ * @inheritdoc
349
+ */
350
+ setFetchesSuppressed(suppressed) {
351
+ this.suppressFetches = suppressed;
352
+ }
353
+ /**
354
+ * @inheritdoc
355
+ */
356
+ setEndOfDataReached(reached) {
357
+ this.endOfDataReached = reached;
358
+ }
359
+ /**
360
+ * @inheritdoc
361
+ */
362
+ async handleQueryChange() {
363
+ // Don't react to the change if fetches are suppressed for this data source
364
+ if (this.suppressFetches)
365
+ return;
366
+ this.reset();
367
+ // Reset the `initialSearchComplete` promise with a new value for the imminent search
368
+ let initialSearchCompleteResolver;
369
+ this._initialSearchCompletePromise = new Promise(res => {
370
+ initialSearchCompleteResolver = res;
371
+ });
372
+ // Fire the initial page & facet requests
373
+ this.queryInitialized = true;
374
+ await Promise.all([
375
+ this.doInitialPageFetch(),
376
+ this.canFetchFacets ? this.fetchFacets() : null,
377
+ ]);
378
+ // Resolve the `initialSearchComplete` promise for this search
379
+ initialSearchCompleteResolver(true);
380
+ }
381
+ /**
382
+ * @inheritdoc
383
+ */
384
+ async handleFacetReadinessChange(ready) {
385
+ const facetsBecameReady = !this.facetsReadyToLoad && ready;
386
+ this.facetsReadyToLoad = ready;
387
+ const needsFetch = facetsBecameReady && this.canFetchFacets;
388
+ if (needsFetch) {
389
+ this.fetchFacets();
390
+ }
391
+ }
392
+ /**
393
+ * Whether the data source & its host are in a state where a facet request should be fired.
394
+ * (i.e., they aren't suppressed or already loading, etc.)
395
+ */
396
+ get canFetchFacets() {
397
+ var _a;
398
+ // Don't fetch facets if they are suppressed entirely or not required for the current profile page element
399
+ if (this.host.facetLoadStrategy === 'off')
400
+ return false;
401
+ if (FACETLESS_PAGE_ELEMENTS.includes(this.host.profileElement))
402
+ return false;
403
+ // If facets are to be lazy-loaded, don't fetch them if they are not going to be visible anyway
404
+ // (wait until they become visible instead)
405
+ if (this.host.facetLoadStrategy !== 'eager' && !this.facetsReadyToLoad)
406
+ return false;
407
+ // Don't fetch facets again if they are already fetched or pending
408
+ const facetsAlreadyFetched = Object.keys((_a = this.aggregations) !== null && _a !== void 0 ? _a : {}).length > 0;
409
+ if (this.facetsLoading || facetsAlreadyFetched)
410
+ return false;
411
+ return true;
412
+ }
413
+ /**
414
+ * @inheritdoc
415
+ */
416
+ map(callback) {
417
+ if (!Object.keys(this.pages).length)
418
+ return;
419
+ this.pages = Object.fromEntries(Object.entries(this.pages).map(([page, tileModels]) => [
420
+ page,
421
+ tileModels.map((model, index, array) => model ? callback(model, index, array) : model),
422
+ ]));
423
+ this.requestHostUpdate();
424
+ this.refreshVisibleResults();
425
+ }
426
+ /**
427
+ * @inheritdoc
428
+ */
429
+ get checkedTileModels() {
430
+ return this.getFilteredTileModels(model => model.checked);
431
+ }
432
+ /**
433
+ * @inheritdoc
434
+ */
435
+ get uncheckedTileModels() {
436
+ return this.getFilteredTileModels(model => !model.checked);
437
+ }
438
+ /**
439
+ * Returns a flattened, filtered array of all the tile models in the data source
440
+ * for which the given predicate returns a truthy value.
441
+ *
442
+ * @param predicate A callback function to apply on each tile model, as with Array.filter
443
+ * @returns A filtered array of tile models satisfying the predicate
444
+ */
445
+ getFilteredTileModels(predicate) {
446
+ return Object.values(this.pages)
447
+ .flat()
448
+ .filter((model, index, array) => model ? predicate(model, index, array) : false);
449
+ }
450
+ /**
451
+ * @inheritdoc
452
+ */
453
+ get canPerformSearch() {
454
+ var _a, _b;
455
+ if (!this.host.searchService)
456
+ return false;
457
+ const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
458
+ const hasNonEmptyQuery = !!trimmedQuery;
459
+ const hasIdentifiers = !!((_b = this.host.identifiers) === null || _b === void 0 ? void 0 : _b.length);
460
+ const isCollectionSearch = !!this.host.withinCollection;
461
+ const isProfileSearch = !!this.host.withinProfile;
462
+ const hasProfileElement = !!this.host.profileElement;
463
+ const isDefaultedSearch = this.host.searchType === SearchType.DEFAULT;
464
+ const isMetadataSearch = this.host.searchType === SearchType.METADATA;
465
+ const isTvSearch = this.host.searchType === SearchType.TV;
466
+ // Metadata/tv searches within a collection are allowed to have no query.
467
+ const isValidForCollectionSearch = isDefaultedSearch || isMetadataSearch || isTvSearch;
468
+ // Searches within a profile page may also be performed without a query, provided the profile element is set.
469
+ const isValidForProfileSearch = hasProfileElement && (isDefaultedSearch || isMetadataSearch);
470
+ // Otherwise, a non-empty query must be set.
471
+ return (hasNonEmptyQuery ||
472
+ hasIdentifiers ||
473
+ (isCollectionSearch && isValidForCollectionSearch) ||
474
+ (isProfileSearch && isValidForProfileSearch));
475
+ }
476
+ /**
477
+ * Sets the state for whether the initial set of search results for the
478
+ * current query is loading
479
+ */
480
+ setSearchResultsLoading(loading) {
481
+ this.searchResultsLoading = loading;
482
+ if (this.activeOnHost) {
483
+ this.host.setSearchResultsLoading(loading);
484
+ }
485
+ }
486
+ /**
487
+ * Sets the state for whether the facets for a query is loading
488
+ */
489
+ setFacetsLoading(loading) {
490
+ this.facetsLoading = loading;
491
+ if (this.activeOnHost) {
492
+ this.host.setFacetsLoading(loading);
493
+ }
494
+ }
495
+ /**
496
+ * Requests that the host perform an update, provided this data
497
+ * source is actively installed on it.
498
+ */
499
+ requestHostUpdate() {
500
+ if (this.activeOnHost) {
501
+ this.host.requestUpdate();
502
+ }
503
+ }
504
+ /**
505
+ * Requests that the host refresh its visible tiles, provided this
506
+ * data source is actively installed on it.
507
+ */
508
+ refreshVisibleResults() {
509
+ if (this.activeOnHost) {
510
+ this.host.refreshVisibleResults();
511
+ }
512
+ }
513
+ /**
514
+ * The query key is a string that uniquely identifies the current search.
515
+ * It consists of:
516
+ * - The current base query
517
+ * - The current collection/profile target & page element
518
+ * - The current search type
519
+ * - Any currently-applied facets
520
+ * - Any currently-applied date range
521
+ * - Any currently-applied prefix filters
522
+ * - The current sort options
523
+ *
524
+ * This lets us internally keep track of queries so we don't persist data that's
525
+ * no longer relevant. Not meant to be human-readable.
526
+ */
527
+ get pageFetchQueryKey() {
528
+ var _a, _b, _c;
529
+ const profileKey = `pf;${this.host.withinProfile}--pe;${this.host.profileElement}`;
530
+ const pageTarget = (_a = this.host.withinCollection) !== null && _a !== void 0 ? _a : profileKey;
531
+ const sortField = (_b = this.host.selectedSort) !== null && _b !== void 0 ? _b : 'none';
532
+ const sortDirection = (_c = this.host.sortDirection) !== null && _c !== void 0 ? _c : 'none';
533
+ return `fq:${this.fullQuery}-pt:${pageTarget}-st:${this.host.searchType}-sf:${sortField}-sd:${sortDirection}`;
534
+ }
535
+ /**
536
+ * Similar to `pageFetchQueryKey` above, but excludes sort fields since they
537
+ * are not relevant in determining aggregation queries.
538
+ */
539
+ get facetFetchQueryKey() {
540
+ var _a;
541
+ const profileKey = `pf;${this.host.withinProfile}--pe;${this.host.profileElement}`;
542
+ const pageTarget = (_a = this.host.withinCollection) !== null && _a !== void 0 ? _a : profileKey;
543
+ return `facets-fq:${this.fullQuery}-pt:${pageTarget}-st:${this.host.searchType}`;
544
+ }
545
+ /**
546
+ * Constructs a search service FilterMap object from the combination of
547
+ * all the currently-applied filters. This includes any facets, letter
548
+ * filters, and date range.
549
+ */
550
+ get filterMap() {
551
+ const builder = new FilterMapBuilder();
552
+ const { minSelectedDate, maxSelectedDate, selectedFacets, internalFilters, selectedTitleFilter, selectedCreatorFilter, } = this.host;
553
+ const dateField = this.host.searchType === SearchType.TV ? 'date' : 'year';
554
+ if (minSelectedDate) {
555
+ builder.addFilter(dateField, minSelectedDate, FilterConstraint.GREATER_OR_EQUAL);
556
+ }
557
+ if (maxSelectedDate) {
558
+ builder.addFilter(dateField, maxSelectedDate, FilterConstraint.LESS_OR_EQUAL);
559
+ }
560
+ // Add any selected facets and internal filters
561
+ const combinedFilters = mergeSelectedFacets(internalFilters, selectedFacets);
562
+ if (combinedFilters) {
563
+ for (const [facetName, facetValues] of Object.entries(combinedFilters)) {
564
+ const { name, values } = this.prepareFacetForFetch(facetName, facetValues);
565
+ for (const [value, bucket] of Object.entries(values)) {
566
+ let constraint;
567
+ if (bucket.state === 'selected') {
568
+ constraint = FilterConstraint.INCLUDE;
569
+ }
570
+ else if (bucket.state === 'hidden') {
571
+ constraint = FilterConstraint.EXCLUDE;
572
+ }
573
+ if (constraint) {
574
+ builder.addFilter(name, value, constraint);
575
+ }
576
+ }
577
+ }
578
+ }
579
+ // Add any letter filters
580
+ if (selectedTitleFilter) {
581
+ builder.addFilter('firstTitle', selectedTitleFilter, FilterConstraint.INCLUDE);
582
+ }
583
+ if (selectedCreatorFilter) {
584
+ builder.addFilter('firstCreator', selectedCreatorFilter, FilterConstraint.INCLUDE);
585
+ }
586
+ const filterMap = builder.build();
587
+ return filterMap;
588
+ }
589
+ /**
590
+ * Produces a compact unique ID for a search request that can help with debugging
591
+ * on the backend by making related requests easier to trace through different services.
592
+ * (e.g., tying the hits/aggregations requests for the same page back to a single hash).
593
+ *
594
+ * @param params The search service parameters for the request
595
+ * @param kind The kind of request (hits-only, aggregations-only, or both)
596
+ * @returns A Promise resolving to the uid to apply to the request
597
+ */
598
+ async requestUID(params, kind) {
599
+ var _a;
600
+ const paramsToHash = JSON.stringify({
601
+ pageType: params.pageType,
602
+ pageTarget: params.pageTarget,
603
+ query: params.query,
604
+ fields: params.fields,
605
+ filters: params.filters,
606
+ sort: params.sort,
607
+ searchType: this.host.searchType,
608
+ });
609
+ const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this
610
+ const sessionId = (await this.host.getSessionId()).slice(0, 20); // Likewise
611
+ const page = (_a = params.page) !== null && _a !== void 0 ? _a : 0;
612
+ const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations
613
+ const currentTime = Date.now();
614
+ return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;
615
+ }
616
+ /**
617
+ * @inheritdoc
618
+ */
619
+ get pageSpecifierParams() {
620
+ var _a;
621
+ if ((_a = this.host.identifiers) === null || _a === void 0 ? void 0 : _a.length) {
622
+ return {
623
+ pageType: 'client_document_fetch',
624
+ };
625
+ }
626
+ if (this.host.withinCollection) {
627
+ return {
628
+ pageType: 'collection_details',
629
+ pageTarget: this.host.withinCollection,
630
+ };
631
+ }
632
+ if (this.host.withinProfile) {
633
+ return {
634
+ pageType: 'account_details',
635
+ pageTarget: this.host.withinProfile,
636
+ pageElements: this.host.profileElement
637
+ ? [this.host.profileElement]
638
+ : [],
639
+ };
640
+ }
641
+ return null;
642
+ }
643
+ /**
644
+ * The full query, including year facets and date range clauses
645
+ */
646
+ get fullQuery() {
647
+ var _a;
648
+ const parts = [];
649
+ const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
650
+ if (trimmedQuery)
651
+ parts.push(trimmedQuery);
652
+ if (this.host.identifiers) {
653
+ parts.push(`identifier:(${this.host.identifiers.join(' OR ')})`);
654
+ }
655
+ const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;
656
+ if (facetQuery)
657
+ parts.push(facetQuery);
658
+ if (dateRangeQueryClause)
659
+ parts.push(dateRangeQueryClause);
660
+ if (sortFilterQueries)
661
+ parts.push(sortFilterQueries);
662
+ return parts.join(' AND ').trim();
663
+ }
664
+ /**
665
+ * Generates a query string representing the current set of applied facets
666
+ *
667
+ * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
668
+ */
669
+ get facetQuery() {
670
+ var _a;
671
+ if (!this.host.selectedFacets)
672
+ return undefined;
673
+ const facetClauses = [];
674
+ for (const [facetName, facetValues] of Object.entries(this.host.selectedFacets)) {
675
+ facetClauses.push(this.buildFacetClause(facetName, facetValues));
676
+ }
677
+ return (_a = this.joinFacetClauses(facetClauses)) === null || _a === void 0 ? void 0 : _a.trim();
678
+ }
679
+ get dateRangeQueryClause() {
680
+ if (!this.host.minSelectedDate || !this.host.maxSelectedDate) {
681
+ return undefined;
682
+ }
683
+ return `year:[${this.host.minSelectedDate} TO ${this.host.maxSelectedDate}]`;
684
+ }
685
+ get sortFilterQueries() {
686
+ const queries = [this.titleQuery, this.creatorQuery];
687
+ return queries.filter(q => q).join(' AND ');
688
+ }
689
+ /**
690
+ * Returns a query clause identifying the currently selected title filter,
691
+ * e.g., `firstTitle:X`.
692
+ */
693
+ get titleQuery() {
694
+ return this.host.selectedTitleFilter
695
+ ? `firstTitle:${this.host.selectedTitleFilter}`
696
+ : undefined;
697
+ }
698
+ /**
699
+ * Returns a query clause identifying the currently selected creator filter,
700
+ * e.g., `firstCreator:X`.
701
+ */
702
+ get creatorQuery() {
703
+ return this.host.selectedCreatorFilter
704
+ ? `firstCreator:${this.host.selectedCreatorFilter}`
705
+ : undefined;
706
+ }
707
+ /**
708
+ * Builds an OR-joined facet clause for the given facet name and values.
709
+ *
710
+ * E.g., for name `subject` and values
711
+ * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`
712
+ * this will produce the clause
713
+ * `subject:("foo" OR -"bar")`.
714
+ *
715
+ * @param facetName The facet type (e.g., 'collection')
716
+ * @param facetValues The facet buckets, mapped by their keys
717
+ */
718
+ buildFacetClause(facetName, facetValues) {
719
+ const { name: facetQueryName, values } = this.prepareFacetForFetch(facetName, facetValues);
720
+ const facetEntries = Object.entries(values);
721
+ if (facetEntries.length === 0)
722
+ return '';
723
+ const facetValuesArray = [];
724
+ for (const [key, facetData] of facetEntries) {
725
+ const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
726
+ facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
727
+ }
728
+ const valueQuery = facetValuesArray.join(` OR `);
729
+ return `${facetQueryName}:(${valueQuery})`;
730
+ }
731
+ /**
732
+ * Handles some special pre-request normalization steps for certain facet types
733
+ * that require them.
734
+ *
735
+ * @param facetName The name of the facet type (e.g., 'language')
736
+ * @param facetValues An array of values for that facet type
737
+ */
738
+ prepareFacetForFetch(facetName, facetValues) {
739
+ // eslint-disable-next-line prefer-const
740
+ let [normalizedName, normalizedValues] = [facetName, facetValues];
741
+ // The full "search engine" name of the lending field is "lending___status"
742
+ if (facetName === 'lending') {
743
+ normalizedName = 'lending___status';
744
+ }
745
+ return {
746
+ name: normalizedName,
747
+ values: normalizedValues,
748
+ };
749
+ }
750
+ /**
751
+ * Takes an array of facet clauses, and combines them into a
752
+ * full AND-joined facet query string. Empty clauses are ignored.
753
+ */
754
+ joinFacetClauses(facetClauses) {
755
+ const nonEmptyFacetClauses = facetClauses.filter(clause => clause.length > 0);
756
+ return nonEmptyFacetClauses.length > 0
757
+ ? `(${nonEmptyFacetClauses.join(' AND ')})`
758
+ : undefined;
759
+ }
760
+ /**
761
+ * Fires a backend request to fetch a set of aggregations (representing UI facets) for
762
+ * the current search state.
763
+ */
764
+ async fetchFacets() {
765
+ var _a, _b, _c, _d, _e, _f, _g;
766
+ const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
767
+ if (!this.canPerformSearch)
768
+ return;
769
+ const { facetFetchQueryKey } = this;
770
+ if (this.fetchesInProgress.has(facetFetchQueryKey))
771
+ return;
772
+ this.fetchesInProgress.add(facetFetchQueryKey);
773
+ this.setFacetsLoading(true);
774
+ const sortParams = this.host.sortParam ? [this.host.sortParam] : [];
775
+ const params = {
776
+ ...this.pageSpecifierParams,
777
+ query: trimmedQuery || '',
778
+ identifiers: this.host.identifiers,
779
+ rows: 0,
780
+ filters: this.filterMap,
781
+ // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
782
+ aggregationsSize: 10,
783
+ // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
784
+ // The default aggregations for the search_results page type should be what we need here.
785
+ };
786
+ params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
787
+ const searchResponse = await ((_b = this.host.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.host.searchType));
788
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
789
+ // This is checking to see if the query has changed since the data was fetched.
790
+ // If so, we just want to discard this set of aggregations because they are
791
+ // likely no longer valid for the newer query.
792
+ const queryChangedSinceFetch = !this.fetchesInProgress.has(facetFetchQueryKey);
793
+ this.fetchesInProgress.delete(facetFetchQueryKey);
794
+ if (queryChangedSinceFetch)
795
+ return;
796
+ if (!success) {
797
+ const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
798
+ const detailMsg = (_e = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.details) === null || _e === void 0 ? void 0 : _e.message;
799
+ if (!errorMsg && !detailMsg) {
800
+ // @ts-expect-error: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
801
+ (_g = (_f = window === null || window === void 0 ? void 0 : window.Sentry) === null || _f === void 0 ? void 0 : _f.captureMessage) === null || _g === void 0 ? void 0 : _g.call(_f, 'Missing or malformed facet response from backend', 'error');
802
+ }
803
+ this.setFacetsLoading(false);
804
+ return;
805
+ }
806
+ const { aggregations, collectionTitles, tvChannelAliases } = success.response;
807
+ this.aggregations = aggregations;
808
+ this.histogramAggregation =
809
+ this.host.searchType === SearchType.TV
810
+ ? aggregations === null || aggregations === void 0 ? void 0 : aggregations.date_histogram
811
+ : aggregations === null || aggregations === void 0 ? void 0 : aggregations.year_histogram;
812
+ if (collectionTitles) {
813
+ for (const [id, title] of Object.entries(collectionTitles)) {
814
+ this.collectionTitles.set(id, title);
815
+ }
816
+ }
817
+ if (tvChannelAliases) {
818
+ for (const [channel, network] of Object.entries(tvChannelAliases)) {
819
+ this.tvChannelAliases.set(channel, network);
820
+ }
821
+ }
822
+ this.setFacetsLoading(false);
823
+ this.requestHostUpdate();
824
+ }
825
+ /**
826
+ * Performs the initial page fetch(es) for the current search state.
827
+ */
828
+ async doInitialPageFetch() {
829
+ this.setSearchResultsLoading(true);
830
+ // Try to batch 2 initial page requests when possible
831
+ await this.fetchPage(this.host.initialPageNumber, this.numInitialPages);
832
+ }
833
+ /**
834
+ * Fetches one or more pages of results and updates the data source.
835
+ *
836
+ * @param pageNumber The page number to fetch
837
+ * @param numInitialPages If this is an initial page fetch (`pageNumber = 1`),
838
+ * specifies how many pages to batch together in one request. Ignored
839
+ * if `pageNumber != 1`, defaulting to a single page.
840
+ */
841
+ async fetchPage(pageNumber, numInitialPages = 1) {
842
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
843
+ const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
844
+ // reset loading status
845
+ if (!this.canPerformSearch) {
846
+ this.setSearchResultsLoading(false);
847
+ return;
848
+ }
849
+ // if we already have data, don't fetch again
850
+ if (this.hasPage(pageNumber))
851
+ return;
852
+ if (this.endOfDataReached)
853
+ return;
854
+ // Batch multiple initial page requests together if needed (e.g., can request
855
+ // pages 1 and 2 together in a single request).
856
+ let numPages = pageNumber === 1 ? numInitialPages : 1;
857
+ const numRows = this.pageSize * numPages;
858
+ // if a fetch is already in progress for this query and page, don't fetch again
859
+ const { pageFetchQueryKey } = this;
860
+ const currentPageKey = `${pageFetchQueryKey}-p:${pageNumber}`;
861
+ if (this.fetchesInProgress.has(currentPageKey))
862
+ return;
863
+ for (let i = 0; i < numPages; i += 1) {
864
+ this.fetchesInProgress.add(`${pageFetchQueryKey}-p:${pageNumber + i}`);
865
+ }
866
+ this.previousQueryKey = pageFetchQueryKey;
867
+ const { withinCollection, withinProfile } = this.host;
868
+ let sortParams = this.host.sortParam ? [this.host.sortParam] : [];
869
+ // TODO eventually the PPS should handle these defaults natively
870
+ const isDefaultProfileSort = withinProfile && this.host.selectedSort === SortField.default;
871
+ if (isDefaultProfileSort && this.host.defaultSortField) {
872
+ const sortOption = SORT_OPTIONS[this.host.defaultSortField];
873
+ if (sortOption.searchServiceKey) {
874
+ sortParams = [
875
+ {
876
+ field: sortOption.searchServiceKey,
877
+ direction: 'desc',
878
+ },
879
+ ];
880
+ }
881
+ }
882
+ const params = {
883
+ ...this.pageSpecifierParams,
884
+ query: trimmedQuery || '',
885
+ identifiers: this.host.identifiers,
886
+ page: pageNumber,
887
+ rows: numRows,
888
+ sort: sortParams,
889
+ filters: this.filterMap,
890
+ aggregations: { omit: true },
891
+ };
892
+ params.uid = await this.requestUID(params, 'hits');
893
+ // log('=== FIRING PAGE REQUEST ===', params);
894
+ const searchResponse = await ((_b = this.host.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.host.searchType));
895
+ // log('=== RECEIVED PAGE RESPONSE IN CB ===', searchResponse);
896
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
897
+ // This is checking to see if the fetch has been invalidated since it was fired off.
898
+ // If so, we just want to discard the response since it is for an obsolete query state.
899
+ if (!this.fetchesInProgress.has(currentPageKey))
900
+ return;
901
+ for (let i = 0; i < numPages; i += 1) {
902
+ this.fetchesInProgress.delete(`${pageFetchQueryKey}-p:${pageNumber + i}`);
903
+ }
904
+ if (!success) {
905
+ const errorMsg = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _c === void 0 ? void 0 : _c.message;
906
+ const detailMsg = (_e = (_d = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.error) === null || _d === void 0 ? void 0 : _d.details) === null || _e === void 0 ? void 0 : _e.message;
907
+ this.queryErrorMessage = `${errorMsg !== null && errorMsg !== void 0 ? errorMsg : ''}${detailMsg ? `; ${detailMsg}` : ''}`;
908
+ if (!this.queryErrorMessage) {
909
+ this.queryErrorMessage = 'Missing or malformed response from backend';
910
+ // @ts-expect-error: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
911
+ (_g = (_f = window === null || window === void 0 ? void 0 : window.Sentry) === null || _f === void 0 ? void 0 : _f.captureMessage) === null || _g === void 0 ? void 0 : _g.call(_f, this.queryErrorMessage, 'error');
912
+ }
913
+ this.setSearchResultsLoading(false);
914
+ this.requestHostUpdate();
915
+ this.host.emitSearchError();
916
+ return;
917
+ }
918
+ this.setTotalResultCount(success.response.totalResults - this.offset);
919
+ if (this.activeOnHost && this.totalResults === 0) {
920
+ // display event to offshoot when result count is zero.
921
+ this.host.emitEmptyResults();
922
+ }
923
+ this.sessionContext = success.sessionContext;
924
+ if (withinCollection) {
925
+ this.collectionExtraInfo = success.response.collectionExtraInfo;
926
+ // For collections, we want the UI to respect the default sort option
927
+ // which can be specified in metadata, or otherwise assumed to be week:desc
928
+ if (this.activeOnHost) {
929
+ this.host.applyDefaultCollectionSort(this.collectionExtraInfo);
930
+ }
931
+ if (this.collectionExtraInfo) {
932
+ this.parentCollections = [].concat((_j = (_h = this.collectionExtraInfo.public_metadata) === null || _h === void 0 ? void 0 : _h.collection) !== null && _j !== void 0 ? _j : []);
933
+ // Update the TV collection status now that we know the parent collections
934
+ this.host.isTVCollection =
935
+ ((_k = this.host.withinCollection) === null || _k === void 0 ? void 0 : _k.startsWith('TV-')) ||
936
+ this.host.withinCollection === 'tvnews' ||
937
+ this.host.withinCollection === 'tvarchive' ||
938
+ this.parentCollections.includes('tvnews') ||
939
+ this.parentCollections.includes('tvarchive');
940
+ }
941
+ }
942
+ else if (withinProfile) {
943
+ this.accountExtraInfo = success.response.accountExtraInfo;
944
+ this.pageElements = success.response.pageElements;
945
+ }
946
+ const { results, collectionTitles, tvChannelAliases } = success.response;
947
+ if (results && results.length > 0) {
948
+ // Load any collection titles present on the response into the cache,
949
+ // or queue up preload fetches for them if none were present.
950
+ if (collectionTitles) {
951
+ for (const [id, title] of Object.entries(collectionTitles)) {
952
+ this.collectionTitles.set(id, title);
953
+ }
954
+ // Also add the target collection's title if available
955
+ const targetTitle = (_m = (_l = this.collectionExtraInfo) === null || _l === void 0 ? void 0 : _l.public_metadata) === null || _m === void 0 ? void 0 : _m.title;
956
+ if (withinCollection && targetTitle) {
957
+ this.collectionTitles.set(withinCollection, targetTitle);
958
+ }
959
+ }
960
+ if (tvChannelAliases) {
961
+ for (const [channel, network] of Object.entries(tvChannelAliases)) {
962
+ this.tvChannelAliases.set(channel, network);
963
+ }
964
+ }
965
+ // Update the data source for each returned page.
966
+ // For loans and web archives, we must account for receiving more pages than we asked for.
967
+ const isUnpagedElement = ['lending', 'web_archives'].includes(this.host.profileElement);
968
+ if (isUnpagedElement) {
969
+ numPages = Math.ceil(results.length / this.pageSize);
970
+ this.endOfDataReached = true;
971
+ if (this.activeOnHost)
972
+ this.host.setTileCount(this.totalResults);
973
+ }
974
+ for (let i = 0; i < numPages; i += 1) {
975
+ const pageStartIndex = this.pageSize * i;
976
+ this.addFetchedResultsToDataSource(pageNumber + i, results.slice(pageStartIndex, pageStartIndex + this.pageSize), !isUnpagedElement || i === numPages - 1);
977
+ }
978
+ }
979
+ // When we reach the end of the data, we can set the infinite scroller's
980
+ // item count to the real total number of results (rather than the
981
+ // temporary estimates based on pages rendered so far).
982
+ if (this.size >= this.totalResults || results.length === 0) {
983
+ this.endOfDataReached = true;
984
+ if (this.activeOnHost)
985
+ this.host.setTileCount(this.size);
986
+ }
987
+ this.setSearchResultsLoading(false);
988
+ this.requestHostUpdate();
989
+ }
990
+ /**
991
+ * Returns the type of request that produced the current set of hits,
992
+ * based on the presence of a search query or profile/collection target
993
+ * on the host.
994
+ */
995
+ get hitRequestSource() {
996
+ const { host } = this;
997
+ if (host.baseQuery)
998
+ return 'search_query';
999
+ if (host.withinProfile)
1000
+ return 'profile_tab';
1001
+ if (host.withinCollection)
1002
+ return 'collection_members';
1003
+ return 'unknown';
1004
+ }
1005
+ /**
1006
+ * Update the datasource from the fetch response
1007
+ *
1008
+ * @param pageNumber
1009
+ * @param results
1010
+ */
1011
+ addFetchedResultsToDataSource(pageNumber, results, needsReload = true) {
1012
+ const tiles = [];
1013
+ const requestSource = this.hitRequestSource;
1014
+ results === null || results === void 0 ? void 0 : results.forEach(result => {
1015
+ if (!result.identifier)
1016
+ return;
1017
+ tiles.push(new TileModel(result, requestSource));
1018
+ });
1019
+ this.addPage(pageNumber, tiles);
1020
+ if (needsReload) {
1021
+ this.refreshVisibleResults();
1022
+ }
1023
+ }
1024
+ /**
1025
+ * Fetches the aggregation buckets for the given prefix filter type.
1026
+ */
1027
+ async fetchPrefixFilterBuckets(filterType) {
1028
+ var _a, _b, _c, _d, _e, _f, _g;
1029
+ const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
1030
+ if (!this.canPerformSearch)
1031
+ return [];
1032
+ const filterAggregationKey = prefixFilterAggregationKeys[filterType];
1033
+ const sortParams = this.host.sortParam ? [this.host.sortParam] : [];
1034
+ const params = {
1035
+ ...this.pageSpecifierParams,
1036
+ query: trimmedQuery || '',
1037
+ identifiers: this.host.identifiers,
1038
+ rows: 0,
1039
+ filters: this.filterMap,
1040
+ // Only fetch the firstTitle or firstCreator aggregation
1041
+ aggregations: { simpleParams: [filterAggregationKey] },
1042
+ // Fetch all 26 letter buckets
1043
+ aggregationsSize: 26,
1044
+ };
1045
+ params.uid = await this.requestUID({ ...params, sort: sortParams }, 'aggregations');
1046
+ const searchResponse = await ((_b = this.host.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.host.searchType));
1047
+ return ((_g = (_f = (_e = (_d = (_c = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.aggregations) === null || _e === void 0 ? void 0 : _e[filterAggregationKey]) === null || _f === void 0 ? void 0 : _f.buckets) !== null && _g !== void 0 ? _g : []);
1048
+ }
1049
+ /**
1050
+ * Fetches and caches the prefix filter counts for the given filter type.
1051
+ */
1052
+ async updatePrefixFilterCounts(filterType) {
1053
+ const { facetFetchQueryKey } = this;
1054
+ const buckets = await this.fetchPrefixFilterBuckets(filterType);
1055
+ // Don't update the filter counts for an outdated query (if it has been changed
1056
+ // since we sent the request)
1057
+ const queryChangedSinceFetch = facetFetchQueryKey !== this.facetFetchQueryKey;
1058
+ if (queryChangedSinceFetch)
1059
+ return;
1060
+ // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }
1061
+ this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update
1062
+ this.prefixFilterCountMap[filterType] = buckets.reduce((acc, bucket) => {
1063
+ acc[bucket.key.toUpperCase()] = bucket.doc_count;
1064
+ return acc;
1065
+ }, {});
1066
+ this.requestHostUpdate();
1067
+ }
1068
+ /**
1069
+ * @inheritdoc
1070
+ */
1071
+ async updatePrefixFiltersForCurrentSort() {
1072
+ if (['title', 'creator'].includes(this.host.selectedSort)) {
1073
+ const filterType = this.host.selectedSort;
1074
+ if (!this.prefixFilterCountMap[filterType]) {
1075
+ this.updatePrefixFilterCounts(filterType);
1076
+ }
1077
+ }
1078
+ }
1079
+ /**
1080
+ * @inheritdoc
1081
+ */
1082
+ refreshLetterCounts() {
1083
+ if (Object.keys(this.prefixFilterCountMap).length > 0) {
1084
+ this.prefixFilterCountMap = {};
1085
+ }
1086
+ this.updatePrefixFiltersForCurrentSort();
1087
+ this.requestHostUpdate();
1088
+ }
1089
+ /**
1090
+ * @inheritdoc
1091
+ */
1092
+ populateTVChannelMaps() {
1093
+ // To ensure that we only make these requests once, cache the Promise returned by the
1094
+ // first call, and return the same Promise on repeated calls.
1095
+ // Resolves once both maps have been retrieved and saved in the data source.
1096
+ if (!this._tvMapsPromise) {
1097
+ this._tvMapsPromise = this._fetchTVChannelMaps();
1098
+ }
1099
+ return this._tvMapsPromise;
1100
+ }
1101
+ /**
1102
+ * Internal function implementing the actual fetches for TV channel mappings.
1103
+ * This should only called by the public populateTVChannelMaps method, which is guarded so
1104
+ * that we do not make extra requests for these rather large mappings.
1105
+ */
1106
+ async _fetchTVChannelMaps() {
1107
+ const baseURL = 'https://av.archive.org/etc';
1108
+ const dateStr = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
1109
+ const chan2networkPromise = fetch(`${baseURL}/chan2network.json?date=${dateStr}`);
1110
+ const program2chansPromise = fetch(`${baseURL}/program2chans.json?date=${dateStr}`);
1111
+ const [chan2networkResponse, program2chansResponse] = await Promise.all([
1112
+ chan2networkPromise,
1113
+ program2chansPromise,
1114
+ ]);
1115
+ this.tvChannelMaps.channelToNetwork = new Map(Object.entries(await chan2networkResponse.json()));
1116
+ this.tvChannelMaps.programToChannels = new Map(Object.entries(await program2chansResponse.json()));
1117
+ this.requestHostUpdate();
1118
+ return this.tvChannelMaps;
1119
+ }
1120
+ }
1121
+ //# sourceMappingURL=collection-browser-data-source.js.map