@internetarchive/collection-browser 0.3.2 → 0.3.3-alpha.2

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