@internetarchive/collection-browser 4.2.0-alpha-webdev8164.2 → 4.2.0

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 (84) hide show
  1. package/.claude/settings.local.json +11 -0
  2. package/.editorconfig +29 -29
  3. package/.github/workflows/ci.yml +27 -27
  4. package/.github/workflows/gh-pages-main.yml +39 -39
  5. package/.github/workflows/npm-publish.yml +39 -39
  6. package/.github/workflows/pr-preview.yml +38 -38
  7. package/.husky/pre-commit +1 -1
  8. package/.prettierignore +1 -1
  9. package/LICENSE +661 -661
  10. package/README.md +83 -83
  11. package/dist/src/app-root.js +4 -0
  12. package/dist/src/app-root.js.map +1 -1
  13. package/dist/src/collection-browser.js +32 -27
  14. package/dist/src/collection-browser.js.map +1 -1
  15. package/dist/src/collection-facets/facets-template.js +0 -5
  16. package/dist/src/collection-facets/facets-template.js.map +1 -1
  17. package/dist/src/collection-facets/more-facets-content.d.ts +8 -102
  18. package/dist/src/collection-facets/more-facets-content.js +102 -610
  19. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  20. package/dist/src/collection-facets/more-facets-pagination.d.ts +3 -12
  21. package/dist/src/collection-facets/more-facets-pagination.js +9 -71
  22. package/dist/src/collection-facets/more-facets-pagination.js.map +1 -1
  23. package/dist/src/collection-facets/toggle-switch.js +0 -1
  24. package/dist/src/collection-facets/toggle-switch.js.map +1 -1
  25. package/dist/src/collection-facets.js +9 -10
  26. package/dist/src/collection-facets.js.map +1 -1
  27. package/dist/src/data-source/collection-browser-data-source.js +3 -2
  28. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  29. package/dist/src/mediatype/mediatype-config.js +1 -1
  30. package/dist/src/mediatype/mediatype-config.js.map +1 -1
  31. package/dist/src/models.d.ts +12 -2
  32. package/dist/src/models.js +13 -8
  33. package/dist/src/models.js.map +1 -1
  34. package/dist/src/restoration-state-handler.js +9 -3
  35. package/dist/src/restoration-state-handler.js.map +1 -1
  36. package/dist/src/tiles/hover/hover-pane-controller.js +2 -1
  37. package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -1
  38. package/dist/src/tiles/tile-dispatcher.d.ts +6 -0
  39. package/dist/src/tiles/tile-dispatcher.js +11 -3
  40. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  41. package/dist/test/collection-browser.test.js +72 -0
  42. package/dist/test/collection-browser.test.js.map +1 -1
  43. package/dist/test/collection-facets/more-facets-content.test.js +3 -212
  44. package/dist/test/collection-facets/more-facets-content.test.js.map +1 -1
  45. package/dist/test/collection-facets/more-facets-pagination.test.js +3 -63
  46. package/dist/test/collection-facets/more-facets-pagination.test.js.map +1 -1
  47. package/dist/test/mocks/mock-search-responses.d.ts +0 -5
  48. package/dist/test/mocks/mock-search-responses.js +0 -44
  49. package/dist/test/mocks/mock-search-responses.js.map +1 -1
  50. package/dist/test/mocks/mock-search-service.js +1 -2
  51. package/dist/test/mocks/mock-search-service.js.map +1 -1
  52. package/dist/test/tiles/tile-dispatcher.test.js +14 -0
  53. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  54. package/dist/test/tiles/tile-mediatype-icon.test.js +4 -4
  55. package/dist/test/tiles/tile-mediatype-icon.test.js.map +1 -1
  56. package/eslint.config.mjs +53 -53
  57. package/index.html +24 -24
  58. package/local.archive.org.cert +86 -86
  59. package/local.archive.org.key +27 -27
  60. package/package.json +120 -121
  61. package/renovate.json +6 -6
  62. package/src/app-root.ts +4 -0
  63. package/src/collection-browser.ts +43 -36
  64. package/src/collection-facets/facets-template.ts +0 -5
  65. package/src/collection-facets/more-facets-content.ts +113 -664
  66. package/src/collection-facets/more-facets-pagination.ts +10 -84
  67. package/src/collection-facets/toggle-switch.ts +0 -1
  68. package/src/collection-facets.ts +13 -10
  69. package/src/data-source/collection-browser-data-source.ts +3 -2
  70. package/src/mediatype/mediatype-config.ts +1 -1
  71. package/src/models.ts +30 -8
  72. package/src/restoration-state-handler.ts +7 -3
  73. package/src/tiles/hover/hover-pane-controller.ts +2 -1
  74. package/src/tiles/tile-dispatcher.ts +12 -3
  75. package/test/collection-browser.test.ts +105 -0
  76. package/test/collection-facets/more-facets-content.test.ts +4 -326
  77. package/test/collection-facets/more-facets-pagination.test.ts +3 -87
  78. package/test/mocks/mock-search-responses.ts +0 -48
  79. package/test/mocks/mock-search-service.ts +0 -2
  80. package/test/tiles/tile-dispatcher.test.ts +17 -0
  81. package/test/tiles/tile-mediatype-icon.test.ts +4 -4
  82. package/tsconfig.json +25 -25
  83. package/web-dev-server.config.mjs +30 -30
  84. package/web-test-runner.config.mjs +52 -52
@@ -1,27 +1,17 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { css, html, LitElement, nothing, } from 'lit';
3
- import { customElement, property, query, state } from 'lit/decorators.js';
4
- import { classMap } from 'lit/directives/class-map.js';
5
- import { when } from 'lit/directives/when.js';
3
+ import { customElement, property, state } from 'lit/decorators.js';
6
4
  import { SearchType, AggregationSortType, } from '@internetarchive/search-service';
7
5
  import { msg } from '@lit/localize';
8
6
  import { facetTitles, suppressedCollections, valueFacetSort, defaultFacetSort, getDefaultSelectedFacets, tvMoreFacetSort, } from '../models';
9
7
  import '@internetarchive/elements/ia-status-indicator/ia-status-indicator';
8
+ import './more-facets-pagination';
10
9
  import './facets-template';
11
10
  import { analyticsActions, analyticsCategories, } from '../utils/analytics-events';
12
11
  import './toggle-switch';
13
- import './more-facets-pagination';
14
- import '@internetarchive/ia-clearable-text-input';
15
- import arrowLeftIcon from '../assets/img/icons/arrow-left';
16
- import arrowRightIcon from '../assets/img/icons/arrow-right';
17
12
  import { srOnlyStyle } from '../styles/sr-only';
18
13
  import { mergeSelectedFacets, sortBucketsBySelectionState, updateSelectedFacetBucket, } from '../utils/facet-utils';
19
14
  import { MORE_FACETS__DEFAULT_PAGE_SIZE, MORE_FACETS__MAX_AGGREGATIONS, } from './models';
20
- /**
21
- * Threshold for switching from horizontal scroll to pagination.
22
- * If facet count >= this value, use pagination. Otherwise use horizontal scroll.
23
- */
24
- const PAGINATION_THRESHOLD = 1000;
25
15
  let MoreFacetsContent = class MoreFacetsContent extends LitElement {
26
16
  constructor() {
27
17
  super(...arguments);
@@ -44,36 +34,9 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
44
34
  */
45
35
  this.unappliedFacetChanges = getDefaultSelectedFacets();
46
36
  /**
47
- * Text entered by the user to filter facet buckets.
48
- * Applied to bucket.key for case-insensitive matching.
49
- */
50
- this.filterText = '';
51
- /**
52
- * Current page number for pagination (when facet count >= PAGINATION_THRESHOLD).
37
+ * Which page of facets we are showing.
53
38
  */
54
39
  this.pageNumber = 1;
55
- /**
56
- * Whether the component is narrow enough to warrant compact pagination.
57
- * Updated via a ResizeObserver-based container query approach.
58
- */
59
- this.isCompactView = false;
60
- /**
61
- * Whether the horizontal scroll is at the leftmost position.
62
- */
63
- this.atScrollStart = true;
64
- /**
65
- * Whether the horizontal scroll is at the rightmost position.
66
- */
67
- this.atScrollEnd = true;
68
- this.scrollHandler = () => this.updateScrollState();
69
- this.scrollListenerAttached = false;
70
- /**
71
- * Close more facets modal on Escape click
72
- */
73
- this.escapeHandler = (e) => {
74
- if (e.key === 'Escape')
75
- this.modalManager?.closeModal();
76
- };
77
40
  }
78
41
  willUpdate(changed) {
79
42
  if (changed.has('aggregations') ||
@@ -85,12 +48,6 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
85
48
  // store it for reuse across pages.
86
49
  this.facetGroup = this.mergedFacets;
87
50
  }
88
- // Reset to page 1 when filter text changes (only matters for pagination mode)
89
- if (changed.has('filterText')) {
90
- this.pageNumber = 1;
91
- }
92
- }
93
- updated(changed) {
94
51
  // If any of the search properties change, it triggers a facet fetch
95
52
  if (changed.has('facetKey') ||
96
53
  changed.has('query') ||
@@ -104,177 +61,23 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
104
61
  : defaultFacetSort[this.facetKey];
105
62
  this.updateSpecificFacets();
106
63
  }
107
- // Reset horizontal scroll when filter text changes (e.g., switching from
108
- // horizontal-scroll mode back to pagination mode)
109
- if (changed.has('filterText')) {
110
- const facetsContent = this.shadowRoot?.querySelector('.facets-content');
111
- if (facetsContent) {
112
- facetsContent.scrollLeft = 0;
113
- }
114
- }
115
- // Manage scroll listener for horizontal scroll mode arrows.
116
- // Only re-evaluate when properties that affect the displayed content change.
117
- if (changed.has('filterText') ||
118
- changed.has('aggregations') ||
119
- changed.has('facetKey') ||
120
- changed.has('sortedBy') ||
121
- changed.has('selectedFacets') ||
122
- changed.has('unappliedFacetChanges')) {
123
- if (!this.usePagination) {
124
- this.attachScrollListener();
125
- // Refresh scroll state whenever content may have changed (e.g., filtering)
126
- requestAnimationFrame(() => this.updateScrollState());
127
- }
128
- else {
129
- this.removeScrollListener();
130
- }
131
- }
132
64
  }
133
65
  firstUpdated() {
134
66
  this.setupEscapeListeners();
135
- this.setupCompactViewObserver();
136
- this.constrainToScrollContainer();
137
- }
138
- disconnectedCallback() {
139
- super.disconnectedCallback();
140
- this.resizeObserver?.disconnect();
141
- this.removeScrollListener();
142
- document.removeEventListener('keydown', this.escapeHandler);
143
- }
144
- /**
145
- * Attaches a scroll event listener to the facets content element
146
- * to track horizontal scroll position for arrow button states.
147
- */
148
- attachScrollListener() {
149
- if (this.scrollListenerAttached || !this.facetsContentEl)
150
- return;
151
- this.scrollListenerTarget = this.facetsContentEl;
152
- this.scrollListenerTarget.addEventListener('scroll', this.scrollHandler, {
153
- passive: true,
154
- });
155
- this.scrollListenerAttached = true;
156
- // Defer initial state check until after browser layout, so scrollWidth
157
- // reflects the actual content dimensions.
158
- requestAnimationFrame(() => this.updateScrollState());
159
- }
160
- removeScrollListener() {
161
- if (!this.scrollListenerAttached || !this.scrollListenerTarget)
162
- return;
163
- this.scrollListenerTarget.removeEventListener('scroll', this.scrollHandler);
164
- this.scrollListenerTarget = undefined;
165
- this.scrollListenerAttached = false;
166
67
  }
167
68
  /**
168
- * Updates the scroll arrow disabled states based on current scroll position.
69
+ * Close more facets modal on Escape click
169
70
  */
170
- updateScrollState() {
171
- const el = this.facetsContentEl;
172
- if (!el)
173
- return;
174
- this.atScrollStart = el.scrollLeft <= 0;
175
- this.atScrollEnd = el.scrollLeft + el.clientWidth >= el.scrollWidth - 1;
176
- }
177
- /**
178
- * Calculates the width of one column step (column width + gap) based on
179
- * the CSS multi-column layout of the scroll container.
180
- */
181
- getColumnStep() {
182
- const el = this.facetsContentEl;
183
- if (!el)
184
- return 0;
185
- const facetRows = el.querySelector('.facet-rows');
186
- const styles = facetRows
187
- ? getComputedStyle(facetRows)
188
- : getComputedStyle(el);
189
- const columnCount = parseInt(styles.columnCount, 10) || 3;
190
- const columnGap = parseInt(styles.columnGap, 10) || 15;
191
- // Column width = (visible width - total gaps) / column count
192
- // Column step = column width + gap = (visible width + gap) / column count
193
- return (el.clientWidth + columnGap) / columnCount;
194
- }
195
- /**
196
- * Snaps a scroll target to the nearest column boundary.
197
- */
198
- snapToColumn(target) {
199
- const step = this.getColumnStep();
200
- if (step <= 0)
201
- return target;
202
- return Math.round(target / step) * step;
203
- }
204
- /**
205
- * Scrolls the facet content left by approximately one page, snapping to
206
- * the nearest column boundary.
207
- */
208
- onScrollLeft() {
209
- const el = this.facetsContentEl;
210
- if (!el)
211
- return;
212
- const rawTarget = el.scrollLeft - el.clientWidth;
213
- const snapped = Math.max(0, this.snapToColumn(rawTarget));
214
- el.scrollTo({ left: snapped, behavior: 'smooth' });
215
- }
216
- /**
217
- * Scrolls the facet content right by approximately one page, snapping to
218
- * the nearest column boundary.
219
- */
220
- onScrollRight() {
221
- const el = this.facetsContentEl;
222
- if (!el)
223
- return;
224
- const maxScroll = el.scrollWidth - el.clientWidth;
225
- const rawTarget = el.scrollLeft + el.clientWidth;
226
- const snapped = Math.min(maxScroll, this.snapToColumn(rawTarget));
227
- el.scrollTo({ left: snapped, behavior: 'smooth' });
228
- }
229
- /**
230
- * Sets up a ResizeObserver to toggle compact pagination based on component width.
231
- */
232
- setupCompactViewObserver() {
233
- this.resizeObserver = new ResizeObserver(entries => {
234
- for (const entry of entries) {
235
- const compact = entry.contentRect.width <= 560;
236
- if (this.isCompactView !== compact)
237
- this.isCompactView = compact;
238
- }
239
- });
240
- this.resizeObserver.observe(this);
241
- }
242
- /**
243
- * Constrains the section's max-height to fit within the nearest
244
- * scroll-container ancestor (e.g., the modal's content area).
245
- * This is a safety net for cases where the CSS max-height calculation
246
- * doesn't perfectly match the container's available space.
247
- */
248
- constrainToScrollContainer() {
249
- requestAnimationFrame(() => {
250
- const section = this.shadowRoot?.querySelector('section#more-facets');
251
- if (!section)
252
- return;
253
- // Walk up from the assigned slot to find the nearest overflow container
254
- let el = this.assignedSlot?.parentElement;
255
- while (el) {
256
- const cs = getComputedStyle(el);
257
- if (cs.overflowY === 'auto' ||
258
- cs.overflowY === 'scroll' ||
259
- cs.overflowY === 'hidden') {
260
- const containerBottom = el.getBoundingClientRect().bottom;
261
- const sectionTop = section.getBoundingClientRect().top;
262
- const available = containerBottom - sectionTop;
263
- // Compare against the CSS max-height rather than actual height,
264
- // since content may not have loaded yet at firstUpdated time
265
- const computedMax = parseFloat(getComputedStyle(section).maxHeight);
266
- if (available > 0 && available < computedMax) {
267
- section.style.maxHeight = `${available}px`;
268
- }
269
- return;
270
- }
271
- el = el.parentElement;
272
- }
273
- });
274
- }
275
71
  setupEscapeListeners() {
276
72
  if (this.modalManager) {
277
- document.addEventListener('keydown', this.escapeHandler);
73
+ document.addEventListener('keydown', (e) => {
74
+ if (e.key === 'Escape') {
75
+ this.modalManager?.closeModal();
76
+ }
77
+ });
78
+ }
79
+ else {
80
+ document.removeEventListener('keydown', () => { });
278
81
  }
279
82
  }
280
83
  /**
@@ -309,19 +112,29 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
309
112
  aggregationsSize,
310
113
  rows: 0, // todo - do we want server-side pagination with offset/page/limit flag?
311
114
  };
312
- try {
313
- const results = await this.searchService?.search(params, this.searchType);
314
- this.aggregations = results?.success?.response.aggregations;
315
- const collectionTitles = results?.success?.response?.collectionTitles;
316
- if (collectionTitles) {
317
- for (const [id, title] of Object.entries(collectionTitles)) {
318
- this.collectionTitles?.set(id, title);
319
- }
115
+ const results = await this.searchService?.search(params, this.searchType);
116
+ this.aggregations = results?.success?.response.aggregations;
117
+ this.facetsLoading = false;
118
+ const collectionTitles = results?.success?.response?.collectionTitles;
119
+ if (collectionTitles) {
120
+ for (const [id, title] of Object.entries(collectionTitles)) {
121
+ this.collectionTitles?.set(id, title);
320
122
  }
321
123
  }
322
- finally {
323
- this.facetsLoading = false;
124
+ }
125
+ /**
126
+ * Handler for page number changes from the pagination widget.
127
+ */
128
+ pageNumberClicked(e) {
129
+ const page = e?.detail?.page;
130
+ if (page) {
131
+ this.pageNumber = Number(page);
324
132
  }
133
+ this.analyticsHandler?.sendEvent({
134
+ category: analyticsCategories.default,
135
+ action: analyticsActions.moreFacetsPageChange,
136
+ label: `${this.pageNumber}`,
137
+ });
325
138
  }
326
139
  /**
327
140
  * Combines the selected facets with the aggregations to create a single list of facets
@@ -389,9 +202,7 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
389
202
  return undefined;
390
203
  const facetGroupTitle = facetTitles[this.facetKey];
391
204
  const buckets = Object.entries(selectedFacetsForKey).map(([value, data]) => {
392
- const displayText = (this.facetKey === 'collection'
393
- ? this.collectionTitles?.get(value)
394
- : undefined) ?? value;
205
+ const displayText = value;
395
206
  return {
396
207
  displayText,
397
208
  key: value,
@@ -425,26 +236,16 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
425
236
  return (!suppressedCollections[bucketKey] && !bucketKey?.startsWith('fav-'));
426
237
  });
427
238
  }
428
- // Construct the array of facet buckets from the aggregation buckets,
429
- // using collection display titles where available.
239
+ // Construct the array of facet buckets from the aggregation buckets
430
240
  const facetBuckets = sortedBuckets.map(bucket => {
431
241
  const bucketKeyStr = `${bucket.key}`;
432
- const displayText = (this.facetKey === 'collection'
433
- ? this.collectionTitles?.get(bucketKeyStr)
434
- : undefined) ?? bucketKeyStr;
435
242
  return {
436
- displayText,
243
+ displayText: `${bucketKeyStr}`,
437
244
  key: `${bucketKeyStr}`,
438
245
  count: bucket.doc_count,
439
246
  state: 'none',
440
247
  };
441
248
  });
442
- // For collection facets sorted alphabetically, re-sort by display title
443
- // instead of the raw identifier used by getSortedBuckets.
444
- if (this.facetKey === 'collection' &&
445
- this.sortedBy === AggregationSortType.ALPHABETICAL) {
446
- facetBuckets.sort((a, b) => (a.displayText ?? a.key).localeCompare(b.displayText ?? b.key));
447
- }
448
249
  return {
449
250
  title: facetGroupTitle,
450
251
  key: this.facetKey,
@@ -452,70 +253,24 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
452
253
  };
453
254
  }
454
255
  /**
455
- * Returns the facet group with buckets filtered by the current filter text.
456
- * Filters are applied to the full bucket list before pagination.
256
+ * Returns a FacetGroup representing only the current page of facet buckets to show.
457
257
  */
458
- get filteredFacetGroup() {
459
- const { facetGroup, filterText } = this;
258
+ get facetGroupForCurrentPage() {
259
+ const { facetGroup } = this;
460
260
  if (!facetGroup)
461
261
  return undefined;
462
- // If no filter text, return the full group
463
- if (!filterText.trim()) {
464
- return facetGroup;
465
- }
466
- // Filter buckets by the text the user actually sees.
467
- // For collections, match against the displayed collection title (not the identifier).
468
- // For other facet types, match against the bucket key (which is also the display text).
469
- const lowerFilter = filterText.toLowerCase().trim();
470
- const filteredBuckets = facetGroup.buckets.filter(bucket => {
471
- const displayText = this.collectionTitles?.get(bucket.key) ?? bucket.key;
472
- return displayText.toLowerCase().includes(lowerFilter);
473
- });
262
+ // Slice out only the current page of facet buckets
263
+ const firstBucketIndexOnPage = (this.pageNumber - 1) * this.facetsPerPage;
264
+ const truncatedBuckets = facetGroup.buckets.slice(firstBucketIndexOnPage, firstBucketIndexOnPage + this.facetsPerPage);
474
265
  return {
475
266
  ...facetGroup,
476
- buckets: filteredBuckets,
477
- };
478
- }
479
- /**
480
- * Determines whether to use pagination based on the number of filtered facets.
481
- * Returns true if facet count >= PAGINATION_THRESHOLD, false otherwise.
482
- */
483
- get usePagination() {
484
- const facetCount = this.filteredFacetGroup?.buckets.length ?? 0;
485
- return facetCount >= PAGINATION_THRESHOLD;
486
- }
487
- /**
488
- * Returns the facet group for the current page.
489
- * If using pagination (>= 1000 facets), slices to show only the current page.
490
- * Otherwise, returns all facets for horizontal scrolling.
491
- */
492
- get facetGroupForCurrentPage() {
493
- const filteredGroup = this.filteredFacetGroup;
494
- if (!filteredGroup)
495
- return undefined;
496
- // If facet count is below threshold, show all facets with horizontal scroll
497
- if (!this.usePagination) {
498
- return filteredGroup;
499
- }
500
- // Otherwise, use pagination - slice to current page
501
- const startIndex = (this.pageNumber - 1) * this.facetsPerPage;
502
- const endIndex = startIndex + this.facetsPerPage;
503
- const slicedBuckets = filteredGroup.buckets.slice(startIndex, endIndex);
504
- return {
505
- ...filteredGroup,
506
- buckets: slicedBuckets,
267
+ buckets: truncatedBuckets,
507
268
  };
508
269
  }
509
270
  get moreFacetsTemplate() {
510
- const facetGroup = this.facetGroupForCurrentPage;
511
- // Show empty state if filtering returned no results
512
- if (this.filterText.trim() &&
513
- (!facetGroup || facetGroup.buckets.length === 0)) {
514
- return this.emptyFilterResultsTemplate;
515
- }
516
271
  return html `
517
272
  <facets-template
518
- .facetGroup=${facetGroup}
273
+ .facetGroup=${this.facetGroupForCurrentPage}
519
274
  .selectedFacets=${this.selectedFacets}
520
275
  .collectionTitles=${this.collectionTitles}
521
276
  @facetClick=${(e) => {
@@ -534,171 +289,83 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
534
289
  ></ia-status-indicator>
535
290
  `;
536
291
  }
537
- get emptyFilterResultsTemplate() {
538
- return html `
539
- <div class="empty-results">
540
- <p>${msg('No matching values found.')}</p>
541
- <p class="hint">${msg('Try a different search term.')}</p>
542
- </div>
543
- `;
544
- }
545
292
  /**
546
- * Number of pages for pagination (only used when facet count >= PAGINATION_THRESHOLD).
293
+ * How many pages of facets to show in the modal pagination widget
547
294
  */
548
295
  get paginationSize() {
549
- const filteredBuckets = this.filteredFacetGroup?.buckets ?? [];
550
- return Math.ceil(filteredBuckets.length / this.facetsPerPage);
296
+ if (!this.aggregations || !this.facetKey)
297
+ return 0;
298
+ // Calculate the appropriate number of pages to show in the modal pagination widget
299
+ const length = this.aggregations[this.facetKey]?.buckets.length;
300
+ return Math.ceil(length / this.facetsPerPage);
551
301
  }
552
- /**
553
- * Template for pagination component.
554
- */
302
+ // render pagination if more then 1 page
555
303
  get facetsPaginationTemplate() {
556
- return html `<more-facets-pagination
557
- .size=${this.paginationSize}
558
- .currentPage=${this.pageNumber}
559
- .compact=${this.isCompactView}
560
- @pageNumberClicked=${this.pageNumberClicked}
561
- ></more-facets-pagination>`;
304
+ return this.paginationSize > 1
305
+ ? html `<more-facets-pagination
306
+ .size=${this.paginationSize}
307
+ .currentPage=${1}
308
+ @pageNumberClicked=${this.pageNumberClicked}
309
+ ></more-facets-pagination>`
310
+ : nothing;
562
311
  }
563
312
  get footerTemplate() {
564
- return html `
565
- ${when(this.usePagination, () => this.facetsPaginationTemplate)}
566
- <div class="footer">
567
- <button class="btn btn-cancel" type="button" @click=${this.cancelClick}>
568
- Cancel
569
- </button>
570
- <button
571
- class="btn btn-submit"
572
- type="button"
573
- @click=${this.applySearchFacetsClicked}
574
- >
575
- Apply filters
576
- </button>
577
- </div>
578
- `;
313
+ if (this.paginationSize > 0) {
314
+ return html `${this.facetsPaginationTemplate}
315
+ <div class="footer">
316
+ <button
317
+ class="btn btn-cancel"
318
+ type="button"
319
+ @click=${this.cancelClick}
320
+ >
321
+ Cancel
322
+ </button>
323
+ <button
324
+ class="btn btn-submit"
325
+ type="button"
326
+ @click=${this.applySearchFacetsClicked}
327
+ >
328
+ Apply filters
329
+ </button>
330
+ </div> `;
331
+ }
332
+ return nothing;
579
333
  }
580
334
  sortFacetAggregation(facetSortType) {
581
335
  this.sortedBy = facetSortType;
582
336
  this.dispatchEvent(new CustomEvent('sortedFacets', { detail: this.sortedBy }));
583
337
  }
584
- /**
585
- * Handler for filter input changes. Updates the filter text and triggers re-render.
586
- */
587
- handleFilterInput(e) {
588
- const input = e.target;
589
- this.filterText = input.value;
590
- }
591
- /**
592
- * Handler for when the filter input is cleared via the clear button.
593
- */
594
- handleFilterClear() {
595
- this.filterText = '';
596
- }
597
- /**
598
- * Handler for pagination page number clicks.
599
- * Only used when facet count >= PAGINATION_THRESHOLD.
600
- */
601
- pageNumberClicked(e) {
602
- this.pageNumber = e.detail.page;
603
- // Track page navigation in analytics
604
- this.analyticsHandler?.sendEvent({
605
- category: analyticsCategories.default,
606
- action: analyticsActions.moreFacetsPageChange,
607
- label: `${this.pageNumber}`,
608
- });
609
- this.dispatchEvent(new CustomEvent('pageChanged', {
610
- detail: this.pageNumber,
611
- bubbles: true,
612
- composed: true,
613
- }));
614
- }
615
338
  get modalHeaderTemplate() {
616
339
  const facetSort = this.sortedBy ?? defaultFacetSort[this.facetKey];
617
340
  const defaultSwitchSide = facetSort === AggregationSortType.COUNT ? 'left' : 'right';
618
341
  return html `<span class="sr-only">${msg('More facets for:')}</span>
619
- <span class="title"> ${this.facetGroup?.title} </span>
620
- <span class="header-controls">
621
- <span class="sort-controls">
622
- <label class="sort-label">${msg('Sort by:')}</label>
623
- ${this.facetKey
342
+ <span class="title">
343
+ ${this.facetGroup?.title}
344
+
345
+ <label class="sort-label">${msg('Sort by:')}</label>
346
+ ${this.facetKey
624
347
  ? html `<toggle-switch
625
- class="sort-toggle"
626
- leftValue=${AggregationSortType.COUNT}
627
- leftLabel="Count"
628
- rightValue=${valueFacetSort[this.facetKey]}
629
- .rightLabel=${this.facetGroup?.title}
630
- side=${defaultSwitchSide}
631
- @change=${(e) => {
348
+ class="sort-toggle"
349
+ leftValue=${AggregationSortType.COUNT}
350
+ leftLabel="Count"
351
+ rightValue=${valueFacetSort[this.facetKey]}
352
+ .rightLabel=${this.facetGroup?.title}
353
+ side=${defaultSwitchSide}
354
+ @change=${(e) => {
632
355
  this.sortFacetAggregation(Number(e.detail));
633
356
  }}
634
- ></toggle-switch>`
357
+ ></toggle-switch>`
635
358
  : nothing}
636
- </span>
637
-
638
- <span class="filter-controls">
639
- <label class="filter-label">${msg('Filter by:')}</label>
640
- <ia-clearable-text-input
641
- class="filter-input"
642
- .value=${this.filterText}
643
- .placeholder=${msg('Search...')}
644
- .screenReaderLabel=${msg('Filter facets')}
645
- .clearButtonScreenReaderLabel=${msg('Clear filter')}
646
- @input=${this.handleFilterInput}
647
- @clear=${this.handleFilterClear}
648
- ></ia-clearable-text-input>
649
- </span>
650
359
  </span>`;
651
360
  }
652
- get horizontalScrollTemplate() {
653
- const contentClasses = classMap({
654
- 'facets-content': true,
655
- 'horizontal-scroll-mode': true,
656
- });
657
- const showArrows = !this.atScrollStart || !this.atScrollEnd;
658
- return html `<div class="scroll-nav-container">
659
- ${when(showArrows, () => html `<button
660
- class="scroll-arrow scroll-left"
661
- @click=${this.onScrollLeft}
662
- ?disabled=${this.atScrollStart}
663
- aria-label="Scroll facets left"
664
- >
665
- ${arrowLeftIcon}
666
- </button>`)}
667
- <div class=${contentClasses}>
668
- <div class="facets-horizontal-container">
669
- ${this.moreFacetsTemplate}
670
- </div>
671
- </div>
672
- ${when(showArrows, () => html `<button
673
- class="scroll-arrow scroll-right"
674
- @click=${this.onScrollRight}
675
- ?disabled=${this.atScrollEnd}
676
- aria-label="Scroll facets right"
677
- >
678
- ${arrowRightIcon}
679
- </button>`)}
680
- </div>`;
681
- }
682
361
  render() {
683
- const sectionClasses = classMap({
684
- 'pagination-mode': this.usePagination,
685
- 'horizontal-scroll-mode': !this.usePagination,
686
- });
687
- const contentClasses = classMap({
688
- 'facets-content': true,
689
- 'pagination-mode': this.usePagination,
690
- });
691
362
  return html `
692
363
  ${this.facetsLoading
693
364
  ? this.loaderTemplate
694
365
  : html `
695
- <section id="more-facets" class=${sectionClasses}>
366
+ <section id="more-facets">
696
367
  <div class="header-content">${this.modalHeaderTemplate}</div>
697
- ${this.usePagination
698
- ? html `<div class=${contentClasses}>
699
- ${this.moreFacetsTemplate}
700
- </div>`
701
- : this.horizontalScrollTemplate}
368
+ <div class="facets-content">${this.moreFacetsTemplate}</div>
702
369
  ${this.footerTemplate}
703
370
  </section>
704
371
  `}
@@ -714,8 +381,6 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
714
381
  this.dispatchEvent(event);
715
382
  // Reset the unapplied changes back to default, now that they have been applied
716
383
  this.unappliedFacetChanges = getDefaultSelectedFacets();
717
- // Reset filter text
718
- this.filterText = '';
719
384
  this.modalManager?.closeModal();
720
385
  this.analyticsHandler?.sendEvent({
721
386
  category: analyticsCategories.default,
@@ -726,8 +391,6 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
726
391
  cancelClick() {
727
392
  // Reset the unapplied changes back to default
728
393
  this.unappliedFacetChanges = getDefaultSelectedFacets();
729
- // Reset filter text
730
- this.filterText = '';
731
394
  this.modalManager?.closeModal();
732
395
  this.analyticsHandler?.sendEvent({
733
396
  category: analyticsCategories.default,
@@ -741,26 +404,10 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
741
404
  srOnlyStyle,
742
405
  css `
743
406
  section#more-facets {
744
- display: flex;
745
- flex-direction: column;
746
- max-height: calc(100vh - 16.5rem - var(--modalBottomMargin, 2.5rem));
747
- padding: 10px;
748
- box-sizing: border-box;
407
+ overflow: auto;
408
+ padding: 10px; /* leaves room for scroll bar to appear without overlaying on content */
749
409
  --facetsColumnCount: 3;
750
410
  }
751
-
752
- /* Both modes need a height constraint for proper column flow */
753
- section#more-facets.horizontal-scroll-mode,
754
- section#more-facets.pagination-mode {
755
- --facetsMaxHeight: 280px;
756
- }
757
- .header-content {
758
- flex-shrink: 0;
759
- position: relative;
760
- z-index: 1;
761
- background: #fff;
762
- }
763
-
764
411
  .header-content .title {
765
412
  display: block;
766
413
  text-align: left;
@@ -769,22 +416,8 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
769
416
  font-weight: bold;
770
417
  }
771
418
 
772
- .header-controls {
773
- display: flex;
774
- flex-wrap: wrap;
775
- align-items: center;
776
- gap: 8px 20px;
777
- padding: 0 10px 8px;
778
- }
779
-
780
- .sort-controls {
781
- display: inline-flex;
782
- align-items: center;
783
- white-space: nowrap;
784
- gap: 5px;
785
- }
786
-
787
419
  .sort-label {
420
+ margin-left: 20px;
788
421
  font-size: 1.3rem;
789
422
  }
790
423
 
@@ -792,115 +425,11 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
792
425
  font-weight: normal;
793
426
  }
794
427
 
795
- .filter-controls {
796
- display: inline-flex;
797
- align-items: center;
798
- white-space: nowrap;
799
- }
800
-
801
- .filter-label {
802
- font-size: 1.3rem;
803
- }
804
-
805
- .filter-input {
806
- --input-height: 2.5rem;
807
- --input-font-size: 1.3rem;
808
- --input-border-radius: 4px;
809
- --input-padding: 4px 8px;
810
- --input-focused-border-color: ${modalSubmitButton};
811
- width: 150px;
812
- margin-left: 5px;
813
- }
814
-
815
- .empty-results {
816
- text-align: center;
817
- padding: 40px 20px;
818
- color: #666;
819
- }
820
-
821
- .empty-results .hint {
822
- margin-top: 10px;
823
- }
824
-
825
428
  .facets-content {
826
429
  font-size: 1.2rem;
827
- flex: 1 1 auto;
828
- min-height: 0;
829
- overflow-y: auto;
830
- overflow-x: hidden;
430
+ max-height: 300px;
431
+ overflow: auto;
831
432
  padding: 10px;
832
- /* Force scrollbar to always be visible */
833
- scrollbar-width: thin; /* Firefox */
834
- scrollbar-color: #888 #f1f1f1; /* Firefox - thumb and track colors */
835
- }
836
-
837
- /* Horizontal scroll mode: horizontal scrolling only */
838
- .facets-content.horizontal-scroll-mode {
839
- overflow-x: auto;
840
- overflow-y: hidden;
841
- }
842
-
843
- /* Webkit browsers scrollbar styling - always visible */
844
- .facets-content::-webkit-scrollbar {
845
- width: 12px; /* Vertical scrollbar width */
846
- height: 12px; /* Horizontal scrollbar height */
847
- }
848
-
849
- .facets-content::-webkit-scrollbar-track {
850
- background: #f1f1f1;
851
- border-radius: 6px;
852
- }
853
-
854
- .facets-content::-webkit-scrollbar-thumb {
855
- background: #888;
856
- border-radius: 6px;
857
- min-height: 30px; /* Ensure thumb is always visible when scrolling is possible */
858
- }
859
-
860
- .facets-content::-webkit-scrollbar-thumb:hover {
861
- background: #555;
862
- }
863
-
864
- /* Force corner to match track color */
865
- .facets-content::-webkit-scrollbar-corner {
866
- background: #f1f1f1;
867
- }
868
-
869
- .facets-horizontal-container {
870
- display: inline-block;
871
- min-width: 100%;
872
- /* Allow natural width expansion based on content */
873
- width: fit-content;
874
- }
875
-
876
- .scroll-nav-container {
877
- display: flex;
878
- align-items: center;
879
- flex: 1 1 auto;
880
- min-height: 0;
881
- }
882
-
883
- .scroll-nav-container .facets-content {
884
- flex: 1 1 auto;
885
- min-width: 0;
886
- }
887
-
888
- .scroll-arrow {
889
- background: none;
890
- border: none;
891
- cursor: pointer;
892
- padding: 5px;
893
- flex-shrink: 0;
894
- }
895
-
896
- .scroll-arrow svg {
897
- height: 14px;
898
- fill: #2c2c2c;
899
- }
900
-
901
- .scroll-arrow:disabled {
902
- opacity: 0.3;
903
- cursor: default;
904
433
  }
905
434
  .facets-loader {
906
435
  --icon-width: 70px;
@@ -916,7 +445,6 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
916
445
  width: auto;
917
446
  border-radius: 4px;
918
447
  cursor: pointer;
919
- font-family: inherit;
920
448
  }
921
449
  .btn-cancel {
922
450
  background-color: #2c2c2c;
@@ -926,37 +454,19 @@ let MoreFacetsContent = class MoreFacetsContent extends LitElement {
926
454
  background-color: ${modalSubmitButton};
927
455
  color: white;
928
456
  }
929
- more-facets-pagination {
930
- flex-shrink: 0;
931
- }
932
-
933
457
  .footer {
934
458
  text-align: center;
935
459
  margin-top: 10px;
936
- flex-shrink: 0;
937
460
  }
938
461
 
939
462
  @media (max-width: 560px) {
940
- section#more-facets.horizontal-scroll-mode,
941
- section#more-facets.pagination-mode {
942
- --facetsColumnCount: 1; /* Single column on mobile */
943
- --facetsMaxHeight: none; /* Remove fixed height for vertical scrolling */
463
+ section#more-facets {
464
+ max-height: 450px;
465
+ --facetsColumnCount: 1;
944
466
  }
945
- /* On mobile, always use vertical scrolling regardless of mode */
946
- .facets-content,
947
- .facets-content.horizontal-scroll-mode {
467
+ .facets-content {
948
468
  overflow-y: auto;
949
- overflow-x: hidden;
950
- }
951
- .scroll-nav-container {
952
- display: contents; /* Remove wrapper from layout so section flex-column works */
953
- }
954
- .scroll-arrow {
955
- display: none;
956
- }
957
- .filter-input {
958
- width: 120px;
959
- --input-font-size: 1.2rem;
469
+ height: 300px;
960
470
  }
961
471
  }
962
472
  `,
@@ -1020,27 +530,9 @@ __decorate([
1020
530
  __decorate([
1021
531
  state()
1022
532
  ], MoreFacetsContent.prototype, "unappliedFacetChanges", void 0);
1023
- __decorate([
1024
- state()
1025
- ], MoreFacetsContent.prototype, "filterText", void 0);
1026
533
  __decorate([
1027
534
  state()
1028
535
  ], MoreFacetsContent.prototype, "pageNumber", void 0);
1029
- __decorate([
1030
- state()
1031
- ], MoreFacetsContent.prototype, "isCompactView", void 0);
1032
- __decorate([
1033
- state()
1034
- ], MoreFacetsContent.prototype, "atScrollStart", void 0);
1035
- __decorate([
1036
- state()
1037
- ], MoreFacetsContent.prototype, "atScrollEnd", void 0);
1038
- __decorate([
1039
- query('ia-clearable-text-input')
1040
- ], MoreFacetsContent.prototype, "filterInput", void 0);
1041
- __decorate([
1042
- query('.facets-content')
1043
- ], MoreFacetsContent.prototype, "facetsContentEl", void 0);
1044
536
  MoreFacetsContent = __decorate([
1045
537
  customElement('more-facets-content')
1046
538
  ], MoreFacetsContent);