@internetarchive/collection-browser 0.3.10-alpha.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +26 -26
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +4 -4
  7. package/LICENSE +661 -661
  8. package/README.md +83 -83
  9. package/dist/index.d.ts +9 -9
  10. package/dist/index.js +9 -9
  11. package/dist/src/app-root.d.ts +48 -48
  12. package/dist/src/app-root.js +258 -258
  13. package/dist/src/app-root.js.map +1 -1
  14. package/dist/src/assets/img/icons/arrow-left.d.ts +2 -2
  15. package/dist/src/assets/img/icons/arrow-left.js +2 -2
  16. package/dist/src/assets/img/icons/arrow-right.d.ts +2 -2
  17. package/dist/src/assets/img/icons/arrow-right.js +2 -2
  18. package/dist/src/assets/img/icons/chevron.d.ts +2 -2
  19. package/dist/src/assets/img/icons/chevron.js +2 -2
  20. package/dist/src/assets/img/icons/empty-query.d.ts +2 -2
  21. package/dist/src/assets/img/icons/empty-query.js +2 -2
  22. package/dist/src/assets/img/icons/eye-closed.d.ts +2 -2
  23. package/dist/src/assets/img/icons/eye-closed.js +2 -2
  24. package/dist/src/assets/img/icons/eye.d.ts +2 -2
  25. package/dist/src/assets/img/icons/eye.js +2 -2
  26. package/dist/src/assets/img/icons/favorite-filled.d.ts +1 -1
  27. package/dist/src/assets/img/icons/favorite-filled.js +2 -2
  28. package/dist/src/assets/img/icons/login-required.d.ts +1 -1
  29. package/dist/src/assets/img/icons/login-required.js +5 -17
  30. package/dist/src/assets/img/icons/login-required.js.map +1 -1
  31. package/dist/src/assets/img/icons/mediatype/account.d.ts +1 -1
  32. package/dist/src/assets/img/icons/mediatype/account.js +2 -2
  33. package/dist/src/assets/img/icons/mediatype/audio.d.ts +1 -1
  34. package/dist/src/assets/img/icons/mediatype/audio.js +2 -2
  35. package/dist/src/assets/img/icons/mediatype/collection.d.ts +1 -1
  36. package/dist/src/assets/img/icons/mediatype/collection.js +2 -2
  37. package/dist/src/assets/img/icons/mediatype/data.d.ts +1 -1
  38. package/dist/src/assets/img/icons/mediatype/data.js +2 -2
  39. package/dist/src/assets/img/icons/mediatype/etree.d.ts +1 -1
  40. package/dist/src/assets/img/icons/mediatype/etree.js +2 -2
  41. package/dist/src/assets/img/icons/mediatype/film.d.ts +1 -1
  42. package/dist/src/assets/img/icons/mediatype/film.js +2 -2
  43. package/dist/src/assets/img/icons/mediatype/images.d.ts +1 -1
  44. package/dist/src/assets/img/icons/mediatype/images.js +2 -2
  45. package/dist/src/assets/img/icons/mediatype/radio.d.ts +1 -1
  46. package/dist/src/assets/img/icons/mediatype/radio.js +2 -2
  47. package/dist/src/assets/img/icons/mediatype/software.d.ts +1 -1
  48. package/dist/src/assets/img/icons/mediatype/software.js +2 -2
  49. package/dist/src/assets/img/icons/mediatype/texts.d.ts +1 -1
  50. package/dist/src/assets/img/icons/mediatype/texts.js +2 -2
  51. package/dist/src/assets/img/icons/mediatype/tv.d.ts +1 -1
  52. package/dist/src/assets/img/icons/mediatype/tv.js +2 -2
  53. package/dist/src/assets/img/icons/mediatype/video.d.ts +1 -1
  54. package/dist/src/assets/img/icons/mediatype/video.js +2 -2
  55. package/dist/src/assets/img/icons/mediatype/web.d.ts +1 -1
  56. package/dist/src/assets/img/icons/mediatype/web.js +2 -2
  57. package/dist/src/assets/img/icons/null-result.d.ts +2 -2
  58. package/dist/src/assets/img/icons/null-result.js +2 -2
  59. package/dist/src/assets/img/icons/restricted.d.ts +1 -1
  60. package/dist/src/assets/img/icons/restricted.js +3 -19
  61. package/dist/src/assets/img/icons/restricted.js.map +1 -1
  62. package/dist/src/assets/img/icons/reviews.d.ts +1 -1
  63. package/dist/src/assets/img/icons/reviews.js +2 -2
  64. package/dist/src/assets/img/icons/upload.d.ts +1 -1
  65. package/dist/src/assets/img/icons/upload.js +2 -2
  66. package/dist/src/assets/img/icons/views.d.ts +1 -1
  67. package/dist/src/assets/img/icons/views.js +2 -2
  68. package/dist/src/circular-activity-indicator.d.ts +5 -5
  69. package/dist/src/circular-activity-indicator.js +17 -17
  70. package/dist/src/collection-browser.d.ts +315 -278
  71. package/dist/src/collection-browser.js +1275 -1119
  72. package/dist/src/collection-browser.js.map +1 -1
  73. package/dist/src/collection-facets/facet-tombstone-row.d.ts +5 -5
  74. package/dist/src/collection-facets/facet-tombstone-row.js +15 -15
  75. package/dist/src/collection-facets/facets-template.d.ts +16 -16
  76. package/dist/src/collection-facets/facets-template.js +125 -125
  77. package/dist/src/collection-facets/more-facets-content.d.ts +77 -76
  78. package/dist/src/collection-facets/more-facets-content.js +357 -353
  79. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  80. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -36
  81. package/dist/src/collection-facets/more-facets-pagination.js +192 -192
  82. package/dist/src/collection-facets.d.ts +78 -77
  83. package/dist/src/collection-facets.js +393 -389
  84. package/dist/src/collection-facets.js.map +1 -1
  85. package/dist/src/empty-placeholder.d.ts +11 -11
  86. package/dist/src/empty-placeholder.js +42 -42
  87. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  88. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  89. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  90. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  91. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  92. package/dist/src/mediatype/mediatype-config.js +85 -85
  93. package/dist/src/models.d.ts +112 -103
  94. package/dist/src/models.js +125 -117
  95. package/dist/src/models.js.map +1 -1
  96. package/dist/src/restoration-state-handler.d.ts +45 -46
  97. package/dist/src/restoration-state-handler.js +230 -230
  98. package/dist/src/restoration-state-handler.js.map +1 -1
  99. package/dist/src/sort-filter-bar/alpha-bar.d.ts +12 -9
  100. package/dist/src/sort-filter-bar/alpha-bar.js +69 -50
  101. package/dist/src/sort-filter-bar/alpha-bar.js.map +1 -1
  102. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  103. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  104. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  105. package/dist/src/sort-filter-bar/img/list.js +2 -2
  106. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  107. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  108. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  109. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  110. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +108 -107
  111. package/dist/src/sort-filter-bar/sort-filter-bar.js +430 -423
  112. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  113. package/dist/src/styles/item-image-styles.d.ts +8 -8
  114. package/dist/src/styles/item-image-styles.js +12 -15
  115. package/dist/src/styles/item-image-styles.js.map +1 -1
  116. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  117. package/dist/src/tiles/collection-browser-loading-tile.js +15 -15
  118. package/dist/src/tiles/grid/account-tile.d.ts +8 -8
  119. package/dist/src/tiles/grid/account-tile.js +20 -20
  120. package/dist/src/tiles/grid/collection-tile.d.ts +7 -7
  121. package/dist/src/tiles/grid/collection-tile.js +23 -23
  122. package/dist/src/tiles/grid/item-tile.d.ts +24 -24
  123. package/dist/src/tiles/grid/item-tile.js +89 -87
  124. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  125. package/dist/src/tiles/grid/tile-stats.d.ts +10 -10
  126. package/dist/src/tiles/grid/tile-stats.js +40 -40
  127. package/dist/src/tiles/image-block.d.ts +17 -17
  128. package/dist/src/tiles/image-block.js +77 -69
  129. package/dist/src/tiles/image-block.js.map +1 -1
  130. package/dist/src/tiles/item-image.d.ts +31 -31
  131. package/dist/src/tiles/item-image.js +106 -106
  132. package/dist/src/tiles/list/account-label.d.ts +1 -1
  133. package/dist/src/tiles/list/account-label.js +6 -6
  134. package/dist/src/tiles/list/date-label.d.ts +1 -1
  135. package/dist/src/tiles/list/date-label.js +12 -12
  136. package/dist/src/tiles/list/tile-list-compact-header.d.ts +12 -12
  137. package/dist/src/tiles/list/tile-list-compact-header.js +41 -41
  138. package/dist/src/tiles/list/tile-list-compact.d.ts +21 -21
  139. package/dist/src/tiles/list/tile-list-compact.js +93 -93
  140. package/dist/src/tiles/list/tile-list.d.ts +50 -50
  141. package/dist/src/tiles/list/tile-list.js +276 -276
  142. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  143. package/dist/src/tiles/mediatype-icon.js +47 -47
  144. package/dist/src/tiles/overlay/icon-overlay.d.ts +10 -7
  145. package/dist/src/tiles/overlay/icon-overlay.js +63 -33
  146. package/dist/src/tiles/overlay/icon-overlay.js.map +1 -1
  147. package/dist/src/tiles/overlay/icon-text-overlay.d.ts +9 -0
  148. package/dist/src/tiles/overlay/icon-text-overlay.js +83 -0
  149. package/dist/src/tiles/overlay/icon-text-overlay.js.map +1 -0
  150. package/dist/src/tiles/overlay/text-overlay.d.ts +10 -8
  151. package/dist/src/tiles/overlay/text-overlay.js +63 -35
  152. package/dist/src/tiles/overlay/text-overlay.js.map +1 -1
  153. package/dist/src/tiles/text-snippet-block.d.ts +29 -29
  154. package/dist/src/tiles/text-snippet-block.js +81 -81
  155. package/dist/src/tiles/tile-dispatcher.d.ts +36 -36
  156. package/dist/src/tiles/tile-dispatcher.js +128 -128
  157. package/dist/src/utils/analytics-events.d.ts +22 -22
  158. package/dist/src/utils/analytics-events.js +24 -24
  159. package/dist/src/utils/format-count.d.ts +7 -7
  160. package/dist/src/utils/format-count.js +76 -76
  161. package/dist/src/utils/format-date.d.ts +2 -2
  162. package/dist/src/utils/format-date.js +23 -23
  163. package/dist/test/collection-browser.test.d.ts +1 -1
  164. package/dist/test/collection-browser.test.js +647 -575
  165. package/dist/test/collection-browser.test.js.map +1 -1
  166. package/dist/test/collection-facets/facets-template.test.d.ts +1 -1
  167. package/dist/test/collection-facets/facets-template.test.js +62 -62
  168. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -1
  169. package/dist/test/collection-facets/more-facets-content.test.js +114 -114
  170. package/dist/test/collection-facets/more-facets-content.test.js.map +1 -1
  171. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -1
  172. package/dist/test/collection-facets/more-facets-pagination.test.js +117 -117
  173. package/dist/test/collection-facets.test.d.ts +2 -2
  174. package/dist/test/collection-facets.test.js +544 -544
  175. package/dist/test/empty-placeholder.test.d.ts +1 -1
  176. package/dist/test/empty-placeholder.test.js +33 -33
  177. package/dist/test/icon-overlay.test.d.ts +1 -1
  178. package/dist/test/icon-overlay.test.js +24 -24
  179. package/dist/test/image-block.test.d.ts +1 -1
  180. package/dist/test/image-block.test.js +48 -48
  181. package/dist/test/item-image.test.d.ts +1 -1
  182. package/dist/test/item-image.test.js +80 -80
  183. package/dist/test/item-image.test.js.map +1 -1
  184. package/dist/test/mediatype-config.test.d.ts +1 -1
  185. package/dist/test/mediatype-config.test.js +16 -16
  186. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  187. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  188. package/dist/test/mocks/mock-collection-name-cache.d.ts +7 -7
  189. package/dist/test/mocks/mock-collection-name-cache.js +13 -13
  190. package/dist/test/mocks/mock-search-responses.d.ts +12 -10
  191. package/dist/test/mocks/mock-search-responses.js +341 -271
  192. package/dist/test/mocks/mock-search-responses.js.map +1 -1
  193. package/dist/test/mocks/mock-search-service.d.ts +13 -13
  194. package/dist/test/mocks/mock-search-service.js +40 -36
  195. package/dist/test/mocks/mock-search-service.js.map +1 -1
  196. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  197. package/dist/test/restoration-state-handler.test.js +125 -126
  198. package/dist/test/restoration-state-handler.test.js.map +1 -1
  199. package/dist/test/sort-filter-bar/alpha-bar.test.d.ts +1 -0
  200. package/dist/test/sort-filter-bar/alpha-bar.test.js +44 -0
  201. package/dist/test/sort-filter-bar/alpha-bar.test.js.map +1 -0
  202. package/dist/test/sort-filter-bar/sort-filter-bar.test.d.ts +1 -1
  203. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +145 -113
  204. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  205. package/dist/test/text-overlay.test.d.ts +1 -1
  206. package/dist/test/text-overlay.test.js +48 -41
  207. package/dist/test/text-overlay.test.js.map +1 -1
  208. package/dist/test/text-snippet-block.test.d.ts +1 -1
  209. package/dist/test/text-snippet-block.test.js +57 -57
  210. package/dist/test/tile-stats.test.d.ts +1 -1
  211. package/dist/test/tile-stats.test.js +33 -33
  212. package/dist/test/tiles/grid/item-tile.test.d.ts +1 -1
  213. package/dist/test/tiles/grid/item-tile.test.js +107 -107
  214. package/dist/test/tiles/list/tile-list-compact.test.d.ts +1 -1
  215. package/dist/test/tiles/list/tile-list-compact.test.js +92 -92
  216. package/dist/test/tiles/list/tile-list.test.d.ts +1 -1
  217. package/dist/test/tiles/list/tile-list.test.js +123 -123
  218. package/dist/test/utils/format-count.test.d.ts +1 -1
  219. package/dist/test/utils/format-count.test.js +23 -23
  220. package/dist/test/utils/format-date.test.d.ts +1 -1
  221. package/dist/test/utils/format-date.test.js +17 -17
  222. package/index.html +24 -24
  223. package/local.archive.org.cert +86 -86
  224. package/local.archive.org.key +27 -27
  225. package/package.json +3 -3
  226. package/renovate.json +6 -6
  227. package/src/app-root.ts +1 -1
  228. package/src/assets/img/icons/login-required.ts +3 -15
  229. package/src/assets/img/icons/restricted.ts +1 -17
  230. package/src/collection-browser.ts +273 -57
  231. package/src/collection-facets/more-facets-content.ts +6 -2
  232. package/src/collection-facets.ts +6 -2
  233. package/src/models.ts +15 -0
  234. package/src/restoration-state-handler.ts +7 -5
  235. package/src/sort-filter-bar/alpha-bar.ts +26 -9
  236. package/src/sort-filter-bar/sort-filter-bar.ts +9 -0
  237. package/src/styles/item-image-styles.ts +3 -6
  238. package/src/tiles/grid/item-tile.ts +2 -0
  239. package/src/tiles/image-block.ts +8 -0
  240. package/src/tiles/overlay/icon-overlay.ts +33 -3
  241. package/src/tiles/overlay/icon-text-overlay.ts +75 -0
  242. package/src/tiles/overlay/text-overlay.ts +34 -7
  243. package/test/collection-browser.test.ts +90 -10
  244. package/test/collection-facets/more-facets-content.test.ts +2 -2
  245. package/test/item-image.test.ts +2 -2
  246. package/test/mocks/mock-search-responses.ts +78 -0
  247. package/test/mocks/mock-search-service.ts +6 -0
  248. package/test/restoration-state-handler.test.ts +0 -3
  249. package/test/sort-filter-bar/alpha-bar.test.ts +52 -0
  250. package/test/sort-filter-bar/sort-filter-bar.test.ts +44 -0
  251. package/test/text-overlay.test.ts +10 -3
  252. package/tsconfig.json +21 -21
  253. package/web-dev-server.config.mjs +30 -30
  254. package/web-test-runner.config.mjs +41 -41
@@ -1,188 +1,193 @@
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 { ifDefined } from 'lit/directives/if-defined.js';
6
- import { 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 './collection-facets';
12
- import './circular-activity-indicator';
13
- import './sort-filter-bar/sort-filter-bar';
14
- import { SortField, SortFieldToMetadataField, defaultSelectedFacets, } from './models';
15
- import { RestorationStateHandler, } from './restoration-state-handler';
16
- import chevronIcon from './assets/img/icons/chevron';
17
- import { LanguageCodeHandler } from './language-code-handler/language-code-handler';
18
- import './empty-placeholder';
19
- import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
20
- let CollectionBrowser = class CollectionBrowser extends LitElement {
21
- constructor() {
22
- super(...arguments);
23
- this.baseImageUrl = 'https://archive.org';
24
- this.searchType = SearchType.METADATA;
25
- this.sortParam = null;
26
- this.selectedSort = SortField.relevance;
27
- this.selectedTitleFilter = null;
28
- this.selectedCreatorFilter = null;
29
- this.sortDirection = null;
30
- this.pageSize = 50;
31
- this.showHistogramDatePicker = false;
32
- /** describes where this component is being used */
33
- this.searchContext = analyticsCategories.default;
34
- this.pageContext = 'search';
35
- this.restorationStateHandler = new RestorationStateHandler({
36
- context: this.pageContext,
37
- });
38
- this.mobileBreakpoint = 600;
39
- this.loggedIn = false;
40
- this.modalManager = undefined;
41
- /**
42
- * If item management UI active
43
- */
44
- this.isManageView = false;
45
- /**
46
- * The page that the consumer wants to load.
47
- */
48
- this.initialPageNumber = 1;
49
- /**
50
- * This the the number of pages that we want to show.
51
- *
52
- * The data isn't necessarily loaded for all of the pages, but this lets us
53
- * know how many cells we should render.
54
- */
55
- this.pagesToRender = this.initialPageNumber;
56
- this.searchResultsLoading = false;
57
- this.facetsLoading = false;
58
- this.fullYearAggregationLoading = false;
59
- this.mobileView = false;
60
- this.mobileFacetsVisible = false;
61
- this.placeholderType = null;
62
- this.languageCodeHandler = new LanguageCodeHandler();
63
- /**
64
- * When we're animated scrolling to the page, we don't want to fetch
65
- * all of the pages as it scrolls so this lets us know if we're scrolling
66
- */
67
- this.isScrollingToCell = false;
68
- /**
69
- * When we've reached the end of the data, stop trying to fetch more
70
- */
71
- this.endOfDataReached = false;
72
- /**
73
- * When page width resizes from desktop to mobile, set true to
74
- * disable expand/collapse transition when loading.
75
- */
76
- this.isResizeToMobile = false;
77
- this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
78
- /**
79
- * The results per page so we can paginate.
80
- *
81
- * This allows us to start in the middle of the search results and
82
- * fetch data before or after the current page. If we don't have a key
83
- * for the previous/next page, we'll fetch the next/previous page to populate it
84
- */
85
- this.dataSource = {};
86
- // we only want to scroll on the very first query change
87
- // so this keeps track of whether we've already set the initial query
88
- this.initialQueryChangeHappened = false;
89
- this.historyPopOccurred = false;
90
- // this maps the query to the pages being fetched for that query
91
- this.pageFetchesInProgress = {};
92
- }
93
- tileModelAtCellIndex(index) {
94
- var _a;
95
- const pageNumber = Math.floor(index / this.pageSize) + 1;
96
- const itemIndex = index % this.pageSize;
97
- const model = (_a = this.dataSource[pageNumber]) === null || _a === void 0 ? void 0 : _a[itemIndex];
98
- /**
99
- * If we encounter a model we don't have yet and we're not in the middle of an
100
- * automated scroll, fetch the page and just return undefined.
101
- * The datasource will be updated once the page is loaded and the cell will be rendered.
102
- *
103
- * We disable it during the automated scroll since we may fetch pages for cells the
104
- * user may never see.
105
- */
106
- if (!model && !this.isScrollingToCell) {
107
- this.fetchPage(pageNumber);
108
- }
109
- return model;
110
- }
111
- get sortFilterQueries() {
112
- const queries = [this.titleQuery, this.creatorQuery];
113
- return queries.filter(q => q).join(' AND ');
114
- }
115
- // this is the total number of tiles we expect if
116
- // the data returned is a full page worth
117
- // this is useful for putting in placeholders for the expected number of tiles
118
- get estimatedTileCount() {
119
- return this.pagesToRender * this.pageSize;
120
- }
121
- // this is the actual number of tiles in the datasource,
122
- // which is useful for removing excess placeholder tiles
123
- // once we reached the end of the data
124
- get actualTileCount() {
125
- return Object.keys(this.dataSource).reduce((acc, page) => acc + this.dataSource[page].length, 0);
126
- }
127
- /**
128
- * Go to the given page of results
129
- *
130
- * @param pageNumber
131
- */
132
- goToPage(pageNumber) {
133
- this.initialPageNumber = pageNumber;
134
- this.pagesToRender = pageNumber;
135
- this.scrollToPage(pageNumber);
136
- }
137
- clearFilters() {
138
- this.selectedFacets = defaultSelectedFacets;
139
- this.sortParam = null;
140
- this.selectedTitleFilter = null;
141
- this.selectedCreatorFilter = null;
142
- this.titleQuery = undefined;
143
- this.creatorQuery = undefined;
144
- this.selectedSort = SortField.relevance;
145
- this.sortDirection = null;
146
- }
147
- /**
148
- * Manually requests to perform a search, which will only be executed if one of
149
- * the query, the search type, or the sort has changed.
150
- */
151
- requestSearch() {
152
- this.handleQueryChange();
153
- }
154
- render() {
155
- 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 { ifDefined } from 'lit/directives/if-defined.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 './collection-facets';
12
+ import './circular-activity-indicator';
13
+ import './sort-filter-bar/sort-filter-bar';
14
+ import { SortField, SortFieldToMetadataField, defaultSelectedFacets, prefixFilterAggregationKeys, } from './models';
15
+ import { RestorationStateHandler, } from './restoration-state-handler';
16
+ import chevronIcon from './assets/img/icons/chevron';
17
+ import { LanguageCodeHandler } from './language-code-handler/language-code-handler';
18
+ import './empty-placeholder';
19
+ import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
20
+ let CollectionBrowser = class CollectionBrowser extends LitElement {
21
+ constructor() {
22
+ super(...arguments);
23
+ this.baseImageUrl = 'https://archive.org';
24
+ this.searchType = SearchType.METADATA;
25
+ this.sortParam = null;
26
+ this.selectedSort = SortField.relevance;
27
+ this.selectedTitleFilter = null;
28
+ this.selectedCreatorFilter = null;
29
+ this.sortDirection = null;
30
+ this.pageSize = 50;
31
+ this.showHistogramDatePicker = false;
32
+ /** describes where this component is being used */
33
+ this.searchContext = analyticsCategories.default;
34
+ this.pageContext = 'search';
35
+ this.restorationStateHandler = new RestorationStateHandler({
36
+ context: this.pageContext,
37
+ });
38
+ this.mobileBreakpoint = 600;
39
+ this.loggedIn = false;
40
+ this.modalManager = undefined;
41
+ /**
42
+ * If item management UI active
43
+ */
44
+ this.isManageView = false;
45
+ /**
46
+ * The page that the consumer wants to load.
47
+ */
48
+ this.initialPageNumber = 1;
49
+ /**
50
+ * This the the number of pages that we want to show.
51
+ *
52
+ * The data isn't necessarily loaded for all of the pages, but this lets us
53
+ * know how many cells we should render.
54
+ */
55
+ this.pagesToRender = this.initialPageNumber;
56
+ this.searchResultsLoading = false;
57
+ this.facetsLoading = false;
58
+ this.fullYearAggregationLoading = false;
59
+ this.mobileView = false;
60
+ this.mobileFacetsVisible = false;
61
+ this.placeholderType = null;
62
+ this.prefixFilterCountMap = {};
63
+ this.languageCodeHandler = new LanguageCodeHandler();
64
+ /**
65
+ * When we're animated scrolling to the page, we don't want to fetch
66
+ * all of the pages as it scrolls so this lets us know if we're scrolling
67
+ */
68
+ this.isScrollingToCell = false;
69
+ /**
70
+ * When we've reached the end of the data, stop trying to fetch more
71
+ */
72
+ this.endOfDataReached = false;
73
+ /**
74
+ * When page width resizes from desktop to mobile, set true to
75
+ * disable expand/collapse transition when loading.
76
+ */
77
+ this.isResizeToMobile = false;
78
+ this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
79
+ /**
80
+ * The results per page so we can paginate.
81
+ *
82
+ * This allows us to start in the middle of the search results and
83
+ * fetch data before or after the current page. If we don't have a key
84
+ * for the previous/next page, we'll fetch the next/previous page to populate it
85
+ */
86
+ this.dataSource = {};
87
+ // we only want to scroll on the very first query change
88
+ // so this keeps track of whether we've already set the initial query
89
+ this.initialQueryChangeHappened = false;
90
+ this.historyPopOccurred = false;
91
+ // this maps the query to the pages being fetched for that query
92
+ this.pageFetchesInProgress = {};
93
+ }
94
+ tileModelAtCellIndex(index) {
95
+ var _a;
96
+ const pageNumber = Math.floor(index / this.pageSize) + 1;
97
+ const itemIndex = index % this.pageSize;
98
+ const model = (_a = this.dataSource[pageNumber]) === null || _a === void 0 ? void 0 : _a[itemIndex];
99
+ /**
100
+ * If we encounter a model we don't have yet and we're not in the middle of an
101
+ * automated scroll, fetch the page and just return undefined.
102
+ * The datasource will be updated once the page is loaded and the cell will be rendered.
103
+ *
104
+ * We disable it during the automated scroll since we may fetch pages for cells the
105
+ * user may never see.
106
+ */
107
+ if (!model && !this.isScrollingToCell) {
108
+ this.fetchPage(pageNumber);
109
+ }
110
+ return model;
111
+ }
112
+ get sortFilterQueries() {
113
+ const queries = [this.titleQuery, this.creatorQuery];
114
+ return queries.filter(q => q).join(' AND ');
115
+ }
116
+ // this is the total number of tiles we expect if
117
+ // the data returned is a full page worth
118
+ // this is useful for putting in placeholders for the expected number of tiles
119
+ get estimatedTileCount() {
120
+ return this.pagesToRender * this.pageSize;
121
+ }
122
+ // this is the actual number of tiles in the datasource,
123
+ // which is useful for removing excess placeholder tiles
124
+ // once we reached the end of the data
125
+ get actualTileCount() {
126
+ return Object.keys(this.dataSource).reduce((acc, page) => acc + this.dataSource[page].length, 0);
127
+ }
128
+ /**
129
+ * Go to the given page of results
130
+ *
131
+ * @param pageNumber
132
+ */
133
+ goToPage(pageNumber) {
134
+ this.initialPageNumber = pageNumber;
135
+ this.pagesToRender = pageNumber;
136
+ this.scrollToPage(pageNumber);
137
+ }
138
+ clearFilters() {
139
+ this.selectedFacets = defaultSelectedFacets;
140
+ this.sortParam = null;
141
+ this.selectedTitleFilter = null;
142
+ this.selectedCreatorFilter = null;
143
+ this.titleQuery = undefined;
144
+ this.creatorQuery = undefined;
145
+ this.selectedSort = SortField.relevance;
146
+ this.sortDirection = null;
147
+ }
148
+ /**
149
+ * Manually requests to perform a search, which will only be executed if one of
150
+ * the query, the search type, or the sort has changed.
151
+ */
152
+ requestSearch() {
153
+ this.handleQueryChange();
154
+ }
155
+ render() {
156
+ this.setPlaceholderType();
156
157
  return html `
157
158
  <div
158
159
  id="content-container"
159
160
  class=${this.mobileView ? 'mobile' : 'desktop'}
160
161
  >
161
- ${this.placeholderType
162
- ? this.emptyPlaceholderTemplate
162
+ ${this.placeholderType
163
+ ? this.emptyPlaceholderTemplate
163
164
  : this.collectionBrowserTemplate}
164
165
  </div>
165
- `;
166
- }
167
- setPlaceholderType() {
168
- this.placeholderType = null;
169
- if (!this.baseQuery) {
170
- this.placeholderType = 'empty-query';
171
- }
172
- if ((!this.searchResultsLoading && this.totalResults === 0) ||
173
- !this.searchService) {
174
- this.placeholderType = 'null-result';
175
- }
176
- }
177
- get emptyPlaceholderTemplate() {
166
+ `;
167
+ }
168
+ setPlaceholderType() {
169
+ this.placeholderType = null;
170
+ if (!this.baseQuery) {
171
+ this.placeholderType = 'empty-query';
172
+ }
173
+ if ((!this.searchResultsLoading && this.totalResults === 0) ||
174
+ !this.searchService) {
175
+ this.placeholderType = 'null-result';
176
+ }
177
+ }
178
+ get emptyPlaceholderTemplate() {
178
179
  return html `
179
180
  <empty-placeholder
180
181
  .placeholderType=${this.placeholderType}
181
182
  ?isMobileView=${this.mobileView}
182
183
  ></empty-placeholder>
183
- `;
184
- }
185
- get collectionBrowserTemplate() {
184
+ `;
185
+ }
186
+ get collectionBrowserTemplate() {
187
+ var _a;
188
+ const shouldShowSearching = this.searchResultsLoading || this.totalResults === undefined;
189
+ const resultsCount = (_a = this.totalResults) === null || _a === void 0 ? void 0 : _a.toLocaleString();
190
+ const resultsLabel = this.totalResults === 1 ? 'Result' : 'Results';
186
191
  return html `<div
187
192
  id="left-column"
188
193
  class="column${this.isResizeToMobile ? ' preload' : ''}"
@@ -191,19 +196,17 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
191
196
  ${this.mobileView ? this.mobileFacetsTemplate : nothing}
192
197
  <div id="results-total">
193
198
  <span id="big-results-count">
194
- ${this.totalResults !== undefined
195
- ? this.totalResults.toLocaleString()
196
- : '-'}
199
+ ${shouldShowSearching ? html `Searching&hellip;` : resultsCount}
197
200
  </span>
198
201
  <span id="big-results-label">
199
- ${this.totalResults === 1 ? 'Result' : 'Results'}
202
+ ${shouldShowSearching ? nothing : resultsLabel}
200
203
  </span>
201
204
  </div>
202
205
  </div>
203
206
  <div
204
207
  id="facets-container"
205
- class=${!this.mobileView || this.mobileFacetsVisible
206
- ? 'expanded'
208
+ class=${!this.mobileView || this.mobileFacetsVisible
209
+ ? 'expanded'
207
210
  : ''}
208
211
  >
209
212
  ${this.facetsTemplate}
@@ -211,22 +214,22 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
211
214
  </div>
212
215
  <div id="right-column" class="column">
213
216
  ${this.sortFilterBarTemplate}
214
- ${this.displayMode === `list-compact`
215
- ? this.listHeaderTemplate
217
+ ${this.displayMode === `list-compact`
218
+ ? this.listHeaderTemplate
216
219
  : nothing}
217
220
  ${this.infiniteScrollerTemplate}
218
- </div>`;
219
- }
220
- get infiniteScrollerTemplate() {
221
+ </div>`;
222
+ }
223
+ get infiniteScrollerTemplate() {
221
224
  return html `<infinite-scroller
222
225
  class="${ifDefined(this.displayMode)}"
223
226
  .cellProvider=${this}
224
227
  .placeholderCellTemplate=${this.placeholderCellTemplate}
225
228
  @scrollThresholdReached=${this.scrollThresholdReached}
226
229
  @visibleCellsChanged=${this.visibleCellsChanged}
227
- ></infinite-scroller>`;
228
- }
229
- get sortFilterBarTemplate() {
230
+ ></infinite-scroller>`;
231
+ }
232
+ get sortFilterBarTemplate() {
230
233
  return html `
231
234
  <sort-filter-bar
232
235
  .selectedSort=${this.selectedSort}
@@ -234,6 +237,7 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
234
237
  .displayMode=${this.displayMode}
235
238
  .selectedTitleFilter=${this.selectedTitleFilter}
236
239
  .selectedCreatorFilter=${this.selectedCreatorFilter}
240
+ .prefixFilterCountMap=${this.prefixFilterCountMap}
237
241
  .resizeObserver=${this.resizeObserver}
238
242
  @sortChanged=${this.userChangedSort}
239
243
  @displayModeChanged=${this.displayModeChanged}
@@ -241,114 +245,116 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
241
245
  @creatorLetterChanged=${this.creatorLetterSelected}
242
246
  >
243
247
  </sort-filter-bar>
244
- `;
245
- }
246
- userChangedSort(e) {
247
- var _a;
248
- const { selectedSort, sortDirection } = e.detail;
249
- this.selectedSort = selectedSort;
250
- this.sortDirection = sortDirection;
251
- if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
252
- this.goToPage(1);
253
- }
254
- this.currentPage = 1;
255
- }
256
- sendSortByAnalytics(prevSortDirection) {
257
- var _a;
258
- const directionCleared = prevSortDirection && !this.sortDirection;
259
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
260
- category: this.searchContext,
261
- action: analyticsActions.sortBy,
262
- label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
263
- });
264
- }
265
- selectedSortChanged() {
266
- if (this.selectedSort === 'relevance' || this.sortDirection === null) {
267
- this.sortParam = null;
268
- return;
269
- }
270
- const sortField = SortFieldToMetadataField[this.selectedSort];
271
- if (!sortField)
272
- return;
273
- this.sortParam = { field: sortField, direction: this.sortDirection };
274
- }
275
- displayModeChanged(e) {
276
- var _a;
277
- this.displayMode = e.detail.displayMode;
278
- if (this.displayMode) {
279
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
280
- category: this.searchContext,
281
- action: analyticsActions.displayMode,
282
- label: this.displayMode,
283
- });
284
- }
285
- }
286
- /** Send Analytics when sorting by title's first letter
287
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
288
- * */
289
- sendFilterByTitleAnalytics(prevSelectedLetter) {
290
- var _a;
291
- if (!prevSelectedLetter && !this.selectedTitleFilter) {
292
- return;
293
- }
294
- const cleared = prevSelectedLetter && this.selectedTitleFilter === null;
295
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
296
- category: this.searchContext,
297
- action: analyticsActions.filterByTitle,
298
- label: cleared
299
- ? `clear-${prevSelectedLetter}`
300
- : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
301
- });
302
- }
303
- selectedTitleLetterChanged() {
304
- this.titleQuery = this.selectedTitleFilter
305
- ? `firstTitle:${this.selectedTitleFilter}`
306
- : undefined;
307
- }
308
- /** Send Analytics when filtering by creator's first letter
309
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
310
- * */
311
- sendFilterByCreatorAnalytics(prevSelectedLetter) {
312
- var _a;
313
- if (!prevSelectedLetter && !this.selectedCreatorFilter) {
314
- return;
315
- }
316
- const cleared = prevSelectedLetter && this.selectedCreatorFilter === null;
317
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
318
- category: this.searchContext,
319
- action: analyticsActions.filterByCreator,
320
- label: cleared
321
- ? `clear-${prevSelectedLetter}`
322
- : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
323
- });
324
- }
325
- selectedCreatorLetterChanged() {
326
- this.creatorQuery = this.selectedCreatorFilter
327
- ? `firstCreator:${this.selectedCreatorFilter}`
328
- : undefined;
329
- }
330
- titleLetterSelected(e) {
331
- this.selectedCreatorFilter = null;
332
- this.selectedTitleFilter = e.detail.selectedLetter;
333
- }
334
- creatorLetterSelected(e) {
335
- this.selectedTitleFilter = null;
336
- this.selectedCreatorFilter = e.detail.selectedLetter;
337
- }
338
- get facetDataLoading() {
339
- return this.facetsLoading || this.fullYearAggregationLoading;
340
- }
341
- get mobileFacetsTemplate() {
248
+ `;
249
+ }
250
+ userChangedSort(e) {
251
+ var _a;
252
+ const { selectedSort, sortDirection } = e.detail;
253
+ this.selectedSort = selectedSort;
254
+ this.sortDirection = sortDirection;
255
+ if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
256
+ this.goToPage(1);
257
+ }
258
+ this.currentPage = 1;
259
+ }
260
+ sendSortByAnalytics(prevSortDirection) {
261
+ var _a;
262
+ const directionCleared = prevSortDirection && !this.sortDirection;
263
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
264
+ category: this.searchContext,
265
+ action: analyticsActions.sortBy,
266
+ label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
267
+ });
268
+ }
269
+ selectedSortChanged() {
270
+ if (this.selectedSort === 'relevance' || this.sortDirection === null) {
271
+ this.sortParam = null;
272
+ return;
273
+ }
274
+ const sortField = SortFieldToMetadataField[this.selectedSort];
275
+ if (!sortField)
276
+ return;
277
+ this.sortParam = { field: sortField, direction: this.sortDirection };
278
+ // Lazy-load the alphabet counts for title/creator sort bar as needed
279
+ this.updatePrefixFiltersForCurrentSort();
280
+ }
281
+ displayModeChanged(e) {
282
+ var _a;
283
+ this.displayMode = e.detail.displayMode;
284
+ if (this.displayMode) {
285
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
286
+ category: this.searchContext,
287
+ action: analyticsActions.displayMode,
288
+ label: this.displayMode,
289
+ });
290
+ }
291
+ }
292
+ /** Send Analytics when sorting by title's first letter
293
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
294
+ * */
295
+ sendFilterByTitleAnalytics(prevSelectedLetter) {
296
+ var _a;
297
+ if (!prevSelectedLetter && !this.selectedTitleFilter) {
298
+ return;
299
+ }
300
+ const cleared = prevSelectedLetter && this.selectedTitleFilter === null;
301
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
302
+ category: this.searchContext,
303
+ action: analyticsActions.filterByTitle,
304
+ label: cleared
305
+ ? `clear-${prevSelectedLetter}`
306
+ : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
307
+ });
308
+ }
309
+ selectedTitleLetterChanged() {
310
+ this.titleQuery = this.selectedTitleFilter
311
+ ? `firstTitle:${this.selectedTitleFilter}`
312
+ : undefined;
313
+ }
314
+ /** Send Analytics when filtering by creator's first letter
315
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
316
+ * */
317
+ sendFilterByCreatorAnalytics(prevSelectedLetter) {
318
+ var _a;
319
+ if (!prevSelectedLetter && !this.selectedCreatorFilter) {
320
+ return;
321
+ }
322
+ const cleared = prevSelectedLetter && this.selectedCreatorFilter === null;
323
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
324
+ category: this.searchContext,
325
+ action: analyticsActions.filterByCreator,
326
+ label: cleared
327
+ ? `clear-${prevSelectedLetter}`
328
+ : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
329
+ });
330
+ }
331
+ selectedCreatorLetterChanged() {
332
+ this.creatorQuery = this.selectedCreatorFilter
333
+ ? `firstCreator:${this.selectedCreatorFilter}`
334
+ : undefined;
335
+ }
336
+ titleLetterSelected(e) {
337
+ this.selectedCreatorFilter = null;
338
+ this.selectedTitleFilter = e.detail.selectedLetter;
339
+ }
340
+ creatorLetterSelected(e) {
341
+ this.selectedTitleFilter = null;
342
+ this.selectedCreatorFilter = e.detail.selectedLetter;
343
+ }
344
+ get facetDataLoading() {
345
+ return this.facetsLoading || this.fullYearAggregationLoading;
346
+ }
347
+ get mobileFacetsTemplate() {
342
348
  return html `
343
349
  <div id="mobile-filter-collapse">
344
350
  <h1
345
- @click=${() => {
346
- this.isResizeToMobile = false;
347
- this.mobileFacetsVisible = !this.mobileFacetsVisible;
351
+ @click=${() => {
352
+ this.isResizeToMobile = false;
353
+ this.mobileFacetsVisible = !this.mobileFacetsVisible;
348
354
  }}
349
- @keyup=${() => {
350
- this.isResizeToMobile = false;
351
- this.mobileFacetsVisible = !this.mobileFacetsVisible;
355
+ @keyup=${() => {
356
+ this.isResizeToMobile = false;
357
+ this.mobileFacetsVisible = !this.mobileFacetsVisible;
352
358
  }}
353
359
  >
354
360
  <span class="collapser ${this.mobileFacetsVisible ? 'open' : ''}">
@@ -357,9 +363,9 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
357
363
  Filters
358
364
  </h1>
359
365
  </div>
360
- `;
361
- }
362
- get facetsTemplate() {
366
+ `;
367
+ }
368
+ get facetsTemplate() {
363
369
  return html `
364
370
  <collection-facets
365
371
  @facetsChanged=${this.facetsChanged}
@@ -375,7 +381,8 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
375
381
  .collectionNameCache=${this.collectionNameCache}
376
382
  .languageCodeHandler=${this.languageCodeHandler}
377
383
  .showHistogramDatePicker=${this.showHistogramDatePicker}
378
- .fullQuery=${this.fullQuery}
384
+ .query=${this.filteredQuery}
385
+ .filterMap=${this.filterMap}
379
386
  .modalManager=${this.modalManager}
380
387
  ?collapsableFacets=${this.mobileView}
381
388
  ?facetsLoading=${this.facetDataLoading}
@@ -384,16 +391,16 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
384
391
  .analyticsHandler=${this.analyticsHandler}
385
392
  >
386
393
  </collection-facets>
387
- `;
388
- }
389
- get loadingTemplate() {
394
+ `;
395
+ }
396
+ get loadingTemplate() {
390
397
  return html `
391
398
  <div class="loading-cover">
392
399
  <circular-activity-indicator></circular-activity-indicator>
393
400
  </div>
394
- `;
395
- }
396
- get listHeaderTemplate() {
401
+ `;
402
+ }
403
+ get listHeaderTemplate() {
397
404
  return html `
398
405
  <div id="list-header">
399
406
  <tile-dispatcher
@@ -405,679 +412,826 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
405
412
  >
406
413
  </tile-dispatcher>
407
414
  </div>
408
- `;
409
- }
410
- get queryDebuggingTemplate() {
411
- var _a, _b;
412
- return html `
413
- <div>
414
- <ul>
415
- <li>Base Query: ${this.baseQuery}</li>
416
- <li>Facet Query: ${this.facetQuery}</li>
417
- <li>Sort Filter Query: ${this.sortFilterQueries}</li>
418
- <li>Date Range Query: ${this.dateRangeQueryClause}</li>
419
- <li>Sort: ${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field} ${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}</li>
420
- <li>Full Query: ${this.fullQuery}</li>
421
- </ul>
422
- </div>
423
- `;
424
- }
425
- histogramDateRangeUpdated(e) {
426
- var _a;
427
- const { minDate, maxDate } = e.detail;
428
- [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
429
- this.dateRangeQueryClause = `year:[${minDate} TO ${maxDate}]`;
430
- if (this.dateRangeQueryClause) {
431
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
432
- category: this.searchContext,
433
- action: analyticsActions.histogramChanged,
434
- label: this.dateRangeQueryClause,
435
- });
436
- }
437
- }
438
- firstUpdated() {
439
- this.setupStateRestorationObserver();
440
- this.restoreState();
441
- }
442
- updated(changed) {
443
- var _a;
444
- if (changed.has('displayMode') ||
445
- changed.has('baseNavigationUrl') ||
446
- changed.has('baseImageUrl') ||
447
- changed.has('loggedIn')) {
448
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
449
- }
450
- if (changed.has('baseQuery')) {
451
- this.emitBaseQueryChanged();
452
- }
453
- if (changed.has('searchType')) {
454
- this.emitSearchTypeChanged();
455
- }
456
- if (changed.has('currentPage') || changed.has('displayMode')) {
457
- this.persistState();
458
- }
459
- if (changed.has('baseQuery') ||
460
- changed.has('titleQuery') ||
461
- changed.has('creatorQuery') ||
462
- changed.has('dateRangeQueryClause') ||
463
- changed.has('sortParam') ||
464
- changed.has('selectedFacets') ||
465
- changed.has('searchService')) {
466
- this.handleQueryChange();
467
- }
468
- if (changed.has('selectedSort') || changed.has('sortDirection')) {
469
- const prevSortDirection = changed.get('sortDirection');
470
- this.sendSortByAnalytics(prevSortDirection);
471
- this.selectedSortChanged();
472
- }
473
- if (changed.has('selectedTitleFilter')) {
474
- this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
475
- this.selectedTitleLetterChanged();
476
- }
477
- if (changed.has('selectedCreatorFilter')) {
478
- this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
479
- this.selectedCreatorLetterChanged();
480
- }
481
- if (changed.has('pagesToRender')) {
482
- if (!this.endOfDataReached && this.infiniteScroller) {
483
- this.infiniteScroller.itemCount = this.estimatedTileCount;
484
- }
485
- }
486
- if (changed.has('resizeObserver')) {
487
- const oldObserver = changed.get('resizeObserver');
488
- if (oldObserver)
489
- this.disconnectResizeObserver(oldObserver);
490
- this.setupResizeObserver();
491
- }
492
- }
493
- disconnectedCallback() {
494
- if (this.resizeObserver) {
495
- this.disconnectResizeObserver(this.resizeObserver);
496
- }
497
- if (this.boundNavigationHandler) {
498
- window.removeEventListener('popstate', this.boundNavigationHandler);
499
- }
500
- }
501
- handleResize(entry) {
502
- const previousView = this.mobileView;
503
- if (entry.target === this.contentContainer) {
504
- this.mobileView = entry.contentRect.width < this.mobileBreakpoint;
505
- // If changing from desktop to mobile disable transition
506
- if (this.mobileView && !previousView) {
507
- this.isResizeToMobile = true;
508
- }
509
- }
510
- }
511
- emitBaseQueryChanged() {
512
- this.dispatchEvent(new CustomEvent('baseQueryChanged', {
513
- detail: {
514
- baseQuery: this.baseQuery,
515
- },
516
- }));
517
- }
518
- emitSearchTypeChanged() {
519
- this.dispatchEvent(new CustomEvent('searchTypeChanged', {
520
- detail: this.searchType,
521
- }));
522
- }
523
- disconnectResizeObserver(resizeObserver) {
524
- resizeObserver.removeObserver({
525
- target: this.contentContainer,
526
- handler: this,
527
- });
528
- }
529
- setupResizeObserver() {
530
- if (!this.resizeObserver)
531
- return;
532
- this.resizeObserver.addObserver({
533
- target: this.contentContainer,
534
- handler: this,
535
- });
536
- }
537
- /**
538
- * When the visible cells change from the infinite scroller, we want to emit
539
- * which page is currently visible so the consumer can update its UI or the URL
540
- *
541
- * @param e
542
- * @returns
543
- */
544
- visibleCellsChanged(e) {
545
- if (this.isScrollingToCell)
546
- return;
547
- const { visibleCellIndices } = e.detail;
548
- if (visibleCellIndices.length === 0)
549
- return;
550
- const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
551
- const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
552
- if (this.currentPage !== lastVisibleCellPage) {
553
- this.currentPage = lastVisibleCellPage;
554
- }
555
- const event = new CustomEvent('visiblePageChanged', {
556
- detail: {
557
- pageNumber: lastVisibleCellPage,
558
- },
559
- });
560
- this.dispatchEvent(event);
561
- }
562
- async handleQueryChange() {
563
- var _a;
564
- // only reset if the query has actually changed
565
- if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
566
- return;
567
- this.previousQueryKey = this.pageFetchQueryKey;
568
- this.dataSource = {};
569
- this.pageFetchesInProgress = {};
570
- this.endOfDataReached = false;
571
- this.pagesToRender = this.initialPageNumber;
572
- // Reset the infinite scroller's item count, so that it
573
- // shows tile placeholders until the new query's results load in
574
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
575
- if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
576
- this.scrollToPage(this.initialPageNumber);
577
- }
578
- this.initialQueryChangeHappened = true;
579
- // if the query changed as part of a window.history pop event, we don't want to
580
- // persist the state because it overwrites the forward history
581
- if (!this.historyPopOccurred) {
582
- this.persistState();
583
- this.historyPopOccurred = false;
584
- }
585
- await Promise.all([
586
- this.doInitialPageFetch(),
587
- this.fetchFacets(),
588
- // Only fetch histogram data separately if we need it b/c of date filters
589
- this.shouldRequestYearHistogram && this.fetchFullYearHistogram(),
590
- ]);
591
- }
592
- setupStateRestorationObserver() {
593
- if (this.boundNavigationHandler)
594
- return;
595
- this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
596
- // when the user navigates back, we want to update the UI to match the URL
597
- window.addEventListener('popstate', this.boundNavigationHandler);
598
- }
599
- historyNavigationHandler() {
600
- this.historyPopOccurred = true;
601
- this.restoreState();
602
- }
603
- restoreState() {
604
- var _a, _b, _c, _d, _e, _f;
605
- const restorationState = this.restorationStateHandler.getRestorationState();
606
- this.displayMode = restorationState.displayMode;
607
- if (restorationState.searchType != null)
608
- this.searchType = restorationState.searchType;
609
- this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.relevance;
610
- this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
611
- this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
612
- this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
613
- this.selectedFacets = restorationState.selectedFacets;
614
- this.baseQuery = restorationState.baseQuery;
615
- this.titleQuery = restorationState.titleQuery;
616
- this.creatorQuery = restorationState.creatorQuery;
617
- this.dateRangeQueryClause = restorationState.dateRangeQueryClause;
618
- this.sortParam = (_e = restorationState.sortParam) !== null && _e !== void 0 ? _e : null;
619
- this.currentPage = (_f = restorationState.currentPage) !== null && _f !== void 0 ? _f : 1;
620
- this.minSelectedDate = restorationState.minSelectedDate;
621
- this.maxSelectedDate = restorationState.maxSelectedDate;
622
- if (this.currentPage > 1) {
623
- this.goToPage(this.currentPage);
624
- }
625
- }
626
- persistState() {
627
- var _a, _b, _c, _d, _e;
628
- const restorationState = {
629
- displayMode: this.displayMode,
630
- searchType: this.searchType,
631
- sortParam: (_a = this.sortParam) !== null && _a !== void 0 ? _a : undefined,
632
- selectedSort: this.selectedSort,
633
- sortDirection: (_b = this.sortDirection) !== null && _b !== void 0 ? _b : undefined,
634
- selectedFacets: (_c = this.selectedFacets) !== null && _c !== void 0 ? _c : defaultSelectedFacets,
635
- baseQuery: this.baseQuery,
636
- currentPage: this.currentPage,
637
- dateRangeQueryClause: this.dateRangeQueryClause,
638
- titleQuery: this.titleQuery,
639
- creatorQuery: this.creatorQuery,
640
- minSelectedDate: this.minSelectedDate,
641
- maxSelectedDate: this.maxSelectedDate,
642
- selectedTitleFilter: (_d = this.selectedTitleFilter) !== null && _d !== void 0 ? _d : undefined,
643
- selectedCreatorFilter: (_e = this.selectedCreatorFilter) !== null && _e !== void 0 ? _e : undefined,
644
- };
645
- this.restorationStateHandler.persistState(restorationState);
646
- }
647
- async doInitialPageFetch() {
648
- this.searchResultsLoading = true;
649
- await this.fetchPage(this.initialPageNumber);
650
- this.searchResultsLoading = false;
651
- }
652
- /** The full query, including year facets and date range clauses */
653
- get fullQuery() {
654
- if (!this.baseQuery)
655
- return undefined;
656
- let fullQuery = this.baseQuery;
657
- const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;
658
- if (facetQuery) {
659
- fullQuery += ` AND ${facetQuery}`;
660
- }
661
- if (dateRangeQueryClause) {
662
- fullQuery += ` AND ${dateRangeQueryClause}`;
663
- }
664
- if (sortFilterQueries) {
665
- fullQuery += ` AND ${sortFilterQueries}`;
666
- }
667
- return fullQuery;
668
- }
669
- /** The full query without any year facets or date range clauses */
670
- get fullQueryWithoutDates() {
671
- if (!this.baseQuery)
672
- return undefined;
673
- let fullQuery = this.baseQuery;
674
- const { facetQueryWithoutYear, sortFilterQueries } = this;
675
- if (facetQueryWithoutYear) {
676
- fullQuery += ` AND ${facetQueryWithoutYear}`;
677
- }
678
- if (sortFilterQueries) {
679
- fullQuery += ` AND ${sortFilterQueries}`;
680
- }
681
- return fullQuery;
682
- }
683
- /**
684
- * Generates a query string for the given facets
685
- *
686
- * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
687
- */
688
- get facetQuery() {
689
- if (!this.selectedFacets)
690
- return undefined;
691
- const facetClauses = [];
692
- for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
693
- facetClauses.push(this.buildFacetClause(facetName, facetValues));
694
- }
695
- return this.joinFacetClauses(facetClauses);
696
- }
697
- /**
698
- * Generates a query string for the currently selected facets, excluding 'year' facets.
699
- *
700
- * Example: `mediatype:("collection" OR "audio" OR -"etree") AND subject:("foo" OR -"bar")`
701
- */
702
- get facetQueryWithoutYear() {
703
- if (!this.selectedFacets)
704
- return undefined;
705
- const facetClauses = [];
706
- for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
707
- if (facetName !== 'year') {
708
- facetClauses.push(this.buildFacetClause(facetName, facetValues));
709
- }
710
- }
711
- return this.joinFacetClauses(facetClauses);
712
- }
713
- /**
714
- * Builds an OR-joined facet clause for the given facet name and values.
715
- *
716
- * E.g., for name `subject` and values
717
- * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`
718
- * this will produce the clause
719
- * `subject:("foo" OR -"bar")`.
720
- *
721
- * @param facetName The facet type (e.g., 'collection')
722
- * @param facetValues The facet buckets, mapped by their keys
723
- */
724
- buildFacetClause(facetName, facetValues) {
725
- const facetEntries = Object.entries(facetValues);
726
- if (facetEntries.length === 0)
727
- return '';
728
- const facetQueryName = facetName === 'lending' ? 'lending___status' : facetName;
729
- const facetValuesArray = [];
730
- for (const [key, facetData] of facetEntries) {
731
- const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
732
- if (facetName === 'language') {
733
- const languages = this.languageCodeHandler.getCodeArrayFromCodeString(key);
734
- for (const language of languages) {
735
- facetValuesArray.push(`${plusMinusPrefix}"${language}"`);
736
- }
737
- }
738
- else {
739
- facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
740
- }
741
- }
742
- const valueQuery = facetValuesArray.join(` OR `);
743
- return `${facetQueryName}:(${valueQuery})`;
744
- }
745
- /**
746
- * Takes an array of facet clauses, and combines them into a
747
- * full AND-joined facet query string. Empty clauses are ignored.
748
- */
749
- joinFacetClauses(facetClauses) {
750
- const nonEmptyFacetClauses = facetClauses.filter(clause => clause.length > 0);
751
- return nonEmptyFacetClauses.length > 0
752
- ? `(${nonEmptyFacetClauses.join(' AND ')})`
753
- : undefined;
754
- }
755
- facetsChanged(e) {
756
- this.selectedFacets = e.detail;
757
- }
758
- facetClickHandler(name, facetSelected, negative) {
759
- var _a, _b;
760
- if (negative) {
761
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
762
- category: this.searchContext,
763
- action: facetSelected
764
- ? analyticsActions.facetNegativeSelected
765
- : analyticsActions.facetNegativeDeselected,
766
- label: name,
767
- });
768
- }
769
- else {
770
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
771
- category: this.searchContext,
772
- action: facetSelected
773
- ? analyticsActions.facetSelected
774
- : analyticsActions.facetDeselected,
775
- label: name,
776
- });
777
- }
778
- }
779
- async fetchFacets() {
780
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
781
- if (!this.fullQuery)
782
- return;
783
- const params = {
784
- query: this.fullQuery,
785
- rows: 0,
786
- // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
787
- aggregationsSize: 10,
788
- // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
789
- // The default aggregations for the search_results page type should be what we need here.
790
- };
791
- this.facetsLoading = true;
792
- this.previousSearchType = this.searchType;
793
- const results = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
794
- this.facetsLoading = false;
795
- this.aggregations = (_b = results === null || results === void 0 ? void 0 : results.success) === null || _b === void 0 ? void 0 : _b.response.aggregations;
796
- // If we're not fetching year histogram data separately, set it from the newly-fetched aggregations
797
- if (!this.shouldRequestYearHistogram) {
798
- this.fullYearsHistogramAggregation =
799
- (_f = (_e = (_d = (_c = results === null || results === void 0 ? void 0 : results.success) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.aggregations) === null || _e === void 0 ? void 0 : _e.year_histogram) !== null && _f !== void 0 ? _f : (_j = (_h = (_g = results === null || results === void 0 ? void 0 : results.success) === null || _g === void 0 ? void 0 : _g.response) === null || _h === void 0 ? void 0 : _h.aggregations) === null || _j === void 0 ? void 0 : _j['year-histogram']; // Temp fix until PPS FTS key is fixed to use underscore
800
- }
801
- }
802
- /**
803
- * The query key is a string that uniquely identifies the current query
804
- * without the date range.
805
- *
806
- * If this doesn't change, we don't need to re-fetch the histogram date range
807
- */
808
- get fullQueryNoDateKey() {
809
- var _a, _b;
810
- return `${this.fullQueryWithoutDates}-${this.searchType}-${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field}-${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}`;
811
- }
812
- /**
813
- * This method is similar to fetching the facets above,
814
- * but only fetching the year histogram. There is a subtle difference
815
- * in how you have to fetch the year histogram where you can't use the
816
- * advanced JSON syntax like the other aggregations. It's a special
817
- * case that @ximm put it place.
818
- */
819
- async fetchFullYearHistogram() {
820
- var _a, _b, _c, _d, _e, _f, _g, _h;
821
- const { fullQueryNoDateKey } = this;
822
- if (!this.fullQueryWithoutDates ||
823
- fullQueryNoDateKey === this.previousFullQueryNoDate) {
824
- return;
825
- }
826
- this.previousFullQueryNoDate = fullQueryNoDateKey;
827
- const aggregations = {
828
- simpleParams: ['year'],
829
- };
830
- const params = {
831
- query: this.fullQueryWithoutDates,
832
- aggregations,
833
- rows: 0,
834
- };
835
- this.fullYearAggregationLoading = true;
836
- const results = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
837
- this.fullYearAggregationLoading = false;
838
- this.fullYearsHistogramAggregation =
839
- (_e = (_d = (_c = (_b = results === null || results === void 0 ? void 0 : results.success) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.aggregations) === null || _d === void 0 ? void 0 : _d.year_histogram) !== null && _e !== void 0 ? _e : (_h = (_g = (_f = results === null || results === void 0 ? void 0 : results.success) === null || _f === void 0 ? void 0 : _f.response) === null || _g === void 0 ? void 0 : _g.aggregations) === null || _h === void 0 ? void 0 : _h['year-histogram']; // Temp fix until PPS FTS key is fixed to use underscore
840
- }
841
- /**
842
- * We only want to send a separate request for the year_histogram data
843
- * if (a) the date picker component is enabled and (b) there is a year facet or date-range filter applied.
844
- *
845
- * Otherwise, we should just be using the histogram data supplied by the "normal" facet request.
846
- */
847
- get shouldRequestYearHistogram() {
848
- var _a, _b;
849
- const datePickerEnabled = this.showHistogramDatePicker;
850
- const hasDateRange = !!this.dateRangeQueryClause;
851
- const hasYearFacet = Object.keys((_b = (_a = this.selectedFacets) === null || _a === void 0 ? void 0 : _a.year) !== null && _b !== void 0 ? _b : {}).length > 0;
852
- return datePickerEnabled && (hasDateRange || hasYearFacet);
853
- }
854
- scrollToPage(pageNumber) {
855
- const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
856
- // without this setTimeout, Safari just pauses until the `fetchPage` is complete
857
- // then scrolls to the cell
858
- setTimeout(() => {
859
- this.isScrollingToCell = true;
860
- this.infiniteScroller.scrollToCell(cellIndexToScrollTo, true);
861
- // This timeout is to give the scroll animation time to finish
862
- // then updating the infinite scroller once we're done scrolling
863
- // There's no scroll animation completion callback so we're
864
- // giving it 0.5s to finish.
865
- setTimeout(() => {
866
- this.isScrollingToCell = false;
867
- this.infiniteScroller.reload();
868
- }, 500);
869
- }, 0);
870
- }
871
- /**
872
- * The query key is a string that uniquely identifies the current query
873
- *
874
- * This lets us keep track of queries so we don't persist data that's
875
- * no longer relevant.
876
- */
877
- get pageFetchQueryKey() {
878
- var _a, _b;
879
- return `${this.fullQuery}-${this.searchType}-${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field}-${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}`;
880
- }
881
- async fetchPage(pageNumber) {
882
- var _a, _b, _c, _d, _e;
883
- if (!this.fullQuery)
884
- return;
885
- // if we already have data, don't fetch again
886
- if (this.dataSource[pageNumber])
887
- return;
888
- if (this.endOfDataReached)
889
- return;
890
- // if a fetch is already in progress for this query and page, don't fetch again
891
- const { pageFetchQueryKey } = this;
892
- const pageFetches = (_a = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _a !== void 0 ? _a : new Set();
893
- if (pageFetches.has(pageNumber))
894
- return;
895
- pageFetches.add(pageNumber);
896
- this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
897
- const sortParams = this.sortParam ? [this.sortParam] : [];
898
- const params = {
899
- query: this.fullQuery,
900
- page: pageNumber,
901
- rows: this.pageSize,
902
- sort: sortParams,
903
- aggregations: { omit: true },
904
- };
905
- const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
906
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
907
- if (!success)
908
- return;
909
- this.totalResults = success.response.totalResults;
910
- // this is checking to see if the query has changed since the data was fetched
911
- // if so, we just want to discard the data since there should be a new query
912
- // right behind it
913
- const searchQuery = success.request.clientParameters.user_query;
914
- const searchSort = success.request.clientParameters.sort;
915
- let sortChanged = false;
916
- if (!searchSort || searchSort.length === 0) {
917
- // if we went from no sort to sort, the sort has changed
918
- if (this.sortParam) {
919
- sortChanged = true;
920
- }
921
- }
922
- else {
923
- // check if the sort has changed
924
- for (const sortType of searchSort) {
925
- const [field, direction] = sortType.split(':');
926
- if (field !== ((_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.field) ||
927
- direction !== ((_d = this.sortParam) === null || _d === void 0 ? void 0 : _d.direction)) {
928
- sortChanged = true;
929
- break;
930
- }
931
- }
932
- }
933
- const queryChangedSinceFetch = searchQuery !== this.fullQuery || sortChanged;
934
- if (queryChangedSinceFetch)
935
- return;
936
- const { results } = success.response;
937
- if (results && results.length > 0) {
938
- this.preloadCollectionNames(results);
939
- this.updateDataSource(pageNumber, results);
940
- }
941
- if (results.length < this.pageSize) {
942
- this.endOfDataReached = true;
943
- // this updates the infinite scroller to show the actual size
944
- if (this.infiniteScroller) {
945
- this.infiniteScroller.itemCount = this.actualTileCount;
946
- }
947
- }
948
- (_e = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _e === void 0 ? void 0 : _e.delete(pageNumber);
949
- this.searchResultsLoading = false;
950
- }
951
- preloadCollectionNames(results) {
952
- var _a;
953
- const collectionIds = results
954
- .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
955
- .flat();
956
- const collectionIdsArray = Array.from(new Set(collectionIds));
957
- (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
958
- }
959
- /**
960
- * This is useful for determining whether we need to reload the scroller.
961
- *
962
- * When the fetch completes, we need to reload the scroller if the cells for that
963
- * page are visible, but if the page is not currenlty visible, we don't need to reload
964
- */
965
- get currentVisiblePageNumbers() {
966
- var _a, _b;
967
- const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
968
- const visiblePages = new Set();
969
- visibleCells.forEach(cellIndex => {
970
- const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
971
- visiblePages.add(visiblePage);
972
- });
973
- return Array.from(visiblePages);
974
- }
975
- /**
976
- * Update the datasource from the fetch response
977
- *
978
- * @param pageNumber
979
- * @param results
980
- */
981
- updateDataSource(pageNumber, results) {
982
- // copy our existing datasource so when we set it below, it gets set
983
- // instead of modifying the existing dataSource since object changes
984
- // don't trigger a re-render
985
- const datasource = { ...this.dataSource };
986
- const tiles = [];
987
- results === null || results === void 0 ? void 0 : results.forEach(result => {
988
- 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;
989
- if (!result.identifier)
990
- return;
991
- let loginRequired = false;
992
- let contentWarning = false;
993
- // Check if item and item in "modifying" collection, setting above flags
994
- if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
995
- ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
996
- for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
997
- if (collection === 'loggedin') {
998
- loginRequired = true;
999
- if (contentWarning)
1000
- break;
1001
- }
1002
- if (collection === 'no-preview') {
1003
- contentWarning = true;
1004
- if (loginRequired)
1005
- break;
1006
- }
1007
- }
1008
- }
1009
- tiles.push({
1010
- averageRating: (_e = result.avg_rating) === null || _e === void 0 ? void 0 : _e.value,
1011
- collections: (_g = (_f = result.collection) === null || _f === void 0 ? void 0 : _f.values) !== null && _g !== void 0 ? _g : [],
1012
- commentCount: (_j = (_h = result.num_reviews) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : 0,
1013
- creator: (_k = result.creator) === null || _k === void 0 ? void 0 : _k.value,
1014
- creators: (_m = (_l = result.creator) === null || _l === void 0 ? void 0 : _l.values) !== null && _m !== void 0 ? _m : [],
1015
- dateAdded: (_o = result.addeddate) === null || _o === void 0 ? void 0 : _o.value,
1016
- dateArchived: (_p = result.publicdate) === null || _p === void 0 ? void 0 : _p.value,
1017
- datePublished: (_q = result.date) === null || _q === void 0 ? void 0 : _q.value,
1018
- dateReviewed: (_r = result.reviewdate) === null || _r === void 0 ? void 0 : _r.value,
1019
- description: (_s = result.description) === null || _s === void 0 ? void 0 : _s.values.join('\n'),
1020
- favCount: (_u = (_t = result.num_favorites) === null || _t === void 0 ? void 0 : _t.value) !== null && _u !== void 0 ? _u : 0,
1021
- identifier: result.identifier,
1022
- issue: (_v = result.issue) === null || _v === void 0 ? void 0 : _v.value,
1023
- itemCount: (_x = (_w = result.item_count) === null || _w === void 0 ? void 0 : _w.value) !== null && _x !== void 0 ? _x : 0,
1024
- mediatype: (_z = (_y = result.mediatype) === null || _y === void 0 ? void 0 : _y.value) !== null && _z !== void 0 ? _z : 'data',
1025
- snippets: (_1 = (_0 = result.highlight) === null || _0 === void 0 ? void 0 : _0.values) !== null && _1 !== void 0 ? _1 : [],
1026
- source: (_2 = result.source) === null || _2 === void 0 ? void 0 : _2.value,
1027
- subjects: (_4 = (_3 = result.subject) === null || _3 === void 0 ? void 0 : _3.values) !== null && _4 !== void 0 ? _4 : [],
1028
- title: this.etreeTitle((_5 = result.title) === null || _5 === void 0 ? void 0 : _5.value, (_6 = result.mediatype) === null || _6 === void 0 ? void 0 : _6.value, (_7 = result.collection) === null || _7 === void 0 ? void 0 : _7.values),
1029
- volume: (_8 = result.volume) === null || _8 === void 0 ? void 0 : _8.value,
1030
- viewCount: (_10 = (_9 = result.downloads) === null || _9 === void 0 ? void 0 : _9.value) !== null && _10 !== void 0 ? _10 : 0,
1031
- weeklyViewCount: (_11 = result.week) === null || _11 === void 0 ? void 0 : _11.value,
1032
- loginRequired,
1033
- contentWarning,
1034
- });
1035
- });
1036
- datasource[pageNumber] = tiles;
1037
- this.dataSource = datasource;
1038
- const visiblePages = this.currentVisiblePageNumbers;
1039
- const needsReload = visiblePages.includes(pageNumber);
1040
- if (needsReload) {
1041
- this.infiniteScroller.reload();
1042
- }
1043
- }
1044
- /*
1045
- * Convert etree titles
1046
- * "[Creator] Live at [Place] on [Date]" => "[Date]: [Place]"
1047
- *
1048
- * Todo: Check collection(s) for etree, need to get as array.
1049
- * Current search-service only returns first collection as string.
1050
- */
1051
- etreeTitle(title, mediatype, collections) {
1052
- if (mediatype === 'etree' || (collections === null || collections === void 0 ? void 0 : collections.includes('etree'))) {
1053
- const regex = /^(.*) Live at (.*) on (\d\d\d\d-\d\d-\d\d)$/;
1054
- const newTitle = title === null || title === void 0 ? void 0 : title.replace(regex, '$3: $2');
1055
- if (newTitle) {
1056
- return `${newTitle}`;
1057
- }
1058
- }
1059
- return title !== null && title !== void 0 ? title : '';
1060
- }
1061
- /**
1062
- * Callback when a result is selected
1063
- */
1064
- resultSelected(event) {
1065
- var _a, _b;
1066
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1067
- category: this.searchContext,
1068
- action: analyticsActions.resultSelected,
1069
- label: event.detail.mediatype,
1070
- });
1071
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1072
- category: this.searchContext,
1073
- action: analyticsActions.resultSelected,
1074
- label: `page-${this.currentPage}`,
1075
- });
1076
- }
1077
- cellForIndex(index) {
1078
- const model = this.tileModelAtCellIndex(index);
1079
- if (!model)
1080
- return undefined;
415
+ `;
416
+ }
417
+ histogramDateRangeUpdated(e) {
418
+ var _a;
419
+ const { minDate, maxDate } = e.detail;
420
+ [this.minSelectedDate, this.maxSelectedDate] = [minDate, maxDate];
421
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
422
+ category: this.searchContext,
423
+ action: analyticsActions.histogramChanged,
424
+ label: this.dateRangeQueryClause,
425
+ });
426
+ }
427
+ get dateRangeQueryClause() {
428
+ if (!this.minSelectedDate || !this.maxSelectedDate) {
429
+ return undefined;
430
+ }
431
+ return `year:[${this.minSelectedDate} TO ${this.maxSelectedDate}]`;
432
+ }
433
+ firstUpdated() {
434
+ this.setupStateRestorationObserver();
435
+ this.restoreState();
436
+ }
437
+ updated(changed) {
438
+ var _a;
439
+ if (changed.has('displayMode') ||
440
+ changed.has('baseNavigationUrl') ||
441
+ changed.has('baseImageUrl') ||
442
+ changed.has('loggedIn')) {
443
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
444
+ }
445
+ if (changed.has('baseQuery')) {
446
+ this.emitBaseQueryChanged();
447
+ }
448
+ if (changed.has('searchType')) {
449
+ this.emitSearchTypeChanged();
450
+ }
451
+ if (changed.has('currentPage') || changed.has('displayMode')) {
452
+ this.persistState();
453
+ }
454
+ if (changed.has('baseQuery') ||
455
+ changed.has('titleQuery') ||
456
+ changed.has('creatorQuery') ||
457
+ changed.has('minSelectedDate') ||
458
+ changed.has('maxSelectedDate') ||
459
+ changed.has('sortParam') ||
460
+ changed.has('selectedFacets') ||
461
+ changed.has('searchService')) {
462
+ this.handleQueryChange();
463
+ }
464
+ if (changed.has('baseQuery') ||
465
+ changed.has('minSelectedDate') ||
466
+ changed.has('maxSelectedDate') ||
467
+ changed.has('selectedFacets')) {
468
+ this.refreshLetterCounts();
469
+ }
470
+ if (changed.has('selectedSort') || changed.has('sortDirection')) {
471
+ const prevSortDirection = changed.get('sortDirection');
472
+ this.sendSortByAnalytics(prevSortDirection);
473
+ this.selectedSortChanged();
474
+ }
475
+ if (changed.has('selectedTitleFilter')) {
476
+ this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
477
+ this.selectedTitleLetterChanged();
478
+ }
479
+ if (changed.has('selectedCreatorFilter')) {
480
+ this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
481
+ this.selectedCreatorLetterChanged();
482
+ }
483
+ if (changed.has('pagesToRender')) {
484
+ if (!this.endOfDataReached && this.infiniteScroller) {
485
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
486
+ }
487
+ }
488
+ if (changed.has('resizeObserver')) {
489
+ const oldObserver = changed.get('resizeObserver');
490
+ if (oldObserver)
491
+ this.disconnectResizeObserver(oldObserver);
492
+ this.setupResizeObserver();
493
+ }
494
+ }
495
+ disconnectedCallback() {
496
+ if (this.resizeObserver) {
497
+ this.disconnectResizeObserver(this.resizeObserver);
498
+ }
499
+ if (this.boundNavigationHandler) {
500
+ window.removeEventListener('popstate', this.boundNavigationHandler);
501
+ }
502
+ }
503
+ handleResize(entry) {
504
+ const previousView = this.mobileView;
505
+ if (entry.target === this.contentContainer) {
506
+ this.mobileView = entry.contentRect.width < this.mobileBreakpoint;
507
+ // If changing from desktop to mobile disable transition
508
+ if (this.mobileView && !previousView) {
509
+ this.isResizeToMobile = true;
510
+ }
511
+ }
512
+ }
513
+ emitBaseQueryChanged() {
514
+ this.dispatchEvent(new CustomEvent('baseQueryChanged', {
515
+ detail: {
516
+ baseQuery: this.baseQuery,
517
+ },
518
+ }));
519
+ }
520
+ emitSearchTypeChanged() {
521
+ this.dispatchEvent(new CustomEvent('searchTypeChanged', {
522
+ detail: this.searchType,
523
+ }));
524
+ }
525
+ disconnectResizeObserver(resizeObserver) {
526
+ resizeObserver.removeObserver({
527
+ target: this.contentContainer,
528
+ handler: this,
529
+ });
530
+ }
531
+ setupResizeObserver() {
532
+ if (!this.resizeObserver)
533
+ return;
534
+ this.resizeObserver.addObserver({
535
+ target: this.contentContainer,
536
+ handler: this,
537
+ });
538
+ }
539
+ /**
540
+ * When the visible cells change from the infinite scroller, we want to emit
541
+ * which page is currently visible so the consumer can update its UI or the URL
542
+ *
543
+ * @param e
544
+ * @returns
545
+ */
546
+ visibleCellsChanged(e) {
547
+ if (this.isScrollingToCell)
548
+ return;
549
+ const { visibleCellIndices } = e.detail;
550
+ if (visibleCellIndices.length === 0)
551
+ return;
552
+ const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
553
+ const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
554
+ if (this.currentPage !== lastVisibleCellPage) {
555
+ this.currentPage = lastVisibleCellPage;
556
+ }
557
+ const event = new CustomEvent('visiblePageChanged', {
558
+ detail: {
559
+ pageNumber: lastVisibleCellPage,
560
+ },
561
+ });
562
+ this.dispatchEvent(event);
563
+ }
564
+ async handleQueryChange() {
565
+ var _a;
566
+ // only reset if the query has actually changed
567
+ if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
568
+ return;
569
+ this.previousQueryKey = this.pageFetchQueryKey;
570
+ this.dataSource = {};
571
+ this.totalResults = undefined;
572
+ this.aggregations = undefined;
573
+ this.fullYearsHistogramAggregation = undefined;
574
+ this.pageFetchesInProgress = {};
575
+ this.endOfDataReached = false;
576
+ this.pagesToRender = this.initialPageNumber;
577
+ // Reset the infinite scroller's item count, so that it
578
+ // shows tile placeholders until the new query's results load in
579
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
580
+ if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
581
+ this.scrollToPage(this.initialPageNumber);
582
+ }
583
+ this.initialQueryChangeHappened = true;
584
+ // if the query changed as part of a window.history pop event, we don't want to
585
+ // persist the state because it overwrites the forward history
586
+ if (!this.historyPopOccurred) {
587
+ this.persistState();
588
+ this.historyPopOccurred = false;
589
+ }
590
+ await Promise.all([
591
+ this.doInitialPageFetch(),
592
+ this.fetchFacets(),
593
+ // Only fetch histogram data separately if we need it b/c of date filters
594
+ this.shouldRequestYearHistogram && this.fetchFullYearHistogram(),
595
+ ]);
596
+ }
597
+ setupStateRestorationObserver() {
598
+ if (this.boundNavigationHandler)
599
+ return;
600
+ this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
601
+ // when the user navigates back, we want to update the UI to match the URL
602
+ window.addEventListener('popstate', this.boundNavigationHandler);
603
+ }
604
+ historyNavigationHandler() {
605
+ this.historyPopOccurred = true;
606
+ this.restoreState();
607
+ }
608
+ restoreState() {
609
+ var _a, _b, _c, _d, _e, _f;
610
+ const restorationState = this.restorationStateHandler.getRestorationState();
611
+ this.displayMode = restorationState.displayMode;
612
+ if (restorationState.searchType != null)
613
+ this.searchType = restorationState.searchType;
614
+ this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.relevance;
615
+ this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
616
+ this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
617
+ this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
618
+ this.selectedFacets = restorationState.selectedFacets;
619
+ this.baseQuery = restorationState.baseQuery;
620
+ this.titleQuery = restorationState.titleQuery;
621
+ this.creatorQuery = restorationState.creatorQuery;
622
+ this.sortParam = (_e = restorationState.sortParam) !== null && _e !== void 0 ? _e : null;
623
+ this.currentPage = (_f = restorationState.currentPage) !== null && _f !== void 0 ? _f : 1;
624
+ this.minSelectedDate = restorationState.minSelectedDate;
625
+ this.maxSelectedDate = restorationState.maxSelectedDate;
626
+ if (this.currentPage > 1) {
627
+ this.goToPage(this.currentPage);
628
+ }
629
+ }
630
+ persistState() {
631
+ var _a, _b, _c, _d, _e;
632
+ const restorationState = {
633
+ displayMode: this.displayMode,
634
+ searchType: this.searchType,
635
+ sortParam: (_a = this.sortParam) !== null && _a !== void 0 ? _a : undefined,
636
+ selectedSort: this.selectedSort,
637
+ sortDirection: (_b = this.sortDirection) !== null && _b !== void 0 ? _b : undefined,
638
+ selectedFacets: (_c = this.selectedFacets) !== null && _c !== void 0 ? _c : defaultSelectedFacets,
639
+ baseQuery: this.baseQuery,
640
+ currentPage: this.currentPage,
641
+ titleQuery: this.titleQuery,
642
+ creatorQuery: this.creatorQuery,
643
+ minSelectedDate: this.minSelectedDate,
644
+ maxSelectedDate: this.maxSelectedDate,
645
+ selectedTitleFilter: (_d = this.selectedTitleFilter) !== null && _d !== void 0 ? _d : undefined,
646
+ selectedCreatorFilter: (_e = this.selectedCreatorFilter) !== null && _e !== void 0 ? _e : undefined,
647
+ };
648
+ this.restorationStateHandler.persistState(restorationState);
649
+ }
650
+ async doInitialPageFetch() {
651
+ this.searchResultsLoading = true;
652
+ await this.fetchPage(this.initialPageNumber);
653
+ this.searchResultsLoading = false;
654
+ }
655
+ get filterMap() {
656
+ const builder = new FilterMapBuilder();
657
+ // Add the date range, if applicable
658
+ if (this.minSelectedDate) {
659
+ builder.addFilter('year', this.minSelectedDate, FilterConstraint.GREATER_OR_EQUAL);
660
+ }
661
+ if (this.maxSelectedDate) {
662
+ builder.addFilter('year', this.maxSelectedDate, FilterConstraint.LESS_OR_EQUAL);
663
+ }
664
+ // Add any selected facets
665
+ if (this.selectedFacets) {
666
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
667
+ const { name, values } = this.prepareFacetForFetch(facetName, facetValues);
668
+ for (const [value, bucket] of Object.entries(values)) {
669
+ let constraint;
670
+ if (bucket.state === 'selected') {
671
+ constraint = FilterConstraint.INCLUDE;
672
+ }
673
+ else if (bucket.state === 'hidden') {
674
+ constraint = FilterConstraint.EXCLUDE;
675
+ }
676
+ if (constraint) {
677
+ builder.addFilter(name, value, constraint);
678
+ }
679
+ }
680
+ }
681
+ }
682
+ const filterMap = builder.build();
683
+ // TEMP: At present, the backend search engine incorrectly returns 0 results if
684
+ // the _first_ language filter contains a space, so let's try to avoid that if possible.
685
+ if (filterMap.language) {
686
+ for (const [value, constraint] of Object.entries(filterMap.language)) {
687
+ if (value.includes(' ')) {
688
+ // Delete and re-add this filter to make it the last one on the parent object
689
+ // (Technically this isn't in the standard, but most browser impls output
690
+ // object keys in the order they were added.)
691
+ delete filterMap.language[value];
692
+ filterMap.language[value] = constraint;
693
+ }
694
+ else {
695
+ // As soon as we reach one without a space, we're done
696
+ break;
697
+ }
698
+ }
699
+ }
700
+ return filterMap;
701
+ }
702
+ /** The base query joined with any title/creator letter filters */
703
+ get filteredQuery() {
704
+ if (!this.baseQuery)
705
+ return undefined;
706
+ let filteredQuery = this.baseQuery;
707
+ const { sortFilterQueries } = this;
708
+ if (sortFilterQueries) {
709
+ filteredQuery += ` AND ${sortFilterQueries}`;
710
+ }
711
+ return filteredQuery;
712
+ }
713
+ /** The full query, including year facets and date range clauses */
714
+ get fullQuery() {
715
+ if (!this.baseQuery)
716
+ return undefined;
717
+ let fullQuery = this.baseQuery;
718
+ const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;
719
+ if (facetQuery) {
720
+ fullQuery += ` AND ${facetQuery}`;
721
+ }
722
+ if (dateRangeQueryClause) {
723
+ fullQuery += ` AND ${dateRangeQueryClause}`;
724
+ }
725
+ if (sortFilterQueries) {
726
+ fullQuery += ` AND ${sortFilterQueries}`;
727
+ }
728
+ return fullQuery;
729
+ }
730
+ /** The full query without any title/creator letter filters */
731
+ get fullQueryWithoutAlphaFilters() {
732
+ if (!this.baseQuery)
733
+ return undefined;
734
+ let fullQuery = this.baseQuery;
735
+ const { facetQuery, dateRangeQueryClause } = this;
736
+ if (facetQuery) {
737
+ fullQuery += ` AND ${facetQuery}`;
738
+ }
739
+ if (dateRangeQueryClause) {
740
+ fullQuery += ` AND ${dateRangeQueryClause}`;
741
+ }
742
+ return fullQuery;
743
+ }
744
+ /** The full query without any year facets or date range clauses */
745
+ get fullQueryWithoutDates() {
746
+ if (!this.baseQuery)
747
+ return undefined;
748
+ let fullQuery = this.baseQuery;
749
+ const { facetQueryWithoutYear, sortFilterQueries } = this;
750
+ if (facetQueryWithoutYear) {
751
+ fullQuery += ` AND ${facetQueryWithoutYear}`;
752
+ }
753
+ if (sortFilterQueries) {
754
+ fullQuery += ` AND ${sortFilterQueries}`;
755
+ }
756
+ return fullQuery;
757
+ }
758
+ /**
759
+ * Generates a query string for the given facets
760
+ *
761
+ * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
762
+ */
763
+ get facetQuery() {
764
+ if (!this.selectedFacets)
765
+ return undefined;
766
+ const facetClauses = [];
767
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
768
+ facetClauses.push(this.buildFacetClause(facetName, facetValues));
769
+ }
770
+ return this.joinFacetClauses(facetClauses);
771
+ }
772
+ /**
773
+ * Generates a query string for the currently selected facets, excluding 'year' facets.
774
+ *
775
+ * Example: `mediatype:("collection" OR "audio" OR -"etree") AND subject:("foo" OR -"bar")`
776
+ */
777
+ get facetQueryWithoutYear() {
778
+ if (!this.selectedFacets)
779
+ return undefined;
780
+ const facetClauses = [];
781
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
782
+ if (facetName !== 'year') {
783
+ facetClauses.push(this.buildFacetClause(facetName, facetValues));
784
+ }
785
+ }
786
+ return this.joinFacetClauses(facetClauses);
787
+ }
788
+ /**
789
+ * Builds an OR-joined facet clause for the given facet name and values.
790
+ *
791
+ * E.g., for name `subject` and values
792
+ * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`
793
+ * this will produce the clause
794
+ * `subject:("foo" OR -"bar")`.
795
+ *
796
+ * @param facetName The facet type (e.g., 'collection')
797
+ * @param facetValues The facet buckets, mapped by their keys
798
+ */
799
+ buildFacetClause(facetName, facetValues) {
800
+ const { name: facetQueryName, values } = this.prepareFacetForFetch(facetName, facetValues);
801
+ const facetEntries = Object.entries(values);
802
+ if (facetEntries.length === 0)
803
+ return '';
804
+ const facetValuesArray = [];
805
+ for (const [key, facetData] of facetEntries) {
806
+ const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
807
+ facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
808
+ }
809
+ const valueQuery = facetValuesArray.join(` OR `);
810
+ return `${facetQueryName}:(${valueQuery})`;
811
+ }
812
+ /**
813
+ * Handles some special pre-request normalization steps for certain facet types
814
+ * that require them.
815
+ *
816
+ * @param facetName The name of the facet type (e.g., 'language')
817
+ * @param facetValues An array of values for that facet type
818
+ */
819
+ prepareFacetForFetch(facetName, facetValues) {
820
+ let [normalizedName, normalizedValues] = [facetName, facetValues];
821
+ // The full "search engine" name of the lending field is "lending___status"
822
+ if (facetName === 'lending') {
823
+ normalizedName = 'lending___status';
824
+ }
825
+ // Language codes like "en-US|en-GB|en" need to be broken apart into individual values
826
+ if (facetName === 'language') {
827
+ normalizedValues = {};
828
+ for (const [facetValue, facetData] of Object.entries(facetValues)) {
829
+ const languages = this.languageCodeHandler.getCodeArrayFromCodeString(facetValue);
830
+ for (const lang of languages) {
831
+ normalizedValues[lang] = { ...facetData };
832
+ }
833
+ }
834
+ }
835
+ return {
836
+ name: normalizedName,
837
+ values: normalizedValues,
838
+ };
839
+ }
840
+ /**
841
+ * Takes an array of facet clauses, and combines them into a
842
+ * full AND-joined facet query string. Empty clauses are ignored.
843
+ */
844
+ joinFacetClauses(facetClauses) {
845
+ const nonEmptyFacetClauses = facetClauses.filter(clause => clause.length > 0);
846
+ return nonEmptyFacetClauses.length > 0
847
+ ? `(${nonEmptyFacetClauses.join(' AND ')})`
848
+ : undefined;
849
+ }
850
+ facetsChanged(e) {
851
+ this.selectedFacets = e.detail;
852
+ }
853
+ facetClickHandler(name, facetSelected, negative) {
854
+ var _a, _b;
855
+ if (negative) {
856
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
857
+ category: this.searchContext,
858
+ action: facetSelected
859
+ ? analyticsActions.facetNegativeSelected
860
+ : analyticsActions.facetNegativeDeselected,
861
+ label: name,
862
+ });
863
+ }
864
+ else {
865
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
866
+ category: this.searchContext,
867
+ action: facetSelected
868
+ ? analyticsActions.facetSelected
869
+ : analyticsActions.facetDeselected,
870
+ label: name,
871
+ });
872
+ }
873
+ }
874
+ async fetchFacets() {
875
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
876
+ if (!this.filteredQuery)
877
+ return;
878
+ const params = {
879
+ query: this.filteredQuery,
880
+ rows: 0,
881
+ filters: this.filterMap,
882
+ // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
883
+ aggregationsSize: 10,
884
+ // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
885
+ // The default aggregations for the search_results page type should be what we need here.
886
+ };
887
+ this.facetsLoading = true;
888
+ this.previousSearchType = this.searchType;
889
+ const results = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
890
+ this.facetsLoading = false;
891
+ this.aggregations = (_b = results === null || results === void 0 ? void 0 : results.success) === null || _b === void 0 ? void 0 : _b.response.aggregations;
892
+ // If we're not fetching year histogram data separately, set it from the newly-fetched aggregations
893
+ if (!this.shouldRequestYearHistogram) {
894
+ this.fullYearsHistogramAggregation =
895
+ (_f = (_e = (_d = (_c = results === null || results === void 0 ? void 0 : results.success) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.aggregations) === null || _e === void 0 ? void 0 : _e.year_histogram) !== null && _f !== void 0 ? _f : (_j = (_h = (_g = results === null || results === void 0 ? void 0 : results.success) === null || _g === void 0 ? void 0 : _g.response) === null || _h === void 0 ? void 0 : _h.aggregations) === null || _j === void 0 ? void 0 : _j['year-histogram']; // Temp fix until PPS FTS key is fixed to use underscore
896
+ }
897
+ }
898
+ /**
899
+ * The query key is a string that uniquely identifies the current query
900
+ * without the date range.
901
+ *
902
+ * If this doesn't change, we don't need to re-fetch the histogram date range
903
+ */
904
+ get fullQueryNoDateKey() {
905
+ var _a, _b;
906
+ return `${this.fullQueryWithoutDates}-${this.searchType}-${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field}-${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}`;
907
+ }
908
+ /**
909
+ * This method is similar to fetching the facets above,
910
+ * but only fetching the year histogram. There is a subtle difference
911
+ * in how you have to fetch the year histogram where you can't use the
912
+ * advanced JSON syntax like the other aggregations. It's a special
913
+ * case that @ximm put it place.
914
+ */
915
+ async fetchFullYearHistogram() {
916
+ var _a, _b, _c, _d, _e, _f, _g, _h;
917
+ const { fullQueryNoDateKey } = this;
918
+ if (!this.fullQueryWithoutDates ||
919
+ fullQueryNoDateKey === this.previousFullQueryNoDate) {
920
+ return;
921
+ }
922
+ this.previousFullQueryNoDate = fullQueryNoDateKey;
923
+ const aggregations = {
924
+ simpleParams: ['year'],
925
+ };
926
+ const params = {
927
+ query: this.fullQueryWithoutDates,
928
+ aggregations,
929
+ rows: 0,
930
+ };
931
+ this.fullYearAggregationLoading = true;
932
+ const results = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
933
+ this.fullYearAggregationLoading = false;
934
+ this.fullYearsHistogramAggregation =
935
+ (_e = (_d = (_c = (_b = results === null || results === void 0 ? void 0 : results.success) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.aggregations) === null || _d === void 0 ? void 0 : _d.year_histogram) !== null && _e !== void 0 ? _e : (_h = (_g = (_f = results === null || results === void 0 ? void 0 : results.success) === null || _f === void 0 ? void 0 : _f.response) === null || _g === void 0 ? void 0 : _g.aggregations) === null || _h === void 0 ? void 0 : _h['year-histogram']; // Temp fix until PPS FTS key is fixed to use underscore
936
+ }
937
+ /**
938
+ * We only want to send a separate request for the year_histogram data
939
+ * if (a) the date picker component is enabled and (b) there is a year facet or date-range filter applied.
940
+ *
941
+ * Otherwise, we should just be using the histogram data supplied by the "normal" facet request.
942
+ */
943
+ get shouldRequestYearHistogram() {
944
+ var _a, _b;
945
+ const datePickerEnabled = this.showHistogramDatePicker;
946
+ const hasDateRange = !!this.dateRangeQueryClause;
947
+ const hasYearFacet = Object.keys((_b = (_a = this.selectedFacets) === null || _a === void 0 ? void 0 : _a.year) !== null && _b !== void 0 ? _b : {}).length > 0;
948
+ return datePickerEnabled && (hasDateRange || hasYearFacet);
949
+ }
950
+ scrollToPage(pageNumber) {
951
+ const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
952
+ // without this setTimeout, Safari just pauses until the `fetchPage` is complete
953
+ // then scrolls to the cell
954
+ setTimeout(() => {
955
+ this.isScrollingToCell = true;
956
+ this.infiniteScroller.scrollToCell(cellIndexToScrollTo, true);
957
+ // This timeout is to give the scroll animation time to finish
958
+ // then updating the infinite scroller once we're done scrolling
959
+ // There's no scroll animation completion callback so we're
960
+ // giving it 0.5s to finish.
961
+ setTimeout(() => {
962
+ this.isScrollingToCell = false;
963
+ this.infiniteScroller.reload();
964
+ }, 500);
965
+ }, 0);
966
+ }
967
+ /**
968
+ * The query key is a string that uniquely identifies the current search.
969
+ * It consists of:
970
+ * - The current base query
971
+ * - The current search type
972
+ * - Any currently-applied facets
973
+ * - Any currently-applied date range
974
+ * - Any currently-applied prefix filters
975
+ * - The current sort options
976
+ *
977
+ * This lets us keep track of queries so we don't persist data that's
978
+ * no longer relevant.
979
+ */
980
+ get pageFetchQueryKey() {
981
+ var _a, _b;
982
+ return `${this.fullQuery}-${this.searchType}-${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field}-${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}`;
983
+ }
984
+ async fetchPage(pageNumber) {
985
+ var _a, _b, _c, _d, _e;
986
+ if (!this.filteredQuery)
987
+ return;
988
+ // if we already have data, don't fetch again
989
+ if (this.dataSource[pageNumber])
990
+ return;
991
+ if (this.endOfDataReached)
992
+ return;
993
+ // if a fetch is already in progress for this query and page, don't fetch again
994
+ const { pageFetchQueryKey } = this;
995
+ const pageFetches = (_a = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _a !== void 0 ? _a : new Set();
996
+ if (pageFetches.has(pageNumber))
997
+ return;
998
+ pageFetches.add(pageNumber);
999
+ this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
1000
+ const sortParams = this.sortParam ? [this.sortParam] : [];
1001
+ const params = {
1002
+ query: this.filteredQuery,
1003
+ page: pageNumber,
1004
+ rows: this.pageSize,
1005
+ sort: sortParams,
1006
+ filters: this.filterMap,
1007
+ aggregations: { omit: true },
1008
+ };
1009
+ const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
1010
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
1011
+ if (!success)
1012
+ return;
1013
+ this.totalResults = success.response.totalResults;
1014
+ // this is checking to see if the query has changed since the data was fetched
1015
+ // if so, we just want to discard the data since there should be a new query
1016
+ // right behind it
1017
+ const searchQuery = success.request.clientParameters.user_query;
1018
+ const searchSort = success.request.clientParameters.sort;
1019
+ let sortChanged = false;
1020
+ if (!searchSort || searchSort.length === 0) {
1021
+ // if we went from no sort to sort, the sort has changed
1022
+ if (this.sortParam) {
1023
+ sortChanged = true;
1024
+ }
1025
+ }
1026
+ else {
1027
+ // check if the sort has changed
1028
+ for (const sortType of searchSort) {
1029
+ const [field, direction] = sortType.split(':');
1030
+ if (field !== ((_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.field) ||
1031
+ direction !== ((_d = this.sortParam) === null || _d === void 0 ? void 0 : _d.direction)) {
1032
+ sortChanged = true;
1033
+ break;
1034
+ }
1035
+ }
1036
+ }
1037
+ const queryChangedSinceFetch = searchQuery !== this.filteredQuery || sortChanged;
1038
+ if (queryChangedSinceFetch)
1039
+ return;
1040
+ const { results } = success.response;
1041
+ if (results && results.length > 0) {
1042
+ this.preloadCollectionNames(results);
1043
+ this.updateDataSource(pageNumber, results);
1044
+ }
1045
+ // When we reach the end of the data, we can set the infinite scroller's
1046
+ // item count to the real total number of results (rather than the
1047
+ // temporary estimates based on pages rendered so far).
1048
+ if (results.length < this.pageSize) {
1049
+ this.endOfDataReached = true;
1050
+ this.infiniteScroller.itemCount = this.totalResults;
1051
+ }
1052
+ (_e = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _e === void 0 ? void 0 : _e.delete(pageNumber);
1053
+ this.searchResultsLoading = false;
1054
+ }
1055
+ preloadCollectionNames(results) {
1056
+ var _a;
1057
+ const collectionIds = results
1058
+ .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
1059
+ .flat();
1060
+ const collectionIdsArray = Array.from(new Set(collectionIds));
1061
+ (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
1062
+ }
1063
+ /**
1064
+ * This is useful for determining whether we need to reload the scroller.
1065
+ *
1066
+ * When the fetch completes, we need to reload the scroller if the cells for that
1067
+ * page are visible, but if the page is not currenlty visible, we don't need to reload
1068
+ */
1069
+ get currentVisiblePageNumbers() {
1070
+ var _a, _b;
1071
+ const visibleCells = (_b = (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.getVisibleCellIndices()) !== null && _b !== void 0 ? _b : [];
1072
+ const visiblePages = new Set();
1073
+ visibleCells.forEach(cellIndex => {
1074
+ const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
1075
+ visiblePages.add(visiblePage);
1076
+ });
1077
+ return Array.from(visiblePages);
1078
+ }
1079
+ /**
1080
+ * Update the datasource from the fetch response
1081
+ *
1082
+ * @param pageNumber
1083
+ * @param results
1084
+ */
1085
+ updateDataSource(pageNumber, results) {
1086
+ // copy our existing datasource so when we set it below, it gets set
1087
+ // instead of modifying the existing dataSource since object changes
1088
+ // don't trigger a re-render
1089
+ const datasource = { ...this.dataSource };
1090
+ const tiles = [];
1091
+ results === null || results === void 0 ? void 0 : results.forEach(result => {
1092
+ 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;
1093
+ if (!result.identifier)
1094
+ return;
1095
+ let loginRequired = false;
1096
+ let contentWarning = false;
1097
+ // Check if item and item in "modifying" collection, setting above flags
1098
+ if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
1099
+ ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
1100
+ for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
1101
+ if (collection === 'loggedin') {
1102
+ loginRequired = true;
1103
+ if (contentWarning)
1104
+ break;
1105
+ }
1106
+ if (collection === 'no-preview') {
1107
+ contentWarning = true;
1108
+ if (loginRequired)
1109
+ break;
1110
+ }
1111
+ }
1112
+ }
1113
+ tiles.push({
1114
+ averageRating: (_e = result.avg_rating) === null || _e === void 0 ? void 0 : _e.value,
1115
+ collections: (_g = (_f = result.collection) === null || _f === void 0 ? void 0 : _f.values) !== null && _g !== void 0 ? _g : [],
1116
+ commentCount: (_j = (_h = result.num_reviews) === null || _h === void 0 ? void 0 : _h.value) !== null && _j !== void 0 ? _j : 0,
1117
+ creator: (_k = result.creator) === null || _k === void 0 ? void 0 : _k.value,
1118
+ creators: (_m = (_l = result.creator) === null || _l === void 0 ? void 0 : _l.values) !== null && _m !== void 0 ? _m : [],
1119
+ dateAdded: (_o = result.addeddate) === null || _o === void 0 ? void 0 : _o.value,
1120
+ dateArchived: (_p = result.publicdate) === null || _p === void 0 ? void 0 : _p.value,
1121
+ datePublished: (_q = result.date) === null || _q === void 0 ? void 0 : _q.value,
1122
+ dateReviewed: (_r = result.reviewdate) === null || _r === void 0 ? void 0 : _r.value,
1123
+ description: (_s = result.description) === null || _s === void 0 ? void 0 : _s.values.join('\n'),
1124
+ favCount: (_u = (_t = result.num_favorites) === null || _t === void 0 ? void 0 : _t.value) !== null && _u !== void 0 ? _u : 0,
1125
+ identifier: result.identifier,
1126
+ issue: (_v = result.issue) === null || _v === void 0 ? void 0 : _v.value,
1127
+ itemCount: (_x = (_w = result.item_count) === null || _w === void 0 ? void 0 : _w.value) !== null && _x !== void 0 ? _x : 0,
1128
+ mediatype: (_z = (_y = result.mediatype) === null || _y === void 0 ? void 0 : _y.value) !== null && _z !== void 0 ? _z : 'data',
1129
+ snippets: (_1 = (_0 = result.highlight) === null || _0 === void 0 ? void 0 : _0.values) !== null && _1 !== void 0 ? _1 : [],
1130
+ source: (_2 = result.source) === null || _2 === void 0 ? void 0 : _2.value,
1131
+ subjects: (_4 = (_3 = result.subject) === null || _3 === void 0 ? void 0 : _3.values) !== null && _4 !== void 0 ? _4 : [],
1132
+ title: this.etreeTitle((_5 = result.title) === null || _5 === void 0 ? void 0 : _5.value, (_6 = result.mediatype) === null || _6 === void 0 ? void 0 : _6.value, (_7 = result.collection) === null || _7 === void 0 ? void 0 : _7.values),
1133
+ volume: (_8 = result.volume) === null || _8 === void 0 ? void 0 : _8.value,
1134
+ viewCount: (_10 = (_9 = result.downloads) === null || _9 === void 0 ? void 0 : _9.value) !== null && _10 !== void 0 ? _10 : 0,
1135
+ weeklyViewCount: (_11 = result.week) === null || _11 === void 0 ? void 0 : _11.value,
1136
+ loginRequired,
1137
+ contentWarning,
1138
+ });
1139
+ });
1140
+ datasource[pageNumber] = tiles;
1141
+ this.dataSource = datasource;
1142
+ const visiblePages = this.currentVisiblePageNumbers;
1143
+ const needsReload = visiblePages.includes(pageNumber);
1144
+ if (needsReload) {
1145
+ this.infiniteScroller.reload();
1146
+ }
1147
+ }
1148
+ /** Fetches the aggregation buckets for the given prefix filter type. */
1149
+ async fetchPrefixFilterBuckets(filterType) {
1150
+ var _a, _b, _c, _d, _e, _f;
1151
+ if (!this.fullQueryWithoutAlphaFilters)
1152
+ return [];
1153
+ const filterAggregationKey = prefixFilterAggregationKeys[filterType];
1154
+ const params = {
1155
+ query: this.fullQueryWithoutAlphaFilters,
1156
+ rows: 0,
1157
+ // Only fetch the firstTitle or firstCreator aggregation
1158
+ aggregations: { simpleParams: [filterAggregationKey] },
1159
+ // Fetch all 26 letter buckets
1160
+ aggregationsSize: 26,
1161
+ };
1162
+ const searchResponse = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
1163
+ return ((_f = (_e = (_d = (_c = (_b = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.aggregations) === null || _d === void 0 ? void 0 : _d[filterAggregationKey]) === null || _e === void 0 ? void 0 : _e.buckets) !== null && _f !== void 0 ? _f : []);
1164
+ }
1165
+ /** Fetches and caches the prefix filter counts for the given filter type. */
1166
+ async updatePrefixFilterCounts(filterType) {
1167
+ const buckets = await this.fetchPrefixFilterBuckets(filterType);
1168
+ // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }
1169
+ this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update
1170
+ this.prefixFilterCountMap[filterType] = buckets.reduce((acc, bucket) => {
1171
+ acc[bucket.key.toUpperCase()] = bucket.doc_count;
1172
+ return acc;
1173
+ }, {});
1174
+ }
1175
+ /**
1176
+ * Fetches and caches the prefix filter counts for the current sort type,
1177
+ * provided it is one that permits prefix filtering. (If not, this does nothing).
1178
+ */
1179
+ async updatePrefixFiltersForCurrentSort() {
1180
+ if (['title', 'creator'].includes(this.selectedSort)) {
1181
+ const filterType = this.selectedSort;
1182
+ if (!this.prefixFilterCountMap[filterType]) {
1183
+ this.updatePrefixFilterCounts(filterType);
1184
+ }
1185
+ }
1186
+ }
1187
+ /**
1188
+ * Clears the cached letter counts for both title and creator, and
1189
+ * fetches a new set of counts for whichever of them is the currently
1190
+ * selected sort option (which may be neither).
1191
+ *
1192
+ * Call this whenever the counts are invalidated (e.g., by a query change).
1193
+ */
1194
+ refreshLetterCounts() {
1195
+ this.prefixFilterCountMap = {};
1196
+ this.updatePrefixFiltersForCurrentSort();
1197
+ }
1198
+ /*
1199
+ * Convert etree titles
1200
+ * "[Creator] Live at [Place] on [Date]" => "[Date]: [Place]"
1201
+ *
1202
+ * Todo: Check collection(s) for etree, need to get as array.
1203
+ * Current search-service only returns first collection as string.
1204
+ */
1205
+ etreeTitle(title, mediatype, collections) {
1206
+ if (mediatype === 'etree' || (collections === null || collections === void 0 ? void 0 : collections.includes('etree'))) {
1207
+ const regex = /^(.*) Live at (.*) on (\d\d\d\d-\d\d-\d\d)$/;
1208
+ const newTitle = title === null || title === void 0 ? void 0 : title.replace(regex, '$3: $2');
1209
+ if (newTitle) {
1210
+ return `${newTitle}`;
1211
+ }
1212
+ }
1213
+ return title !== null && title !== void 0 ? title : '';
1214
+ }
1215
+ /**
1216
+ * Callback when a result is selected
1217
+ */
1218
+ resultSelected(event) {
1219
+ var _a, _b;
1220
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEvent({
1221
+ category: this.searchContext,
1222
+ action: analyticsActions.resultSelected,
1223
+ label: event.detail.mediatype,
1224
+ });
1225
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEvent({
1226
+ category: this.searchContext,
1227
+ action: analyticsActions.resultSelected,
1228
+ label: `page-${this.currentPage}`,
1229
+ });
1230
+ }
1231
+ cellForIndex(index) {
1232
+ const model = this.tileModelAtCellIndex(index);
1233
+ if (!model)
1234
+ return undefined;
1081
1235
  return html `
1082
1236
  <tile-dispatcher
1083
1237
  .baseNavigationUrl=${this.baseNavigationUrl}
@@ -1092,17 +1246,19 @@ let CollectionBrowser = class CollectionBrowser extends LitElement {
1092
1246
  @resultSelected=${(e) => this.resultSelected(e)}
1093
1247
  >
1094
1248
  </tile-dispatcher>
1095
- `;
1096
- }
1097
- /**
1098
- * When the user scrolls near to the bottom of the page, fetch the next page
1099
- * increase the number of pages to render and start fetching data for the new page
1100
- */
1101
- scrollThresholdReached() {
1102
- this.pagesToRender += 1;
1103
- this.fetchPage(this.pagesToRender);
1104
- }
1105
- };
1249
+ `;
1250
+ }
1251
+ /**
1252
+ * When the user scrolls near to the bottom of the page, fetch the next page
1253
+ * increase the number of pages to render and start fetching data for the new page
1254
+ */
1255
+ scrollThresholdReached() {
1256
+ if (!this.endOfDataReached) {
1257
+ this.pagesToRender += 1;
1258
+ this.fetchPage(this.pagesToRender);
1259
+ }
1260
+ }
1261
+ };
1106
1262
  CollectionBrowser.styles = css `
1107
1263
  :host {
1108
1264
  display: block;
@@ -1308,138 +1464,138 @@ CollectionBrowser.styles = css `
1308
1464
  29rem
1309
1465
  );
1310
1466
  }
1311
- `;
1312
- __decorate([
1313
- property({ type: String })
1314
- ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
1315
- __decorate([
1316
- property({ type: String })
1317
- ], CollectionBrowser.prototype, "baseImageUrl", void 0);
1318
- __decorate([
1319
- property({ type: Object })
1320
- ], CollectionBrowser.prototype, "searchService", void 0);
1321
- __decorate([
1322
- property({ type: String })
1323
- ], CollectionBrowser.prototype, "searchType", void 0);
1324
- __decorate([
1325
- property({ type: String })
1326
- ], CollectionBrowser.prototype, "baseQuery", void 0);
1327
- __decorate([
1328
- property({ type: String })
1329
- ], CollectionBrowser.prototype, "displayMode", void 0);
1330
- __decorate([
1331
- property({ type: Object })
1332
- ], CollectionBrowser.prototype, "sortParam", void 0);
1333
- __decorate([
1334
- property({ type: String })
1335
- ], CollectionBrowser.prototype, "selectedSort", void 0);
1336
- __decorate([
1337
- property({ type: String })
1338
- ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
1339
- __decorate([
1340
- property({ type: String })
1341
- ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
1342
- __decorate([
1343
- property({ type: String })
1344
- ], CollectionBrowser.prototype, "sortDirection", void 0);
1345
- __decorate([
1346
- property({ type: String })
1347
- ], CollectionBrowser.prototype, "dateRangeQueryClause", void 0);
1348
- __decorate([
1349
- property({ type: Number })
1350
- ], CollectionBrowser.prototype, "pageSize", void 0);
1351
- __decorate([
1352
- property({ type: Object })
1353
- ], CollectionBrowser.prototype, "resizeObserver", void 0);
1354
- __decorate([
1355
- property({ type: String })
1356
- ], CollectionBrowser.prototype, "titleQuery", void 0);
1357
- __decorate([
1358
- property({ type: String })
1359
- ], CollectionBrowser.prototype, "creatorQuery", void 0);
1360
- __decorate([
1361
- property({ type: Number })
1362
- ], CollectionBrowser.prototype, "currentPage", void 0);
1363
- __decorate([
1364
- property({ type: String })
1365
- ], CollectionBrowser.prototype, "minSelectedDate", void 0);
1366
- __decorate([
1367
- property({ type: String })
1368
- ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
1369
- __decorate([
1370
- property({ type: Object })
1371
- ], CollectionBrowser.prototype, "selectedFacets", void 0);
1372
- __decorate([
1373
- property({ type: Boolean })
1374
- ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
1375
- __decorate([
1376
- property({ type: String, reflect: true })
1377
- ], CollectionBrowser.prototype, "searchContext", void 0);
1378
- __decorate([
1379
- property({ type: Object })
1380
- ], CollectionBrowser.prototype, "collectionNameCache", void 0);
1381
- __decorate([
1382
- property({ type: String })
1383
- ], CollectionBrowser.prototype, "pageContext", void 0);
1384
- __decorate([
1385
- property({ type: Object })
1386
- ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
1387
- __decorate([
1388
- property({ type: Number })
1389
- ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
1390
- __decorate([
1391
- property({ type: Boolean })
1392
- ], CollectionBrowser.prototype, "loggedIn", void 0);
1393
- __decorate([
1394
- property({ type: Object })
1395
- ], CollectionBrowser.prototype, "modalManager", void 0);
1396
- __decorate([
1397
- property({ type: Boolean })
1398
- ], CollectionBrowser.prototype, "isManageView", void 0);
1399
- __decorate([
1400
- state()
1401
- ], CollectionBrowser.prototype, "pagesToRender", void 0);
1402
- __decorate([
1403
- state()
1404
- ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
1405
- __decorate([
1406
- state()
1407
- ], CollectionBrowser.prototype, "facetsLoading", void 0);
1408
- __decorate([
1409
- state()
1410
- ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
1411
- __decorate([
1412
- state()
1413
- ], CollectionBrowser.prototype, "aggregations", void 0);
1414
- __decorate([
1415
- state()
1416
- ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
1417
- __decorate([
1418
- state()
1419
- ], CollectionBrowser.prototype, "previousSearchType", void 0);
1420
- __decorate([
1421
- state()
1422
- ], CollectionBrowser.prototype, "totalResults", void 0);
1423
- __decorate([
1424
- state()
1425
- ], CollectionBrowser.prototype, "mobileView", void 0);
1426
- __decorate([
1427
- state()
1428
- ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
1429
- __decorate([
1430
- state()
1431
- ], CollectionBrowser.prototype, "placeholderType", void 0);
1432
- __decorate([
1433
- query('#content-container')
1434
- ], CollectionBrowser.prototype, "contentContainer", void 0);
1435
- __decorate([
1436
- property({ type: Object, attribute: false })
1437
- ], CollectionBrowser.prototype, "analyticsHandler", void 0);
1438
- __decorate([
1439
- query('infinite-scroller')
1440
- ], CollectionBrowser.prototype, "infiniteScroller", void 0);
1441
- CollectionBrowser = __decorate([
1442
- customElement('collection-browser')
1443
- ], CollectionBrowser);
1444
- export { CollectionBrowser };
1467
+ `;
1468
+ __decorate([
1469
+ property({ type: String })
1470
+ ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
1471
+ __decorate([
1472
+ property({ type: String })
1473
+ ], CollectionBrowser.prototype, "baseImageUrl", void 0);
1474
+ __decorate([
1475
+ property({ type: Object })
1476
+ ], CollectionBrowser.prototype, "searchService", void 0);
1477
+ __decorate([
1478
+ property({ type: String })
1479
+ ], CollectionBrowser.prototype, "searchType", void 0);
1480
+ __decorate([
1481
+ property({ type: String })
1482
+ ], CollectionBrowser.prototype, "baseQuery", void 0);
1483
+ __decorate([
1484
+ property({ type: String })
1485
+ ], CollectionBrowser.prototype, "displayMode", void 0);
1486
+ __decorate([
1487
+ property({ type: Object })
1488
+ ], CollectionBrowser.prototype, "sortParam", void 0);
1489
+ __decorate([
1490
+ property({ type: String })
1491
+ ], CollectionBrowser.prototype, "selectedSort", void 0);
1492
+ __decorate([
1493
+ property({ type: String })
1494
+ ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
1495
+ __decorate([
1496
+ property({ type: String })
1497
+ ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
1498
+ __decorate([
1499
+ property({ type: String })
1500
+ ], CollectionBrowser.prototype, "sortDirection", void 0);
1501
+ __decorate([
1502
+ property({ type: Number })
1503
+ ], CollectionBrowser.prototype, "pageSize", void 0);
1504
+ __decorate([
1505
+ property({ type: Object })
1506
+ ], CollectionBrowser.prototype, "resizeObserver", void 0);
1507
+ __decorate([
1508
+ property({ type: String })
1509
+ ], CollectionBrowser.prototype, "titleQuery", void 0);
1510
+ __decorate([
1511
+ property({ type: String })
1512
+ ], CollectionBrowser.prototype, "creatorQuery", void 0);
1513
+ __decorate([
1514
+ property({ type: Number })
1515
+ ], CollectionBrowser.prototype, "currentPage", void 0);
1516
+ __decorate([
1517
+ property({ type: String })
1518
+ ], CollectionBrowser.prototype, "minSelectedDate", void 0);
1519
+ __decorate([
1520
+ property({ type: String })
1521
+ ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
1522
+ __decorate([
1523
+ property({ type: Object })
1524
+ ], CollectionBrowser.prototype, "selectedFacets", void 0);
1525
+ __decorate([
1526
+ property({ type: Boolean })
1527
+ ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
1528
+ __decorate([
1529
+ property({ type: String, reflect: true })
1530
+ ], CollectionBrowser.prototype, "searchContext", void 0);
1531
+ __decorate([
1532
+ property({ type: Object })
1533
+ ], CollectionBrowser.prototype, "collectionNameCache", void 0);
1534
+ __decorate([
1535
+ property({ type: String })
1536
+ ], CollectionBrowser.prototype, "pageContext", void 0);
1537
+ __decorate([
1538
+ property({ type: Object })
1539
+ ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
1540
+ __decorate([
1541
+ property({ type: Number })
1542
+ ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
1543
+ __decorate([
1544
+ property({ type: Boolean })
1545
+ ], CollectionBrowser.prototype, "loggedIn", void 0);
1546
+ __decorate([
1547
+ property({ type: Object })
1548
+ ], CollectionBrowser.prototype, "modalManager", void 0);
1549
+ __decorate([
1550
+ property({ type: Boolean })
1551
+ ], CollectionBrowser.prototype, "isManageView", void 0);
1552
+ __decorate([
1553
+ state()
1554
+ ], CollectionBrowser.prototype, "pagesToRender", void 0);
1555
+ __decorate([
1556
+ state()
1557
+ ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
1558
+ __decorate([
1559
+ state()
1560
+ ], CollectionBrowser.prototype, "facetsLoading", void 0);
1561
+ __decorate([
1562
+ state()
1563
+ ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
1564
+ __decorate([
1565
+ state()
1566
+ ], CollectionBrowser.prototype, "aggregations", void 0);
1567
+ __decorate([
1568
+ state()
1569
+ ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
1570
+ __decorate([
1571
+ state()
1572
+ ], CollectionBrowser.prototype, "previousSearchType", void 0);
1573
+ __decorate([
1574
+ state()
1575
+ ], CollectionBrowser.prototype, "totalResults", void 0);
1576
+ __decorate([
1577
+ state()
1578
+ ], CollectionBrowser.prototype, "mobileView", void 0);
1579
+ __decorate([
1580
+ state()
1581
+ ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
1582
+ __decorate([
1583
+ state()
1584
+ ], CollectionBrowser.prototype, "placeholderType", void 0);
1585
+ __decorate([
1586
+ state()
1587
+ ], CollectionBrowser.prototype, "prefixFilterCountMap", void 0);
1588
+ __decorate([
1589
+ query('#content-container')
1590
+ ], CollectionBrowser.prototype, "contentContainer", void 0);
1591
+ __decorate([
1592
+ property({ type: Object, attribute: false })
1593
+ ], CollectionBrowser.prototype, "analyticsHandler", void 0);
1594
+ __decorate([
1595
+ query('infinite-scroller')
1596
+ ], CollectionBrowser.prototype, "infiniteScroller", void 0);
1597
+ CollectionBrowser = __decorate([
1598
+ customElement('collection-browser')
1599
+ ], CollectionBrowser);
1600
+ export { CollectionBrowser };
1445
1601
  //# sourceMappingURL=collection-browser.js.map