@internetarchive/collection-browser 0.3.0 → 0.3.1-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 (212) 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 +43 -43
  12. package/dist/src/app-root.js +233 -233
  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 +234 -234
  68. package/dist/src/collection-browser.js +1368 -1367
  69. package/dist/src/collection-browser.js.map +1 -1
  70. package/dist/src/collection-facets/facets-template.d.ts +16 -16
  71. package/dist/src/collection-facets/facets-template.js +125 -125
  72. package/dist/src/collection-facets/facets-util.d.ts +10 -10
  73. package/dist/src/collection-facets/facets-util.js +19 -19
  74. package/dist/src/collection-facets/facets-util.js.map +1 -1
  75. package/dist/src/collection-facets/more-facets-content.d.ts +74 -74
  76. package/dist/src/collection-facets/more-facets-content.js +330 -330
  77. package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -36
  78. package/dist/src/collection-facets/more-facets-pagination.js +192 -192
  79. package/dist/src/collection-facets.d.ts +71 -71
  80. package/dist/src/collection-facets.js +476 -476
  81. package/dist/src/collection-facets.js.map +1 -1
  82. package/dist/src/empty-placeholder.d.ts +11 -11
  83. package/dist/src/empty-placeholder.js +42 -42
  84. package/dist/src/language-code-handler/language-code-handler.d.ts +37 -37
  85. package/dist/src/language-code-handler/language-code-handler.js +26 -26
  86. package/dist/src/language-code-handler/language-code-mapping.d.ts +1 -1
  87. package/dist/src/language-code-handler/language-code-mapping.js +562 -562
  88. package/dist/src/mediatype/mediatype-config.d.ts +3 -3
  89. package/dist/src/mediatype/mediatype-config.js +85 -85
  90. package/dist/src/models.d.ts +89 -89
  91. package/dist/src/models.js +85 -85
  92. package/dist/src/models.js.map +1 -1
  93. package/dist/src/restoration-state-handler.d.ts +46 -45
  94. package/dist/src/restoration-state-handler.js +230 -219
  95. package/dist/src/restoration-state-handler.js.map +1 -1
  96. package/dist/src/sort-filter-bar/alpha-bar.d.ts +9 -9
  97. package/dist/src/sort-filter-bar/alpha-bar.js +41 -41
  98. package/dist/src/sort-filter-bar/img/compact.d.ts +1 -1
  99. package/dist/src/sort-filter-bar/img/compact.js +2 -2
  100. package/dist/src/sort-filter-bar/img/list.d.ts +1 -1
  101. package/dist/src/sort-filter-bar/img/list.js +2 -2
  102. package/dist/src/sort-filter-bar/img/sort-triangle.d.ts +1 -1
  103. package/dist/src/sort-filter-bar/img/sort-triangle.js +2 -2
  104. package/dist/src/sort-filter-bar/img/tile.d.ts +1 -1
  105. package/dist/src/sort-filter-bar/img/tile.js +2 -2
  106. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +107 -107
  107. package/dist/src/sort-filter-bar/sort-filter-bar.js +423 -423
  108. package/dist/src/styles/item-image-styles.d.ts +8 -8
  109. package/dist/src/styles/item-image-styles.js +9 -9
  110. package/dist/src/tiles/collection-browser-loading-tile.d.ts +5 -5
  111. package/dist/src/tiles/collection-browser-loading-tile.js +15 -15
  112. package/dist/src/tiles/grid/account-tile.d.ts +8 -8
  113. package/dist/src/tiles/grid/account-tile.js +20 -20
  114. package/dist/src/tiles/grid/collection-tile.d.ts +7 -7
  115. package/dist/src/tiles/grid/collection-tile.js +23 -23
  116. package/dist/src/tiles/grid/item-tile.d.ts +24 -24
  117. package/dist/src/tiles/grid/item-tile.js +87 -87
  118. package/dist/src/tiles/grid/tile-stats.d.ts +10 -10
  119. package/dist/src/tiles/grid/tile-stats.js +35 -35
  120. package/dist/src/tiles/image-block.d.ts +17 -17
  121. package/dist/src/tiles/image-block.js +73 -73
  122. package/dist/src/tiles/item-image.d.ts +31 -31
  123. package/dist/src/tiles/item-image.js +103 -103
  124. package/dist/src/tiles/list/account-label.d.ts +1 -1
  125. package/dist/src/tiles/list/account-label.js +6 -6
  126. package/dist/src/tiles/list/date-label.d.ts +1 -1
  127. package/dist/src/tiles/list/date-label.js +12 -12
  128. package/dist/src/tiles/list/tile-list-compact-header.d.ts +12 -12
  129. package/dist/src/tiles/list/tile-list-compact-header.js +41 -41
  130. package/dist/src/tiles/list/tile-list-compact.d.ts +20 -20
  131. package/dist/src/tiles/list/tile-list-compact.js +87 -87
  132. package/dist/src/tiles/list/tile-list.d.ts +50 -50
  133. package/dist/src/tiles/list/tile-list.js +263 -263
  134. package/dist/src/tiles/mediatype-icon.d.ts +9 -9
  135. package/dist/src/tiles/mediatype-icon.js +47 -47
  136. package/dist/src/tiles/overlay/icon-overlay.d.ts +7 -7
  137. package/dist/src/tiles/overlay/icon-overlay.js +31 -31
  138. package/dist/src/tiles/overlay/text-overlay.d.ts +8 -8
  139. package/dist/src/tiles/overlay/text-overlay.js +31 -31
  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 +18 -18
  145. package/dist/src/utils/analytics-events.js +20 -20
  146. package/dist/src/utils/format-count.d.ts +7 -7
  147. package/dist/src/utils/format-count.js +75 -75
  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 +342 -342
  152. package/dist/test/collection-browser.test.js.map +1 -1
  153. package/dist/test/collection-facets/facets-template.test.d.ts +1 -1
  154. package/dist/test/collection-facets/facets-template.test.js +62 -62
  155. package/dist/test/collection-facets/facets-util.test.d.ts +1 -1
  156. package/dist/test/collection-facets/facets-util.test.js +12 -12
  157. package/dist/test/collection-facets/facets-util.test.js.map +1 -1
  158. package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -1
  159. package/dist/test/collection-facets/more-facets-content.test.js +91 -91
  160. package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -1
  161. package/dist/test/collection-facets/more-facets-pagination.test.js +117 -117
  162. package/dist/test/collection-facets.test.d.ts +2 -2
  163. package/dist/test/collection-facets.test.js +182 -182
  164. package/dist/test/empty-placeholder.test.d.ts +1 -1
  165. package/dist/test/empty-placeholder.test.js +33 -33
  166. package/dist/test/icon-overlay.test.d.ts +1 -1
  167. package/dist/test/icon-overlay.test.js +24 -24
  168. package/dist/test/item-image.test.d.ts +1 -1
  169. package/dist/test/item-image.test.js +56 -56
  170. package/dist/test/mediatype-config.test.d.ts +1 -1
  171. package/dist/test/mediatype-config.test.js +16 -16
  172. package/dist/test/mocks/mock-analytics-handler.d.ts +10 -10
  173. package/dist/test/mocks/mock-analytics-handler.js +15 -15
  174. package/dist/test/mocks/mock-collection-name-cache.d.ts +7 -7
  175. package/dist/test/mocks/mock-collection-name-cache.js +13 -13
  176. package/dist/test/mocks/mock-search-responses.d.ts +5 -5
  177. package/dist/test/mocks/mock-search-responses.js +103 -103
  178. package/dist/test/mocks/mock-search-service.d.ts +13 -13
  179. package/dist/test/mocks/mock-search-service.js +25 -25
  180. package/dist/test/restoration-state-handler.test.d.ts +1 -1
  181. package/dist/test/restoration-state-handler.test.js +117 -117
  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 +113 -113
  184. package/dist/test/text-overlay.test.d.ts +1 -1
  185. package/dist/test/text-overlay.test.js +41 -41
  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.test.d.ts +1 -1
  193. package/dist/test/tiles/list/tile-list.test.js +36 -36
  194. package/dist/test/utils/format-count.test.d.ts +1 -1
  195. package/dist/test/utils/format-count.test.js +23 -23
  196. package/dist/test/utils/format-date.test.d.ts +1 -1
  197. package/dist/test/utils/format-date.test.js +17 -17
  198. package/index.html +24 -24
  199. package/local.archive.org.cert +86 -86
  200. package/local.archive.org.key +27 -27
  201. package/package.json +115 -115
  202. package/renovate.json +6 -6
  203. package/src/collection-browser.ts +1490 -1489
  204. package/src/collection-facets/facets-util.ts +22 -22
  205. package/src/collection-facets.ts +541 -541
  206. package/src/models.ts +188 -188
  207. package/src/restoration-state-handler.ts +313 -301
  208. package/test/collection-browser.test.ts +488 -488
  209. package/test/collection-facets/facets-util.test.ts +18 -18
  210. package/tsconfig.json +21 -21
  211. package/web-dev-server.config.mjs +30 -30
  212. package/web-test-runner.config.mjs +41 -41
@@ -1,1368 +1,1369 @@
1
- import { __decorate } from "tslib";
2
- /* eslint-disable import/no-duplicates */
3
- import { html, css, LitElement, nothing, } from 'lit';
4
- import { customElement, property, query, state } from 'lit/decorators.js';
5
- import { ifDefined } from 'lit/directives/if-defined.js';
6
- import { SearchType, } from '@internetarchive/search-service';
7
- import '@internetarchive/infinite-scroller';
8
- import './tiles/tile-dispatcher';
9
- import './tiles/collection-browser-loading-tile';
10
- import './sort-filter-bar/sort-filter-bar';
11
- import './collection-facets';
12
- import './circular-activity-indicator';
13
- import './sort-filter-bar/sort-filter-bar';
14
- import { SortField, SortFieldToMetadataField, defaultSelectedFacets, } from './models';
15
- import { RestorationStateHandler, } from './restoration-state-handler';
16
- import chevronIcon from './assets/img/icons/chevron';
17
- import { LanguageCodeHandler } from './language-code-handler/language-code-handler';
18
- import './empty-placeholder';
19
- import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
20
- let CollectionBrowser = class CollectionBrowser extends LitElement {
21
- constructor() {
22
- super(...arguments);
23
- this.baseImageUrl = 'https://archive.org';
24
- this.searchType = SearchType.METADATA;
25
- this.sortParam = null;
26
- this.selectedSort = SortField.relevance;
27
- this.selectedTitleFilter = null;
28
- this.selectedCreatorFilter = null;
29
- this.sortDirection = null;
30
- this.pageSize = 50;
31
- this.showHistogramDatePicker = false;
32
- /** describes where this component is being used */
33
- this.searchContext = analyticsCategories.default;
34
- this.pageContext = 'search';
35
- this.restorationStateHandler = new RestorationStateHandler({
36
- context: this.pageContext,
37
- });
38
- this.mobileBreakpoint = 600;
39
- this.loggedIn = false;
40
- this.modalManager = undefined;
41
- /**
42
- * If item management UI active
43
- */
44
- this.isManageView = false;
45
- /**
46
- * The page that the consumer wants to load.
47
- */
48
- this.initialPageNumber = 1;
49
- /**
50
- * This the the number of pages that we want to show.
51
- *
52
- * The data isn't necessarily loaded for all of the pages, but this lets us
53
- * know how many cells we should render.
54
- */
55
- this.pagesToRender = this.initialPageNumber;
56
- this.searchResultsLoading = false;
57
- this.facetsLoading = false;
58
- this.fullYearAggregationLoading = false;
59
- this.mobileView = false;
60
- this.mobileFacetsVisible = false;
61
- this.placeholderType = null;
62
- this.languageCodeHandler = new LanguageCodeHandler();
63
- /**
64
- * When we're animated scrolling to the page, we don't want to fetch
65
- * all of the pages as it scrolls so this lets us know if we're scrolling
66
- */
67
- this.isScrollingToCell = false;
68
- /**
69
- * When we've reached the end of the data, stop trying to fetch more
70
- */
71
- this.endOfDataReached = false;
72
- /**
73
- * When page width resizes from desktop to mobile, set true to
74
- * disable expand/collapse transition when loading.
75
- */
76
- this.isResizeToMobile = false;
77
- this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
78
- /**
79
- * The results per page so we can paginate.
80
- *
81
- * This allows us to start in the middle of the search results and
82
- * fetch data before or after the current page. If we don't have a key
83
- * for the previous/next page, we'll fetch the next/previous page to populate it
84
- */
85
- this.dataSource = {};
86
- // we only want to scroll on the very first query change
87
- // so this keeps track of whether we've already set the initial query
88
- this.initialQueryChangeHappened = false;
89
- this.historyPopOccurred = false;
90
- // this maps the query to the pages being fetched for that query
91
- this.pageFetchesInProgress = {};
92
- }
93
- tileModelAtCellIndex(index) {
94
- var _a;
95
- const pageNumber = Math.floor(index / this.pageSize) + 1;
96
- const itemIndex = index % this.pageSize;
97
- const model = (_a = this.dataSource[pageNumber]) === null || _a === void 0 ? void 0 : _a[itemIndex];
98
- /**
99
- * If we encounter a model we don't have yet and we're not in the middle of an
100
- * automated scroll, fetch the page and just return undefined.
101
- * The datasource will be updated once the page is loaded and the cell will be rendered.
102
- *
103
- * We disable it during the automated scroll since we may fetch pages for cells the
104
- * user may never see.
105
- */
106
- if (!model && !this.isScrollingToCell) {
107
- this.fetchPage(pageNumber);
108
- }
109
- return model;
110
- }
111
- get sortFilterQueries() {
112
- const queries = [this.titleQuery, this.creatorQuery];
113
- return queries.filter(q => q).join(' AND ');
114
- }
115
- // this is the total number of tiles we expect if
116
- // the data returned is a full page worth
117
- // this is useful for putting in placeholders for the expected number of tiles
118
- get estimatedTileCount() {
119
- return this.pagesToRender * this.pageSize;
120
- }
121
- // this is the actual number of tiles in the datasource,
122
- // which is useful for removing excess placeholder tiles
123
- // once we reached the end of the data
124
- get actualTileCount() {
125
- return Object.keys(this.dataSource).reduce((acc, page) => acc + this.dataSource[page].length, 0);
126
- }
127
- /**
128
- * Go to the given page of results
129
- *
130
- * @param pageNumber
131
- */
132
- goToPage(pageNumber) {
133
- this.initialPageNumber = pageNumber;
134
- this.pagesToRender = pageNumber;
135
- this.scrollToPage(pageNumber);
136
- }
137
- clearFilters() {
138
- this.selectedFacets = defaultSelectedFacets;
139
- this.sortParam = null;
140
- this.selectedTitleFilter = null;
141
- this.selectedCreatorFilter = null;
142
- this.titleQuery = undefined;
143
- this.creatorQuery = undefined;
144
- this.selectedSort = SortField.relevance;
145
- this.sortDirection = null;
146
- }
147
- render() {
148
- this.setPlaceholderType();
149
- return html `
150
- <div
151
- id="content-container"
152
- class=${this.mobileView ? 'mobile' : 'desktop'}
153
- >
154
- ${this.placeholderType
155
- ? this.emptyPlaceholderTemplate
156
- : this.collectionBrowserTemplate}
157
- </div>
158
- `;
159
- }
160
- setPlaceholderType() {
161
- this.placeholderType = null;
162
- if (!this.baseQuery) {
163
- this.placeholderType = 'empty-query';
164
- }
165
- if (!this.searchResultsLoading && this.totalResults === 0) {
166
- this.placeholderType = 'null-result';
167
- }
168
- }
169
- get emptyPlaceholderTemplate() {
170
- return html `
171
- <empty-placeholder
172
- .placeholderType=${this.placeholderType}
173
- ?isMobileView=${this.mobileView}
174
- ></empty-placeholder>
175
- `;
176
- }
177
- get collectionBrowserTemplate() {
178
- return html `<div
179
- id="left-column"
180
- class="column${this.isResizeToMobile ? ' preload' : ''}"
181
- >
182
- <div id="mobile-header-container">
183
- ${this.mobileView ? this.mobileFacetsTemplate : nothing}
184
- <div id="results-total">
185
- <span id="big-results-count">
186
- ${this.totalResults !== undefined
187
- ? this.totalResults.toLocaleString()
188
- : '-'}
189
- </span>
190
- <span id="big-results-label">
191
- ${this.totalResults === 1 ? 'Result' : 'Results'}
192
- </span>
193
- </div>
194
- </div>
195
- <div
196
- id="facets-container"
197
- class=${!this.mobileView || this.mobileFacetsVisible
198
- ? 'expanded'
199
- : ''}
200
- >
201
- ${this.facetsTemplate}
202
- </div>
203
- </div>
204
- <div id="right-column" class="column">
205
- ${this.searchResultsLoading ? this.loadingTemplate : nothing}
206
- ${this.sortFilterBarTemplate}
207
- ${this.displayMode === `list-compact`
208
- ? this.listHeaderTemplate
209
- : nothing}
210
- ${this.infiniteScrollerTemplate}
211
- </div>`;
212
- }
213
- get infiniteScrollerTemplate() {
214
- return html `<infinite-scroller
215
- class="${ifDefined(this.displayMode)}"
216
- .cellProvider=${this}
217
- .placeholderCellTemplate=${this.placeholderCellTemplate}
218
- @scrollThresholdReached=${this.scrollThresholdReached}
219
- @visibleCellsChanged=${this.visibleCellsChanged}
220
- ></infinite-scroller>`;
221
- }
222
- get sortFilterBarTemplate() {
223
- return html `
224
- <sort-filter-bar
225
- .selectedSort=${this.selectedSort}
226
- .sortDirection=${this.sortDirection}
227
- .displayMode=${this.displayMode}
228
- .selectedTitleFilter=${this.selectedTitleFilter}
229
- .selectedCreatorFilter=${this.selectedCreatorFilter}
230
- .resizeObserver=${this.resizeObserver}
231
- @sortChanged=${this.userChangedSort}
232
- @displayModeChanged=${this.displayModeChanged}
233
- @titleLetterChanged=${this.titleLetterSelected}
234
- @creatorLetterChanged=${this.creatorLetterSelected}
235
- >
236
- </sort-filter-bar>
237
- `;
238
- }
239
- userChangedSort(e) {
240
- var _a;
241
- const { selectedSort, sortDirection } = e.detail;
242
- this.selectedSort = selectedSort;
243
- this.sortDirection = sortDirection;
244
- if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
245
- this.goToPage(1);
246
- }
247
- this.currentPage = 1;
248
- }
249
- sendSortByAnalytics(prevSortDirection) {
250
- var _a;
251
- const directionCleared = prevSortDirection && !this.sortDirection;
252
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
253
- category: this.searchContext,
254
- action: analyticsActions.sortBy,
255
- label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
256
- });
257
- }
258
- selectedSortChanged() {
259
- if (this.selectedSort === 'relevance' || this.sortDirection === null) {
260
- this.sortParam = null;
261
- return;
262
- }
263
- const sortField = SortFieldToMetadataField[this.selectedSort];
264
- if (!sortField)
265
- return;
266
- this.sortParam = { field: sortField, direction: this.sortDirection };
267
- }
268
- displayModeChanged(e) {
269
- var _a;
270
- this.displayMode = e.detail.displayMode;
271
- if (this.displayMode) {
272
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
273
- category: this.searchContext,
274
- action: analyticsActions.displayMode,
275
- label: this.displayMode,
276
- });
277
- }
278
- }
279
- /** Send Analytics when sorting by title's first letter
280
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
281
- * */
282
- sendFilterByTitleAnalytics(prevSelectedLetter) {
283
- var _a;
284
- if (!prevSelectedLetter && !this.selectedTitleFilter) {
285
- return;
286
- }
287
- const cleared = prevSelectedLetter && this.selectedTitleFilter === null;
288
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
289
- category: this.searchContext,
290
- action: analyticsActions.filterByTitle,
291
- label: cleared
292
- ? `clear-${prevSelectedLetter}`
293
- : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
294
- });
295
- }
296
- selectedTitleLetterChanged() {
297
- this.titleQuery = this.selectedTitleFilter
298
- ? `firstTitle:${this.selectedTitleFilter}`
299
- : undefined;
300
- }
301
- /** Send Analytics when filtering by creator's first letter
302
- * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
303
- * */
304
- sendFilterByCreatorAnalytics(prevSelectedLetter) {
305
- var _a;
306
- if (!prevSelectedLetter && !this.selectedCreatorFilter) {
307
- return;
308
- }
309
- const cleared = prevSelectedLetter && this.selectedCreatorFilter === null;
310
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
311
- category: this.searchContext,
312
- action: analyticsActions.filterByCreator,
313
- label: cleared
314
- ? `clear-${prevSelectedLetter}`
315
- : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
316
- });
317
- }
318
- selectedCreatorLetterChanged() {
319
- this.creatorQuery = this.selectedCreatorFilter
320
- ? `firstCreator:${this.selectedCreatorFilter}`
321
- : undefined;
322
- }
323
- titleLetterSelected(e) {
324
- this.selectedCreatorFilter = null;
325
- this.selectedTitleFilter = e.detail.selectedLetter;
326
- }
327
- creatorLetterSelected(e) {
328
- this.selectedTitleFilter = null;
329
- this.selectedCreatorFilter = e.detail.selectedLetter;
330
- }
331
- get facetDataLoading() {
332
- return this.facetsLoading || this.fullYearAggregationLoading;
333
- }
334
- get mobileFacetsTemplate() {
335
- return html `
336
- <div id="mobile-filter-collapse">
337
- <h1
338
- @click=${() => {
339
- this.isResizeToMobile = false;
340
- this.mobileFacetsVisible = !this.mobileFacetsVisible;
341
- }}
342
- @keyup=${() => {
343
- this.isResizeToMobile = false;
344
- this.mobileFacetsVisible = !this.mobileFacetsVisible;
345
- }}
346
- >
347
- <span class="collapser ${this.mobileFacetsVisible ? 'open' : ''}">
348
- ${chevronIcon}
349
- </span>
350
- Filters
351
- </h1>
352
- </div>
353
- `;
354
- }
355
- get facetsTemplate() {
356
- return html `
357
- ${this.facetsLoading ? this.loadingTemplate : nothing}
358
- <collection-facets
359
- @facetsChanged=${this.facetsChanged}
360
- @histogramDateRangeUpdated=${this.histogramDateRangeUpdated}
361
- .searchService=${this.searchService}
362
- .searchType=${this.searchType}
363
- .aggregations=${this.aggregations}
364
- .fullYearsHistogramAggregation=${this.fullYearsHistogramAggregation}
365
- .minSelectedDate=${this.minSelectedDate}
366
- .maxSelectedDate=${this.maxSelectedDate}
367
- .selectedFacets=${this.selectedFacets}
368
- .collectionNameCache=${this.collectionNameCache}
369
- .languageCodeHandler=${this.languageCodeHandler}
370
- .showHistogramDatePicker=${this.showHistogramDatePicker}
371
- .fullQuery=${this.fullQuery}
372
- .modalManager=${this.modalManager}
373
- ?collapsableFacets=${this.mobileView}
374
- ?facetsLoading=${this.facetDataLoading}
375
- ?fullYearAggregationLoading=${this.fullYearAggregationLoading}
376
- .onFacetClick=${this.facetClickHandler}
377
- .analyticsHandler=${this.analyticsHandler}
378
- >
379
- </collection-facets>
380
- `;
381
- }
382
- get loadingTemplate() {
383
- return html `
384
- <div class="loading-cover">
385
- <circular-activity-indicator></circular-activity-indicator>
386
- </div>
387
- `;
388
- }
389
- get listHeaderTemplate() {
390
- return html `
391
- <div id="list-header">
392
- <tile-dispatcher
393
- .tileDisplayMode=${'list-header'}
394
- .resizeObserver=${this.resizeObserver}
395
- .sortParam=${this.sortParam}
396
- .mobileBreakpoint=${this.mobileBreakpoint}
397
- .loggedIn=${this.loggedIn}
398
- >
399
- </tile-dispatcher>
400
- </div>
401
- `;
402
- }
403
- get queryDebuggingTemplate() {
404
- var _a, _b;
405
- return html `
406
- <div>
407
- <ul>
408
- <li>Base Query: ${this.baseQuery}</li>
409
- <li>Facet Query: ${this.facetQuery}</li>
410
- <li>Sort Filter Query: ${this.sortFilterQueries}</li>
411
- <li>Date Range Query: ${this.dateRangeQueryClause}</li>
412
- <li>Sort: ${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field} ${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}</li>
413
- <li>Full Query: ${this.fullQuery}</li>
414
- </ul>
415
- </div>
416
- `;
417
- }
418
- histogramDateRangeUpdated(e) {
419
- var _a;
420
- const { minDate, maxDate } = e.detail;
421
- this.dateRangeQueryClause = `year:[${minDate} TO ${maxDate}]`;
422
- if (this.dateRangeQueryClause) {
423
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
424
- category: this.searchContext,
425
- action: analyticsActions.histogramChanged,
426
- label: this.dateRangeQueryClause,
427
- });
428
- }
429
- }
430
- firstUpdated() {
431
- this.setupStateRestorationObserver();
432
- this.restoreState();
433
- }
434
- updated(changed) {
435
- var _a;
436
- if (changed.has('displayMode') ||
437
- changed.has('baseNavigationUrl') ||
438
- changed.has('baseImageUrl') ||
439
- changed.has('loggedIn')) {
440
- (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
441
- }
442
- if (changed.has('baseQuery')) {
443
- this.emitBaseQueryChanged();
444
- }
445
- if (changed.has('currentPage') || changed.has('displayMode')) {
446
- this.persistState();
447
- }
448
- if (changed.has('baseQuery') ||
449
- changed.has('titleQuery') ||
450
- changed.has('creatorQuery') ||
451
- changed.has('dateRangeQueryClause') ||
452
- changed.has('sortParam') ||
453
- changed.has('selectedFacets') ||
454
- changed.has('searchService')) {
455
- this.handleQueryChange();
456
- }
457
- if (changed.has('selectedSort') || changed.has('sortDirection')) {
458
- const prevSortDirection = changed.get('sortDirection');
459
- this.sendSortByAnalytics(prevSortDirection);
460
- this.selectedSortChanged();
461
- }
462
- if (changed.has('selectedTitleFilter')) {
463
- this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
464
- this.selectedTitleLetterChanged();
465
- }
466
- if (changed.has('selectedCreatorFilter')) {
467
- this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
468
- this.selectedCreatorLetterChanged();
469
- }
470
- if (changed.has('pagesToRender')) {
471
- if (!this.endOfDataReached && this.infiniteScroller) {
472
- this.infiniteScroller.itemCount = this.estimatedTileCount;
473
- }
474
- }
475
- if (changed.has('resizeObserver')) {
476
- const oldObserver = changed.get('resizeObserver');
477
- if (oldObserver)
478
- this.disconnectResizeObserver(oldObserver);
479
- this.setupResizeObserver();
480
- }
481
- }
482
- disconnectedCallback() {
483
- if (this.resizeObserver) {
484
- this.disconnectResizeObserver(this.resizeObserver);
485
- }
486
- if (this.boundNavigationHandler) {
487
- window.removeEventListener('popstate', this.boundNavigationHandler);
488
- }
489
- }
490
- handleResize(entry) {
491
- const previousView = this.mobileView;
492
- if (entry.target === this.contentContainer) {
493
- this.mobileView = entry.contentRect.width < this.mobileBreakpoint;
494
- // If changing from desktop to mobile disable transition
495
- if (this.mobileView && !previousView) {
496
- this.isResizeToMobile = true;
497
- }
498
- }
499
- }
500
- emitBaseQueryChanged() {
501
- this.dispatchEvent(new CustomEvent('baseQueryChanged', {
502
- detail: {
503
- baseQuery: this.baseQuery,
504
- },
505
- }));
506
- }
507
- disconnectResizeObserver(resizeObserver) {
508
- resizeObserver.removeObserver({
509
- target: this.contentContainer,
510
- handler: this,
511
- });
512
- }
513
- setupResizeObserver() {
514
- if (!this.resizeObserver)
515
- return;
516
- this.resizeObserver.addObserver({
517
- target: this.contentContainer,
518
- handler: this,
519
- });
520
- }
521
- /**
522
- * When the visible cells change from the infinite scroller, we want to emit
523
- * which page is currently visible so the consumer can update its UI or the URL
524
- *
525
- * @param e
526
- * @returns
527
- */
528
- visibleCellsChanged(e) {
529
- if (this.isScrollingToCell)
530
- return;
531
- const { visibleCellIndices } = e.detail;
532
- if (visibleCellIndices.length === 0)
533
- return;
534
- const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
535
- const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
536
- if (this.currentPage !== lastVisibleCellPage) {
537
- this.currentPage = lastVisibleCellPage;
538
- }
539
- const event = new CustomEvent('visiblePageChanged', {
540
- detail: {
541
- pageNumber: lastVisibleCellPage,
542
- },
543
- });
544
- this.dispatchEvent(event);
545
- }
546
- async handleQueryChange() {
547
- // only reset if the query has actually changed
548
- if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
549
- return;
550
- this.previousQueryKey = this.pageFetchQueryKey;
551
- this.dataSource = {};
552
- this.pageFetchesInProgress = {};
553
- this.endOfDataReached = false;
554
- this.pagesToRender = this.initialPageNumber;
555
- if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
556
- this.scrollToPage(this.initialPageNumber);
557
- }
558
- this.initialQueryChangeHappened = true;
559
- // if the query changed as part of a window.history pop event, we don't want to
560
- // persist the state because it overwrites the forward history
561
- if (!this.historyPopOccurred) {
562
- this.persistState();
563
- this.historyPopOccurred = false;
564
- }
565
- await Promise.all([
566
- this.doInitialPageFetch(),
567
- this.fetchFacets(),
568
- this.fetchFullYearHistogram(),
569
- ]);
570
- }
571
- setupStateRestorationObserver() {
572
- if (this.boundNavigationHandler)
573
- return;
574
- this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
575
- // when the user navigates back, we want to update the UI to match the URL
576
- window.addEventListener('popstate', this.boundNavigationHandler);
577
- }
578
- historyNavigationHandler() {
579
- this.historyPopOccurred = true;
580
- this.restoreState();
581
- }
582
- restoreState() {
583
- var _a, _b, _c, _d, _e, _f;
584
- const restorationState = this.restorationStateHandler.getRestorationState();
585
- this.displayMode = restorationState.displayMode;
586
- this.selectedSort = (_a = restorationState.selectedSort) !== null && _a !== void 0 ? _a : SortField.relevance;
587
- this.sortDirection = (_b = restorationState.sortDirection) !== null && _b !== void 0 ? _b : null;
588
- this.selectedTitleFilter = (_c = restorationState.selectedTitleFilter) !== null && _c !== void 0 ? _c : null;
589
- this.selectedCreatorFilter = (_d = restorationState.selectedCreatorFilter) !== null && _d !== void 0 ? _d : null;
590
- this.selectedFacets = restorationState.selectedFacets;
591
- this.baseQuery = restorationState.baseQuery;
592
- this.titleQuery = restorationState.titleQuery;
593
- this.creatorQuery = restorationState.creatorQuery;
594
- this.dateRangeQueryClause = restorationState.dateRangeQueryClause;
595
- this.sortParam = (_e = restorationState.sortParam) !== null && _e !== void 0 ? _e : null;
596
- this.currentPage = (_f = restorationState.currentPage) !== null && _f !== void 0 ? _f : 1;
597
- this.minSelectedDate = restorationState.minSelectedDate;
598
- this.maxSelectedDate = restorationState.maxSelectedDate;
599
- if (this.currentPage > 1) {
600
- this.goToPage(this.currentPage);
601
- }
602
- }
603
- persistState() {
604
- var _a, _b, _c, _d, _e;
605
- const restorationState = {
606
- displayMode: this.displayMode,
607
- sortParam: (_a = this.sortParam) !== null && _a !== void 0 ? _a : undefined,
608
- selectedSort: this.selectedSort,
609
- sortDirection: (_b = this.sortDirection) !== null && _b !== void 0 ? _b : undefined,
610
- selectedFacets: (_c = this.selectedFacets) !== null && _c !== void 0 ? _c : defaultSelectedFacets,
611
- baseQuery: this.baseQuery,
612
- currentPage: this.currentPage,
613
- dateRangeQueryClause: this.dateRangeQueryClause,
614
- titleQuery: this.titleQuery,
615
- creatorQuery: this.creatorQuery,
616
- minSelectedDate: this.minSelectedDate,
617
- maxSelectedDate: this.maxSelectedDate,
618
- selectedTitleFilter: (_d = this.selectedTitleFilter) !== null && _d !== void 0 ? _d : undefined,
619
- selectedCreatorFilter: (_e = this.selectedCreatorFilter) !== null && _e !== void 0 ? _e : undefined,
620
- };
621
- this.restorationStateHandler.persistState(restorationState);
622
- }
623
- async doInitialPageFetch() {
624
- this.searchResultsLoading = true;
625
- await this.fetchPage(this.initialPageNumber);
626
- this.searchResultsLoading = false;
627
- }
628
- get fullQuery() {
629
- let { fullQueryWithoutDate } = this;
630
- const { dateRangeQueryClause } = this;
631
- if (dateRangeQueryClause) {
632
- fullQueryWithoutDate += ` AND ${dateRangeQueryClause}`;
633
- }
634
- return fullQueryWithoutDate;
635
- }
636
- get fullQueryWithoutDate() {
637
- if (!this.baseQuery)
638
- return undefined;
639
- let fullQuery = this.baseQuery;
640
- const { facetQuery, sortFilterQueries } = this;
641
- if (facetQuery) {
642
- fullQuery += ` AND ${facetQuery}`;
643
- }
644
- if (sortFilterQueries) {
645
- fullQuery += ` AND ${sortFilterQueries}`;
646
- }
647
- return fullQuery;
648
- }
649
- /**
650
- * Generates a query string for the given facets
651
- *
652
- * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
653
- */
654
- get facetQuery() {
655
- if (!this.selectedFacets)
656
- return undefined;
657
- const facetQuery = [];
658
- for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
659
- const facetEntries = Object.entries(facetValues);
660
- // eslint-disable-next-line no-continue
661
- if (facetEntries.length === 0)
662
- continue;
663
- const facetValuesArray = [];
664
- for (const [key, facetData] of facetEntries) {
665
- const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
666
- if (facetName === 'language') {
667
- const languages = this.languageCodeHandler.getCodeArrayFromCodeString(key);
668
- for (const language of languages) {
669
- facetValuesArray.push(`${plusMinusPrefix}"${language}"`);
670
- }
671
- }
672
- else {
673
- facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
674
- }
675
- }
676
- const valueQuery = facetValuesArray.join(` OR `);
677
- facetQuery.push(`${facetName}:(${valueQuery})`);
678
- }
679
- return facetQuery.length > 0 ? `(${facetQuery.join(' AND ')})` : undefined;
680
- }
681
- facetsChanged(e) {
682
- this.selectedFacets = e.detail;
683
- }
684
- facetClickHandler(name, facetSelected, negative) {
685
- var _a, _b;
686
- if (negative) {
687
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
688
- category: this.searchContext,
689
- action: facetSelected
690
- ? analyticsActions.facetNegativeSelected
691
- : analyticsActions.facetNegativeDeselected,
692
- label: name,
693
- });
694
- }
695
- else {
696
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEventNoSampling({
697
- category: this.searchContext,
698
- action: facetSelected
699
- ? analyticsActions.facetSelected
700
- : analyticsActions.facetDeselected,
701
- label: name,
702
- });
703
- }
704
- }
705
- async fetchFacets() {
706
- var _a, _b;
707
- if (!this.fullQuery)
708
- return;
709
- const params = {
710
- query: this.fullQuery,
711
- rows: 0,
712
- // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
713
- // The default aggregations for the search_results page type should be what we need here.
714
- };
715
- this.facetsLoading = true;
716
- const results = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
717
- this.facetsLoading = false;
718
- this.aggregations = (_b = results === null || results === void 0 ? void 0 : results.success) === null || _b === void 0 ? void 0 : _b.response.aggregations;
719
- }
720
- /**
721
- * The query key is a string that uniquely identifies the current query
722
- * without the date range.
723
- *
724
- * If this doesn't change, we don't need to re-fetch the histogram date range
725
- */
726
- get fullQueryNoDateKey() {
727
- var _a, _b;
728
- return `${this.fullQueryWithoutDate}-${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field}-${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}`;
729
- }
730
- /**
731
- * This method is similar to fetching the facets above,
732
- * but only fetching the year histogram. There is a subtle difference
733
- * in how you have to fetch the year histogram where you can't use the
734
- * advanced JSON syntax like the other aggregations. It's a special
735
- * case that @ximm put it place.
736
- */
737
- async fetchFullYearHistogram() {
738
- var _a, _b, _c, _d;
739
- const { fullQueryNoDateKey } = this;
740
- if (!this.fullQueryWithoutDate ||
741
- fullQueryNoDateKey === this.previousFullQueryNoDate)
742
- return;
743
- this.previousFullQueryNoDate = fullQueryNoDateKey;
744
- const aggregations = {
745
- simpleParams: ['year'],
746
- };
747
- const params = {
748
- query: this.fullQueryWithoutDate,
749
- aggregations,
750
- rows: 0,
751
- };
752
- this.fullYearAggregationLoading = true;
753
- const results = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
754
- this.fullYearAggregationLoading = false;
755
- this.fullYearsHistogramAggregation =
756
- (_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;
757
- }
758
- scrollToPage(pageNumber) {
759
- const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
760
- // without this setTimeout, Safari just pauses until the `fetchPage` is complete
761
- // then scrolls to the cell
762
- setTimeout(() => {
763
- this.isScrollingToCell = true;
764
- this.infiniteScroller.scrollToCell(cellIndexToScrollTo, true);
765
- // This timeout is to give the scroll animation time to finish
766
- // then updating the infinite scroller once we're done scrolling
767
- // There's no scroll animation completion callback so we're
768
- // giving it 0.5s to finish.
769
- setTimeout(() => {
770
- this.isScrollingToCell = false;
771
- this.infiniteScroller.reload();
772
- }, 500);
773
- }, 0);
774
- }
775
- /**
776
- * The query key is a string that uniquely identifies the current query
777
- *
778
- * This lets us keep track of queries so we don't persist data that's
779
- * no longer relevant.
780
- */
781
- get pageFetchQueryKey() {
782
- var _a, _b;
783
- return `${this.fullQuery}-${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field}-${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}`;
784
- }
785
- async fetchPage(pageNumber) {
786
- var _a, _b, _c, _d, _e;
787
- if (!this.fullQuery)
788
- return;
789
- // if we already have data, don't fetch again
790
- if (this.dataSource[pageNumber])
791
- return;
792
- if (this.endOfDataReached)
793
- return;
794
- // if a fetch is already in progress for this query and page, don't fetch again
795
- const { pageFetchQueryKey } = this;
796
- const pageFetches = (_a = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _a !== void 0 ? _a : new Set();
797
- if (pageFetches.has(pageNumber))
798
- return;
799
- pageFetches.add(pageNumber);
800
- this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
801
- const sortParams = this.sortParam ? [this.sortParam] : [];
802
- const params = {
803
- query: this.fullQuery,
804
- fields: [
805
- 'addeddate',
806
- 'avg_rating',
807
- 'collections_raw',
808
- 'creator',
809
- 'date',
810
- 'description',
811
- 'downloads',
812
- 'identifier',
813
- 'issue',
814
- 'item_count',
815
- 'mediatype',
816
- 'num_favorites',
817
- 'num_reviews',
818
- 'publicdate',
819
- 'reviewdate',
820
- 'source',
821
- 'subject',
822
- 'title',
823
- 'volume',
824
- ],
825
- page: pageNumber,
826
- rows: this.pageSize,
827
- sort: sortParams,
828
- aggregations: { omit: true },
829
- };
830
- const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
831
- const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
832
- if (!success)
833
- return;
834
- this.totalResults = success.response.totalResults;
835
- // this is checking to see if the query has changed since the data was fetched
836
- // if so, we just want to discard the data since there should be a new query
837
- // right behind it
838
- const searchQuery = success.request.clientParameters.user_query;
839
- const searchSort = success.request.clientParameters.sort;
840
- let sortChanged = false;
841
- if (!searchSort || searchSort.length === 0) {
842
- // if we went from no sort to sort, the sort has changed
843
- if (this.sortParam) {
844
- sortChanged = true;
845
- }
846
- }
847
- else {
848
- // check if the sort has changed
849
- for (const sortType of searchSort) {
850
- const [field, direction] = sortType.split(':');
851
- if (field !== ((_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.field) ||
852
- direction !== ((_d = this.sortParam) === null || _d === void 0 ? void 0 : _d.direction)) {
853
- sortChanged = true;
854
- break;
855
- }
856
- }
857
- }
858
- const queryChangedSinceFetch = searchQuery !== this.fullQuery || sortChanged;
859
- if (queryChangedSinceFetch)
860
- return;
861
- const { results } = success.response;
862
- if (results && results.length > 0) {
863
- this.preloadCollectionNames(results);
864
- this.updateDataSource(pageNumber, results);
865
- }
866
- if (results.length < this.pageSize) {
867
- this.endOfDataReached = true;
868
- // this updates the infinite scroller to show the actual size
869
- if (this.infiniteScroller) {
870
- this.infiniteScroller.itemCount = this.actualTileCount;
871
- }
872
- }
873
- (_e = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _e === void 0 ? void 0 : _e.delete(pageNumber);
874
- this.searchResultsLoading = false;
875
- }
876
- preloadCollectionNames(results) {
877
- var _a;
878
- const collectionIds = results
879
- .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
880
- .flat();
881
- const collectionIdsArray = Array.from(new Set(collectionIds));
882
- (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
883
- }
884
- /**
885
- * This is useful for determining whether we need to reload the scroller.
886
- *
887
- * When the fetch completes, we need to reload the scroller if the cells for that
888
- * page are visible, but if the page is not currenlty visible, we don't need to reload
889
- */
890
- get currentVisiblePageNumbers() {
891
- const visibleCells = this.infiniteScroller.getVisibleCellIndices();
892
- const visiblePages = new Set();
893
- visibleCells.forEach(cellIndex => {
894
- const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
895
- visiblePages.add(visiblePage);
896
- });
897
- return Array.from(visiblePages);
898
- }
899
- /**
900
- * Update the datasource from the fetch response
901
- *
902
- * @param pageNumber
903
- * @param results
904
- */
905
- updateDataSource(pageNumber, results) {
906
- // copy our existing datasource so when we set it below, it gets set
907
- // instead of modifying the existing dataSource since object changes
908
- // don't trigger a re-render
909
- const datasource = { ...this.dataSource };
910
- const tiles = [];
911
- results === null || results === void 0 ? void 0 : results.forEach(result => {
912
- 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;
913
- if (!result.identifier)
914
- return;
915
- let loginRequired = false;
916
- let contentWarning = false;
917
- // Check if item and item in "modifying" collection, setting above flags
918
- if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
919
- ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
920
- for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
921
- if (collection === 'loggedin') {
922
- loginRequired = true;
923
- if (contentWarning)
924
- break;
925
- }
926
- if (collection === 'no-preview') {
927
- contentWarning = true;
928
- if (loginRequired)
929
- break;
930
- }
931
- }
932
- }
933
- tiles.push({
934
- // TODO the commented items are not currently being returned by the PPS and
935
- // we will need to have them added to the PPS hit schemas where appropriate
936
- // averageRating: result.avg_rating?.value,
937
- collections: (_f = (_e = result.collection) === null || _e === void 0 ? void 0 : _e.values) !== null && _f !== void 0 ? _f : [],
938
- commentCount: (_h = (_g = result.num_reviews) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : 0,
939
- creator: (_j = result.creator) === null || _j === void 0 ? void 0 : _j.value,
940
- creators: (_l = (_k = result.creator) === null || _k === void 0 ? void 0 : _k.values) !== null && _l !== void 0 ? _l : [],
941
- // dateAdded: result.addeddate?.value,
942
- dateArchived: (_m = result.publicdate) === null || _m === void 0 ? void 0 : _m.value,
943
- datePublished: (_o = result.date) === null || _o === void 0 ? void 0 : _o.value,
944
- dateReviewed: (_p = result.reviewdate) === null || _p === void 0 ? void 0 : _p.value,
945
- description: (_q = result.description) === null || _q === void 0 ? void 0 : _q.value,
946
- favCount: (_s = (_r = result.num_favorites) === null || _r === void 0 ? void 0 : _r.value) !== null && _s !== void 0 ? _s : 0,
947
- identifier: result.identifier,
948
- // issue: result.issue?.value,
949
- itemCount: 0,
950
- mediatype: (_u = (_t = result.mediatype) === null || _t === void 0 ? void 0 : _t.value) !== null && _u !== void 0 ? _u : 'data',
951
- snippets: (_w = (_v = result.highlight) === null || _v === void 0 ? void 0 : _v.values) !== null && _w !== void 0 ? _w : [],
952
- // source: result.source?.value,
953
- subjects: (_y = (_x = result.subject) === null || _x === void 0 ? void 0 : _x.values) !== null && _y !== void 0 ? _y : [],
954
- title: this.etreeTitle((_z = result.title) === null || _z === void 0 ? void 0 : _z.value, (_0 = result.mediatype) === null || _0 === void 0 ? void 0 : _0.value, (_1 = result.collection) === null || _1 === void 0 ? void 0 : _1.values),
955
- volume: (_2 = result.volume) === null || _2 === void 0 ? void 0 : _2.value,
956
- viewCount: (_4 = (_3 = result.downloads) === null || _3 === void 0 ? void 0 : _3.value) !== null && _4 !== void 0 ? _4 : 0,
957
- loginRequired,
958
- contentWarning,
959
- });
960
- });
961
- datasource[pageNumber] = tiles;
962
- this.dataSource = datasource;
963
- const visiblePages = this.currentVisiblePageNumbers;
964
- const needsReload = visiblePages.includes(pageNumber);
965
- if (needsReload) {
966
- this.infiniteScroller.reload();
967
- }
968
- }
969
- /*
970
- * Convert etree titles
971
- * "[Creator] Live at [Place] on [Date]" => "[Date]: [Place]"
972
- *
973
- * Todo: Check collection(s) for etree, need to get as array.
974
- * Current search-service only returns first collection as string.
975
- */
976
- etreeTitle(title, mediatype, collections) {
977
- if (mediatype === 'etree' || (collections === null || collections === void 0 ? void 0 : collections.includes('etree'))) {
978
- const regex = /^(.*) Live at (.*) on (\d\d\d\d-\d\d-\d\d)$/;
979
- const newTitle = title === null || title === void 0 ? void 0 : title.replace(regex, '$3: $2');
980
- if (newTitle) {
981
- return `${newTitle}`;
982
- }
983
- }
984
- return title !== null && title !== void 0 ? title : '';
985
- }
986
- /**
987
- * Callback when a result is selected
988
- */
989
- resultSelected(event) {
990
- var _a, _b;
991
- (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
992
- category: this.searchContext,
993
- action: analyticsActions.resultSelected,
994
- label: event.detail.mediatype,
995
- });
996
- (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEventNoSampling({
997
- category: this.searchContext,
998
- action: analyticsActions.resultSelected,
999
- label: `page-${this.currentPage}`,
1000
- });
1001
- }
1002
- cellForIndex(index) {
1003
- const model = this.tileModelAtCellIndex(index);
1004
- if (!model)
1005
- return undefined;
1006
- return html `
1007
- <tile-dispatcher
1008
- .baseNavigationUrl=${this.baseNavigationUrl}
1009
- .baseImageUrl=${this.baseImageUrl}
1010
- .model=${model}
1011
- .tileDisplayMode=${this.displayMode}
1012
- .resizeObserver=${this.resizeObserver}
1013
- .collectionNameCache=${this.collectionNameCache}
1014
- .sortParam=${this.sortParam}
1015
- .mobileBreakpoint=${this.mobileBreakpoint}
1016
- .loggedIn=${this.loggedIn}
1017
- @resultSelected=${(e) => this.resultSelected(e)}
1018
- >
1019
- </tile-dispatcher>
1020
- `;
1021
- }
1022
- /**
1023
- * When the user scrolls near to the bottom of the page, fetch the next page
1024
- * increase the number of pages to render and start fetching data for the new page
1025
- */
1026
- scrollThresholdReached() {
1027
- this.pagesToRender += 1;
1028
- this.fetchPage(this.pagesToRender);
1029
- }
1030
- };
1031
- CollectionBrowser.styles = css `
1032
- :host {
1033
- display: block;
1034
- }
1035
-
1036
- /**
1037
- * When page width resizes from desktop to mobile, use this class to
1038
- * disable expand/collapse transition when loading.
1039
- */
1040
- .preload * {
1041
- transition: none !important;
1042
- -webkit-transition: none !important;
1043
- -moz-transition: none !important;
1044
- -ms-transition: none !important;
1045
- -o-transition: none !important;
1046
- }
1047
-
1048
- #content-container {
1049
- display: flex;
1050
- }
1051
-
1052
- .collapser {
1053
- display: inline-block;
1054
- }
1055
-
1056
- .collapser svg {
1057
- width: 10px;
1058
- height: 10px;
1059
- transition: transform 0.2s ease-out;
1060
- }
1061
-
1062
- .collapser.open svg {
1063
- transform: rotate(90deg);
1064
- }
1065
-
1066
- #mobile-filter-collapse h1 {
1067
- cursor: pointer;
1068
- }
1069
-
1070
- #content-container.mobile {
1071
- display: block;
1072
- }
1073
-
1074
- .column {
1075
- padding-top: 2rem;
1076
- }
1077
-
1078
- #right-column {
1079
- flex: 1;
1080
- position: relative;
1081
- border-left: 1px solid rgb(232, 232, 232);
1082
- padding-left: 1rem;
1083
- }
1084
-
1085
- .mobile #right-column {
1086
- border-left: none;
1087
- padding: 0;
1088
- }
1089
-
1090
- #left-column {
1091
- width: 18rem;
1092
- min-width: 18rem; /* Prevents Safari from shrinking col at first draw */
1093
- padding-right: 12px;
1094
- padding-right: 1rem;
1095
- }
1096
-
1097
- .desktop #left-column::-webkit-scrollbar {
1098
- display: none;
1099
- }
1100
-
1101
- .mobile #left-column {
1102
- width: 100%;
1103
- padding: 0;
1104
- }
1105
-
1106
- .desktop #left-column {
1107
- top: 0;
1108
- position: sticky;
1109
- max-height: 100vh;
1110
- overflow: scroll;
1111
- -ms-overflow-style: none; /* hide scrollbar IE and Edge */
1112
- scrollbar-width: none; /* hide scrollbar Firefox */
1113
- }
1114
-
1115
- #mobile-header-container {
1116
- display: flex;
1117
- justify-content: space-between;
1118
- }
1119
-
1120
- #facets-container {
1121
- position: relative;
1122
- max-height: 0;
1123
- transition: max-height 0.2s ease-in-out;
1124
- z-index: 1;
1125
- padding-bottom: 2rem;
1126
- }
1127
-
1128
- .mobile #facets-container {
1129
- overflow: hidden;
1130
- padding-bottom: 0;
1131
- }
1132
-
1133
- #facets-container.expanded {
1134
- max-height: 2000px;
1135
- }
1136
-
1137
- #results-total {
1138
- display: flex;
1139
- align-items: center;
1140
- margin-bottom: 5rem;
1141
- }
1142
-
1143
- .mobile #results-total {
1144
- margin-bottom: 0;
1145
- }
1146
-
1147
- #big-results-count {
1148
- font-size: 2.4rem;
1149
- font-weight: 500;
1150
- margin-right: 5px;
1151
- }
1152
-
1153
- #big-results-label {
1154
- font-size: 1rem;
1155
- font-weight: 200;
1156
- text-transform: uppercase;
1157
- }
1158
-
1159
- #list-header {
1160
- max-height: 4.2rem;
1161
- }
1162
-
1163
- .loading-cover {
1164
- position: absolute;
1165
- top: 0;
1166
- left: 0;
1167
- width: 100%;
1168
- height: 100%;
1169
- display: flex;
1170
- justify-content: center;
1171
- z-index: 1;
1172
- padding-top: 50px;
1173
- }
1174
-
1175
- circular-activity-indicator {
1176
- width: 30px;
1177
- height: 30px;
1178
- }
1179
-
1180
- sort-filter-bar {
1181
- display: block;
1182
- margin-bottom: 4rem;
1183
- }
1184
-
1185
- infinite-scroller {
1186
- display: block;
1187
- --infiniteScrollerRowGap: var(--collectionBrowserRowGap, 1.7rem);
1188
- --infiniteScrollerColGap: var(--collectionBrowserColGap, 1.7rem);
1189
- }
1190
-
1191
- infinite-scroller.list-compact {
1192
- --infiniteScrollerCellMinWidth: var(
1193
- --collectionBrowserCellMinWidth,
1194
- 100%
1195
- );
1196
- --infiniteScrollerCellMinHeight: 34px; /* override infinite scroller component */
1197
- --infiniteScrollerCellMaxHeight: 56px;
1198
- --infiniteScrollerRowGap: 0px;
1199
- }
1200
-
1201
- infinite-scroller.list-detail {
1202
- --infiniteScrollerCellMinWidth: var(
1203
- --collectionBrowserCellMinWidth,
1204
- 100%
1205
- );
1206
- --infiniteScrollerCellMinHeight: var(
1207
- --collectionBrowserCellMinHeight,
1208
- 5rem
1209
- );
1210
- /*
1211
- 30px in spec, compensating for a -4px margin
1212
- to align title with top of item image
1213
- src/tiles/list/tile-list.ts
1214
- */
1215
- --infiniteScrollerRowGap: 34px;
1216
- }
1217
-
1218
- .mobile infinite-scroller.list-detail {
1219
- --infiniteScrollerRowGap: 24px;
1220
- }
1221
-
1222
- infinite-scroller.grid {
1223
- --infiniteScrollerCellMinWidth: var(
1224
- --collectionBrowserCellMinWidth,
1225
- 18rem
1226
- );
1227
- --infiniteScrollerCellMaxWidth: var(--collectionBrowserCellMaxWidth, 1fr);
1228
- --infiniteScrollerCellMinHeight: var(
1229
- --collectionBrowserCellMinHeight,
1230
- 29rem
1231
- );
1232
- --infiniteScrollerCellMaxHeight: var(
1233
- --collectionBrowserCellMaxHeight,
1234
- 29rem
1235
- );
1236
- }
1237
- `;
1238
- __decorate([
1239
- property({ type: String })
1240
- ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
1241
- __decorate([
1242
- property({ type: String })
1243
- ], CollectionBrowser.prototype, "baseImageUrl", void 0);
1244
- __decorate([
1245
- property({ type: Object })
1246
- ], CollectionBrowser.prototype, "searchService", void 0);
1247
- __decorate([
1248
- property({ type: String })
1249
- ], CollectionBrowser.prototype, "searchType", void 0);
1250
- __decorate([
1251
- property({ type: String })
1252
- ], CollectionBrowser.prototype, "baseQuery", void 0);
1253
- __decorate([
1254
- property({ type: String })
1255
- ], CollectionBrowser.prototype, "displayMode", void 0);
1256
- __decorate([
1257
- property({ type: Object })
1258
- ], CollectionBrowser.prototype, "sortParam", void 0);
1259
- __decorate([
1260
- property({ type: String })
1261
- ], CollectionBrowser.prototype, "selectedSort", void 0);
1262
- __decorate([
1263
- property({ type: String })
1264
- ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
1265
- __decorate([
1266
- property({ type: String })
1267
- ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
1268
- __decorate([
1269
- property({ type: String })
1270
- ], CollectionBrowser.prototype, "sortDirection", void 0);
1271
- __decorate([
1272
- property({ type: String })
1273
- ], CollectionBrowser.prototype, "dateRangeQueryClause", void 0);
1274
- __decorate([
1275
- property({ type: Number })
1276
- ], CollectionBrowser.prototype, "pageSize", void 0);
1277
- __decorate([
1278
- property({ type: Object })
1279
- ], CollectionBrowser.prototype, "resizeObserver", void 0);
1280
- __decorate([
1281
- property({ type: String })
1282
- ], CollectionBrowser.prototype, "titleQuery", void 0);
1283
- __decorate([
1284
- property({ type: String })
1285
- ], CollectionBrowser.prototype, "creatorQuery", void 0);
1286
- __decorate([
1287
- property({ type: Number })
1288
- ], CollectionBrowser.prototype, "currentPage", void 0);
1289
- __decorate([
1290
- property({ type: String })
1291
- ], CollectionBrowser.prototype, "minSelectedDate", void 0);
1292
- __decorate([
1293
- property({ type: String })
1294
- ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
1295
- __decorate([
1296
- property({ type: Object })
1297
- ], CollectionBrowser.prototype, "selectedFacets", void 0);
1298
- __decorate([
1299
- property({ type: Boolean })
1300
- ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
1301
- __decorate([
1302
- property({ type: String, reflect: true })
1303
- ], CollectionBrowser.prototype, "searchContext", void 0);
1304
- __decorate([
1305
- property({ type: Object })
1306
- ], CollectionBrowser.prototype, "collectionNameCache", void 0);
1307
- __decorate([
1308
- property({ type: String })
1309
- ], CollectionBrowser.prototype, "pageContext", void 0);
1310
- __decorate([
1311
- property({ type: Object })
1312
- ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
1313
- __decorate([
1314
- property({ type: Number })
1315
- ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
1316
- __decorate([
1317
- property({ type: Boolean })
1318
- ], CollectionBrowser.prototype, "loggedIn", void 0);
1319
- __decorate([
1320
- property({ type: Object })
1321
- ], CollectionBrowser.prototype, "modalManager", void 0);
1322
- __decorate([
1323
- property({ type: Boolean })
1324
- ], CollectionBrowser.prototype, "isManageView", void 0);
1325
- __decorate([
1326
- state()
1327
- ], CollectionBrowser.prototype, "pagesToRender", void 0);
1328
- __decorate([
1329
- state()
1330
- ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
1331
- __decorate([
1332
- state()
1333
- ], CollectionBrowser.prototype, "facetsLoading", void 0);
1334
- __decorate([
1335
- state()
1336
- ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
1337
- __decorate([
1338
- state()
1339
- ], CollectionBrowser.prototype, "aggregations", void 0);
1340
- __decorate([
1341
- state()
1342
- ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
1343
- __decorate([
1344
- state()
1345
- ], CollectionBrowser.prototype, "totalResults", void 0);
1346
- __decorate([
1347
- state()
1348
- ], CollectionBrowser.prototype, "mobileView", void 0);
1349
- __decorate([
1350
- state()
1351
- ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
1352
- __decorate([
1353
- state()
1354
- ], CollectionBrowser.prototype, "placeholderType", void 0);
1355
- __decorate([
1356
- query('#content-container')
1357
- ], CollectionBrowser.prototype, "contentContainer", void 0);
1358
- __decorate([
1359
- property({ type: Object, attribute: false })
1360
- ], CollectionBrowser.prototype, "analyticsHandler", void 0);
1361
- __decorate([
1362
- query('infinite-scroller')
1363
- ], CollectionBrowser.prototype, "infiniteScroller", void 0);
1364
- CollectionBrowser = __decorate([
1365
- customElement('collection-browser')
1366
- ], CollectionBrowser);
1367
- export { CollectionBrowser };
1
+ import { __decorate } from "tslib";
2
+ /* eslint-disable import/no-duplicates */
3
+ import { html, css, LitElement, nothing, } from 'lit';
4
+ import { customElement, property, query, state } from 'lit/decorators.js';
5
+ import { ifDefined } from 'lit/directives/if-defined.js';
6
+ import { SearchType, } from '@internetarchive/search-service';
7
+ import '@internetarchive/infinite-scroller';
8
+ import './tiles/tile-dispatcher';
9
+ import './tiles/collection-browser-loading-tile';
10
+ import './sort-filter-bar/sort-filter-bar';
11
+ import './collection-facets';
12
+ import './circular-activity-indicator';
13
+ import './sort-filter-bar/sort-filter-bar';
14
+ import { SortField, SortFieldToMetadataField, defaultSelectedFacets, } from './models';
15
+ import { RestorationStateHandler, } from './restoration-state-handler';
16
+ import chevronIcon from './assets/img/icons/chevron';
17
+ import { LanguageCodeHandler } from './language-code-handler/language-code-handler';
18
+ import './empty-placeholder';
19
+ import { analyticsActions, analyticsCategories, } from './utils/analytics-events';
20
+ let CollectionBrowser = class CollectionBrowser extends LitElement {
21
+ constructor() {
22
+ super(...arguments);
23
+ this.baseImageUrl = 'https://archive.org';
24
+ this.searchType = SearchType.METADATA;
25
+ this.sortParam = null;
26
+ this.selectedSort = SortField.relevance;
27
+ this.selectedTitleFilter = null;
28
+ this.selectedCreatorFilter = null;
29
+ this.sortDirection = null;
30
+ this.pageSize = 50;
31
+ this.showHistogramDatePicker = false;
32
+ /** describes where this component is being used */
33
+ this.searchContext = analyticsCategories.default;
34
+ this.pageContext = 'search';
35
+ this.restorationStateHandler = new RestorationStateHandler({
36
+ context: this.pageContext,
37
+ });
38
+ this.mobileBreakpoint = 600;
39
+ this.loggedIn = false;
40
+ this.modalManager = undefined;
41
+ /**
42
+ * If item management UI active
43
+ */
44
+ this.isManageView = false;
45
+ /**
46
+ * The page that the consumer wants to load.
47
+ */
48
+ this.initialPageNumber = 1;
49
+ /**
50
+ * This the the number of pages that we want to show.
51
+ *
52
+ * The data isn't necessarily loaded for all of the pages, but this lets us
53
+ * know how many cells we should render.
54
+ */
55
+ this.pagesToRender = this.initialPageNumber;
56
+ this.searchResultsLoading = false;
57
+ this.facetsLoading = false;
58
+ this.fullYearAggregationLoading = false;
59
+ this.mobileView = false;
60
+ this.mobileFacetsVisible = false;
61
+ this.placeholderType = null;
62
+ this.languageCodeHandler = new LanguageCodeHandler();
63
+ /**
64
+ * When we're animated scrolling to the page, we don't want to fetch
65
+ * all of the pages as it scrolls so this lets us know if we're scrolling
66
+ */
67
+ this.isScrollingToCell = false;
68
+ /**
69
+ * When we've reached the end of the data, stop trying to fetch more
70
+ */
71
+ this.endOfDataReached = false;
72
+ /**
73
+ * When page width resizes from desktop to mobile, set true to
74
+ * disable expand/collapse transition when loading.
75
+ */
76
+ this.isResizeToMobile = false;
77
+ this.placeholderCellTemplate = html `<collection-browser-loading-tile></collection-browser-loading-tile>`;
78
+ /**
79
+ * The results per page so we can paginate.
80
+ *
81
+ * This allows us to start in the middle of the search results and
82
+ * fetch data before or after the current page. If we don't have a key
83
+ * for the previous/next page, we'll fetch the next/previous page to populate it
84
+ */
85
+ this.dataSource = {};
86
+ // we only want to scroll on the very first query change
87
+ // so this keeps track of whether we've already set the initial query
88
+ this.initialQueryChangeHappened = false;
89
+ this.historyPopOccurred = false;
90
+ // this maps the query to the pages being fetched for that query
91
+ this.pageFetchesInProgress = {};
92
+ }
93
+ tileModelAtCellIndex(index) {
94
+ var _a;
95
+ const pageNumber = Math.floor(index / this.pageSize) + 1;
96
+ const itemIndex = index % this.pageSize;
97
+ const model = (_a = this.dataSource[pageNumber]) === null || _a === void 0 ? void 0 : _a[itemIndex];
98
+ /**
99
+ * If we encounter a model we don't have yet and we're not in the middle of an
100
+ * automated scroll, fetch the page and just return undefined.
101
+ * The datasource will be updated once the page is loaded and the cell will be rendered.
102
+ *
103
+ * We disable it during the automated scroll since we may fetch pages for cells the
104
+ * user may never see.
105
+ */
106
+ if (!model && !this.isScrollingToCell) {
107
+ this.fetchPage(pageNumber);
108
+ }
109
+ return model;
110
+ }
111
+ get sortFilterQueries() {
112
+ const queries = [this.titleQuery, this.creatorQuery];
113
+ return queries.filter(q => q).join(' AND ');
114
+ }
115
+ // this is the total number of tiles we expect if
116
+ // the data returned is a full page worth
117
+ // this is useful for putting in placeholders for the expected number of tiles
118
+ get estimatedTileCount() {
119
+ return this.pagesToRender * this.pageSize;
120
+ }
121
+ // this is the actual number of tiles in the datasource,
122
+ // which is useful for removing excess placeholder tiles
123
+ // once we reached the end of the data
124
+ get actualTileCount() {
125
+ return Object.keys(this.dataSource).reduce((acc, page) => acc + this.dataSource[page].length, 0);
126
+ }
127
+ /**
128
+ * Go to the given page of results
129
+ *
130
+ * @param pageNumber
131
+ */
132
+ goToPage(pageNumber) {
133
+ this.initialPageNumber = pageNumber;
134
+ this.pagesToRender = pageNumber;
135
+ this.scrollToPage(pageNumber);
136
+ }
137
+ clearFilters() {
138
+ this.selectedFacets = defaultSelectedFacets;
139
+ this.sortParam = null;
140
+ this.selectedTitleFilter = null;
141
+ this.selectedCreatorFilter = null;
142
+ this.titleQuery = undefined;
143
+ this.creatorQuery = undefined;
144
+ this.selectedSort = SortField.relevance;
145
+ this.sortDirection = null;
146
+ }
147
+ render() {
148
+ this.setPlaceholderType();
149
+ return html `
150
+ <div
151
+ id="content-container"
152
+ class=${this.mobileView ? 'mobile' : 'desktop'}
153
+ >
154
+ ${this.placeholderType
155
+ ? this.emptyPlaceholderTemplate
156
+ : this.collectionBrowserTemplate}
157
+ </div>
158
+ `;
159
+ }
160
+ setPlaceholderType() {
161
+ this.placeholderType = null;
162
+ if (!this.baseQuery) {
163
+ this.placeholderType = 'empty-query';
164
+ }
165
+ if (!this.searchResultsLoading && this.totalResults === 0) {
166
+ this.placeholderType = 'null-result';
167
+ }
168
+ }
169
+ get emptyPlaceholderTemplate() {
170
+ return html `
171
+ <empty-placeholder
172
+ .placeholderType=${this.placeholderType}
173
+ ?isMobileView=${this.mobileView}
174
+ ></empty-placeholder>
175
+ `;
176
+ }
177
+ get collectionBrowserTemplate() {
178
+ return html `<div
179
+ id="left-column"
180
+ class="column${this.isResizeToMobile ? ' preload' : ''}"
181
+ >
182
+ <div id="mobile-header-container">
183
+ ${this.mobileView ? this.mobileFacetsTemplate : nothing}
184
+ <div id="results-total">
185
+ <span id="big-results-count">
186
+ ${this.totalResults !== undefined
187
+ ? this.totalResults.toLocaleString()
188
+ : '-'}
189
+ </span>
190
+ <span id="big-results-label">
191
+ ${this.totalResults === 1 ? 'Result' : 'Results'}
192
+ </span>
193
+ </div>
194
+ </div>
195
+ <div
196
+ id="facets-container"
197
+ class=${!this.mobileView || this.mobileFacetsVisible
198
+ ? 'expanded'
199
+ : ''}
200
+ >
201
+ ${this.facetsTemplate}
202
+ </div>
203
+ </div>
204
+ <div id="right-column" class="column">
205
+ ${this.searchResultsLoading ? this.loadingTemplate : nothing}
206
+ ${this.sortFilterBarTemplate}
207
+ ${this.displayMode === `list-compact`
208
+ ? this.listHeaderTemplate
209
+ : nothing}
210
+ ${this.infiniteScrollerTemplate}
211
+ </div>`;
212
+ }
213
+ get infiniteScrollerTemplate() {
214
+ return html `<infinite-scroller
215
+ class="${ifDefined(this.displayMode)}"
216
+ .cellProvider=${this}
217
+ .placeholderCellTemplate=${this.placeholderCellTemplate}
218
+ @scrollThresholdReached=${this.scrollThresholdReached}
219
+ @visibleCellsChanged=${this.visibleCellsChanged}
220
+ ></infinite-scroller>`;
221
+ }
222
+ get sortFilterBarTemplate() {
223
+ return html `
224
+ <sort-filter-bar
225
+ .selectedSort=${this.selectedSort}
226
+ .sortDirection=${this.sortDirection}
227
+ .displayMode=${this.displayMode}
228
+ .selectedTitleFilter=${this.selectedTitleFilter}
229
+ .selectedCreatorFilter=${this.selectedCreatorFilter}
230
+ .resizeObserver=${this.resizeObserver}
231
+ @sortChanged=${this.userChangedSort}
232
+ @displayModeChanged=${this.displayModeChanged}
233
+ @titleLetterChanged=${this.titleLetterSelected}
234
+ @creatorLetterChanged=${this.creatorLetterSelected}
235
+ >
236
+ </sort-filter-bar>
237
+ `;
238
+ }
239
+ userChangedSort(e) {
240
+ var _a;
241
+ const { selectedSort, sortDirection } = e.detail;
242
+ this.selectedSort = selectedSort;
243
+ this.sortDirection = sortDirection;
244
+ if (((_a = this.currentPage) !== null && _a !== void 0 ? _a : 1) > 1) {
245
+ this.goToPage(1);
246
+ }
247
+ this.currentPage = 1;
248
+ }
249
+ sendSortByAnalytics(prevSortDirection) {
250
+ var _a;
251
+ const directionCleared = prevSortDirection && !this.sortDirection;
252
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
253
+ category: this.searchContext,
254
+ action: analyticsActions.sortBy,
255
+ label: `${this.selectedSort}${this.sortDirection || directionCleared ? `-${this.sortDirection}` : ''}`,
256
+ });
257
+ }
258
+ selectedSortChanged() {
259
+ if (this.selectedSort === 'relevance' || this.sortDirection === null) {
260
+ this.sortParam = null;
261
+ return;
262
+ }
263
+ const sortField = SortFieldToMetadataField[this.selectedSort];
264
+ if (!sortField)
265
+ return;
266
+ this.sortParam = { field: sortField, direction: this.sortDirection };
267
+ }
268
+ displayModeChanged(e) {
269
+ var _a;
270
+ this.displayMode = e.detail.displayMode;
271
+ if (this.displayMode) {
272
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
273
+ category: this.searchContext,
274
+ action: analyticsActions.displayMode,
275
+ label: this.displayMode,
276
+ });
277
+ }
278
+ }
279
+ /** Send Analytics when sorting by title's first letter
280
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
281
+ * */
282
+ sendFilterByTitleAnalytics(prevSelectedLetter) {
283
+ var _a;
284
+ if (!prevSelectedLetter && !this.selectedTitleFilter) {
285
+ return;
286
+ }
287
+ const cleared = prevSelectedLetter && this.selectedTitleFilter === null;
288
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
289
+ category: this.searchContext,
290
+ action: analyticsActions.filterByTitle,
291
+ label: cleared
292
+ ? `clear-${prevSelectedLetter}`
293
+ : `${prevSelectedLetter || 'start'}-${this.selectedTitleFilter}`,
294
+ });
295
+ }
296
+ selectedTitleLetterChanged() {
297
+ this.titleQuery = this.selectedTitleFilter
298
+ ? `firstTitle:${this.selectedTitleFilter}`
299
+ : undefined;
300
+ }
301
+ /** Send Analytics when filtering by creator's first letter
302
+ * labels: 'start-<ToLetter>' | 'clear-<FromLetter>' | '<FromLetter>-<ToLetter>'
303
+ * */
304
+ sendFilterByCreatorAnalytics(prevSelectedLetter) {
305
+ var _a;
306
+ if (!prevSelectedLetter && !this.selectedCreatorFilter) {
307
+ return;
308
+ }
309
+ const cleared = prevSelectedLetter && this.selectedCreatorFilter === null;
310
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
311
+ category: this.searchContext,
312
+ action: analyticsActions.filterByCreator,
313
+ label: cleared
314
+ ? `clear-${prevSelectedLetter}`
315
+ : `${prevSelectedLetter || 'start'}-${this.selectedCreatorFilter}`,
316
+ });
317
+ }
318
+ selectedCreatorLetterChanged() {
319
+ this.creatorQuery = this.selectedCreatorFilter
320
+ ? `firstCreator:${this.selectedCreatorFilter}`
321
+ : undefined;
322
+ }
323
+ titleLetterSelected(e) {
324
+ this.selectedCreatorFilter = null;
325
+ this.selectedTitleFilter = e.detail.selectedLetter;
326
+ }
327
+ creatorLetterSelected(e) {
328
+ this.selectedTitleFilter = null;
329
+ this.selectedCreatorFilter = e.detail.selectedLetter;
330
+ }
331
+ get facetDataLoading() {
332
+ return this.facetsLoading || this.fullYearAggregationLoading;
333
+ }
334
+ get mobileFacetsTemplate() {
335
+ return html `
336
+ <div id="mobile-filter-collapse">
337
+ <h1
338
+ @click=${() => {
339
+ this.isResizeToMobile = false;
340
+ this.mobileFacetsVisible = !this.mobileFacetsVisible;
341
+ }}
342
+ @keyup=${() => {
343
+ this.isResizeToMobile = false;
344
+ this.mobileFacetsVisible = !this.mobileFacetsVisible;
345
+ }}
346
+ >
347
+ <span class="collapser ${this.mobileFacetsVisible ? 'open' : ''}">
348
+ ${chevronIcon}
349
+ </span>
350
+ Filters
351
+ </h1>
352
+ </div>
353
+ `;
354
+ }
355
+ get facetsTemplate() {
356
+ return html `
357
+ ${this.facetsLoading ? this.loadingTemplate : nothing}
358
+ <collection-facets
359
+ @facetsChanged=${this.facetsChanged}
360
+ @histogramDateRangeUpdated=${this.histogramDateRangeUpdated}
361
+ .searchService=${this.searchService}
362
+ .searchType=${this.searchType}
363
+ .aggregations=${this.aggregations}
364
+ .fullYearsHistogramAggregation=${this.fullYearsHistogramAggregation}
365
+ .minSelectedDate=${this.minSelectedDate}
366
+ .maxSelectedDate=${this.maxSelectedDate}
367
+ .selectedFacets=${this.selectedFacets}
368
+ .collectionNameCache=${this.collectionNameCache}
369
+ .languageCodeHandler=${this.languageCodeHandler}
370
+ .showHistogramDatePicker=${this.showHistogramDatePicker}
371
+ .fullQuery=${this.fullQuery}
372
+ .modalManager=${this.modalManager}
373
+ ?collapsableFacets=${this.mobileView}
374
+ ?facetsLoading=${this.facetDataLoading}
375
+ ?fullYearAggregationLoading=${this.fullYearAggregationLoading}
376
+ .onFacetClick=${this.facetClickHandler}
377
+ .analyticsHandler=${this.analyticsHandler}
378
+ >
379
+ </collection-facets>
380
+ `;
381
+ }
382
+ get loadingTemplate() {
383
+ return html `
384
+ <div class="loading-cover">
385
+ <circular-activity-indicator></circular-activity-indicator>
386
+ </div>
387
+ `;
388
+ }
389
+ get listHeaderTemplate() {
390
+ return html `
391
+ <div id="list-header">
392
+ <tile-dispatcher
393
+ .tileDisplayMode=${'list-header'}
394
+ .resizeObserver=${this.resizeObserver}
395
+ .sortParam=${this.sortParam}
396
+ .mobileBreakpoint=${this.mobileBreakpoint}
397
+ .loggedIn=${this.loggedIn}
398
+ >
399
+ </tile-dispatcher>
400
+ </div>
401
+ `;
402
+ }
403
+ get queryDebuggingTemplate() {
404
+ var _a, _b;
405
+ return html `
406
+ <div>
407
+ <ul>
408
+ <li>Base Query: ${this.baseQuery}</li>
409
+ <li>Facet Query: ${this.facetQuery}</li>
410
+ <li>Sort Filter Query: ${this.sortFilterQueries}</li>
411
+ <li>Date Range Query: ${this.dateRangeQueryClause}</li>
412
+ <li>Sort: ${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field} ${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}</li>
413
+ <li>Full Query: ${this.fullQuery}</li>
414
+ </ul>
415
+ </div>
416
+ `;
417
+ }
418
+ histogramDateRangeUpdated(e) {
419
+ var _a;
420
+ const { minDate, maxDate } = e.detail;
421
+ this.dateRangeQueryClause = `year:[${minDate} TO ${maxDate}]`;
422
+ if (this.dateRangeQueryClause) {
423
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
424
+ category: this.searchContext,
425
+ action: analyticsActions.histogramChanged,
426
+ label: this.dateRangeQueryClause,
427
+ });
428
+ }
429
+ }
430
+ firstUpdated() {
431
+ this.setupStateRestorationObserver();
432
+ this.restoreState();
433
+ }
434
+ updated(changed) {
435
+ var _a;
436
+ if (changed.has('displayMode') ||
437
+ changed.has('baseNavigationUrl') ||
438
+ changed.has('baseImageUrl') ||
439
+ changed.has('loggedIn')) {
440
+ (_a = this.infiniteScroller) === null || _a === void 0 ? void 0 : _a.reload();
441
+ }
442
+ if (changed.has('baseQuery')) {
443
+ this.emitBaseQueryChanged();
444
+ }
445
+ if (changed.has('currentPage') || changed.has('displayMode')) {
446
+ this.persistState();
447
+ }
448
+ if (changed.has('baseQuery') ||
449
+ changed.has('titleQuery') ||
450
+ changed.has('creatorQuery') ||
451
+ changed.has('dateRangeQueryClause') ||
452
+ changed.has('sortParam') ||
453
+ changed.has('selectedFacets') ||
454
+ changed.has('searchService')) {
455
+ this.handleQueryChange();
456
+ }
457
+ if (changed.has('selectedSort') || changed.has('sortDirection')) {
458
+ const prevSortDirection = changed.get('sortDirection');
459
+ this.sendSortByAnalytics(prevSortDirection);
460
+ this.selectedSortChanged();
461
+ }
462
+ if (changed.has('selectedTitleFilter')) {
463
+ this.sendFilterByTitleAnalytics(changed.get('selectedTitleFilter'));
464
+ this.selectedTitleLetterChanged();
465
+ }
466
+ if (changed.has('selectedCreatorFilter')) {
467
+ this.sendFilterByCreatorAnalytics(changed.get('selectedCreatorFilter'));
468
+ this.selectedCreatorLetterChanged();
469
+ }
470
+ if (changed.has('pagesToRender')) {
471
+ if (!this.endOfDataReached && this.infiniteScroller) {
472
+ this.infiniteScroller.itemCount = this.estimatedTileCount;
473
+ }
474
+ }
475
+ if (changed.has('resizeObserver')) {
476
+ const oldObserver = changed.get('resizeObserver');
477
+ if (oldObserver)
478
+ this.disconnectResizeObserver(oldObserver);
479
+ this.setupResizeObserver();
480
+ }
481
+ }
482
+ disconnectedCallback() {
483
+ if (this.resizeObserver) {
484
+ this.disconnectResizeObserver(this.resizeObserver);
485
+ }
486
+ if (this.boundNavigationHandler) {
487
+ window.removeEventListener('popstate', this.boundNavigationHandler);
488
+ }
489
+ }
490
+ handleResize(entry) {
491
+ const previousView = this.mobileView;
492
+ if (entry.target === this.contentContainer) {
493
+ this.mobileView = entry.contentRect.width < this.mobileBreakpoint;
494
+ // If changing from desktop to mobile disable transition
495
+ if (this.mobileView && !previousView) {
496
+ this.isResizeToMobile = true;
497
+ }
498
+ }
499
+ }
500
+ emitBaseQueryChanged() {
501
+ this.dispatchEvent(new CustomEvent('baseQueryChanged', {
502
+ detail: {
503
+ baseQuery: this.baseQuery,
504
+ },
505
+ }));
506
+ }
507
+ disconnectResizeObserver(resizeObserver) {
508
+ resizeObserver.removeObserver({
509
+ target: this.contentContainer,
510
+ handler: this,
511
+ });
512
+ }
513
+ setupResizeObserver() {
514
+ if (!this.resizeObserver)
515
+ return;
516
+ this.resizeObserver.addObserver({
517
+ target: this.contentContainer,
518
+ handler: this,
519
+ });
520
+ }
521
+ /**
522
+ * When the visible cells change from the infinite scroller, we want to emit
523
+ * which page is currently visible so the consumer can update its UI or the URL
524
+ *
525
+ * @param e
526
+ * @returns
527
+ */
528
+ visibleCellsChanged(e) {
529
+ if (this.isScrollingToCell)
530
+ return;
531
+ const { visibleCellIndices } = e.detail;
532
+ if (visibleCellIndices.length === 0)
533
+ return;
534
+ const lastVisibleCellIndex = visibleCellIndices[visibleCellIndices.length - 1];
535
+ const lastVisibleCellPage = Math.floor(lastVisibleCellIndex / this.pageSize) + 1;
536
+ if (this.currentPage !== lastVisibleCellPage) {
537
+ this.currentPage = lastVisibleCellPage;
538
+ }
539
+ const event = new CustomEvent('visiblePageChanged', {
540
+ detail: {
541
+ pageNumber: lastVisibleCellPage,
542
+ },
543
+ });
544
+ this.dispatchEvent(event);
545
+ }
546
+ async handleQueryChange() {
547
+ // only reset if the query has actually changed
548
+ if (!this.searchService || this.pageFetchQueryKey === this.previousQueryKey)
549
+ return;
550
+ this.previousQueryKey = this.pageFetchQueryKey;
551
+ this.dataSource = {};
552
+ this.pageFetchesInProgress = {};
553
+ this.endOfDataReached = false;
554
+ this.pagesToRender = this.initialPageNumber;
555
+ if (!this.initialQueryChangeHappened && this.initialPageNumber > 1) {
556
+ this.scrollToPage(this.initialPageNumber);
557
+ }
558
+ this.initialQueryChangeHappened = true;
559
+ // if the query changed as part of a window.history pop event, we don't want to
560
+ // persist the state because it overwrites the forward history
561
+ if (!this.historyPopOccurred) {
562
+ this.persistState();
563
+ this.historyPopOccurred = false;
564
+ }
565
+ await Promise.all([
566
+ this.doInitialPageFetch(),
567
+ this.fetchFacets(),
568
+ this.fetchFullYearHistogram(),
569
+ ]);
570
+ }
571
+ setupStateRestorationObserver() {
572
+ if (this.boundNavigationHandler)
573
+ return;
574
+ this.boundNavigationHandler = this.historyNavigationHandler.bind(this);
575
+ // when the user navigates back, we want to update the UI to match the URL
576
+ window.addEventListener('popstate', this.boundNavigationHandler);
577
+ }
578
+ historyNavigationHandler() {
579
+ this.historyPopOccurred = true;
580
+ this.restoreState();
581
+ }
582
+ restoreState() {
583
+ var _a, _b, _c, _d, _e, _f, _g;
584
+ const restorationState = this.restorationStateHandler.getRestorationState();
585
+ this.displayMode = restorationState.displayMode;
586
+ this.searchType = (_a = restorationState.searchType) !== null && _a !== void 0 ? _a : SearchType.METADATA;
587
+ this.selectedSort = (_b = restorationState.selectedSort) !== null && _b !== void 0 ? _b : SortField.relevance;
588
+ this.sortDirection = (_c = restorationState.sortDirection) !== null && _c !== void 0 ? _c : null;
589
+ this.selectedTitleFilter = (_d = restorationState.selectedTitleFilter) !== null && _d !== void 0 ? _d : null;
590
+ this.selectedCreatorFilter = (_e = restorationState.selectedCreatorFilter) !== null && _e !== void 0 ? _e : null;
591
+ this.selectedFacets = restorationState.selectedFacets;
592
+ this.baseQuery = restorationState.baseQuery;
593
+ this.titleQuery = restorationState.titleQuery;
594
+ this.creatorQuery = restorationState.creatorQuery;
595
+ this.dateRangeQueryClause = restorationState.dateRangeQueryClause;
596
+ this.sortParam = (_f = restorationState.sortParam) !== null && _f !== void 0 ? _f : null;
597
+ this.currentPage = (_g = restorationState.currentPage) !== null && _g !== void 0 ? _g : 1;
598
+ this.minSelectedDate = restorationState.minSelectedDate;
599
+ this.maxSelectedDate = restorationState.maxSelectedDate;
600
+ if (this.currentPage > 1) {
601
+ this.goToPage(this.currentPage);
602
+ }
603
+ }
604
+ persistState() {
605
+ var _a, _b, _c, _d, _e;
606
+ const restorationState = {
607
+ displayMode: this.displayMode,
608
+ sortParam: (_a = this.sortParam) !== null && _a !== void 0 ? _a : undefined,
609
+ selectedSort: this.selectedSort,
610
+ sortDirection: (_b = this.sortDirection) !== null && _b !== void 0 ? _b : undefined,
611
+ selectedFacets: (_c = this.selectedFacets) !== null && _c !== void 0 ? _c : defaultSelectedFacets,
612
+ baseQuery: this.baseQuery,
613
+ currentPage: this.currentPage,
614
+ dateRangeQueryClause: this.dateRangeQueryClause,
615
+ titleQuery: this.titleQuery,
616
+ creatorQuery: this.creatorQuery,
617
+ minSelectedDate: this.minSelectedDate,
618
+ maxSelectedDate: this.maxSelectedDate,
619
+ selectedTitleFilter: (_d = this.selectedTitleFilter) !== null && _d !== void 0 ? _d : undefined,
620
+ selectedCreatorFilter: (_e = this.selectedCreatorFilter) !== null && _e !== void 0 ? _e : undefined,
621
+ };
622
+ this.restorationStateHandler.persistState(restorationState);
623
+ }
624
+ async doInitialPageFetch() {
625
+ this.searchResultsLoading = true;
626
+ await this.fetchPage(this.initialPageNumber);
627
+ this.searchResultsLoading = false;
628
+ }
629
+ get fullQuery() {
630
+ let { fullQueryWithoutDate } = this;
631
+ const { dateRangeQueryClause } = this;
632
+ if (dateRangeQueryClause) {
633
+ fullQueryWithoutDate += ` AND ${dateRangeQueryClause}`;
634
+ }
635
+ return fullQueryWithoutDate;
636
+ }
637
+ get fullQueryWithoutDate() {
638
+ if (!this.baseQuery)
639
+ return undefined;
640
+ let fullQuery = this.baseQuery;
641
+ const { facetQuery, sortFilterQueries } = this;
642
+ if (facetQuery) {
643
+ fullQuery += ` AND ${facetQuery}`;
644
+ }
645
+ if (sortFilterQueries) {
646
+ fullQuery += ` AND ${sortFilterQueries}`;
647
+ }
648
+ return fullQuery;
649
+ }
650
+ /**
651
+ * Generates a query string for the given facets
652
+ *
653
+ * Example: `mediatype:("collection" OR "audio" OR -"etree") AND year:("2000" OR "2001")`
654
+ */
655
+ get facetQuery() {
656
+ if (!this.selectedFacets)
657
+ return undefined;
658
+ const facetQuery = [];
659
+ for (const [facetName, facetValues] of Object.entries(this.selectedFacets)) {
660
+ const facetEntries = Object.entries(facetValues);
661
+ // eslint-disable-next-line no-continue
662
+ if (facetEntries.length === 0)
663
+ continue;
664
+ const facetValuesArray = [];
665
+ for (const [key, facetData] of facetEntries) {
666
+ const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';
667
+ if (facetName === 'language') {
668
+ const languages = this.languageCodeHandler.getCodeArrayFromCodeString(key);
669
+ for (const language of languages) {
670
+ facetValuesArray.push(`${plusMinusPrefix}"${language}"`);
671
+ }
672
+ }
673
+ else {
674
+ facetValuesArray.push(`${plusMinusPrefix}"${key}"`);
675
+ }
676
+ }
677
+ const valueQuery = facetValuesArray.join(` OR `);
678
+ facetQuery.push(`${facetName}:(${valueQuery})`);
679
+ }
680
+ return facetQuery.length > 0 ? `(${facetQuery.join(' AND ')})` : undefined;
681
+ }
682
+ facetsChanged(e) {
683
+ this.selectedFacets = e.detail;
684
+ }
685
+ facetClickHandler(name, facetSelected, negative) {
686
+ var _a, _b;
687
+ if (negative) {
688
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
689
+ category: this.searchContext,
690
+ action: facetSelected
691
+ ? analyticsActions.facetNegativeSelected
692
+ : analyticsActions.facetNegativeDeselected,
693
+ label: name,
694
+ });
695
+ }
696
+ else {
697
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEventNoSampling({
698
+ category: this.searchContext,
699
+ action: facetSelected
700
+ ? analyticsActions.facetSelected
701
+ : analyticsActions.facetDeselected,
702
+ label: name,
703
+ });
704
+ }
705
+ }
706
+ async fetchFacets() {
707
+ var _a, _b;
708
+ if (!this.fullQuery)
709
+ return;
710
+ const params = {
711
+ query: this.fullQuery,
712
+ rows: 0,
713
+ // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
714
+ // The default aggregations for the search_results page type should be what we need here.
715
+ };
716
+ this.facetsLoading = true;
717
+ const results = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
718
+ this.facetsLoading = false;
719
+ this.aggregations = (_b = results === null || results === void 0 ? void 0 : results.success) === null || _b === void 0 ? void 0 : _b.response.aggregations;
720
+ }
721
+ /**
722
+ * The query key is a string that uniquely identifies the current query
723
+ * without the date range.
724
+ *
725
+ * If this doesn't change, we don't need to re-fetch the histogram date range
726
+ */
727
+ get fullQueryNoDateKey() {
728
+ var _a, _b;
729
+ return `${this.fullQueryWithoutDate}-${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field}-${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}`;
730
+ }
731
+ /**
732
+ * This method is similar to fetching the facets above,
733
+ * but only fetching the year histogram. There is a subtle difference
734
+ * in how you have to fetch the year histogram where you can't use the
735
+ * advanced JSON syntax like the other aggregations. It's a special
736
+ * case that @ximm put it place.
737
+ */
738
+ async fetchFullYearHistogram() {
739
+ var _a, _b, _c, _d;
740
+ const { fullQueryNoDateKey } = this;
741
+ if (!this.fullQueryWithoutDate ||
742
+ fullQueryNoDateKey === this.previousFullQueryNoDate)
743
+ return;
744
+ this.previousFullQueryNoDate = fullQueryNoDateKey;
745
+ const aggregations = {
746
+ simpleParams: ['year'],
747
+ };
748
+ const params = {
749
+ query: this.fullQueryWithoutDate,
750
+ aggregations,
751
+ rows: 0,
752
+ };
753
+ this.fullYearAggregationLoading = true;
754
+ const results = await ((_a = this.searchService) === null || _a === void 0 ? void 0 : _a.search(params, this.searchType));
755
+ this.fullYearAggregationLoading = false;
756
+ this.fullYearsHistogramAggregation =
757
+ (_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;
758
+ }
759
+ scrollToPage(pageNumber) {
760
+ const cellIndexToScrollTo = this.pageSize * (pageNumber - 1);
761
+ // without this setTimeout, Safari just pauses until the `fetchPage` is complete
762
+ // then scrolls to the cell
763
+ setTimeout(() => {
764
+ this.isScrollingToCell = true;
765
+ this.infiniteScroller.scrollToCell(cellIndexToScrollTo, true);
766
+ // This timeout is to give the scroll animation time to finish
767
+ // then updating the infinite scroller once we're done scrolling
768
+ // There's no scroll animation completion callback so we're
769
+ // giving it 0.5s to finish.
770
+ setTimeout(() => {
771
+ this.isScrollingToCell = false;
772
+ this.infiniteScroller.reload();
773
+ }, 500);
774
+ }, 0);
775
+ }
776
+ /**
777
+ * The query key is a string that uniquely identifies the current query
778
+ *
779
+ * This lets us keep track of queries so we don't persist data that's
780
+ * no longer relevant.
781
+ */
782
+ get pageFetchQueryKey() {
783
+ var _a, _b;
784
+ return `${this.fullQuery}-${(_a = this.sortParam) === null || _a === void 0 ? void 0 : _a.field}-${(_b = this.sortParam) === null || _b === void 0 ? void 0 : _b.direction}`;
785
+ }
786
+ async fetchPage(pageNumber) {
787
+ var _a, _b, _c, _d, _e;
788
+ if (!this.fullQuery)
789
+ return;
790
+ // if we already have data, don't fetch again
791
+ if (this.dataSource[pageNumber])
792
+ return;
793
+ if (this.endOfDataReached)
794
+ return;
795
+ // if a fetch is already in progress for this query and page, don't fetch again
796
+ const { pageFetchQueryKey } = this;
797
+ const pageFetches = (_a = this.pageFetchesInProgress[pageFetchQueryKey]) !== null && _a !== void 0 ? _a : new Set();
798
+ if (pageFetches.has(pageNumber))
799
+ return;
800
+ pageFetches.add(pageNumber);
801
+ this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;
802
+ const sortParams = this.sortParam ? [this.sortParam] : [];
803
+ const params = {
804
+ query: this.fullQuery,
805
+ fields: [
806
+ 'addeddate',
807
+ 'avg_rating',
808
+ 'collections_raw',
809
+ 'creator',
810
+ 'date',
811
+ 'description',
812
+ 'downloads',
813
+ 'identifier',
814
+ 'issue',
815
+ 'item_count',
816
+ 'mediatype',
817
+ 'num_favorites',
818
+ 'num_reviews',
819
+ 'publicdate',
820
+ 'reviewdate',
821
+ 'source',
822
+ 'subject',
823
+ 'title',
824
+ 'volume',
825
+ ],
826
+ page: pageNumber,
827
+ rows: this.pageSize,
828
+ sort: sortParams,
829
+ aggregations: { omit: true },
830
+ };
831
+ const searchResponse = await ((_b = this.searchService) === null || _b === void 0 ? void 0 : _b.search(params, this.searchType));
832
+ const success = searchResponse === null || searchResponse === void 0 ? void 0 : searchResponse.success;
833
+ if (!success)
834
+ return;
835
+ this.totalResults = success.response.totalResults;
836
+ // this is checking to see if the query has changed since the data was fetched
837
+ // if so, we just want to discard the data since there should be a new query
838
+ // right behind it
839
+ const searchQuery = success.request.clientParameters.user_query;
840
+ const searchSort = success.request.clientParameters.sort;
841
+ let sortChanged = false;
842
+ if (!searchSort || searchSort.length === 0) {
843
+ // if we went from no sort to sort, the sort has changed
844
+ if (this.sortParam) {
845
+ sortChanged = true;
846
+ }
847
+ }
848
+ else {
849
+ // check if the sort has changed
850
+ for (const sortType of searchSort) {
851
+ const [field, direction] = sortType.split(':');
852
+ if (field !== ((_c = this.sortParam) === null || _c === void 0 ? void 0 : _c.field) ||
853
+ direction !== ((_d = this.sortParam) === null || _d === void 0 ? void 0 : _d.direction)) {
854
+ sortChanged = true;
855
+ break;
856
+ }
857
+ }
858
+ }
859
+ const queryChangedSinceFetch = searchQuery !== this.fullQuery || sortChanged;
860
+ if (queryChangedSinceFetch)
861
+ return;
862
+ const { results } = success.response;
863
+ if (results && results.length > 0) {
864
+ this.preloadCollectionNames(results);
865
+ this.updateDataSource(pageNumber, results);
866
+ }
867
+ if (results.length < this.pageSize) {
868
+ this.endOfDataReached = true;
869
+ // this updates the infinite scroller to show the actual size
870
+ if (this.infiniteScroller) {
871
+ this.infiniteScroller.itemCount = this.actualTileCount;
872
+ }
873
+ }
874
+ (_e = this.pageFetchesInProgress[pageFetchQueryKey]) === null || _e === void 0 ? void 0 : _e.delete(pageNumber);
875
+ this.searchResultsLoading = false;
876
+ }
877
+ preloadCollectionNames(results) {
878
+ var _a;
879
+ const collectionIds = results
880
+ .map(result => { var _a; return (_a = result.collection) === null || _a === void 0 ? void 0 : _a.values; })
881
+ .flat();
882
+ const collectionIdsArray = Array.from(new Set(collectionIds));
883
+ (_a = this.collectionNameCache) === null || _a === void 0 ? void 0 : _a.preloadIdentifiers(collectionIdsArray);
884
+ }
885
+ /**
886
+ * This is useful for determining whether we need to reload the scroller.
887
+ *
888
+ * When the fetch completes, we need to reload the scroller if the cells for that
889
+ * page are visible, but if the page is not currenlty visible, we don't need to reload
890
+ */
891
+ get currentVisiblePageNumbers() {
892
+ const visibleCells = this.infiniteScroller.getVisibleCellIndices();
893
+ const visiblePages = new Set();
894
+ visibleCells.forEach(cellIndex => {
895
+ const visiblePage = Math.floor(cellIndex / this.pageSize) + 1;
896
+ visiblePages.add(visiblePage);
897
+ });
898
+ return Array.from(visiblePages);
899
+ }
900
+ /**
901
+ * Update the datasource from the fetch response
902
+ *
903
+ * @param pageNumber
904
+ * @param results
905
+ */
906
+ updateDataSource(pageNumber, results) {
907
+ // copy our existing datasource so when we set it below, it gets set
908
+ // instead of modifying the existing dataSource since object changes
909
+ // don't trigger a re-render
910
+ const datasource = { ...this.dataSource };
911
+ const tiles = [];
912
+ results === null || results === void 0 ? void 0 : results.forEach(result => {
913
+ 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;
914
+ if (!result.identifier)
915
+ return;
916
+ let loginRequired = false;
917
+ let contentWarning = false;
918
+ // Check if item and item in "modifying" collection, setting above flags
919
+ if (((_a = result.collection) === null || _a === void 0 ? void 0 : _a.values.length) &&
920
+ ((_b = result.mediatype) === null || _b === void 0 ? void 0 : _b.value) !== 'collection') {
921
+ for (const collection of (_d = (_c = result.collection) === null || _c === void 0 ? void 0 : _c.values) !== null && _d !== void 0 ? _d : []) {
922
+ if (collection === 'loggedin') {
923
+ loginRequired = true;
924
+ if (contentWarning)
925
+ break;
926
+ }
927
+ if (collection === 'no-preview') {
928
+ contentWarning = true;
929
+ if (loginRequired)
930
+ break;
931
+ }
932
+ }
933
+ }
934
+ tiles.push({
935
+ // TODO the commented items are not currently being returned by the PPS and
936
+ // we will need to have them added to the PPS hit schemas where appropriate
937
+ // averageRating: result.avg_rating?.value,
938
+ collections: (_f = (_e = result.collection) === null || _e === void 0 ? void 0 : _e.values) !== null && _f !== void 0 ? _f : [],
939
+ commentCount: (_h = (_g = result.num_reviews) === null || _g === void 0 ? void 0 : _g.value) !== null && _h !== void 0 ? _h : 0,
940
+ creator: (_j = result.creator) === null || _j === void 0 ? void 0 : _j.value,
941
+ creators: (_l = (_k = result.creator) === null || _k === void 0 ? void 0 : _k.values) !== null && _l !== void 0 ? _l : [],
942
+ // dateAdded: result.addeddate?.value,
943
+ dateArchived: (_m = result.publicdate) === null || _m === void 0 ? void 0 : _m.value,
944
+ datePublished: (_o = result.date) === null || _o === void 0 ? void 0 : _o.value,
945
+ dateReviewed: (_p = result.reviewdate) === null || _p === void 0 ? void 0 : _p.value,
946
+ description: (_q = result.description) === null || _q === void 0 ? void 0 : _q.value,
947
+ favCount: (_s = (_r = result.num_favorites) === null || _r === void 0 ? void 0 : _r.value) !== null && _s !== void 0 ? _s : 0,
948
+ identifier: result.identifier,
949
+ // issue: result.issue?.value,
950
+ itemCount: 0,
951
+ mediatype: (_u = (_t = result.mediatype) === null || _t === void 0 ? void 0 : _t.value) !== null && _u !== void 0 ? _u : 'data',
952
+ snippets: (_w = (_v = result.highlight) === null || _v === void 0 ? void 0 : _v.values) !== null && _w !== void 0 ? _w : [],
953
+ // source: result.source?.value,
954
+ subjects: (_y = (_x = result.subject) === null || _x === void 0 ? void 0 : _x.values) !== null && _y !== void 0 ? _y : [],
955
+ title: this.etreeTitle((_z = result.title) === null || _z === void 0 ? void 0 : _z.value, (_0 = result.mediatype) === null || _0 === void 0 ? void 0 : _0.value, (_1 = result.collection) === null || _1 === void 0 ? void 0 : _1.values),
956
+ volume: (_2 = result.volume) === null || _2 === void 0 ? void 0 : _2.value,
957
+ viewCount: (_4 = (_3 = result.downloads) === null || _3 === void 0 ? void 0 : _3.value) !== null && _4 !== void 0 ? _4 : 0,
958
+ loginRequired,
959
+ contentWarning,
960
+ });
961
+ });
962
+ datasource[pageNumber] = tiles;
963
+ this.dataSource = datasource;
964
+ const visiblePages = this.currentVisiblePageNumbers;
965
+ const needsReload = visiblePages.includes(pageNumber);
966
+ if (needsReload) {
967
+ this.infiniteScroller.reload();
968
+ }
969
+ }
970
+ /*
971
+ * Convert etree titles
972
+ * "[Creator] Live at [Place] on [Date]" => "[Date]: [Place]"
973
+ *
974
+ * Todo: Check collection(s) for etree, need to get as array.
975
+ * Current search-service only returns first collection as string.
976
+ */
977
+ etreeTitle(title, mediatype, collections) {
978
+ if (mediatype === 'etree' || (collections === null || collections === void 0 ? void 0 : collections.includes('etree'))) {
979
+ const regex = /^(.*) Live at (.*) on (\d\d\d\d-\d\d-\d\d)$/;
980
+ const newTitle = title === null || title === void 0 ? void 0 : title.replace(regex, '$3: $2');
981
+ if (newTitle) {
982
+ return `${newTitle}`;
983
+ }
984
+ }
985
+ return title !== null && title !== void 0 ? title : '';
986
+ }
987
+ /**
988
+ * Callback when a result is selected
989
+ */
990
+ resultSelected(event) {
991
+ var _a, _b;
992
+ (_a = this.analyticsHandler) === null || _a === void 0 ? void 0 : _a.sendEventNoSampling({
993
+ category: this.searchContext,
994
+ action: analyticsActions.resultSelected,
995
+ label: event.detail.mediatype,
996
+ });
997
+ (_b = this.analyticsHandler) === null || _b === void 0 ? void 0 : _b.sendEventNoSampling({
998
+ category: this.searchContext,
999
+ action: analyticsActions.resultSelected,
1000
+ label: `page-${this.currentPage}`,
1001
+ });
1002
+ }
1003
+ cellForIndex(index) {
1004
+ const model = this.tileModelAtCellIndex(index);
1005
+ if (!model)
1006
+ return undefined;
1007
+ return html `
1008
+ <tile-dispatcher
1009
+ .baseNavigationUrl=${this.baseNavigationUrl}
1010
+ .baseImageUrl=${this.baseImageUrl}
1011
+ .model=${model}
1012
+ .tileDisplayMode=${this.displayMode}
1013
+ .resizeObserver=${this.resizeObserver}
1014
+ .collectionNameCache=${this.collectionNameCache}
1015
+ .sortParam=${this.sortParam}
1016
+ .mobileBreakpoint=${this.mobileBreakpoint}
1017
+ .loggedIn=${this.loggedIn}
1018
+ @resultSelected=${(e) => this.resultSelected(e)}
1019
+ >
1020
+ </tile-dispatcher>
1021
+ `;
1022
+ }
1023
+ /**
1024
+ * When the user scrolls near to the bottom of the page, fetch the next page
1025
+ * increase the number of pages to render and start fetching data for the new page
1026
+ */
1027
+ scrollThresholdReached() {
1028
+ this.pagesToRender += 1;
1029
+ this.fetchPage(this.pagesToRender);
1030
+ }
1031
+ };
1032
+ CollectionBrowser.styles = css `
1033
+ :host {
1034
+ display: block;
1035
+ }
1036
+
1037
+ /**
1038
+ * When page width resizes from desktop to mobile, use this class to
1039
+ * disable expand/collapse transition when loading.
1040
+ */
1041
+ .preload * {
1042
+ transition: none !important;
1043
+ -webkit-transition: none !important;
1044
+ -moz-transition: none !important;
1045
+ -ms-transition: none !important;
1046
+ -o-transition: none !important;
1047
+ }
1048
+
1049
+ #content-container {
1050
+ display: flex;
1051
+ }
1052
+
1053
+ .collapser {
1054
+ display: inline-block;
1055
+ }
1056
+
1057
+ .collapser svg {
1058
+ width: 10px;
1059
+ height: 10px;
1060
+ transition: transform 0.2s ease-out;
1061
+ }
1062
+
1063
+ .collapser.open svg {
1064
+ transform: rotate(90deg);
1065
+ }
1066
+
1067
+ #mobile-filter-collapse h1 {
1068
+ cursor: pointer;
1069
+ }
1070
+
1071
+ #content-container.mobile {
1072
+ display: block;
1073
+ }
1074
+
1075
+ .column {
1076
+ padding-top: 2rem;
1077
+ }
1078
+
1079
+ #right-column {
1080
+ flex: 1;
1081
+ position: relative;
1082
+ border-left: 1px solid rgb(232, 232, 232);
1083
+ padding-left: 1rem;
1084
+ }
1085
+
1086
+ .mobile #right-column {
1087
+ border-left: none;
1088
+ padding: 0;
1089
+ }
1090
+
1091
+ #left-column {
1092
+ width: 18rem;
1093
+ min-width: 18rem; /* Prevents Safari from shrinking col at first draw */
1094
+ padding-right: 12px;
1095
+ padding-right: 1rem;
1096
+ }
1097
+
1098
+ .desktop #left-column::-webkit-scrollbar {
1099
+ display: none;
1100
+ }
1101
+
1102
+ .mobile #left-column {
1103
+ width: 100%;
1104
+ padding: 0;
1105
+ }
1106
+
1107
+ .desktop #left-column {
1108
+ top: 0;
1109
+ position: sticky;
1110
+ max-height: 100vh;
1111
+ overflow: scroll;
1112
+ -ms-overflow-style: none; /* hide scrollbar IE and Edge */
1113
+ scrollbar-width: none; /* hide scrollbar Firefox */
1114
+ }
1115
+
1116
+ #mobile-header-container {
1117
+ display: flex;
1118
+ justify-content: space-between;
1119
+ }
1120
+
1121
+ #facets-container {
1122
+ position: relative;
1123
+ max-height: 0;
1124
+ transition: max-height 0.2s ease-in-out;
1125
+ z-index: 1;
1126
+ padding-bottom: 2rem;
1127
+ }
1128
+
1129
+ .mobile #facets-container {
1130
+ overflow: hidden;
1131
+ padding-bottom: 0;
1132
+ }
1133
+
1134
+ #facets-container.expanded {
1135
+ max-height: 2000px;
1136
+ }
1137
+
1138
+ #results-total {
1139
+ display: flex;
1140
+ align-items: center;
1141
+ margin-bottom: 5rem;
1142
+ }
1143
+
1144
+ .mobile #results-total {
1145
+ margin-bottom: 0;
1146
+ }
1147
+
1148
+ #big-results-count {
1149
+ font-size: 2.4rem;
1150
+ font-weight: 500;
1151
+ margin-right: 5px;
1152
+ }
1153
+
1154
+ #big-results-label {
1155
+ font-size: 1rem;
1156
+ font-weight: 200;
1157
+ text-transform: uppercase;
1158
+ }
1159
+
1160
+ #list-header {
1161
+ max-height: 4.2rem;
1162
+ }
1163
+
1164
+ .loading-cover {
1165
+ position: absolute;
1166
+ top: 0;
1167
+ left: 0;
1168
+ width: 100%;
1169
+ height: 100%;
1170
+ display: flex;
1171
+ justify-content: center;
1172
+ z-index: 1;
1173
+ padding-top: 50px;
1174
+ }
1175
+
1176
+ circular-activity-indicator {
1177
+ width: 30px;
1178
+ height: 30px;
1179
+ }
1180
+
1181
+ sort-filter-bar {
1182
+ display: block;
1183
+ margin-bottom: 4rem;
1184
+ }
1185
+
1186
+ infinite-scroller {
1187
+ display: block;
1188
+ --infiniteScrollerRowGap: var(--collectionBrowserRowGap, 1.7rem);
1189
+ --infiniteScrollerColGap: var(--collectionBrowserColGap, 1.7rem);
1190
+ }
1191
+
1192
+ infinite-scroller.list-compact {
1193
+ --infiniteScrollerCellMinWidth: var(
1194
+ --collectionBrowserCellMinWidth,
1195
+ 100%
1196
+ );
1197
+ --infiniteScrollerCellMinHeight: 34px; /* override infinite scroller component */
1198
+ --infiniteScrollerCellMaxHeight: 56px;
1199
+ --infiniteScrollerRowGap: 0px;
1200
+ }
1201
+
1202
+ infinite-scroller.list-detail {
1203
+ --infiniteScrollerCellMinWidth: var(
1204
+ --collectionBrowserCellMinWidth,
1205
+ 100%
1206
+ );
1207
+ --infiniteScrollerCellMinHeight: var(
1208
+ --collectionBrowserCellMinHeight,
1209
+ 5rem
1210
+ );
1211
+ /*
1212
+ 30px in spec, compensating for a -4px margin
1213
+ to align title with top of item image
1214
+ src/tiles/list/tile-list.ts
1215
+ */
1216
+ --infiniteScrollerRowGap: 34px;
1217
+ }
1218
+
1219
+ .mobile infinite-scroller.list-detail {
1220
+ --infiniteScrollerRowGap: 24px;
1221
+ }
1222
+
1223
+ infinite-scroller.grid {
1224
+ --infiniteScrollerCellMinWidth: var(
1225
+ --collectionBrowserCellMinWidth,
1226
+ 18rem
1227
+ );
1228
+ --infiniteScrollerCellMaxWidth: var(--collectionBrowserCellMaxWidth, 1fr);
1229
+ --infiniteScrollerCellMinHeight: var(
1230
+ --collectionBrowserCellMinHeight,
1231
+ 29rem
1232
+ );
1233
+ --infiniteScrollerCellMaxHeight: var(
1234
+ --collectionBrowserCellMaxHeight,
1235
+ 29rem
1236
+ );
1237
+ }
1238
+ `;
1239
+ __decorate([
1240
+ property({ type: String })
1241
+ ], CollectionBrowser.prototype, "baseNavigationUrl", void 0);
1242
+ __decorate([
1243
+ property({ type: String })
1244
+ ], CollectionBrowser.prototype, "baseImageUrl", void 0);
1245
+ __decorate([
1246
+ property({ type: Object })
1247
+ ], CollectionBrowser.prototype, "searchService", void 0);
1248
+ __decorate([
1249
+ property({ type: String })
1250
+ ], CollectionBrowser.prototype, "searchType", void 0);
1251
+ __decorate([
1252
+ property({ type: String })
1253
+ ], CollectionBrowser.prototype, "baseQuery", void 0);
1254
+ __decorate([
1255
+ property({ type: String })
1256
+ ], CollectionBrowser.prototype, "displayMode", void 0);
1257
+ __decorate([
1258
+ property({ type: Object })
1259
+ ], CollectionBrowser.prototype, "sortParam", void 0);
1260
+ __decorate([
1261
+ property({ type: String })
1262
+ ], CollectionBrowser.prototype, "selectedSort", void 0);
1263
+ __decorate([
1264
+ property({ type: String })
1265
+ ], CollectionBrowser.prototype, "selectedTitleFilter", void 0);
1266
+ __decorate([
1267
+ property({ type: String })
1268
+ ], CollectionBrowser.prototype, "selectedCreatorFilter", void 0);
1269
+ __decorate([
1270
+ property({ type: String })
1271
+ ], CollectionBrowser.prototype, "sortDirection", void 0);
1272
+ __decorate([
1273
+ property({ type: String })
1274
+ ], CollectionBrowser.prototype, "dateRangeQueryClause", void 0);
1275
+ __decorate([
1276
+ property({ type: Number })
1277
+ ], CollectionBrowser.prototype, "pageSize", void 0);
1278
+ __decorate([
1279
+ property({ type: Object })
1280
+ ], CollectionBrowser.prototype, "resizeObserver", void 0);
1281
+ __decorate([
1282
+ property({ type: String })
1283
+ ], CollectionBrowser.prototype, "titleQuery", void 0);
1284
+ __decorate([
1285
+ property({ type: String })
1286
+ ], CollectionBrowser.prototype, "creatorQuery", void 0);
1287
+ __decorate([
1288
+ property({ type: Number })
1289
+ ], CollectionBrowser.prototype, "currentPage", void 0);
1290
+ __decorate([
1291
+ property({ type: String })
1292
+ ], CollectionBrowser.prototype, "minSelectedDate", void 0);
1293
+ __decorate([
1294
+ property({ type: String })
1295
+ ], CollectionBrowser.prototype, "maxSelectedDate", void 0);
1296
+ __decorate([
1297
+ property({ type: Object })
1298
+ ], CollectionBrowser.prototype, "selectedFacets", void 0);
1299
+ __decorate([
1300
+ property({ type: Boolean })
1301
+ ], CollectionBrowser.prototype, "showHistogramDatePicker", void 0);
1302
+ __decorate([
1303
+ property({ type: String, reflect: true })
1304
+ ], CollectionBrowser.prototype, "searchContext", void 0);
1305
+ __decorate([
1306
+ property({ type: Object })
1307
+ ], CollectionBrowser.prototype, "collectionNameCache", void 0);
1308
+ __decorate([
1309
+ property({ type: String })
1310
+ ], CollectionBrowser.prototype, "pageContext", void 0);
1311
+ __decorate([
1312
+ property({ type: Object })
1313
+ ], CollectionBrowser.prototype, "restorationStateHandler", void 0);
1314
+ __decorate([
1315
+ property({ type: Number })
1316
+ ], CollectionBrowser.prototype, "mobileBreakpoint", void 0);
1317
+ __decorate([
1318
+ property({ type: Boolean })
1319
+ ], CollectionBrowser.prototype, "loggedIn", void 0);
1320
+ __decorate([
1321
+ property({ type: Object })
1322
+ ], CollectionBrowser.prototype, "modalManager", void 0);
1323
+ __decorate([
1324
+ property({ type: Boolean })
1325
+ ], CollectionBrowser.prototype, "isManageView", void 0);
1326
+ __decorate([
1327
+ state()
1328
+ ], CollectionBrowser.prototype, "pagesToRender", void 0);
1329
+ __decorate([
1330
+ state()
1331
+ ], CollectionBrowser.prototype, "searchResultsLoading", void 0);
1332
+ __decorate([
1333
+ state()
1334
+ ], CollectionBrowser.prototype, "facetsLoading", void 0);
1335
+ __decorate([
1336
+ state()
1337
+ ], CollectionBrowser.prototype, "fullYearAggregationLoading", void 0);
1338
+ __decorate([
1339
+ state()
1340
+ ], CollectionBrowser.prototype, "aggregations", void 0);
1341
+ __decorate([
1342
+ state()
1343
+ ], CollectionBrowser.prototype, "fullYearsHistogramAggregation", void 0);
1344
+ __decorate([
1345
+ state()
1346
+ ], CollectionBrowser.prototype, "totalResults", void 0);
1347
+ __decorate([
1348
+ state()
1349
+ ], CollectionBrowser.prototype, "mobileView", void 0);
1350
+ __decorate([
1351
+ state()
1352
+ ], CollectionBrowser.prototype, "mobileFacetsVisible", void 0);
1353
+ __decorate([
1354
+ state()
1355
+ ], CollectionBrowser.prototype, "placeholderType", void 0);
1356
+ __decorate([
1357
+ query('#content-container')
1358
+ ], CollectionBrowser.prototype, "contentContainer", void 0);
1359
+ __decorate([
1360
+ property({ type: Object, attribute: false })
1361
+ ], CollectionBrowser.prototype, "analyticsHandler", void 0);
1362
+ __decorate([
1363
+ query('infinite-scroller')
1364
+ ], CollectionBrowser.prototype, "infiniteScroller", void 0);
1365
+ CollectionBrowser = __decorate([
1366
+ customElement('collection-browser')
1367
+ ], CollectionBrowser);
1368
+ export { CollectionBrowser };
1368
1369
  //# sourceMappingURL=collection-browser.js.map