@internetarchive/collection-browser 0.4.3-alpha.9 → 0.4.4-alpha

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