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