@internetarchive/collection-browser 3.3.0 → 3.3.1-alpha3

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 (69) hide show
  1. package/.editorconfig +29 -29
  2. package/.github/workflows/ci.yml +27 -27
  3. package/.github/workflows/gh-pages-main.yml +39 -39
  4. package/.github/workflows/npm-publish.yml +39 -39
  5. package/.github/workflows/pr-preview.yml +38 -38
  6. package/.husky/pre-commit +4 -4
  7. package/.prettierignore +1 -1
  8. package/LICENSE +661 -661
  9. package/README.md +83 -83
  10. package/dist/src/collection-browser.js +683 -683
  11. package/dist/src/collection-browser.js.map +1 -1
  12. package/dist/src/collection-facets/more-facets-content.js +118 -118
  13. package/dist/src/collection-facets/more-facets-content.js.map +1 -1
  14. package/dist/src/collection-facets.js +266 -266
  15. package/dist/src/collection-facets.js.map +1 -1
  16. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  17. package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
  18. package/dist/src/data-source/models.js.map +1 -1
  19. package/dist/src/tiles/base-tile-component.js.map +1 -1
  20. package/dist/src/tiles/grid/account-tile.js +36 -36
  21. package/dist/src/tiles/grid/account-tile.js.map +1 -1
  22. package/dist/src/tiles/grid/collection-tile.js +77 -77
  23. package/dist/src/tiles/grid/collection-tile.js.map +1 -1
  24. package/dist/src/tiles/grid/item-tile.js +137 -137
  25. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  26. package/dist/src/tiles/list/tile-list-compact.js +99 -99
  27. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  28. package/dist/src/tiles/list/tile-list.js +297 -297
  29. package/dist/src/tiles/list/tile-list.js.map +1 -1
  30. package/dist/src/tiles/tile-dispatcher.js +203 -203
  31. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  32. package/dist/src/utils/format-date.js.map +1 -1
  33. package/dist/test/collection-browser.test.js +189 -189
  34. package/dist/test/collection-browser.test.js.map +1 -1
  35. package/dist/test/tiles/grid/item-tile.test.js +77 -77
  36. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  37. package/dist/test/tiles/list/tile-list-compact.test.js +70 -70
  38. package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -1
  39. package/dist/test/tiles/list/tile-list.test.js +126 -126
  40. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  41. package/dist/test/utils/format-date.test.js.map +1 -1
  42. package/eslint.config.mjs +53 -53
  43. package/index.html +24 -24
  44. package/local.archive.org.cert +86 -86
  45. package/local.archive.org.key +27 -27
  46. package/package.json +117 -117
  47. package/renovate.json +6 -6
  48. package/src/collection-browser.ts +2829 -2829
  49. package/src/collection-facets/more-facets-content.ts +639 -639
  50. package/src/collection-facets.ts +995 -995
  51. package/src/data-source/collection-browser-data-source.ts +1401 -1401
  52. package/src/data-source/collection-browser-query-state.ts +65 -65
  53. package/src/data-source/models.ts +43 -43
  54. package/src/tiles/base-tile-component.ts +65 -65
  55. package/src/tiles/grid/account-tile.ts +113 -113
  56. package/src/tiles/grid/collection-tile.ts +163 -163
  57. package/src/tiles/grid/item-tile.ts +340 -340
  58. package/src/tiles/list/tile-list-compact.ts +239 -239
  59. package/src/tiles/list/tile-list.ts +700 -700
  60. package/src/tiles/tile-dispatcher.ts +490 -490
  61. package/src/utils/format-date.ts +62 -62
  62. package/test/collection-browser.test.ts +2403 -2403
  63. package/test/tiles/grid/item-tile.test.ts +520 -520
  64. package/test/tiles/list/tile-list-compact.test.ts +282 -282
  65. package/test/tiles/list/tile-list.test.ts +552 -552
  66. package/test/utils/format-date.test.ts +89 -89
  67. package/tsconfig.json +20 -20
  68. package/web-dev-server.config.mjs +30 -30
  69. package/web-test-runner.config.mjs +41 -41
@@ -1,490 +1,490 @@
1
- import { css, html, nothing, PropertyValues } from 'lit';
2
- import { customElement, property, query } from 'lit/decorators.js';
3
- import { ifDefined } from 'lit/directives/if-defined.js';
4
- import { msg } from '@lit/localize';
5
- import type {
6
- SharedResizeObserverInterface,
7
- SharedResizeObserverResizeHandlerInterface,
8
- } from '@internetarchive/shared-resize-observer';
9
- import type { TileDisplayMode } from '../models';
10
- import type { CollectionTitles } from '../data-source/models';
11
- import './grid/collection-tile';
12
- import './grid/item-tile';
13
- import './grid/account-tile';
14
- import './grid/search-tile';
15
- import './hover/tile-hover-pane';
16
- import './list/tile-list';
17
- import './list/tile-list-compact';
18
- import './list/tile-list-compact-header';
19
- import type { TileHoverPane } from './hover/tile-hover-pane';
20
- import { BaseTileComponent } from './base-tile-component';
21
- import { SimpleLayoutType } from './models';
22
- import {
23
- HoverPaneController,
24
- HoverPaneControllerInterface,
25
- HoverPaneProperties,
26
- HoverPaneProviderInterface,
27
- } from './hover/hover-pane-controller';
28
-
29
- @customElement('tile-dispatcher')
30
- export class TileDispatcher
31
- extends BaseTileComponent
32
- implements
33
- SharedResizeObserverResizeHandlerInterface,
34
- HoverPaneProviderInterface
35
- {
36
- /*
37
- * Reactive properties inherited from BaseTileComponent:
38
- * - model?: TileModel;
39
- * - currentWidth?: number;
40
- * - currentHeight?: number;
41
- * - baseNavigationUrl?: string;
42
- * - baseImageUrl?: string;
43
- * - collectionPagePath?: string;
44
- * - sortParam: SortParam | null = null;
45
- * - defaultSortParam: SortParam | null = null;
46
- * - creatorFilter?: string;
47
- * - mobileBreakpoint?: number;
48
- * - loggedIn = false;
49
- * - suppressTileBlurring = false;
50
- * - useLocalTime = false;
51
- */
52
-
53
- @property({ type: String }) tileDisplayMode?: TileDisplayMode;
54
-
55
- @property({ type: Boolean }) isManageView = false;
56
-
57
- @property({ type: Object }) resizeObserver?: SharedResizeObserverInterface;
58
-
59
- @property({ type: Object })
60
- collectionTitles?: CollectionTitles;
61
-
62
- @property({ type: Boolean }) showTvClips = false;
63
-
64
- /** What type of simple layout to use in grid mode, if any */
65
- @property({ type: String }) simpleLayoutType: SimpleLayoutType = 'none';
66
-
67
- /** Whether this tile should include a hover pane at all (for applicable tile modes) */
68
- @property({ type: Boolean }) enableHoverPane = false;
69
-
70
- @property({ type: String }) manageCheckTitle = msg(
71
- 'Remove this item from the list',
72
- );
73
-
74
- private hoverPaneController?: HoverPaneControllerInterface;
75
-
76
- @query('#container')
77
- private container!: HTMLDivElement;
78
-
79
- @query('tile-hover-pane')
80
- private hoverPane?: TileHoverPane;
81
-
82
- /** Maps each display mode to whether hover panes should appear in that mode */
83
- private static readonly HOVER_PANE_DISPLAY_MODES: Record<
84
- TileDisplayMode,
85
- boolean
86
- > = {
87
- grid: true,
88
- 'list-compact': true,
89
- 'list-detail': false,
90
- 'list-header': false,
91
- };
92
-
93
- render() {
94
- const isGridMode = this.tileDisplayMode === 'grid';
95
- const hoverPaneTemplate =
96
- this.hoverPaneController?.getTemplate() ?? nothing;
97
- return html`
98
- <div id="container" class=${isGridMode ? 'hoverable' : nothing}>
99
- ${this.tileDisplayMode === 'list-header'
100
- ? this.headerTemplate
101
- : this.tileTemplate}
102
- ${this.manageCheckTemplate} ${hoverPaneTemplate}
103
- </div>
104
- `;
105
- }
106
-
107
- protected firstUpdated(): void {
108
- if (this.shouldPrepareHoverPane) {
109
- this.hoverPaneController = new HoverPaneController(this, {
110
- mobileBreakpoint: this.mobileBreakpoint,
111
- enableLongPress: false,
112
- });
113
- }
114
- }
115
-
116
- private get headerTemplate() {
117
- const { currentWidth, sortParam, defaultSortParam, mobileBreakpoint } =
118
- this;
119
- return html`
120
- <tile-list-compact-header
121
- class="header"
122
- .currentWidth=${currentWidth}
123
- .sortParam=${sortParam ?? defaultSortParam}
124
- .mobileBreakpoint=${mobileBreakpoint}
125
- >
126
- </tile-list-compact-header>
127
- `;
128
- }
129
-
130
- private get tileTemplate() {
131
- return html`
132
- ${this.tileDisplayMode === 'list-detail'
133
- ? this.tile
134
- : this.linkTileTemplate}
135
- `;
136
- }
137
-
138
- private get linkTileTemplate() {
139
- return html`
140
- <a
141
- href=${this.linkTileHref}
142
- aria-label=${this.model?.title ?? 'Untitled item'}
143
- title=${this.shouldPrepareHoverPane
144
- ? nothing // Don't show title tooltips when we have the tile info popups
145
- : ifDefined(this.model?.title)}
146
- @click=${this.handleLinkClicked}
147
- @contextmenu=${this.handleLinkContextMenu}
148
- >
149
- ${this.tile}
150
- </a>
151
- `;
152
- }
153
-
154
- private get linkTileHref(): string | typeof nothing {
155
- if (!this.model?.identifier || this.baseNavigationUrl == null)
156
- return nothing;
157
-
158
- // Use the server-specified href if available.
159
- // Otherwise, construct a details page URL from the item identifier.
160
- if (this.model.href) {
161
- return `${this.baseNavigationUrl}${this.model.href}`;
162
- }
163
-
164
- return this.displayValueProvider.itemPageUrl(
165
- this.model.identifier,
166
- this.model.mediatype === 'collection',
167
- );
168
- }
169
-
170
- private get manageCheckTemplate() {
171
- if (!this.isManageView || this.tileDisplayMode !== 'grid') return nothing;
172
-
173
- return html`
174
- <div class="manage-check">
175
- <input
176
- type="checkbox"
177
- title=${this.manageCheckTitle}
178
- .checked=${this.model?.checked}
179
- @change=${this.handleLinkClicked}
180
- />
181
- </div>
182
- `;
183
- }
184
-
185
- /**
186
- * Whether hover pane behavior should be prepared for this tile
187
- * (e.g., whether mouse listeners should be attached, etc.)
188
- */
189
- private get shouldPrepareHoverPane(): boolean {
190
- return (
191
- this.enableHoverPane &&
192
- !!this.tileDisplayMode &&
193
- TileDispatcher.HOVER_PANE_DISPLAY_MODES[this.tileDisplayMode] &&
194
- this.model?.mediatype !== 'search' && // don't show hover panes on search tiles
195
- !this.model?.captureDates // don't show hover panes on web archive tiles
196
- );
197
- }
198
-
199
- private get isHoverEnabled(): boolean {
200
- return window.matchMedia('(hover: hover)').matches;
201
- }
202
-
203
- /** @inheritdoc */
204
- getHoverPane(): TileHoverPane | undefined {
205
- return this.hoverPane;
206
- }
207
-
208
- /** @inheritdoc */
209
- getHoverPaneProps(): HoverPaneProperties {
210
- return this;
211
- }
212
-
213
- handleResize(entry: ResizeObserverEntry): void {
214
- this.currentWidth = entry.contentRect.width;
215
- this.currentHeight = entry.contentRect.height;
216
- }
217
-
218
- disconnectedCallback(): void {
219
- this.stopResizeObservation(this.resizeObserver);
220
- }
221
-
222
- private stopResizeObservation(observer?: SharedResizeObserverInterface) {
223
- observer?.removeObserver({
224
- handler: this,
225
- target: this.container,
226
- });
227
- }
228
-
229
- private startResizeObservation() {
230
- this.stopResizeObservation(this.resizeObserver);
231
- this.resizeObserver?.addObserver({
232
- handler: this,
233
- target: this.container,
234
- });
235
- }
236
-
237
- updated(props: PropertyValues) {
238
- if (props.has('resizeObserver')) {
239
- const previousObserver = props.get(
240
- 'resizeObserver',
241
- ) as SharedResizeObserverInterface;
242
- this.stopResizeObservation(previousObserver);
243
- this.startResizeObservation();
244
- }
245
- }
246
-
247
- /**
248
- * Handler for when the tile link is left-clicked. Emits the `resultSelected` event.
249
- * In manage view, it also checks/unchecks the tile.
250
- */
251
- private handleLinkClicked(e: Event): void {
252
- if (this.isManageView) {
253
- e.preventDefault();
254
- if (this.model) this.model.checked = !this.model.checked;
255
- }
256
-
257
- this.dispatchEvent(
258
- new CustomEvent('resultSelected', { detail: this.model }),
259
- );
260
- }
261
-
262
- /**
263
- * Handler for when the tile link is right-clicked.
264
- * In manage view, it opens the item in a new tab. Otherwise, does nothing.
265
- */
266
- private handleLinkContextMenu(e: Event): void {
267
- if (this.isManageView && this.linkTileHref !== nothing) {
268
- e.preventDefault();
269
- window.open(this.linkTileHref, '_blank');
270
- }
271
- }
272
-
273
- private tileInfoButtonPressed(
274
- e: CustomEvent<{ x: number; y: number }>,
275
- ): void {
276
- this.hoverPaneController?.toggleHoverPane({
277
- coords: e.detail,
278
- enableTouchBackdrop: true,
279
- });
280
- }
281
-
282
- private get tile() {
283
- const {
284
- model,
285
- collectionPagePath,
286
- baseNavigationUrl,
287
- currentWidth,
288
- currentHeight,
289
- sortParam,
290
- creatorFilter,
291
- mobileBreakpoint,
292
- defaultSortParam,
293
- } = this;
294
-
295
- if (!model) return nothing;
296
-
297
- switch (this.tileDisplayMode) {
298
- case 'grid':
299
- switch (model.mediatype) {
300
- case 'collection':
301
- return html`<collection-tile
302
- .model=${model}
303
- .collectionPagePath=${collectionPagePath}
304
- .baseImageUrl=${this.baseImageUrl}
305
- .currentWidth=${currentWidth}
306
- .currentHeight=${currentHeight}
307
- .creatorFilter=${creatorFilter}
308
- .suppressBlurring=${this.suppressBlurring}
309
- .isManageView=${this.isManageView}
310
- ?showInfoButton=${!this.isHoverEnabled}
311
- @infoButtonPressed=${this.tileInfoButtonPressed}
312
- >
313
- </collection-tile>`;
314
- case 'account':
315
- return html`<account-tile
316
- .model=${model}
317
- .collectionPagePath=${collectionPagePath}
318
- .baseImageUrl=${this.baseImageUrl}
319
- .currentWidth=${currentWidth}
320
- .currentHeight=${currentHeight}
321
- .creatorFilter=${creatorFilter}
322
- .suppressBlurring=${this.suppressBlurring}
323
- .isManageView=${this.isManageView}
324
- ?showInfoButton=${!this.isHoverEnabled}
325
- @infoButtonPressed=${this.tileInfoButtonPressed}
326
- >
327
- </account-tile>`;
328
- case 'search':
329
- return html`<search-tile
330
- .model=${model}
331
- .collectionPagePath=${collectionPagePath}
332
- .baseImageUrl=${this.baseImageUrl}
333
- .currentWidth=${currentWidth}
334
- .currentHeight=${currentHeight}
335
- .creatorFilter=${creatorFilter}
336
- .suppressBlurring=${this.suppressBlurring}
337
- .isManageView=${this.isManageView}
338
- ?showInfoButton=${false}
339
- @infoButtonPressed=${this.tileInfoButtonPressed}
340
- >
341
- </search-tile>`;
342
- default:
343
- return html`<item-tile
344
- .model=${model}
345
- .collectionPagePath=${collectionPagePath}
346
- .currentWidth=${this.currentWidth}
347
- .currentHeight=${this.currentHeight}
348
- .baseImageUrl=${this.baseImageUrl}
349
- .sortParam=${sortParam}
350
- .defaultSortParam=${defaultSortParam}
351
- .creatorFilter=${creatorFilter}
352
- .loggedIn=${this.loggedIn}
353
- .suppressBlurring=${this.suppressBlurring}
354
- .isManageView=${this.isManageView}
355
- .simpleLayoutType=${this.simpleLayoutType}
356
- ?showTvClips=${this.showTvClips}
357
- ?showInfoButton=${!this.isHoverEnabled}
358
- ?useLocalTime=${this.useLocalTime}
359
- @infoButtonPressed=${this.tileInfoButtonPressed}
360
- >
361
- </item-tile>`;
362
- }
363
- case 'list-compact':
364
- return html`<tile-list-compact
365
- .model=${model}
366
- .collectionPagePath=${collectionPagePath}
367
- .currentWidth=${currentWidth}
368
- .currentHeight=${currentHeight}
369
- .baseNavigationUrl=${baseNavigationUrl}
370
- .sortParam=${sortParam}
371
- .defaultSortParam=${defaultSortParam}
372
- .creatorFilter=${creatorFilter}
373
- .mobileBreakpoint=${mobileBreakpoint}
374
- .baseImageUrl=${this.baseImageUrl}
375
- .loggedIn=${this.loggedIn}
376
- .suppressBlurring=${this.suppressBlurring}
377
- ?useLocalTime=${this.useLocalTime}
378
- >
379
- </tile-list-compact>`;
380
- case 'list-detail':
381
- return html`<tile-list
382
- .model=${model}
383
- .collectionPagePath=${collectionPagePath}
384
- .collectionTitles=${this.collectionTitles}
385
- .currentWidth=${currentWidth}
386
- .currentHeight=${currentHeight}
387
- .baseNavigationUrl=${baseNavigationUrl}
388
- .sortParam=${sortParam}
389
- .defaultSortParam=${defaultSortParam}
390
- .creatorFilter=${creatorFilter}
391
- .mobileBreakpoint=${mobileBreakpoint}
392
- .baseImageUrl=${this.baseImageUrl}
393
- .loggedIn=${this.loggedIn}
394
- .suppressBlurring=${this.suppressBlurring}
395
- ?useLocalTime=${this.useLocalTime}
396
- >
397
- </tile-list>`;
398
- default:
399
- return nothing;
400
- }
401
- }
402
-
403
- static get styles() {
404
- return css`
405
- :host {
406
- display: block;
407
- height: 100%;
408
- }
409
-
410
- collection-tile {
411
- --tileBorderColor: #555555;
412
- --tileBackgroundColor: #666666;
413
- --imageBlockBackgroundColor: #666666;
414
- }
415
-
416
- account-tile {
417
- --tileBorderColor: #dddddd;
418
- --imageBlockBackgroundColor: #fcf5e6;
419
- }
420
-
421
- item-tile {
422
- --tileBorderColor: #dddddd;
423
- --imageBlockBackgroundColor: #f1f1f4;
424
- }
425
-
426
- search-tile {
427
- --tileBorderColor: #555555;
428
- --tileBackgroundColor: #666666;
429
- --imageBlockBackgroundColor: #666666;
430
- --iconFillColor: #2c2c2c;
431
- }
432
-
433
- #container {
434
- position: relative;
435
- height: 100%;
436
- border-radius: 4px;
437
- }
438
-
439
- #container.hoverable:hover {
440
- box-shadow: var(--tileHoverBoxShadow, 0 0 6px 2px rgba(8, 8, 32, 0.8));
441
- transition: box-shadow 0.1s ease;
442
- }
443
-
444
- a {
445
- display: block;
446
- height: 100%;
447
- color: unset;
448
- text-decoration: none;
449
- transition: transform 0.05s ease;
450
- }
451
-
452
- a :first-child {
453
- display: block;
454
- height: 100%;
455
- }
456
-
457
- .manage-check {
458
- position: absolute;
459
- right: 0;
460
- top: 0;
461
- border: 5px solid #2c2c2c;
462
- border-radius: 3px;
463
- background-color: #2c2c2c;
464
- z-index: 1;
465
- }
466
-
467
- .manage-check > input[type='checkbox'] {
468
- display: block;
469
- margin: 0;
470
- }
471
-
472
- #touch-backdrop {
473
- position: fixed;
474
- width: 100vw;
475
- height: 100vh;
476
- top: 0;
477
- left: 0;
478
- z-index: 2;
479
- background: transparent;
480
- }
481
-
482
- tile-hover-pane {
483
- position: absolute;
484
- top: 0;
485
- left: -9999px;
486
- z-index: 2;
487
- }
488
- `;
489
- }
490
- }
1
+ import { css, html, nothing, PropertyValues } from 'lit';
2
+ import { customElement, property, query } from 'lit/decorators.js';
3
+ import { ifDefined } from 'lit/directives/if-defined.js';
4
+ import { msg } from '@lit/localize';
5
+ import type {
6
+ SharedResizeObserverInterface,
7
+ SharedResizeObserverResizeHandlerInterface,
8
+ } from '@internetarchive/shared-resize-observer';
9
+ import type { TileDisplayMode } from '../models';
10
+ import type { CollectionTitles } from '../data-source/models';
11
+ import './grid/collection-tile';
12
+ import './grid/item-tile';
13
+ import './grid/account-tile';
14
+ import './grid/search-tile';
15
+ import './hover/tile-hover-pane';
16
+ import './list/tile-list';
17
+ import './list/tile-list-compact';
18
+ import './list/tile-list-compact-header';
19
+ import type { TileHoverPane } from './hover/tile-hover-pane';
20
+ import { BaseTileComponent } from './base-tile-component';
21
+ import { SimpleLayoutType } from './models';
22
+ import {
23
+ HoverPaneController,
24
+ HoverPaneControllerInterface,
25
+ HoverPaneProperties,
26
+ HoverPaneProviderInterface,
27
+ } from './hover/hover-pane-controller';
28
+
29
+ @customElement('tile-dispatcher')
30
+ export class TileDispatcher
31
+ extends BaseTileComponent
32
+ implements
33
+ SharedResizeObserverResizeHandlerInterface,
34
+ HoverPaneProviderInterface
35
+ {
36
+ /*
37
+ * Reactive properties inherited from BaseTileComponent:
38
+ * - model?: TileModel;
39
+ * - currentWidth?: number;
40
+ * - currentHeight?: number;
41
+ * - baseNavigationUrl?: string;
42
+ * - baseImageUrl?: string;
43
+ * - collectionPagePath?: string;
44
+ * - sortParam: SortParam | null = null;
45
+ * - defaultSortParam: SortParam | null = null;
46
+ * - creatorFilter?: string;
47
+ * - mobileBreakpoint?: number;
48
+ * - loggedIn = false;
49
+ * - suppressTileBlurring = false;
50
+ * - useLocalTime = false;
51
+ */
52
+
53
+ @property({ type: String }) tileDisplayMode?: TileDisplayMode;
54
+
55
+ @property({ type: Boolean }) isManageView = false;
56
+
57
+ @property({ type: Object }) resizeObserver?: SharedResizeObserverInterface;
58
+
59
+ @property({ type: Object })
60
+ collectionTitles?: CollectionTitles;
61
+
62
+ @property({ type: Boolean }) showTvClips = false;
63
+
64
+ /** What type of simple layout to use in grid mode, if any */
65
+ @property({ type: String }) simpleLayoutType: SimpleLayoutType = 'none';
66
+
67
+ /** Whether this tile should include a hover pane at all (for applicable tile modes) */
68
+ @property({ type: Boolean }) enableHoverPane = false;
69
+
70
+ @property({ type: String }) manageCheckTitle = msg(
71
+ 'Remove this item from the list',
72
+ );
73
+
74
+ private hoverPaneController?: HoverPaneControllerInterface;
75
+
76
+ @query('#container')
77
+ private container!: HTMLDivElement;
78
+
79
+ @query('tile-hover-pane')
80
+ private hoverPane?: TileHoverPane;
81
+
82
+ /** Maps each display mode to whether hover panes should appear in that mode */
83
+ private static readonly HOVER_PANE_DISPLAY_MODES: Record<
84
+ TileDisplayMode,
85
+ boolean
86
+ > = {
87
+ grid: true,
88
+ 'list-compact': true,
89
+ 'list-detail': false,
90
+ 'list-header': false,
91
+ };
92
+
93
+ render() {
94
+ const isGridMode = this.tileDisplayMode === 'grid';
95
+ const hoverPaneTemplate =
96
+ this.hoverPaneController?.getTemplate() ?? nothing;
97
+ return html`
98
+ <div id="container" class=${isGridMode ? 'hoverable' : nothing}>
99
+ ${this.tileDisplayMode === 'list-header'
100
+ ? this.headerTemplate
101
+ : this.tileTemplate}
102
+ ${this.manageCheckTemplate} ${hoverPaneTemplate}
103
+ </div>
104
+ `;
105
+ }
106
+
107
+ protected firstUpdated(): void {
108
+ if (this.shouldPrepareHoverPane) {
109
+ this.hoverPaneController = new HoverPaneController(this, {
110
+ mobileBreakpoint: this.mobileBreakpoint,
111
+ enableLongPress: false,
112
+ });
113
+ }
114
+ }
115
+
116
+ private get headerTemplate() {
117
+ const { currentWidth, sortParam, defaultSortParam, mobileBreakpoint } =
118
+ this;
119
+ return html`
120
+ <tile-list-compact-header
121
+ class="header"
122
+ .currentWidth=${currentWidth}
123
+ .sortParam=${sortParam ?? defaultSortParam}
124
+ .mobileBreakpoint=${mobileBreakpoint}
125
+ >
126
+ </tile-list-compact-header>
127
+ `;
128
+ }
129
+
130
+ private get tileTemplate() {
131
+ return html`
132
+ ${this.tileDisplayMode === 'list-detail'
133
+ ? this.tile
134
+ : this.linkTileTemplate}
135
+ `;
136
+ }
137
+
138
+ private get linkTileTemplate() {
139
+ return html`
140
+ <a
141
+ href=${this.linkTileHref}
142
+ aria-label=${this.model?.title ?? 'Untitled item'}
143
+ title=${this.shouldPrepareHoverPane
144
+ ? nothing // Don't show title tooltips when we have the tile info popups
145
+ : ifDefined(this.model?.title)}
146
+ @click=${this.handleLinkClicked}
147
+ @contextmenu=${this.handleLinkContextMenu}
148
+ >
149
+ ${this.tile}
150
+ </a>
151
+ `;
152
+ }
153
+
154
+ private get linkTileHref(): string | typeof nothing {
155
+ if (!this.model?.identifier || this.baseNavigationUrl == null)
156
+ return nothing;
157
+
158
+ // Use the server-specified href if available.
159
+ // Otherwise, construct a details page URL from the item identifier.
160
+ if (this.model.href) {
161
+ return `${this.baseNavigationUrl}${this.model.href}`;
162
+ }
163
+
164
+ return this.displayValueProvider.itemPageUrl(
165
+ this.model.identifier,
166
+ this.model.mediatype === 'collection',
167
+ );
168
+ }
169
+
170
+ private get manageCheckTemplate() {
171
+ if (!this.isManageView || this.tileDisplayMode !== 'grid') return nothing;
172
+
173
+ return html`
174
+ <div class="manage-check">
175
+ <input
176
+ type="checkbox"
177
+ title=${this.manageCheckTitle}
178
+ .checked=${this.model?.checked}
179
+ @change=${this.handleLinkClicked}
180
+ />
181
+ </div>
182
+ `;
183
+ }
184
+
185
+ /**
186
+ * Whether hover pane behavior should be prepared for this tile
187
+ * (e.g., whether mouse listeners should be attached, etc.)
188
+ */
189
+ private get shouldPrepareHoverPane(): boolean {
190
+ return (
191
+ this.enableHoverPane &&
192
+ !!this.tileDisplayMode &&
193
+ TileDispatcher.HOVER_PANE_DISPLAY_MODES[this.tileDisplayMode] &&
194
+ this.model?.mediatype !== 'search' && // don't show hover panes on search tiles
195
+ !this.model?.captureDates // don't show hover panes on web archive tiles
196
+ );
197
+ }
198
+
199
+ private get isHoverEnabled(): boolean {
200
+ return window.matchMedia('(hover: hover)').matches;
201
+ }
202
+
203
+ /** @inheritdoc */
204
+ getHoverPane(): TileHoverPane | undefined {
205
+ return this.hoverPane;
206
+ }
207
+
208
+ /** @inheritdoc */
209
+ getHoverPaneProps(): HoverPaneProperties {
210
+ return this;
211
+ }
212
+
213
+ handleResize(entry: ResizeObserverEntry): void {
214
+ this.currentWidth = entry.contentRect.width;
215
+ this.currentHeight = entry.contentRect.height;
216
+ }
217
+
218
+ disconnectedCallback(): void {
219
+ this.stopResizeObservation(this.resizeObserver);
220
+ }
221
+
222
+ private stopResizeObservation(observer?: SharedResizeObserverInterface) {
223
+ observer?.removeObserver({
224
+ handler: this,
225
+ target: this.container,
226
+ });
227
+ }
228
+
229
+ private startResizeObservation() {
230
+ this.stopResizeObservation(this.resizeObserver);
231
+ this.resizeObserver?.addObserver({
232
+ handler: this,
233
+ target: this.container,
234
+ });
235
+ }
236
+
237
+ updated(props: PropertyValues) {
238
+ if (props.has('resizeObserver')) {
239
+ const previousObserver = props.get(
240
+ 'resizeObserver',
241
+ ) as SharedResizeObserverInterface;
242
+ this.stopResizeObservation(previousObserver);
243
+ this.startResizeObservation();
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Handler for when the tile link is left-clicked. Emits the `resultSelected` event.
249
+ * In manage view, it also checks/unchecks the tile.
250
+ */
251
+ private handleLinkClicked(e: Event): void {
252
+ if (this.isManageView) {
253
+ e.preventDefault();
254
+ if (this.model) this.model.checked = !this.model.checked;
255
+ }
256
+
257
+ this.dispatchEvent(
258
+ new CustomEvent('resultSelected', { detail: this.model }),
259
+ );
260
+ }
261
+
262
+ /**
263
+ * Handler for when the tile link is right-clicked.
264
+ * In manage view, it opens the item in a new tab. Otherwise, does nothing.
265
+ */
266
+ private handleLinkContextMenu(e: Event): void {
267
+ if (this.isManageView && this.linkTileHref !== nothing) {
268
+ e.preventDefault();
269
+ window.open(this.linkTileHref, '_blank');
270
+ }
271
+ }
272
+
273
+ private tileInfoButtonPressed(
274
+ e: CustomEvent<{ x: number; y: number }>,
275
+ ): void {
276
+ this.hoverPaneController?.toggleHoverPane({
277
+ coords: e.detail,
278
+ enableTouchBackdrop: true,
279
+ });
280
+ }
281
+
282
+ private get tile() {
283
+ const {
284
+ model,
285
+ collectionPagePath,
286
+ baseNavigationUrl,
287
+ currentWidth,
288
+ currentHeight,
289
+ sortParam,
290
+ creatorFilter,
291
+ mobileBreakpoint,
292
+ defaultSortParam,
293
+ } = this;
294
+
295
+ if (!model) return nothing;
296
+
297
+ switch (this.tileDisplayMode) {
298
+ case 'grid':
299
+ switch (model.mediatype) {
300
+ case 'collection':
301
+ return html`<collection-tile
302
+ .model=${model}
303
+ .collectionPagePath=${collectionPagePath}
304
+ .baseImageUrl=${this.baseImageUrl}
305
+ .currentWidth=${currentWidth}
306
+ .currentHeight=${currentHeight}
307
+ .creatorFilter=${creatorFilter}
308
+ .suppressBlurring=${this.suppressBlurring}
309
+ .isManageView=${this.isManageView}
310
+ ?showInfoButton=${!this.isHoverEnabled}
311
+ @infoButtonPressed=${this.tileInfoButtonPressed}
312
+ >
313
+ </collection-tile>`;
314
+ case 'account':
315
+ return html`<account-tile
316
+ .model=${model}
317
+ .collectionPagePath=${collectionPagePath}
318
+ .baseImageUrl=${this.baseImageUrl}
319
+ .currentWidth=${currentWidth}
320
+ .currentHeight=${currentHeight}
321
+ .creatorFilter=${creatorFilter}
322
+ .suppressBlurring=${this.suppressBlurring}
323
+ .isManageView=${this.isManageView}
324
+ ?showInfoButton=${!this.isHoverEnabled}
325
+ @infoButtonPressed=${this.tileInfoButtonPressed}
326
+ >
327
+ </account-tile>`;
328
+ case 'search':
329
+ return html`<search-tile
330
+ .model=${model}
331
+ .collectionPagePath=${collectionPagePath}
332
+ .baseImageUrl=${this.baseImageUrl}
333
+ .currentWidth=${currentWidth}
334
+ .currentHeight=${currentHeight}
335
+ .creatorFilter=${creatorFilter}
336
+ .suppressBlurring=${this.suppressBlurring}
337
+ .isManageView=${this.isManageView}
338
+ ?showInfoButton=${false}
339
+ @infoButtonPressed=${this.tileInfoButtonPressed}
340
+ >
341
+ </search-tile>`;
342
+ default:
343
+ return html`<item-tile
344
+ .model=${model}
345
+ .collectionPagePath=${collectionPagePath}
346
+ .currentWidth=${this.currentWidth}
347
+ .currentHeight=${this.currentHeight}
348
+ .baseImageUrl=${this.baseImageUrl}
349
+ .sortParam=${sortParam}
350
+ .defaultSortParam=${defaultSortParam}
351
+ .creatorFilter=${creatorFilter}
352
+ .loggedIn=${this.loggedIn}
353
+ .suppressBlurring=${this.suppressBlurring}
354
+ .isManageView=${this.isManageView}
355
+ .simpleLayoutType=${this.simpleLayoutType}
356
+ ?showTvClips=${this.showTvClips}
357
+ ?showInfoButton=${!this.isHoverEnabled}
358
+ ?useLocalTime=${this.useLocalTime}
359
+ @infoButtonPressed=${this.tileInfoButtonPressed}
360
+ >
361
+ </item-tile>`;
362
+ }
363
+ case 'list-compact':
364
+ return html`<tile-list-compact
365
+ .model=${model}
366
+ .collectionPagePath=${collectionPagePath}
367
+ .currentWidth=${currentWidth}
368
+ .currentHeight=${currentHeight}
369
+ .baseNavigationUrl=${baseNavigationUrl}
370
+ .sortParam=${sortParam}
371
+ .defaultSortParam=${defaultSortParam}
372
+ .creatorFilter=${creatorFilter}
373
+ .mobileBreakpoint=${mobileBreakpoint}
374
+ .baseImageUrl=${this.baseImageUrl}
375
+ .loggedIn=${this.loggedIn}
376
+ .suppressBlurring=${this.suppressBlurring}
377
+ ?useLocalTime=${this.useLocalTime}
378
+ >
379
+ </tile-list-compact>`;
380
+ case 'list-detail':
381
+ return html`<tile-list
382
+ .model=${model}
383
+ .collectionPagePath=${collectionPagePath}
384
+ .collectionTitles=${this.collectionTitles}
385
+ .currentWidth=${currentWidth}
386
+ .currentHeight=${currentHeight}
387
+ .baseNavigationUrl=${baseNavigationUrl}
388
+ .sortParam=${sortParam}
389
+ .defaultSortParam=${defaultSortParam}
390
+ .creatorFilter=${creatorFilter}
391
+ .mobileBreakpoint=${mobileBreakpoint}
392
+ .baseImageUrl=${this.baseImageUrl}
393
+ .loggedIn=${this.loggedIn}
394
+ .suppressBlurring=${this.suppressBlurring}
395
+ ?useLocalTime=${this.useLocalTime}
396
+ >
397
+ </tile-list>`;
398
+ default:
399
+ return nothing;
400
+ }
401
+ }
402
+
403
+ static get styles() {
404
+ return css`
405
+ :host {
406
+ display: block;
407
+ height: 100%;
408
+ }
409
+
410
+ collection-tile {
411
+ --tileBorderColor: #555555;
412
+ --tileBackgroundColor: #666666;
413
+ --imageBlockBackgroundColor: #666666;
414
+ }
415
+
416
+ account-tile {
417
+ --tileBorderColor: #dddddd;
418
+ --imageBlockBackgroundColor: #fcf5e6;
419
+ }
420
+
421
+ item-tile {
422
+ --tileBorderColor: #dddddd;
423
+ --imageBlockBackgroundColor: #f1f1f4;
424
+ }
425
+
426
+ search-tile {
427
+ --tileBorderColor: #555555;
428
+ --tileBackgroundColor: #666666;
429
+ --imageBlockBackgroundColor: #666666;
430
+ --iconFillColor: #2c2c2c;
431
+ }
432
+
433
+ #container {
434
+ position: relative;
435
+ height: 100%;
436
+ border-radius: 4px;
437
+ }
438
+
439
+ #container.hoverable:hover {
440
+ box-shadow: var(--tileHoverBoxShadow, 0 0 6px 2px rgba(8, 8, 32, 0.8));
441
+ transition: box-shadow 0.1s ease;
442
+ }
443
+
444
+ a {
445
+ display: block;
446
+ height: 100%;
447
+ color: unset;
448
+ text-decoration: none;
449
+ transition: transform 0.05s ease;
450
+ }
451
+
452
+ a :first-child {
453
+ display: block;
454
+ height: 100%;
455
+ }
456
+
457
+ .manage-check {
458
+ position: absolute;
459
+ right: 0;
460
+ top: 0;
461
+ border: 5px solid #2c2c2c;
462
+ border-radius: 3px;
463
+ background-color: #2c2c2c;
464
+ z-index: 1;
465
+ }
466
+
467
+ .manage-check > input[type='checkbox'] {
468
+ display: block;
469
+ margin: 0;
470
+ }
471
+
472
+ #touch-backdrop {
473
+ position: fixed;
474
+ width: 100vw;
475
+ height: 100vh;
476
+ top: 0;
477
+ left: 0;
478
+ z-index: 2;
479
+ background: transparent;
480
+ }
481
+
482
+ tile-hover-pane {
483
+ position: absolute;
484
+ top: 0;
485
+ left: -9999px;
486
+ z-index: 2;
487
+ }
488
+ `;
489
+ }
490
+ }