@internetarchive/collection-browser 2.22.1-alpha-webdev7877.1 → 2.22.1-alpha-webdev7818.1

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.
@@ -1,236 +1,236 @@
1
- import { css, html, nothing } from 'lit';
2
- import { customElement } from 'lit/decorators.js';
3
- import DOMPurify from 'dompurify';
4
- import type { SortParam } from '@internetarchive/search-service';
5
- import { BaseTileComponent } from '../base-tile-component';
6
-
7
- import { formatCount, NumberFormat } from '../../utils/format-count';
8
- import { formatDate, DateFormat } from '../../utils/format-date';
9
- import { isFirstMillisecondOfUTCYear } from '../../utils/local-date-from-utc';
10
-
11
- import '../image-block';
12
- import '../tile-mediatype-icon';
13
-
14
- @customElement('tile-list-compact')
15
- export class TileListCompact extends BaseTileComponent {
16
- /*
17
- * Reactive properties inherited from BaseTileComponent:
18
- * - model?: TileModel;
19
- * - currentWidth?: number;
20
- * - currentHeight?: number;
21
- * - baseNavigationUrl?: string;
22
- * - baseImageUrl?: string;
23
- * - collectionPagePath?: string;
24
- * - sortParam: SortParam | null = null;
25
- * - defaultSortParam: SortParam | null = null;
26
- * - creatorFilter?: string;
27
- * - mobileBreakpoint?: number;
28
- * - loggedIn = false;
29
- * - suppressBlurring = false;
30
- */
31
-
32
- render() {
33
- return html`
34
- <div id="list-line" class="${this.classSize}">
35
- <image-block
36
- .model=${this.model}
37
- .baseImageUrl=${this.baseImageUrl}
38
- .isCompactTile=${true}
39
- .isListTile=${true}
40
- .viewSize=${this.classSize}
41
- .loggedIn=${this.loggedIn}
42
- .suppressBlurring=${this.suppressBlurring}
43
- >
44
- </image-block>
45
- <a href=${this.href} id="title"
46
- >${DOMPurify.sanitize(this.model?.title ?? '')}</a
47
- >
48
- <div id="creator">
49
- ${this.model?.mediatype === 'account'
50
- ? this.displayValueProvider.accountLabel
51
- : this.creator}
52
- </div>
53
- <div id="date">${formatDate(this.date, this.dateFormatSize)}</div>
54
- <div id="icon">
55
- <tile-mediatype-icon .model=${this.model}> </tile-mediatype-icon>
56
- </div>
57
- <div id="views">${formatCount(this.views ?? 0, this.formatSize)}</div>
58
- </div>
59
- `;
60
- }
61
-
62
- private get href(): string | typeof nothing {
63
- if (!this.model?.identifier || this.baseNavigationUrl == null)
64
- return nothing;
65
-
66
- // Use the server-specified href if available.
67
- // Otherwise, construct a details page URL from the item identifier.
68
- if (this.model.href) {
69
- return `${this.baseNavigationUrl}${this.model.href}`;
70
- }
71
-
72
- return this.displayValueProvider.itemPageUrl(
73
- this.model.identifier,
74
- this.model.mediatype === 'collection',
75
- );
76
- }
77
-
78
- private get creator(): string | typeof nothing {
79
- return this.displayValueProvider.firstCreatorMatchingFilter ?? nothing;
80
- }
81
-
82
- /*
83
- * TODO: fix field names to match model in src/collection-browser.ts
84
- * private get dateSortSelector()
85
- * @see src/models.ts
86
- */
87
- private get date(): Date | undefined {
88
- // Note on 'publicdate' vs. 'date':
89
- // The search engine metadata uses 'publicdate' as the key for the date the item
90
- // was created on archive.org, which in the UI is referred to as "Date Archived".
91
- // In contrast, the search engine metadata uses 'date' to refer to the actual
92
- // publication date of the underlying media ("Date Published" in the UI).
93
- // Refer to the full metadata schema for more info.
94
- switch (this.effectiveSort?.field) {
95
- case 'publicdate':
96
- return this.model?.dateArchived;
97
- case 'reviewdate':
98
- return this.model?.dateReviewed;
99
- case 'addeddate':
100
- return this.model?.dateAdded;
101
- default:
102
- return this.model?.datePublished;
103
- }
104
- }
105
-
106
- private get views(): number | undefined {
107
- return this.effectiveSort?.field === 'week'
108
- ? this.model?.weeklyViewCount // weekly views
109
- : this.model?.viewCount; // all-time views
110
- }
111
-
112
- /**
113
- * Returns the active sort param if one is set, or the default sort param otherwise.
114
- */
115
- private get effectiveSort(): SortParam | null {
116
- return this.sortParam ?? this.defaultSortParam;
117
- }
118
-
119
- private get classSize(): string {
120
- if (
121
- this.mobileBreakpoint &&
122
- this.currentWidth &&
123
- this.currentWidth < this.mobileBreakpoint
124
- ) {
125
- return 'mobile';
126
- }
127
- return 'desktop';
128
- }
129
-
130
- private get dateFormatSize(): DateFormat {
131
- // If we're showing a date published of Jan 1 at midnight, only show the year.
132
- // This is because items with only a year for their publication date are normalized to
133
- // Jan 1 at midnight timestamps in the search engine documents.
134
- if (
135
- (!this.isSortedByDate || this.effectiveSort?.field === 'date') && // Any sort except dates that aren't published date
136
- isFirstMillisecondOfUTCYear(this.model?.datePublished)
137
- ) {
138
- return 'year-only';
139
- }
140
- return this.formatSize;
141
- }
142
-
143
- private get formatSize(): NumberFormat {
144
- if (
145
- this.mobileBreakpoint &&
146
- this.currentWidth &&
147
- this.currentWidth < this.mobileBreakpoint
148
- ) {
149
- return 'short';
150
- }
151
- return 'long';
152
- }
153
-
154
- private get isSortedByDate(): boolean {
155
- return ['date', 'reviewdate', 'addeddate', 'publicdate'].includes(
156
- this.effectiveSort?.field as string,
157
- );
158
- }
159
-
160
- static get styles() {
161
- return css`
162
- html {
163
- font-size: unset;
164
- }
165
-
166
- div {
167
- font-size: 14px;
168
- }
169
-
170
- #list-line {
171
- display: grid;
172
- column-gap: 10px;
173
- border-top: 1px solid #ddd;
174
- align-items: center;
175
- line-height: 20px;
176
- padding-top: 5px;
177
- margin-bottom: -5px;
178
- }
179
-
180
- #list-line.mobile {
181
- grid-template-columns: 36px 3fr 2fr 68px 35px;
182
- }
183
-
184
- #list-line.desktop {
185
- grid-template-columns: 51px 3fr 2fr 95px 30px 60px;
186
- }
187
-
188
- #list-line:hover #title {
189
- text-decoration: underline;
190
- }
191
-
192
- #title {
193
- text-decoration: none;
194
- }
195
-
196
- #title:link {
197
- color: var(--ia-theme-link-color, #4b64ff);
198
- }
199
-
200
- #title,
201
- #creator {
202
- text-overflow: ellipsis;
203
- overflow: hidden;
204
- white-space: nowrap;
205
- }
206
-
207
- #icon {
208
- margin-left: 2px;
209
- }
210
-
211
- #views {
212
- text-align: right;
213
- padding-right: 8px;
214
- }
215
-
216
- .mobile #views {
217
- display: none;
218
- }
219
-
220
- .mobile tile-mediatype-icon {
221
- --iconHeight: 14px;
222
- --iconWidth: 14px;
223
- }
224
-
225
- .desktop #icon {
226
- --iconHeight: 20px;
227
- --iconWidth: 20px;
228
- }
229
-
230
- item-image {
231
- --imgHeight: 100%;
232
- --imgWidth: 100%;
233
- }
234
- `;
235
- }
236
- }
1
+ import { css, html, nothing } from 'lit';
2
+ import { customElement } from 'lit/decorators.js';
3
+ import DOMPurify from 'dompurify';
4
+ import type { SortParam } from '@internetarchive/search-service';
5
+ import { BaseTileComponent } from '../base-tile-component';
6
+
7
+ import { formatCount, NumberFormat } from '../../utils/format-count';
8
+ import { formatDate, DateFormat } from '../../utils/format-date';
9
+ import { isFirstMillisecondOfUTCYear } from '../../utils/local-date-from-utc';
10
+
11
+ import '../image-block';
12
+ import '../tile-mediatype-icon';
13
+
14
+ @customElement('tile-list-compact')
15
+ export class TileListCompact extends BaseTileComponent {
16
+ /*
17
+ * Reactive properties inherited from BaseTileComponent:
18
+ * - model?: TileModel;
19
+ * - currentWidth?: number;
20
+ * - currentHeight?: number;
21
+ * - baseNavigationUrl?: string;
22
+ * - baseImageUrl?: string;
23
+ * - collectionPagePath?: string;
24
+ * - sortParam: SortParam | null = null;
25
+ * - defaultSortParam: SortParam | null = null;
26
+ * - creatorFilter?: string;
27
+ * - mobileBreakpoint?: number;
28
+ * - loggedIn = false;
29
+ * - suppressBlurring = false;
30
+ */
31
+
32
+ render() {
33
+ return html`
34
+ <div id="list-line" class="${this.classSize}">
35
+ <image-block
36
+ .model=${this.model}
37
+ .baseImageUrl=${this.baseImageUrl}
38
+ .isCompactTile=${true}
39
+ .isListTile=${true}
40
+ .viewSize=${this.classSize}
41
+ .loggedIn=${this.loggedIn}
42
+ .suppressBlurring=${this.suppressBlurring}
43
+ >
44
+ </image-block>
45
+ <a href=${this.href} id="title"
46
+ >${DOMPurify.sanitize(this.model?.title ?? '')}</a
47
+ >
48
+ <div id="creator">
49
+ ${this.model?.mediatype === 'account'
50
+ ? this.displayValueProvider.accountLabel
51
+ : this.creator}
52
+ </div>
53
+ <div id="date">${formatDate(this.date, this.dateFormatSize)}</div>
54
+ <div id="icon">
55
+ <tile-mediatype-icon .model=${this.model}> </tile-mediatype-icon>
56
+ </div>
57
+ <div id="views">${formatCount(this.views ?? 0, this.formatSize)}</div>
58
+ </div>
59
+ `;
60
+ }
61
+
62
+ private get href(): string | typeof nothing {
63
+ if (!this.model?.identifier || this.baseNavigationUrl == null)
64
+ return nothing;
65
+
66
+ // Use the server-specified href if available.
67
+ // Otherwise, construct a details page URL from the item identifier.
68
+ if (this.model.href) {
69
+ return `${this.baseNavigationUrl}${this.model.href}`;
70
+ }
71
+
72
+ return this.displayValueProvider.itemPageUrl(
73
+ this.model.identifier,
74
+ this.model.mediatype === 'collection',
75
+ );
76
+ }
77
+
78
+ private get creator(): string | typeof nothing {
79
+ return this.displayValueProvider.firstCreatorMatchingFilter ?? nothing;
80
+ }
81
+
82
+ /*
83
+ * TODO: fix field names to match model in src/collection-browser.ts
84
+ * private get dateSortSelector()
85
+ * @see src/models.ts
86
+ */
87
+ private get date(): Date | undefined {
88
+ // Note on 'publicdate' vs. 'date':
89
+ // The search engine metadata uses 'publicdate' as the key for the date the item
90
+ // was created on archive.org, which in the UI is referred to as "Date Archived".
91
+ // In contrast, the search engine metadata uses 'date' to refer to the actual
92
+ // publication date of the underlying media ("Date Published" in the UI).
93
+ // Refer to the full metadata schema for more info.
94
+ switch (this.effectiveSort?.field) {
95
+ case 'publicdate':
96
+ return this.model?.dateArchived;
97
+ case 'reviewdate':
98
+ return this.model?.dateReviewed;
99
+ case 'addeddate':
100
+ return this.model?.dateAdded;
101
+ default:
102
+ return this.model?.datePublished;
103
+ }
104
+ }
105
+
106
+ private get views(): number | undefined {
107
+ return this.effectiveSort?.field === 'week'
108
+ ? this.model?.weeklyViewCount // weekly views
109
+ : this.model?.viewCount; // all-time views
110
+ }
111
+
112
+ /**
113
+ * Returns the active sort param if one is set, or the default sort param otherwise.
114
+ */
115
+ private get effectiveSort(): SortParam | null {
116
+ return this.sortParam ?? this.defaultSortParam;
117
+ }
118
+
119
+ private get classSize(): string {
120
+ if (
121
+ this.mobileBreakpoint &&
122
+ this.currentWidth &&
123
+ this.currentWidth < this.mobileBreakpoint
124
+ ) {
125
+ return 'mobile';
126
+ }
127
+ return 'desktop';
128
+ }
129
+
130
+ private get dateFormatSize(): DateFormat {
131
+ // If we're showing a date published of Jan 1 at midnight, only show the year.
132
+ // This is because items with only a year for their publication date are normalized to
133
+ // Jan 1 at midnight timestamps in the search engine documents.
134
+ if (
135
+ (!this.isSortedByDate || this.effectiveSort?.field === 'date') && // Any sort except dates that aren't published date
136
+ isFirstMillisecondOfUTCYear(this.model?.datePublished)
137
+ ) {
138
+ return 'year-only';
139
+ }
140
+ return this.formatSize;
141
+ }
142
+
143
+ private get formatSize(): NumberFormat {
144
+ if (
145
+ this.mobileBreakpoint &&
146
+ this.currentWidth &&
147
+ this.currentWidth < this.mobileBreakpoint
148
+ ) {
149
+ return 'short';
150
+ }
151
+ return 'long';
152
+ }
153
+
154
+ private get isSortedByDate(): boolean {
155
+ return ['date', 'reviewdate', 'addeddate', 'publicdate'].includes(
156
+ this.effectiveSort?.field as string,
157
+ );
158
+ }
159
+
160
+ static get styles() {
161
+ return css`
162
+ html {
163
+ font-size: unset;
164
+ }
165
+
166
+ div {
167
+ font-size: 14px;
168
+ }
169
+
170
+ #list-line {
171
+ display: grid;
172
+ column-gap: 10px;
173
+ border-top: 1px solid #ddd;
174
+ align-items: center;
175
+ line-height: 20px;
176
+ padding-top: 5px;
177
+ margin-bottom: -5px;
178
+ }
179
+
180
+ #list-line.mobile {
181
+ grid-template-columns: 36px 3fr 2fr 68px 35px;
182
+ }
183
+
184
+ #list-line.desktop {
185
+ grid-template-columns: 51px 3fr 2fr 95px 30px 60px;
186
+ }
187
+
188
+ #list-line:hover #title {
189
+ text-decoration: underline;
190
+ }
191
+
192
+ #title {
193
+ text-decoration: none;
194
+ }
195
+
196
+ #title:link {
197
+ color: var(--ia-theme-link-color, #4b64ff);
198
+ }
199
+
200
+ #title,
201
+ #creator {
202
+ text-overflow: ellipsis;
203
+ overflow: hidden;
204
+ white-space: nowrap;
205
+ }
206
+
207
+ #icon {
208
+ margin-left: 2px;
209
+ }
210
+
211
+ #views {
212
+ text-align: right;
213
+ padding-right: 8px;
214
+ }
215
+
216
+ .mobile #views {
217
+ display: none;
218
+ }
219
+
220
+ .mobile tile-mediatype-icon {
221
+ --iconHeight: 14px;
222
+ --iconWidth: 14px;
223
+ }
224
+
225
+ .desktop #icon {
226
+ --iconHeight: 20px;
227
+ --iconWidth: 20px;
228
+ }
229
+
230
+ item-image {
231
+ --imgHeight: 100%;
232
+ --imgWidth: 100%;
233
+ }
234
+ `;
235
+ }
236
+ }