@internetarchive/collection-browser 0.2.12 → 0.2.14

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