@internetarchive/collection-browser 0.2.15 → 0.2.16-alpha1

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