@internetarchive/collection-browser 4.5.0 → 4.5.1-alpha-webdev8221.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 (70) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/src/app-root.js +683 -683
  3. package/dist/src/app-root.js.map +1 -1
  4. package/dist/src/collection-browser.d.ts +0 -4
  5. package/dist/src/collection-browser.js +767 -776
  6. package/dist/src/collection-browser.js.map +1 -1
  7. package/dist/src/collection-facets/facet-row.js +143 -143
  8. package/dist/src/collection-facets/facet-row.js.map +1 -1
  9. package/dist/src/collection-facets/facets-template.js +24 -24
  10. package/dist/src/collection-facets/facets-template.js.map +1 -1
  11. package/dist/src/data-source/collection-browser-data-source-interface.d.ts +5 -0
  12. package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -1
  13. package/dist/src/data-source/collection-browser-data-source.d.ts +1 -1
  14. package/dist/src/data-source/collection-browser-data-source.js +8 -6
  15. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  16. package/dist/src/restoration-state-handler.js +2 -4
  17. package/dist/src/restoration-state-handler.js.map +1 -1
  18. package/dist/src/styles/tile-action-styles.js +43 -43
  19. package/dist/src/styles/tile-action-styles.js.map +1 -1
  20. package/dist/src/tiles/base-tile-component.js +11 -11
  21. package/dist/src/tiles/base-tile-component.js.map +1 -1
  22. package/dist/src/tiles/grid/item-tile.js +138 -138
  23. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  24. package/dist/src/tiles/list/tile-list-compact-header.js +62 -62
  25. package/dist/src/tiles/list/tile-list-compact-header.js.map +1 -1
  26. package/dist/src/tiles/list/tile-list-compact.js +123 -123
  27. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  28. package/dist/src/tiles/list/tile-list.js +310 -310
  29. package/dist/src/tiles/list/tile-list.js.map +1 -1
  30. package/dist/src/tiles/models.js.map +1 -1
  31. package/dist/src/tiles/tile-dispatcher.js +286 -286
  32. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  33. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  34. package/dist/src/utils/date-filter-field.d.ts +6 -0
  35. package/dist/src/utils/date-filter-field.js +9 -0
  36. package/dist/src/utils/date-filter-field.js.map +1 -0
  37. package/dist/test/collection-browser.test.js +81 -0
  38. package/dist/test/collection-browser.test.js.map +1 -1
  39. package/dist/test/collection-facets/facet-row.test.js +31 -31
  40. package/dist/test/collection-facets/facet-row.test.js.map +1 -1
  41. package/dist/test/tiles/grid/item-tile.test.js +77 -77
  42. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  43. package/dist/test/tiles/list/tile-list.test.js +134 -134
  44. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  45. package/dist/test/tiles/tile-dispatcher.test.js +92 -92
  46. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  47. package/index.ts +29 -29
  48. package/package.json +1 -1
  49. package/src/app-root.ts +1284 -1284
  50. package/src/collection-browser.ts +3165 -3176
  51. package/src/collection-facets/facet-row.ts +309 -309
  52. package/src/collection-facets/facets-template.ts +85 -85
  53. package/src/data-source/collection-browser-data-source-interface.ts +6 -0
  54. package/src/data-source/collection-browser-data-source.ts +16 -7
  55. package/src/restoration-state-handler.ts +5 -5
  56. package/src/styles/tile-action-styles.ts +59 -59
  57. package/src/tiles/base-tile-component.ts +124 -124
  58. package/src/tiles/grid/item-tile.ts +347 -347
  59. package/src/tiles/list/tile-list-compact-header.ts +112 -112
  60. package/src/tiles/list/tile-list-compact.ts +278 -278
  61. package/src/tiles/list/tile-list.ts +718 -718
  62. package/src/tiles/models.ts +21 -21
  63. package/src/tiles/tile-dispatcher.ts +637 -637
  64. package/src/tiles/tile-display-value-provider.ts +133 -133
  65. package/src/utils/date-filter-field.ts +11 -0
  66. package/test/collection-browser.test.ts +132 -0
  67. package/test/collection-facets/facet-row.test.ts +421 -421
  68. package/test/tiles/grid/item-tile.test.ts +520 -520
  69. package/test/tiles/list/tile-list.test.ts +576 -576
  70. package/test/tiles/tile-dispatcher.test.ts +320 -320
@@ -1,278 +1,278 @@
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
- }
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
+ }