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

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