@internetarchive/collection-browser 4.5.0 → 4.5.1-alpha-webdev8221.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/src/app-root.js +683 -683
  3. package/dist/src/app-root.js.map +1 -1
  4. package/dist/src/collection-browser.d.ts +0 -4
  5. package/dist/src/collection-browser.js +767 -776
  6. package/dist/src/collection-browser.js.map +1 -1
  7. package/dist/src/collection-facets/facet-row.js +143 -143
  8. package/dist/src/collection-facets/facet-row.js.map +1 -1
  9. package/dist/src/collection-facets/facets-template.js +24 -24
  10. package/dist/src/collection-facets/facets-template.js.map +1 -1
  11. package/dist/src/data-source/collection-browser-data-source-interface.d.ts +5 -0
  12. package/dist/src/data-source/collection-browser-data-source-interface.js.map +1 -1
  13. package/dist/src/data-source/collection-browser-data-source.d.ts +1 -1
  14. package/dist/src/data-source/collection-browser-data-source.js +8 -6
  15. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  16. package/dist/src/restoration-state-handler.js +2 -4
  17. package/dist/src/restoration-state-handler.js.map +1 -1
  18. package/dist/src/styles/tile-action-styles.js +43 -43
  19. package/dist/src/styles/tile-action-styles.js.map +1 -1
  20. package/dist/src/tiles/base-tile-component.js +11 -11
  21. package/dist/src/tiles/base-tile-component.js.map +1 -1
  22. package/dist/src/tiles/grid/item-tile.js +138 -138
  23. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  24. package/dist/src/tiles/list/tile-list-compact-header.js +62 -62
  25. package/dist/src/tiles/list/tile-list-compact-header.js.map +1 -1
  26. package/dist/src/tiles/list/tile-list-compact.js +123 -123
  27. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  28. package/dist/src/tiles/list/tile-list.js +310 -310
  29. package/dist/src/tiles/list/tile-list.js.map +1 -1
  30. package/dist/src/tiles/models.js.map +1 -1
  31. package/dist/src/tiles/tile-dispatcher.js +286 -286
  32. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  33. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  34. package/dist/src/utils/date-filter-field.d.ts +6 -0
  35. package/dist/src/utils/date-filter-field.js +9 -0
  36. package/dist/src/utils/date-filter-field.js.map +1 -0
  37. package/dist/test/collection-browser.test.js +81 -0
  38. package/dist/test/collection-browser.test.js.map +1 -1
  39. package/dist/test/collection-facets/facet-row.test.js +31 -31
  40. package/dist/test/collection-facets/facet-row.test.js.map +1 -1
  41. package/dist/test/tiles/grid/item-tile.test.js +77 -77
  42. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  43. package/dist/test/tiles/list/tile-list.test.js +134 -134
  44. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  45. package/dist/test/tiles/tile-dispatcher.test.js +92 -92
  46. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  47. package/index.ts +29 -29
  48. package/package.json +1 -1
  49. package/src/app-root.ts +1284 -1284
  50. package/src/collection-browser.ts +3165 -3176
  51. package/src/collection-facets/facet-row.ts +309 -309
  52. package/src/collection-facets/facets-template.ts +85 -85
  53. package/src/data-source/collection-browser-data-source-interface.ts +6 -0
  54. package/src/data-source/collection-browser-data-source.ts +16 -7
  55. package/src/restoration-state-handler.ts +5 -5
  56. package/src/styles/tile-action-styles.ts +59 -59
  57. package/src/tiles/base-tile-component.ts +124 -124
  58. package/src/tiles/grid/item-tile.ts +347 -347
  59. package/src/tiles/list/tile-list-compact-header.ts +112 -112
  60. package/src/tiles/list/tile-list-compact.ts +278 -278
  61. package/src/tiles/list/tile-list.ts +718 -718
  62. package/src/tiles/models.ts +21 -21
  63. package/src/tiles/tile-dispatcher.ts +637 -637
  64. package/src/tiles/tile-display-value-provider.ts +133 -133
  65. package/src/utils/date-filter-field.ts +11 -0
  66. package/test/collection-browser.test.ts +132 -0
  67. package/test/collection-facets/facet-row.test.ts +421 -421
  68. package/test/tiles/grid/item-tile.test.ts +520 -520
  69. package/test/tiles/list/tile-list.test.ts +576 -576
  70. package/test/tiles/tile-dispatcher.test.ts +320 -320
@@ -1,85 +1,85 @@
1
- import {
2
- css,
3
- html,
4
- LitElement,
5
- TemplateResult,
6
- CSSResultGroup,
7
- nothing,
8
- } from 'lit';
9
- import { customElement, property } from 'lit/decorators.js';
10
- import { repeat } from 'lit/directives/repeat.js';
11
- import type { FacetGroup, FacetBucket, FacetEventDetails } from '../models';
12
- import type { CollectionTitles } from '../data-source/models';
13
- import './facet-row';
14
-
15
- @customElement('facets-template')
16
- export class FacetsTemplate extends LitElement {
17
- @property({ type: Object }) facetGroup?: FacetGroup;
18
-
19
- @property({ type: Object })
20
- collectionTitles?: CollectionTitles;
21
-
22
- private facetClicked(e: CustomEvent<FacetEventDetails>) {
23
- this.dispatchFacetClickEvent(e.detail);
24
- }
25
-
26
- private dispatchFacetClickEvent(detail: FacetEventDetails) {
27
- const event = new CustomEvent<FacetEventDetails>('facetClick', {
28
- detail,
29
- composed: true,
30
- });
31
- this.dispatchEvent(event);
32
- }
33
-
34
- private get facetsTemplate(): TemplateResult | typeof nothing {
35
- const { facetGroup } = this;
36
- if (!facetGroup) return nothing;
37
-
38
- const facetBuckets = facetGroup.buckets as FacetBucket[];
39
- const isLoneBucket = facetBuckets.length === 1;
40
-
41
- // Added data-testid for Playwright testing
42
- // Using className and aria-labels is not ideal for Playwright locator
43
- return html`
44
- <div class="facet-rows" data-testid="facets-on-${facetGroup.key}">
45
- ${repeat(
46
- facetBuckets,
47
- bucket => `${facetGroup.key}:${bucket.key}`,
48
- bucket =>
49
- html`<facet-row
50
- .facetType=${facetGroup.key}
51
- .bucket=${bucket}
52
- .collectionTitles=${this.collectionTitles}
53
- ?omitHideButton=${isLoneBucket}
54
- @facetClick=${this.facetClicked}
55
- ></facet-row>`,
56
- )}
57
- </div>
58
- `;
59
- }
60
-
61
- render() {
62
- return html`${this.facetsTemplate}`;
63
- }
64
-
65
- static get styles(): CSSResultGroup {
66
- const columnCount = css`var(--facetsColumnCount, 1)`;
67
- const columnGap = css`var(--facetsColumnGap, 15px)`;
68
-
69
- return css`
70
- .facet-rows {
71
- column-count: ${columnCount};
72
- column-gap: ${columnGap};
73
- }
74
-
75
- a:link,
76
- a:visited {
77
- text-decoration: none;
78
- color: var(--ia-theme-link-color, #4b64ff);
79
- }
80
- a:hover {
81
- text-decoration: underline;
82
- }
83
- `;
84
- }
85
- }
1
+ import {
2
+ css,
3
+ html,
4
+ LitElement,
5
+ TemplateResult,
6
+ CSSResultGroup,
7
+ nothing,
8
+ } from 'lit';
9
+ import { customElement, property } from 'lit/decorators.js';
10
+ import { repeat } from 'lit/directives/repeat.js';
11
+ import type { FacetGroup, FacetBucket, FacetEventDetails } from '../models';
12
+ import type { CollectionTitles } from '../data-source/models';
13
+ import './facet-row';
14
+
15
+ @customElement('facets-template')
16
+ export class FacetsTemplate extends LitElement {
17
+ @property({ type: Object }) facetGroup?: FacetGroup;
18
+
19
+ @property({ type: Object })
20
+ collectionTitles?: CollectionTitles;
21
+
22
+ private facetClicked(e: CustomEvent<FacetEventDetails>) {
23
+ this.dispatchFacetClickEvent(e.detail);
24
+ }
25
+
26
+ private dispatchFacetClickEvent(detail: FacetEventDetails) {
27
+ const event = new CustomEvent<FacetEventDetails>('facetClick', {
28
+ detail,
29
+ composed: true,
30
+ });
31
+ this.dispatchEvent(event);
32
+ }
33
+
34
+ private get facetsTemplate(): TemplateResult | typeof nothing {
35
+ const { facetGroup } = this;
36
+ if (!facetGroup) return nothing;
37
+
38
+ const facetBuckets = facetGroup.buckets as FacetBucket[];
39
+ const isLoneBucket = facetBuckets.length === 1;
40
+
41
+ // Added data-testid for Playwright testing
42
+ // Using className and aria-labels is not ideal for Playwright locator
43
+ return html`
44
+ <div class="facet-rows" data-testid="facets-on-${facetGroup.key}">
45
+ ${repeat(
46
+ facetBuckets,
47
+ bucket => `${facetGroup.key}:${bucket.key}`,
48
+ bucket =>
49
+ html`<facet-row
50
+ .facetType=${facetGroup.key}
51
+ .bucket=${bucket}
52
+ .collectionTitles=${this.collectionTitles}
53
+ ?omitHideButton=${isLoneBucket}
54
+ @facetClick=${this.facetClicked}
55
+ ></facet-row>`,
56
+ )}
57
+ </div>
58
+ `;
59
+ }
60
+
61
+ render() {
62
+ return html`${this.facetsTemplate}`;
63
+ }
64
+
65
+ static get styles(): CSSResultGroup {
66
+ const columnCount = css`var(--facetsColumnCount, 1)`;
67
+ const columnGap = css`var(--facetsColumnGap, 15px)`;
68
+
69
+ return css`
70
+ .facet-rows {
71
+ column-count: ${columnCount};
72
+ column-gap: ${columnGap};
73
+ }
74
+
75
+ a:link,
76
+ a:visited {
77
+ text-decoration: none;
78
+ color: var(--ia-theme-link-color, #4b64ff);
79
+ }
80
+ a:hover {
81
+ text-decoration: underline;
82
+ }
83
+ `;
84
+ }
85
+ }
@@ -71,6 +71,12 @@ export interface CollectionBrowserDataSourceInterface
71
71
  */
72
72
  readonly pageSpecifierParams: PageSpecifierParams | null;
73
73
 
74
+ /**
75
+ * The Lucene query clause corresponding to the current date range,
76
+ * e.g. `year:[2000 TO 2020]` or `date:[2020-01 TO 2020-12]`.
77
+ */
78
+ readonly dateRangeQueryClause: string | undefined;
79
+
74
80
  /**
75
81
  * A FilterMap object representing all filters applied to the current search,
76
82
  * including any facets, letter filters, and date ranges.
@@ -33,6 +33,7 @@ import type { CollectionBrowserDataSourceInterface } from './collection-browser-
33
33
  import type { CollectionBrowserSearchInterface } from './collection-browser-query-state';
34
34
  import { sha1 } from '../utils/sha1';
35
35
  import { mergeSelectedFacets } from '../utils/facet-utils';
36
+ import { dateFilterField } from '../utils/date-filter-field';
36
37
 
37
38
  export class CollectionBrowserDataSource
38
39
  implements CollectionBrowserDataSourceInterface
@@ -746,7 +747,10 @@ export class CollectionBrowserDataSource
746
747
  selectedCreatorFilter,
747
748
  } = this.host;
748
749
 
749
- const dateField = this.host.searchType === SearchType.TV ? 'date' : 'year';
750
+ const dateField = dateFilterField(
751
+ this.host.minSelectedDate,
752
+ this.host.maxSelectedDate,
753
+ );
750
754
 
751
755
  if (minSelectedDate) {
752
756
  builder.addFilter(
@@ -901,12 +905,16 @@ export class CollectionBrowserDataSource
901
905
  return this.joinFacetClauses(facetClauses)?.trim();
902
906
  }
903
907
 
904
- private get dateRangeQueryClause(): string | undefined {
908
+ get dateRangeQueryClause(): string | undefined {
905
909
  if (!this.host.minSelectedDate || !this.host.maxSelectedDate) {
906
910
  return undefined;
907
911
  }
908
912
 
909
- return `year:[${this.host.minSelectedDate} TO ${this.host.maxSelectedDate}]`;
913
+ const dateField = dateFilterField(
914
+ this.host.minSelectedDate,
915
+ this.host.maxSelectedDate,
916
+ );
917
+ return `${dateField}:[${this.host.minSelectedDate} TO ${this.host.maxSelectedDate}]`;
910
918
  }
911
919
 
912
920
  private get sortFilterQueries(): string {
@@ -1069,10 +1077,11 @@ export class CollectionBrowserDataSource
1069
1077
  success.response;
1070
1078
  this.aggregations = aggregations;
1071
1079
 
1072
- this.histogramAggregation =
1073
- this.host.searchType === SearchType.TV
1074
- ? aggregations?.date_histogram
1075
- : aggregations?.year_histogram;
1080
+ const useDateHistogram =
1081
+ this.host.searchType === SearchType.TV || this.host.isTVCollection;
1082
+ this.histogramAggregation = useDateHistogram
1083
+ ? (aggregations?.date_histogram ?? aggregations?.year_histogram)
1084
+ : aggregations?.year_histogram;
1076
1085
 
1077
1086
  if (collectionTitles) {
1078
1087
  for (const [id, title] of Object.entries(collectionTitles)) {
@@ -14,6 +14,7 @@ import {
14
14
  tvClipURLParamsToFilters,
15
15
  } from './models';
16
16
  import { arrayEquals } from './utils/array-equals';
17
+ import { dateFilterField } from './utils/date-filter-field';
17
18
 
18
19
  export interface RestorationState {
19
20
  displayMode?: CollectionDisplayMode;
@@ -190,11 +191,10 @@ export class RestorationStateHandler
190
191
  }
191
192
  }
192
193
 
193
- const dateField =
194
- state.minSelectedDate?.includes('-') ||
195
- state.maxSelectedDate?.includes('-')
196
- ? 'date'
197
- : 'year';
194
+ const dateField = dateFilterField(
195
+ state.minSelectedDate,
196
+ state.maxSelectedDate,
197
+ );
198
198
 
199
199
  if (state.minSelectedDate && state.maxSelectedDate) {
200
200
  newParams.append(
@@ -1,59 +1,59 @@
1
- import { css } from 'lit';
2
-
3
- /**
4
- * Shared styles for tile action buttons rendered in grid, list-detail, and
5
- * list-compact display modes. Layout positioning is handled by each tile
6
- * component; these styles cover only the button appearance and the row
7
- * container's default flex behavior.
8
- *
9
- * Customizable via CSS custom properties:
10
- * - `--tileActionColor` (defaults to --primaryErrorCTAFill, then #d9534f)
11
- * - `--tileActionBg` (default: #fff)
12
- * - `--tileActionBorderColor` (defaults to --primaryErrorCTAFill, then #d9534f)
13
- * - `--tileActionHoverBg` (defaults to --primaryErrorCTAFillRGB at 20% alpha)
14
- * - `--tileActionHoverColor` (defaults to --tileActionColor)
15
- */
16
- export const tileActionStyles = css`
17
- .tile-actions {
18
- flex-shrink: 0;
19
- display: flex;
20
- gap: var(--tileActionGap, 0);
21
- }
22
-
23
- .tile-action-btn {
24
- flex: 1;
25
- padding: 6px 5px;
26
- border: 2px solid
27
- var(--tileActionBorderColor, var(--primaryErrorCTAFill, #d9534f));
28
- border-radius: var(--tileActionBorderRadius, 0);
29
- /* Inherit from the surrounding tile rather than the UA default for <button> */
30
- font-family: inherit;
31
- font-size: 1.2rem;
32
- font-weight: bold;
33
- cursor: pointer;
34
- color: var(--tileActionColor, var(--primaryErrorCTAFill, #d9534f));
35
- background: var(--tileActionBg, #fff);
36
- transition:
37
- background 0.15s,
38
- color 0.15s;
39
- }
40
-
41
- /*
42
- * When buttons are flush against each other (no gap), overlap their shared
43
- * edge by 1px so adjacent borders don't double up.
44
- */
45
- .tile-action-btn + .tile-action-btn {
46
- margin-left: -1px;
47
- }
48
-
49
- .tile-action-btn:hover {
50
- background: var(
51
- --tileActionHoverBg,
52
- rgba(var(--primaryErrorCTAFillRGB, 229, 28, 38), 0.2)
53
- );
54
- color: var(
55
- --tileActionHoverColor,
56
- var(--tileActionColor, var(--primaryErrorCTAFill, #d9534f))
57
- );
58
- }
59
- `;
1
+ import { css } from 'lit';
2
+
3
+ /**
4
+ * Shared styles for tile action buttons rendered in grid, list-detail, and
5
+ * list-compact display modes. Layout positioning is handled by each tile
6
+ * component; these styles cover only the button appearance and the row
7
+ * container's default flex behavior.
8
+ *
9
+ * Customizable via CSS custom properties:
10
+ * - `--tileActionColor` (defaults to --primaryErrorCTAFill, then #d9534f)
11
+ * - `--tileActionBg` (default: #fff)
12
+ * - `--tileActionBorderColor` (defaults to --primaryErrorCTAFill, then #d9534f)
13
+ * - `--tileActionHoverBg` (defaults to --primaryErrorCTAFillRGB at 20% alpha)
14
+ * - `--tileActionHoverColor` (defaults to --tileActionColor)
15
+ */
16
+ export const tileActionStyles = css`
17
+ .tile-actions {
18
+ flex-shrink: 0;
19
+ display: flex;
20
+ gap: var(--tileActionGap, 0);
21
+ }
22
+
23
+ .tile-action-btn {
24
+ flex: 1;
25
+ padding: 6px 5px;
26
+ border: 2px solid
27
+ var(--tileActionBorderColor, var(--primaryErrorCTAFill, #d9534f));
28
+ border-radius: var(--tileActionBorderRadius, 0);
29
+ /* Inherit from the surrounding tile rather than the UA default for <button> */
30
+ font-family: inherit;
31
+ font-size: 1.2rem;
32
+ font-weight: bold;
33
+ cursor: pointer;
34
+ color: var(--tileActionColor, var(--primaryErrorCTAFill, #d9534f));
35
+ background: var(--tileActionBg, #fff);
36
+ transition:
37
+ background 0.15s,
38
+ color 0.15s;
39
+ }
40
+
41
+ /*
42
+ * When buttons are flush against each other (no gap), overlap their shared
43
+ * edge by 1px so adjacent borders don't double up.
44
+ */
45
+ .tile-action-btn + .tile-action-btn {
46
+ margin-left: -1px;
47
+ }
48
+
49
+ .tile-action-btn:hover {
50
+ background: var(
51
+ --tileActionHoverBg,
52
+ rgba(var(--primaryErrorCTAFillRGB, 229, 28, 38), 0.2)
53
+ );
54
+ color: var(
55
+ --tileActionHoverColor,
56
+ var(--tileActionColor, var(--primaryErrorCTAFill, #d9534f))
57
+ );
58
+ }
59
+ `;
@@ -1,124 +1,124 @@
1
- import { html, LitElement, nothing, PropertyValues, TemplateResult } from 'lit';
2
- import { property } from 'lit/decorators.js';
3
- import { classMap } from 'lit/directives/class-map.js';
4
- import type { SortParam } from '@internetarchive/search-service';
5
- import { TileDisplayValueProvider } from './tile-display-value-provider';
6
- import type { TileModel } from '../models';
7
- import { DateFormat, formatDate } from '../utils/format-date';
8
- import type { TileAction } from './models';
9
-
10
- export abstract class BaseTileComponent extends LitElement {
11
- @property({ type: Object }) model?: TileModel;
12
-
13
- /** Action buttons to display on this tile (rendered by subclasses) */
14
- @property({ type: Array }) tileActions: TileAction[] = [];
15
-
16
- @property({ type: Number }) currentWidth?: number;
17
-
18
- @property({ type: Number }) currentHeight?: number;
19
-
20
- @property({ type: String }) baseNavigationUrl?: string;
21
-
22
- @property({ type: String }) baseImageUrl?: string;
23
-
24
- @property({ type: String }) collectionPagePath?: string;
25
-
26
- @property({ type: Object }) sortParam: SortParam | null = null;
27
-
28
- @property({ type: Object }) defaultSortParam: SortParam | null = null;
29
-
30
- @property({ type: String }) creatorFilter?: string;
31
-
32
- @property({ type: Number }) mobileBreakpoint?: number;
33
-
34
- @property({ type: Boolean }) loggedIn = false;
35
-
36
- @property({ type: Boolean }) suppressBlurring = false;
37
-
38
- @property({ type: Boolean }) useLocalTime = false;
39
-
40
- protected displayValueProvider = new TileDisplayValueProvider();
41
-
42
- protected willUpdate(changed: PropertyValues<this>) {
43
- // Ensure the TileDisplayValueProvider stays up-to-date as properties change
44
- if (
45
- changed.has('model') ||
46
- changed.has('baseNavigationUrl') ||
47
- changed.has('collectionPagePath') ||
48
- changed.has('sortParam') ||
49
- changed.has('defaultSortParam') ||
50
- changed.has('creatorFilter')
51
- ) {
52
- this.displayValueProvider = new TileDisplayValueProvider({
53
- model: this.model,
54
- baseNavigationUrl: this.baseNavigationUrl,
55
- collectionPagePath: this.collectionPagePath,
56
- sortParam: this.sortParam ?? this.defaultSortParam ?? undefined,
57
- creatorFilter: this.creatorFilter,
58
- });
59
- }
60
- }
61
-
62
- /**
63
- * The formatted date string for given date and format type, taking into
64
- * account whether this tile component should be using local time or UTC.
65
- */
66
- protected getFormattedDate(date?: Date, format?: DateFormat): string {
67
- const { useLocalTime } = this;
68
- return formatDate(date, format, { useLocalTime });
69
- }
70
-
71
- /**
72
- * Renders the action buttons configured for this tile, or `nothing` if
73
- * there are none. Optional `extraClass` is appended to the container's
74
- * class list so subclasses can target their own layout tweaks.
75
- */
76
- protected renderTileActions(
77
- extraClass: string = '',
78
- ): TemplateResult | typeof nothing {
79
- if (!this.tileActions.length) return nothing;
80
-
81
- const containerClasses = classMap({
82
- 'tile-actions': true,
83
- ...(extraClass && { [extraClass]: true }),
84
- });
85
-
86
- return html`
87
- <div class=${containerClasses}>
88
- ${this.tileActions.map(
89
- action => html`
90
- <button
91
- class="tile-action-btn"
92
- @click=${(e: Event) => this.handleTileActionClick(e, action)}
93
- >
94
- ${action.label}
95
- </button>
96
- `,
97
- )}
98
- </div>
99
- `;
100
- }
101
-
102
- /**
103
- * Click handler for tile action buttons. Stops propagation so the click
104
- * doesn't activate a wrapping tile link, and dispatches a
105
- * `tileActionClicked` event (bubbling + composed) carrying the action ID
106
- * and the tile model.
107
- */
108
- protected handleTileActionClick(e: Event, action: TileAction): void {
109
- e.preventDefault();
110
- e.stopPropagation();
111
- // Pre-set the hover pane controller's clicking flag so that focus
112
- // restoration after a consumer-opened modal won't trigger the hover pane.
113
- this.dispatchEvent(
114
- new PointerEvent('pointerdown', { bubbles: true, composed: true }),
115
- );
116
- this.dispatchEvent(
117
- new CustomEvent('tileActionClicked', {
118
- detail: { actionId: action.id, model: this.model },
119
- bubbles: true,
120
- composed: true,
121
- }),
122
- );
123
- }
124
- }
1
+ import { html, LitElement, nothing, PropertyValues, TemplateResult } from 'lit';
2
+ import { property } from 'lit/decorators.js';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import type { SortParam } from '@internetarchive/search-service';
5
+ import { TileDisplayValueProvider } from './tile-display-value-provider';
6
+ import type { TileModel } from '../models';
7
+ import { DateFormat, formatDate } from '../utils/format-date';
8
+ import type { TileAction } from './models';
9
+
10
+ export abstract class BaseTileComponent extends LitElement {
11
+ @property({ type: Object }) model?: TileModel;
12
+
13
+ /** Action buttons to display on this tile (rendered by subclasses) */
14
+ @property({ type: Array }) tileActions: TileAction[] = [];
15
+
16
+ @property({ type: Number }) currentWidth?: number;
17
+
18
+ @property({ type: Number }) currentHeight?: number;
19
+
20
+ @property({ type: String }) baseNavigationUrl?: string;
21
+
22
+ @property({ type: String }) baseImageUrl?: string;
23
+
24
+ @property({ type: String }) collectionPagePath?: string;
25
+
26
+ @property({ type: Object }) sortParam: SortParam | null = null;
27
+
28
+ @property({ type: Object }) defaultSortParam: SortParam | null = null;
29
+
30
+ @property({ type: String }) creatorFilter?: string;
31
+
32
+ @property({ type: Number }) mobileBreakpoint?: number;
33
+
34
+ @property({ type: Boolean }) loggedIn = false;
35
+
36
+ @property({ type: Boolean }) suppressBlurring = false;
37
+
38
+ @property({ type: Boolean }) useLocalTime = false;
39
+
40
+ protected displayValueProvider = new TileDisplayValueProvider();
41
+
42
+ protected willUpdate(changed: PropertyValues<this>) {
43
+ // Ensure the TileDisplayValueProvider stays up-to-date as properties change
44
+ if (
45
+ changed.has('model') ||
46
+ changed.has('baseNavigationUrl') ||
47
+ changed.has('collectionPagePath') ||
48
+ changed.has('sortParam') ||
49
+ changed.has('defaultSortParam') ||
50
+ changed.has('creatorFilter')
51
+ ) {
52
+ this.displayValueProvider = new TileDisplayValueProvider({
53
+ model: this.model,
54
+ baseNavigationUrl: this.baseNavigationUrl,
55
+ collectionPagePath: this.collectionPagePath,
56
+ sortParam: this.sortParam ?? this.defaultSortParam ?? undefined,
57
+ creatorFilter: this.creatorFilter,
58
+ });
59
+ }
60
+ }
61
+
62
+ /**
63
+ * The formatted date string for given date and format type, taking into
64
+ * account whether this tile component should be using local time or UTC.
65
+ */
66
+ protected getFormattedDate(date?: Date, format?: DateFormat): string {
67
+ const { useLocalTime } = this;
68
+ return formatDate(date, format, { useLocalTime });
69
+ }
70
+
71
+ /**
72
+ * Renders the action buttons configured for this tile, or `nothing` if
73
+ * there are none. Optional `extraClass` is appended to the container's
74
+ * class list so subclasses can target their own layout tweaks.
75
+ */
76
+ protected renderTileActions(
77
+ extraClass: string = '',
78
+ ): TemplateResult | typeof nothing {
79
+ if (!this.tileActions.length) return nothing;
80
+
81
+ const containerClasses = classMap({
82
+ 'tile-actions': true,
83
+ ...(extraClass && { [extraClass]: true }),
84
+ });
85
+
86
+ return html`
87
+ <div class=${containerClasses}>
88
+ ${this.tileActions.map(
89
+ action => html`
90
+ <button
91
+ class="tile-action-btn"
92
+ @click=${(e: Event) => this.handleTileActionClick(e, action)}
93
+ >
94
+ ${action.label}
95
+ </button>
96
+ `,
97
+ )}
98
+ </div>
99
+ `;
100
+ }
101
+
102
+ /**
103
+ * Click handler for tile action buttons. Stops propagation so the click
104
+ * doesn't activate a wrapping tile link, and dispatches a
105
+ * `tileActionClicked` event (bubbling + composed) carrying the action ID
106
+ * and the tile model.
107
+ */
108
+ protected handleTileActionClick(e: Event, action: TileAction): void {
109
+ e.preventDefault();
110
+ e.stopPropagation();
111
+ // Pre-set the hover pane controller's clicking flag so that focus
112
+ // restoration after a consumer-opened modal won't trigger the hover pane.
113
+ this.dispatchEvent(
114
+ new PointerEvent('pointerdown', { bubbles: true, composed: true }),
115
+ );
116
+ this.dispatchEvent(
117
+ new CustomEvent('tileActionClicked', {
118
+ detail: { actionId: action.id, model: this.model },
119
+ bubbles: true,
120
+ composed: true,
121
+ }),
122
+ );
123
+ }
124
+ }