@internetarchive/collection-browser 4.4.0 → 4.5.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 (68) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js.map +1 -1
  3. package/dist/src/app-root.d.ts +8 -0
  4. package/dist/src/app-root.js +26 -0
  5. package/dist/src/app-root.js.map +1 -1
  6. package/dist/src/collection-browser.d.ts +8 -0
  7. package/dist/src/collection-browser.js +19 -1
  8. package/dist/src/collection-browser.js.map +1 -1
  9. package/dist/src/collection-facets/facet-row.d.ts +6 -0
  10. package/dist/src/collection-facets/facet-row.js +158 -140
  11. package/dist/src/collection-facets/facet-row.js.map +1 -1
  12. package/dist/src/collection-facets/facets-template.js +25 -23
  13. package/dist/src/collection-facets/facets-template.js.map +1 -1
  14. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  15. package/dist/src/styles/tile-action-styles.d.ts +14 -0
  16. package/dist/src/styles/tile-action-styles.js +59 -0
  17. package/dist/src/styles/tile-action-styles.js.map +1 -0
  18. package/dist/src/tiles/base-tile-component.d.ts +17 -1
  19. package/dist/src/tiles/base-tile-component.js +50 -1
  20. package/dist/src/tiles/base-tile-component.js.map +1 -1
  21. package/dist/src/tiles/grid/item-tile.js +139 -138
  22. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  23. package/dist/src/tiles/item-image.js +28 -28
  24. package/dist/src/tiles/item-image.js.map +1 -1
  25. package/dist/src/tiles/list/tile-list-compact-header.js +71 -46
  26. package/dist/src/tiles/list/tile-list-compact-header.js.map +1 -1
  27. package/dist/src/tiles/list/tile-list-compact.d.ts +1 -1
  28. package/dist/src/tiles/list/tile-list-compact.js +138 -100
  29. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  30. package/dist/src/tiles/list/tile-list.d.ts +1 -1
  31. package/dist/src/tiles/list/tile-list.js +316 -298
  32. package/dist/src/tiles/list/tile-list.js.map +1 -1
  33. package/dist/src/tiles/models.d.ts +11 -0
  34. package/dist/src/tiles/models.js.map +1 -1
  35. package/dist/src/tiles/tile-dispatcher.d.ts +14 -0
  36. package/dist/src/tiles/tile-dispatcher.js +319 -216
  37. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  38. package/dist/src/tiles/tile-display-value-provider.js +2 -1
  39. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  40. package/dist/test/collection-facets/facet-row.test.js +55 -23
  41. package/dist/test/collection-facets/facet-row.test.js.map +1 -1
  42. package/dist/test/tiles/grid/item-tile.test.js +79 -79
  43. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  44. package/dist/test/tiles/list/tile-list.test.js +136 -136
  45. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  46. package/dist/test/tiles/tile-dispatcher.test.js +101 -87
  47. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  48. package/index.ts +29 -28
  49. package/package.json +2 -2
  50. package/src/app-root.ts +30 -0
  51. package/src/collection-browser.ts +16 -1
  52. package/src/collection-facets/facet-row.ts +309 -299
  53. package/src/collection-facets/facets-template.ts +85 -83
  54. package/src/data-source/collection-browser-data-source.ts +1465 -1465
  55. package/src/styles/tile-action-styles.ts +59 -0
  56. package/src/tiles/base-tile-component.ts +124 -65
  57. package/src/tiles/grid/item-tile.ts +347 -346
  58. package/src/tiles/item-image.ts +214 -214
  59. package/src/tiles/list/tile-list-compact-header.ts +112 -86
  60. package/src/tiles/list/tile-list-compact.ts +278 -239
  61. package/src/tiles/list/tile-list.ts +718 -700
  62. package/src/tiles/models.ts +21 -8
  63. package/src/tiles/tile-dispatcher.ts +637 -527
  64. package/src/tiles/tile-display-value-provider.ts +133 -134
  65. package/test/collection-facets/facet-row.test.ts +421 -375
  66. package/test/tiles/grid/item-tile.test.ts +520 -520
  67. package/test/tiles/list/tile-list.test.ts +576 -576
  68. package/test/tiles/tile-dispatcher.test.ts +320 -300
@@ -0,0 +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,65 +1,124 @@
1
- import { LitElement, PropertyValues } from 'lit';
2
- import { property } from 'lit/decorators.js';
3
- import type { SortParam } from '@internetarchive/search-service';
4
- import { TileDisplayValueProvider } from './tile-display-value-provider';
5
- import type { TileModel } from '../models';
6
- import { DateFormat, formatDate } from '../utils/format-date';
7
-
8
- export abstract class BaseTileComponent extends LitElement {
9
- @property({ type: Object }) model?: TileModel;
10
-
11
- @property({ type: Number }) currentWidth?: number;
12
-
13
- @property({ type: Number }) currentHeight?: number;
14
-
15
- @property({ type: String }) baseNavigationUrl?: string;
16
-
17
- @property({ type: String }) baseImageUrl?: string;
18
-
19
- @property({ type: String }) collectionPagePath?: string;
20
-
21
- @property({ type: Object }) sortParam: SortParam | null = null;
22
-
23
- @property({ type: Object }) defaultSortParam: SortParam | null = null;
24
-
25
- @property({ type: String }) creatorFilter?: string;
26
-
27
- @property({ type: Number }) mobileBreakpoint?: number;
28
-
29
- @property({ type: Boolean }) loggedIn = false;
30
-
31
- @property({ type: Boolean }) suppressBlurring = false;
32
-
33
- @property({ type: Boolean }) useLocalTime = false;
34
-
35
- protected displayValueProvider = new TileDisplayValueProvider();
36
-
37
- protected willUpdate(changed: PropertyValues<this>) {
38
- // Ensure the TileDisplayValueProvider stays up-to-date as properties change
39
- if (
40
- changed.has('model') ||
41
- changed.has('baseNavigationUrl') ||
42
- changed.has('collectionPagePath') ||
43
- changed.has('sortParam') ||
44
- changed.has('defaultSortParam') ||
45
- changed.has('creatorFilter')
46
- ) {
47
- this.displayValueProvider = new TileDisplayValueProvider({
48
- model: this.model,
49
- baseNavigationUrl: this.baseNavigationUrl,
50
- collectionPagePath: this.collectionPagePath,
51
- sortParam: this.sortParam ?? this.defaultSortParam ?? undefined,
52
- creatorFilter: this.creatorFilter,
53
- });
54
- }
55
- }
56
-
57
- /**
58
- * The formatted date string for given date and format type, taking into
59
- * account whether this tile component should be using local time or UTC.
60
- */
61
- protected getFormattedDate(date?: Date, format?: DateFormat): string {
62
- const { useLocalTime } = this;
63
- return formatDate(date, format, { useLocalTime });
64
- }
65
- }
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
+ }