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