@internetarchive/collection-browser 0.2.10 → 0.2.11

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