@internetarchive/collection-browser 1.14.6-alpha.0 → 1.14.6-alpha2

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