@internetarchive/collection-browser 2.19.1-alpha-webdev7818.0 → 2.20.1-alpha-webdev7822.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 (44) hide show
  1. package/dist/src/app-root.js +606 -605
  2. package/dist/src/app-root.js.map +1 -1
  3. package/dist/src/collection-browser.d.ts +5 -0
  4. package/dist/src/collection-browser.js +36 -11
  5. package/dist/src/collection-browser.js.map +1 -1
  6. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js +75 -75
  7. package/dist/src/collection-facets/smart-facets/smart-facet-bar.js.map +1 -1
  8. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js +54 -54
  9. package/dist/src/collection-facets/smart-facets/smart-facet-dropdown.js.map +1 -1
  10. package/dist/src/collection-facets.js +263 -263
  11. package/dist/src/collection-facets.js.map +1 -1
  12. package/dist/src/expanded-date-picker.js +52 -52
  13. package/dist/src/expanded-date-picker.js.map +1 -1
  14. package/dist/src/models.d.ts +13 -0
  15. package/dist/src/models.js +41 -0
  16. package/dist/src/models.js.map +1 -1
  17. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +79 -24
  18. package/dist/src/sort-filter-bar/sort-filter-bar.js +201 -119
  19. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  20. package/dist/src/tiles/grid/item-tile.js +139 -139
  21. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  22. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +118 -118
  23. package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js.map +1 -1
  24. package/dist/src/tiles/list/tile-list.js +289 -289
  25. package/dist/src/tiles/list/tile-list.js.map +1 -1
  26. package/dist/src/tiles/tile-dispatcher.js +200 -200
  27. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  28. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +157 -11
  29. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/app-root.ts +1140 -1140
  32. package/src/collection-browser.ts +38 -10
  33. package/src/collection-facets/smart-facets/smart-facet-bar.ts +437 -437
  34. package/src/collection-facets/smart-facets/smart-facet-dropdown.ts +185 -185
  35. package/src/collection-facets.ts +990 -990
  36. package/src/expanded-date-picker.ts +191 -191
  37. package/src/models.ts +48 -0
  38. package/src/sort-filter-bar/sort-filter-bar.ts +220 -126
  39. package/src/tiles/grid/item-tile.ts +339 -339
  40. package/src/tiles/grid/styles/tile-grid-shared-styles.ts +129 -129
  41. package/src/tiles/list/tile-list.ts +688 -688
  42. package/src/tiles/tile-dispatcher.ts +486 -486
  43. package/test/sort-filter-bar/sort-filter-bar.test.ts +205 -12
  44. package/tsconfig.json +1 -1
@@ -1,191 +1,191 @@
1
- import {
2
- css,
3
- html,
4
- LitElement,
5
- CSSResultGroup,
6
- TemplateResult,
7
- nothing,
8
- } from 'lit';
9
- import { customElement, property } from 'lit/decorators.js';
10
- import { ifDefined } from 'lit/directives/if-defined.js';
11
- import { msg } from '@lit/localize';
12
- import type { ModalManagerInterface } from '@internetarchive/modal-manager';
13
- import type { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
14
- import {
15
- BarScalingOption,
16
- BinSnappingInterval,
17
- } from '@internetarchive/histogram-date-range';
18
- import {
19
- analyticsActions,
20
- analyticsCategories,
21
- } from './utils/analytics-events';
22
-
23
- import '@internetarchive/histogram-date-range';
24
-
25
- @customElement('expanded-date-picker')
26
- export class ExpandedDatePicker extends LitElement {
27
- @property({ type: String }) minDate?: string;
28
-
29
- @property({ type: String }) maxDate?: string;
30
-
31
- @property({ type: String }) minSelectedDate?: string;
32
-
33
- @property({ type: String }) maxSelectedDate?: string;
34
-
35
- @property({ type: Array }) buckets?: number[];
36
-
37
- @property({ type: String }) customDateFormat?: string;
38
-
39
- @property({ type: String }) customTooltipDateFormat?: string;
40
-
41
- @property({ type: String }) customTooltipLabel?: string;
42
-
43
- @property({ type: String }) binSnapping: BinSnappingInterval = 'none';
44
-
45
- @property({ type: String }) barScaling: BarScalingOption = 'logarithmic';
46
-
47
- @property({ type: Object, attribute: false })
48
- modalManager?: ModalManagerInterface;
49
-
50
- @property({ type: Object, attribute: false })
51
- analyticsHandler?: AnalyticsManagerInterface;
52
-
53
- render(): TemplateResult {
54
- return html`
55
- <div id="container">
56
- <histogram-date-range
57
- id="date-picker"
58
- .minDate=${this.minDate}
59
- .maxDate=${this.maxDate}
60
- .minSelectedDate=${this.minSelectedDate ?? this.minDate}
61
- .maxSelectedDate=${this.maxSelectedDate ?? this.maxDate}
62
- dateFormat=${ifDefined(this.customDateFormat)}
63
- tooltipDateFormat=${ifDefined(this.customTooltipDateFormat)}
64
- tooltipLabel=${ifDefined(this.customTooltipLabel)}
65
- .binSnapping=${this.binSnapping}
66
- .barScaling=${this.barScaling ?? nothing}
67
- .updateDelay=${0}
68
- updateWhileFocused
69
- missingDataMessage="..."
70
- .width=${560}
71
- .height=${120}
72
- .bins=${this.buckets}
73
- @histogramDateRangeUpdated=${this.histogramDateRangeUpdated}
74
- >
75
- <button
76
- id="apply-btn"
77
- slot="inputs-right-side"
78
- @click=${this.applyBtnClicked}
79
- >
80
- ${msg('Apply date range')}
81
- </button>
82
- </histogram-date-range>
83
- </div>
84
- `;
85
- }
86
-
87
- connectedCallback(): void {
88
- super.connectedCallback?.();
89
- this.setupEscapeListener();
90
- }
91
-
92
- disconnectedCallback(): void {
93
- super.disconnectedCallback?.();
94
- this.removeEscapeListener();
95
- }
96
-
97
- /**
98
- * Add an event listener to close the date picker modal when the Esc key is pressed
99
- */
100
- private setupEscapeListener() {
101
- document.addEventListener('keydown', this.boundEscapeListener);
102
- }
103
-
104
- /**
105
- * Remove the Esc key listener that was previously added
106
- */
107
- private removeEscapeListener() {
108
- document.removeEventListener('keydown', this.boundEscapeListener);
109
- }
110
-
111
- /**
112
- * Closes the modal dialog if the given event is pressing the Esc key.
113
- * Arrow function to ensure `this` remains bound to the current component.
114
- */
115
- private boundEscapeListener = (e: KeyboardEvent) => {
116
- if (e.key === 'Escape') {
117
- this.closeModal();
118
- }
119
- };
120
-
121
- /**
122
- * When the histogram is updated, keep track of the newly selected date range.
123
- * We don't commit to the new range until the apply button is clicked.
124
- */
125
- private histogramDateRangeUpdated(
126
- e: CustomEvent<{
127
- minDate: string;
128
- maxDate: string;
129
- }>,
130
- ): void {
131
- this.minSelectedDate = e.detail.minDate;
132
- this.maxSelectedDate = e.detail.maxDate;
133
- }
134
-
135
- /**
136
- * When the Apply button is clicked, emit the current date range and close the modal.
137
- */
138
- private applyBtnClicked(): void {
139
- const event = new CustomEvent('histogramDateRangeApplied', {
140
- detail: {
141
- minDate: this.minSelectedDate,
142
- maxDate: this.maxSelectedDate,
143
- },
144
- });
145
- this.dispatchEvent(event);
146
- this.closeModal();
147
-
148
- this.analyticsHandler?.sendEvent({
149
- category: analyticsCategories.default,
150
- action: analyticsActions.histogramChangedFromModal,
151
- label: window.location.href,
152
- });
153
- }
154
-
155
- /**
156
- * Closes the modal associated with this component (if it exists) and dispatches a
157
- * modalClosed event.
158
- */
159
- private closeModal(): void {
160
- if (this.modalManager) {
161
- this.modalManager.closeModal();
162
- this.dispatchEvent(new CustomEvent('modalClosed'));
163
- }
164
- }
165
-
166
- static get styles(): CSSResultGroup {
167
- return css`
168
- #container {
169
- display: flex;
170
- justify-content: center;
171
- padding: 40px 10px 10px;
172
- overflow: hidden;
173
- }
174
-
175
- #date-picker {
176
- --histogramDateRangeInputWidth: 50px;
177
- --histogramDateRangeInputRowMargin: 5px 0 0 0;
178
- }
179
-
180
- #apply-btn {
181
- margin: 0 0 0 5px;
182
- padding: 8px 10px;
183
- border: 0;
184
- border-radius: 4px;
185
- background: var(--primaryButtonBGColor, #194880);
186
- color: white;
187
- cursor: pointer;
188
- }
189
- `;
190
- }
191
- }
1
+ import {
2
+ css,
3
+ html,
4
+ LitElement,
5
+ CSSResultGroup,
6
+ TemplateResult,
7
+ nothing,
8
+ } from 'lit';
9
+ import { customElement, property } from 'lit/decorators.js';
10
+ import { ifDefined } from 'lit/directives/if-defined.js';
11
+ import { msg } from '@lit/localize';
12
+ import type { ModalManagerInterface } from '@internetarchive/modal-manager';
13
+ import type { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
14
+ import {
15
+ BarScalingOption,
16
+ BinSnappingInterval,
17
+ } from '@internetarchive/histogram-date-range';
18
+ import {
19
+ analyticsActions,
20
+ analyticsCategories,
21
+ } from './utils/analytics-events';
22
+
23
+ import '@internetarchive/histogram-date-range';
24
+
25
+ @customElement('expanded-date-picker')
26
+ export class ExpandedDatePicker extends LitElement {
27
+ @property({ type: String }) minDate?: string;
28
+
29
+ @property({ type: String }) maxDate?: string;
30
+
31
+ @property({ type: String }) minSelectedDate?: string;
32
+
33
+ @property({ type: String }) maxSelectedDate?: string;
34
+
35
+ @property({ type: Array }) buckets?: number[];
36
+
37
+ @property({ type: String }) customDateFormat?: string;
38
+
39
+ @property({ type: String }) customTooltipDateFormat?: string;
40
+
41
+ @property({ type: String }) customTooltipLabel?: string;
42
+
43
+ @property({ type: String }) binSnapping: BinSnappingInterval = 'none';
44
+
45
+ @property({ type: String }) barScaling: BarScalingOption = 'logarithmic';
46
+
47
+ @property({ type: Object, attribute: false })
48
+ modalManager?: ModalManagerInterface;
49
+
50
+ @property({ type: Object, attribute: false })
51
+ analyticsHandler?: AnalyticsManagerInterface;
52
+
53
+ render(): TemplateResult {
54
+ return html`
55
+ <div id="container">
56
+ <histogram-date-range
57
+ id="date-picker"
58
+ .minDate=${this.minDate}
59
+ .maxDate=${this.maxDate}
60
+ .minSelectedDate=${this.minSelectedDate ?? this.minDate}
61
+ .maxSelectedDate=${this.maxSelectedDate ?? this.maxDate}
62
+ dateFormat=${ifDefined(this.customDateFormat)}
63
+ tooltipDateFormat=${ifDefined(this.customTooltipDateFormat)}
64
+ tooltipLabel=${ifDefined(this.customTooltipLabel)}
65
+ .binSnapping=${this.binSnapping}
66
+ .barScaling=${this.barScaling ?? nothing}
67
+ .updateDelay=${0}
68
+ updateWhileFocused
69
+ missingDataMessage="..."
70
+ .width=${560}
71
+ .height=${120}
72
+ .bins=${this.buckets}
73
+ @histogramDateRangeUpdated=${this.histogramDateRangeUpdated}
74
+ >
75
+ <button
76
+ id="apply-btn"
77
+ slot="inputs-right-side"
78
+ @click=${this.applyBtnClicked}
79
+ >
80
+ ${msg('Apply date range')}
81
+ </button>
82
+ </histogram-date-range>
83
+ </div>
84
+ `;
85
+ }
86
+
87
+ connectedCallback(): void {
88
+ super.connectedCallback?.();
89
+ this.setupEscapeListener();
90
+ }
91
+
92
+ disconnectedCallback(): void {
93
+ super.disconnectedCallback?.();
94
+ this.removeEscapeListener();
95
+ }
96
+
97
+ /**
98
+ * Add an event listener to close the date picker modal when the Esc key is pressed
99
+ */
100
+ private setupEscapeListener() {
101
+ document.addEventListener('keydown', this.boundEscapeListener);
102
+ }
103
+
104
+ /**
105
+ * Remove the Esc key listener that was previously added
106
+ */
107
+ private removeEscapeListener() {
108
+ document.removeEventListener('keydown', this.boundEscapeListener);
109
+ }
110
+
111
+ /**
112
+ * Closes the modal dialog if the given event is pressing the Esc key.
113
+ * Arrow function to ensure `this` remains bound to the current component.
114
+ */
115
+ private boundEscapeListener = (e: KeyboardEvent) => {
116
+ if (e.key === 'Escape') {
117
+ this.closeModal();
118
+ }
119
+ };
120
+
121
+ /**
122
+ * When the histogram is updated, keep track of the newly selected date range.
123
+ * We don't commit to the new range until the apply button is clicked.
124
+ */
125
+ private histogramDateRangeUpdated(
126
+ e: CustomEvent<{
127
+ minDate: string;
128
+ maxDate: string;
129
+ }>,
130
+ ): void {
131
+ this.minSelectedDate = e.detail.minDate;
132
+ this.maxSelectedDate = e.detail.maxDate;
133
+ }
134
+
135
+ /**
136
+ * When the Apply button is clicked, emit the current date range and close the modal.
137
+ */
138
+ private applyBtnClicked(): void {
139
+ const event = new CustomEvent('histogramDateRangeApplied', {
140
+ detail: {
141
+ minDate: this.minSelectedDate,
142
+ maxDate: this.maxSelectedDate,
143
+ },
144
+ });
145
+ this.dispatchEvent(event);
146
+ this.closeModal();
147
+
148
+ this.analyticsHandler?.sendEvent({
149
+ category: analyticsCategories.default,
150
+ action: analyticsActions.histogramChangedFromModal,
151
+ label: window.location.href,
152
+ });
153
+ }
154
+
155
+ /**
156
+ * Closes the modal associated with this component (if it exists) and dispatches a
157
+ * modalClosed event.
158
+ */
159
+ private closeModal(): void {
160
+ if (this.modalManager) {
161
+ this.modalManager.closeModal();
162
+ this.dispatchEvent(new CustomEvent('modalClosed'));
163
+ }
164
+ }
165
+
166
+ static get styles(): CSSResultGroup {
167
+ return css`
168
+ #container {
169
+ display: flex;
170
+ justify-content: center;
171
+ padding: 40px 10px 10px;
172
+ overflow: hidden;
173
+ }
174
+
175
+ #date-picker {
176
+ --histogramDateRangeInputWidth: 50px;
177
+ --histogramDateRangeInputRowMargin: 5px 0 0 0;
178
+ }
179
+
180
+ #apply-btn {
181
+ margin: 0 0 0 5px;
182
+ padding: 8px 10px;
183
+ border: 0;
184
+ border-radius: 4px;
185
+ background: var(--primaryButtonBGColor, #194880);
186
+ color: white;
187
+ cursor: pointer;
188
+ }
189
+ `;
190
+ }
191
+ }
package/src/models.ts CHANGED
@@ -322,6 +322,27 @@ export enum SortField {
322
322
  'creator' = 'creator',
323
323
  }
324
324
 
325
+ /**
326
+ * Views-related sort fields
327
+ */
328
+ export const ALL_VIEWS_SORT_FIELDS = [
329
+ SortField.weeklyview,
330
+ SortField.alltimeview,
331
+ ] as const;
332
+ export type ViewsSortField = (typeof ALL_VIEWS_SORT_FIELDS)[number];
333
+
334
+ /**
335
+ * Date-related sort fields
336
+ */
337
+ export const ALL_DATE_SORT_FIELDS = [
338
+ SortField.datefavorited,
339
+ SortField.date,
340
+ SortField.datearchived,
341
+ SortField.datereviewed,
342
+ SortField.dateadded,
343
+ ] as const;
344
+ export type DateSortField = (typeof ALL_DATE_SORT_FIELDS)[number];
345
+
325
346
  export interface SortOption {
326
347
  /**
327
348
  * The SortField enum member corresponding to this option.
@@ -532,6 +553,33 @@ export function sortOptionFromAPIString(sortName?: string | null): SortOption {
532
553
  );
533
554
  }
534
555
 
556
+ export const defaultSortAvailability: Record<SortField, boolean> = {
557
+ [SortField.relevance]: true,
558
+ [SortField.weeklyview]: true,
559
+ [SortField.alltimeview]: true,
560
+ [SortField.title]: true,
561
+ [SortField.datefavorited]: false,
562
+ [SortField.date]: true,
563
+ [SortField.datearchived]: true,
564
+ [SortField.datereviewed]: true,
565
+ [SortField.dateadded]: true,
566
+ [SortField.creator]: true,
567
+ [SortField.default]: false,
568
+ [SortField.unrecognized]: false,
569
+ };
570
+
571
+ export const favoritesSortAvailability: Record<SortField, boolean> = {
572
+ ...defaultSortAvailability,
573
+ [SortField.datefavorited]: true,
574
+ };
575
+
576
+ export const tvSortAvailability: Record<SortField, boolean> = {
577
+ ...defaultSortAvailability,
578
+ [SortField.date]: false,
579
+ [SortField.datereviewed]: false,
580
+ [SortField.dateadded]: false,
581
+ };
582
+
535
583
  export const defaultProfileElementSorts: Record<
536
584
  string,
537
585
  Exclude<SortField, SortField.default>