@internetarchive/collection-browser 4.4.1 → 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 (79) 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 +1 -1
  7. package/.prettierignore +1 -1
  8. package/LICENSE +661 -661
  9. package/README.md +83 -83
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/src/app-root.d.ts +8 -0
  13. package/dist/src/app-root.js +698 -672
  14. package/dist/src/app-root.js.map +1 -1
  15. package/dist/src/collection-browser.d.ts +8 -0
  16. package/dist/src/collection-browser.js +782 -764
  17. package/dist/src/collection-browser.js.map +1 -1
  18. package/dist/src/collection-facets/facet-row.d.ts +6 -0
  19. package/dist/src/collection-facets/facet-row.js +158 -140
  20. package/dist/src/collection-facets/facet-row.js.map +1 -1
  21. package/dist/src/collection-facets/facets-template.js +25 -23
  22. package/dist/src/collection-facets/facets-template.js.map +1 -1
  23. package/dist/src/styles/tile-action-styles.d.ts +14 -0
  24. package/dist/src/styles/tile-action-styles.js +59 -0
  25. package/dist/src/styles/tile-action-styles.js.map +1 -0
  26. package/dist/src/tiles/base-tile-component.d.ts +17 -1
  27. package/dist/src/tiles/base-tile-component.js +50 -1
  28. package/dist/src/tiles/base-tile-component.js.map +1 -1
  29. package/dist/src/tiles/grid/item-tile.js +139 -138
  30. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  31. package/dist/src/tiles/list/tile-list-compact-header.js +71 -46
  32. package/dist/src/tiles/list/tile-list-compact-header.js.map +1 -1
  33. package/dist/src/tiles/list/tile-list-compact.d.ts +1 -1
  34. package/dist/src/tiles/list/tile-list-compact.js +138 -100
  35. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  36. package/dist/src/tiles/list/tile-list.d.ts +1 -1
  37. package/dist/src/tiles/list/tile-list.js +316 -298
  38. package/dist/src/tiles/list/tile-list.js.map +1 -1
  39. package/dist/src/tiles/models.d.ts +11 -0
  40. package/dist/src/tiles/models.js.map +1 -1
  41. package/dist/src/tiles/tile-dispatcher.d.ts +14 -0
  42. package/dist/src/tiles/tile-dispatcher.js +319 -216
  43. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  44. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  45. package/dist/test/collection-facets/facet-row.test.js +55 -23
  46. package/dist/test/collection-facets/facet-row.test.js.map +1 -1
  47. package/dist/test/tiles/grid/item-tile.test.js +77 -77
  48. package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
  49. package/dist/test/tiles/list/tile-list.test.js +134 -134
  50. package/dist/test/tiles/list/tile-list.test.js.map +1 -1
  51. package/dist/test/tiles/tile-dispatcher.test.js +92 -92
  52. package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
  53. package/eslint.config.mjs +53 -53
  54. package/index.html +24 -24
  55. package/index.ts +29 -28
  56. package/local.archive.org.cert +86 -86
  57. package/local.archive.org.key +27 -27
  58. package/package.json +120 -120
  59. package/renovate.json +6 -6
  60. package/src/app-root.ts +1284 -1254
  61. package/src/collection-browser.ts +3176 -3161
  62. package/src/collection-facets/facet-row.ts +309 -299
  63. package/src/collection-facets/facets-template.ts +85 -83
  64. package/src/styles/tile-action-styles.ts +59 -0
  65. package/src/tiles/base-tile-component.ts +124 -65
  66. package/src/tiles/grid/item-tile.ts +347 -346
  67. package/src/tiles/list/tile-list-compact-header.ts +112 -86
  68. package/src/tiles/list/tile-list-compact.ts +278 -239
  69. package/src/tiles/list/tile-list.ts +718 -700
  70. package/src/tiles/models.ts +21 -8
  71. package/src/tiles/tile-dispatcher.ts +637 -527
  72. package/src/tiles/tile-display-value-provider.ts +133 -133
  73. package/test/collection-facets/facet-row.test.ts +421 -375
  74. package/test/tiles/grid/item-tile.test.ts +520 -520
  75. package/test/tiles/list/tile-list.test.ts +576 -576
  76. package/test/tiles/tile-dispatcher.test.ts +320 -320
  77. package/tsconfig.json +25 -25
  78. package/web-dev-server.config.mjs +30 -30
  79. package/web-test-runner.config.mjs +52 -52
@@ -1,83 +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
-
40
- // Added data-testid for Playwright testing
41
- // Using className and aria-labels is not ideal for Playwright locator
42
- return html`
43
- <div class="facet-rows" data-testid="facets-on-${facetGroup.key}">
44
- ${repeat(
45
- facetBuckets,
46
- bucket => `${facetGroup.key}:${bucket.key}`,
47
- bucket =>
48
- html`<facet-row
49
- .facetType=${facetGroup.key}
50
- .bucket=${bucket}
51
- .collectionTitles=${this.collectionTitles}
52
- @facetClick=${this.facetClicked}
53
- ></facet-row>`,
54
- )}
55
- </div>
56
- `;
57
- }
58
-
59
- render() {
60
- return html`${this.facetsTemplate}`;
61
- }
62
-
63
- static get styles(): CSSResultGroup {
64
- const columnCount = css`var(--facetsColumnCount, 1)`;
65
- const columnGap = css`var(--facetsColumnGap, 15px)`;
66
-
67
- return css`
68
- .facet-rows {
69
- column-count: ${columnCount};
70
- column-gap: ${columnGap};
71
- }
72
-
73
- a:link,
74
- a:visited {
75
- text-decoration: none;
76
- color: var(--ia-theme-link-color, #4b64ff);
77
- }
78
- a:hover {
79
- text-decoration: underline;
80
- }
81
- `;
82
- }
83
- }
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
+ }
@@ -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
+ }