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