@internetarchive/collection-browser 3.0.0 → 3.0.1-webdev-7936.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.
- package/.editorconfig +29 -29
- package/.github/workflows/ci.yml +27 -27
- package/.github/workflows/gh-pages-main.yml +39 -39
- package/.github/workflows/npm-publish.yml +39 -39
- package/.github/workflows/pr-preview.yml +38 -38
- package/.husky/pre-commit +4 -4
- package/.prettierignore +1 -1
- package/LICENSE +661 -661
- package/README.md +83 -83
- package/dist/src/collection-browser.js +681 -680
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/collection-facets/facet-row.js +131 -130
- package/dist/src/collection-facets/facet-row.js.map +1 -1
- package/dist/src/collection-facets/smart-facets/smart-facet-bar.js +75 -75
- package/dist/src/collection-facets/smart-facets/smart-facet-bar.js.map +1 -1
- package/dist/src/collection-facets.js +264 -263
- package/dist/src/collection-facets.js.map +1 -1
- package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
- package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
- package/dist/src/data-source/models.js.map +1 -1
- package/dist/src/models.js.map +1 -1
- package/dist/src/restoration-state-handler.js.map +1 -1
- package/dist/src/sort-filter-bar/sort-filter-bar.js +1 -1
- package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
- package/dist/src/tiles/base-tile-component.js.map +1 -1
- package/dist/src/tiles/grid/collection-tile.js +3 -2
- package/dist/src/tiles/grid/collection-tile.js.map +1 -1
- package/dist/src/tiles/grid/item-tile.js +139 -139
- package/dist/src/tiles/grid/item-tile.js.map +1 -1
- package/dist/src/tiles/grid/search-tile.js +3 -2
- package/dist/src/tiles/grid/search-tile.js.map +1 -1
- package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js +2 -1
- package/dist/src/tiles/grid/styles/tile-grid-shared-styles.js.map +1 -1
- package/dist/src/tiles/hover/hover-pane-controller.js +21 -21
- package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -1
- package/dist/src/tiles/hover/tile-hover-pane.js +108 -108
- package/dist/src/tiles/hover/tile-hover-pane.js.map +1 -1
- package/dist/src/tiles/list/tile-list-compact-header.js +45 -45
- package/dist/src/tiles/list/tile-list-compact-header.js.map +1 -1
- package/dist/src/tiles/list/tile-list-compact.js +97 -97
- package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
- package/dist/src/tiles/list/tile-list.js +300 -290
- package/dist/src/tiles/list/tile-list.js.map +1 -1
- package/dist/src/tiles/tile-dispatcher.js +200 -200
- package/dist/src/tiles/tile-dispatcher.js.map +1 -1
- package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
- package/dist/test/collection-browser.test.js +183 -183
- package/dist/test/collection-browser.test.js.map +1 -1
- package/dist/test/restoration-state-handler.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list.test.js +13 -0
- package/dist/test/tiles/list/tile-list.test.js.map +1 -1
- package/eslint.config.mjs +53 -53
- package/index.html +24 -24
- package/local.archive.org.cert +86 -86
- package/local.archive.org.key +27 -27
- package/package.json +117 -117
- package/renovate.json +6 -6
- package/src/collection-browser.ts +2776 -2775
- package/src/collection-facets/facet-row.ts +283 -282
- package/src/collection-facets/smart-facets/smart-facet-bar.ts +437 -437
- package/src/collection-facets.ts +991 -990
- package/src/data-source/collection-browser-data-source.ts +1390 -1390
- package/src/data-source/collection-browser-query-state.ts +63 -63
- package/src/data-source/models.ts +43 -43
- package/src/models.ts +870 -870
- package/src/restoration-state-handler.ts +544 -544
- package/src/sort-filter-bar/sort-filter-bar.ts +1 -1
- package/src/tiles/base-tile-component.ts +53 -53
- package/src/tiles/grid/collection-tile.ts +3 -2
- package/src/tiles/grid/item-tile.ts +339 -339
- package/src/tiles/grid/search-tile.ts +3 -2
- package/src/tiles/grid/styles/tile-grid-shared-styles.ts +2 -1
- package/src/tiles/hover/hover-pane-controller.ts +517 -517
- package/src/tiles/hover/tile-hover-pane.ts +180 -180
- package/src/tiles/list/tile-list-compact-header.ts +86 -86
- package/src/tiles/list/tile-list-compact.ts +236 -236
- package/src/tiles/list/tile-list.ts +696 -688
- package/src/tiles/tile-dispatcher.ts +486 -486
- package/src/tiles/tile-display-value-provider.ts +124 -124
- package/test/collection-browser.test.ts +2340 -2340
- package/test/restoration-state-handler.test.ts +510 -510
- package/test/tiles/list/tile-list.test.ts +15 -0
- package/tsconfig.json +20 -20
- package/web-dev-server.config.mjs +30 -30
- package/web-test-runner.config.mjs +41 -41
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
import { TemplateResult, html, nothing } from 'lit';
|
|
2
|
-
import { msg, str } from '@lit/localize';
|
|
3
|
-
import type { SortParam } from '@internetarchive/search-service';
|
|
4
|
-
import type { TileModel } from '../models';
|
|
5
|
-
import { formatDate } from '../utils/format-date';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A class encapsulating shared logic for converting model values into display values
|
|
9
|
-
* across different types of tiles.
|
|
10
|
-
*/
|
|
11
|
-
export class TileDisplayValueProvider {
|
|
12
|
-
private model?: TileModel;
|
|
13
|
-
|
|
14
|
-
private baseNavigationUrl?: string;
|
|
15
|
-
|
|
16
|
-
private collectionPagePath?: string;
|
|
17
|
-
|
|
18
|
-
private sortParam?: SortParam;
|
|
19
|
-
|
|
20
|
-
private creatorFilter?: string;
|
|
21
|
-
|
|
22
|
-
constructor(
|
|
23
|
-
options: {
|
|
24
|
-
model?: TileModel;
|
|
25
|
-
baseNavigationUrl?: string;
|
|
26
|
-
collectionPagePath?: string;
|
|
27
|
-
sortParam?: SortParam;
|
|
28
|
-
creatorFilter?: string;
|
|
29
|
-
} = {},
|
|
30
|
-
) {
|
|
31
|
-
this.model = options.model;
|
|
32
|
-
this.baseNavigationUrl = options.baseNavigationUrl;
|
|
33
|
-
this.collectionPagePath = options.collectionPagePath ?? '/details/';
|
|
34
|
-
this.sortParam = options.sortParam;
|
|
35
|
-
this.creatorFilter = options.creatorFilter;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Examines the creator(s) for the given tile model, returning
|
|
40
|
-
* the first creator whose name matches the provided filter
|
|
41
|
-
* (or simply the first creator overall if no filter is provided).
|
|
42
|
-
*/
|
|
43
|
-
get firstCreatorMatchingFilter(): string | undefined {
|
|
44
|
-
let matchingCreator;
|
|
45
|
-
|
|
46
|
-
// If we're filtering by creator initial and have multiple creators, we want
|
|
47
|
-
// to surface the first creator who matches the filter.
|
|
48
|
-
if (this.creatorFilter && this.model?.creators.length) {
|
|
49
|
-
const firstLetter = this.creatorFilter; // This is just to satisfy tsc
|
|
50
|
-
matchingCreator = this.model.creators.find(creator =>
|
|
51
|
-
// Decompose combining characters first, so that e.g., filtering on E matches É too.
|
|
52
|
-
// Then remove anything that isn't strictly alphabetic, since our filters currently
|
|
53
|
-
// only handle A-Z. The first such letter (if one exists) is what needs to match.
|
|
54
|
-
creator
|
|
55
|
-
.normalize('NFD')
|
|
56
|
-
.replace(/[^A-Z]+/gi, '')
|
|
57
|
-
.toUpperCase()
|
|
58
|
-
.startsWith(firstLetter),
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return matchingCreator ?? this.model?.creator;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The label indicating what year an account item was created.
|
|
67
|
-
* E.g., "Archivist since 2015"
|
|
68
|
-
*/
|
|
69
|
-
get accountLabel(): string {
|
|
70
|
-
return this.model?.dateAdded
|
|
71
|
-
? msg(str`Archivist since ${this.model.dateAdded.getFullYear()}`)
|
|
72
|
-
: '';
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The readable label for the current sort if it is a type of date sort,
|
|
77
|
-
* or the empty string otherwise.
|
|
78
|
-
*/
|
|
79
|
-
get dateLabel(): string {
|
|
80
|
-
switch (this.sortParam?.field) {
|
|
81
|
-
case 'publicdate':
|
|
82
|
-
return msg('Archived');
|
|
83
|
-
case 'reviewdate':
|
|
84
|
-
return msg('Reviewed');
|
|
85
|
-
case 'addeddate':
|
|
86
|
-
return msg('Added');
|
|
87
|
-
case 'date':
|
|
88
|
-
return msg('Published');
|
|
89
|
-
default:
|
|
90
|
-
return '';
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Produces a URL pointing at the item page for the given identifier,
|
|
96
|
-
* using the current base URL and the correct path based on whether the
|
|
97
|
-
* item is specified to be a collection (default false).
|
|
98
|
-
*/
|
|
99
|
-
itemPageUrl(
|
|
100
|
-
identifier?: string,
|
|
101
|
-
isCollection = false,
|
|
102
|
-
): string | typeof nothing {
|
|
103
|
-
if (!identifier || this.baseNavigationUrl == null) return nothing;
|
|
104
|
-
const basePath = isCollection ? this.collectionPagePath : '/details/';
|
|
105
|
-
return `${this.baseNavigationUrl}${basePath}${identifier}`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Produces a template for a link to a single web capture of the given URL and date
|
|
110
|
-
*/
|
|
111
|
-
webArchivesCaptureLink(url: string, date: Date): TemplateResult {
|
|
112
|
-
// Convert the date into the format used to identify wayback captures (e.g., '20150102124550')
|
|
113
|
-
const captureDateStr = date
|
|
114
|
-
.toISOString()
|
|
115
|
-
.replace(/[TZ:-]/g, '')
|
|
116
|
-
.replace(/\..*/, '');
|
|
117
|
-
const captureHref = `https://web.archive.org/web/${captureDateStr}/${encodeURIComponent(
|
|
118
|
-
url,
|
|
119
|
-
)}`;
|
|
120
|
-
const captureText = formatDate(date, 'long');
|
|
121
|
-
|
|
122
|
-
return html` <a href=${captureHref}> ${captureText} </a> `;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
1
|
+
import { TemplateResult, html, nothing } from 'lit';
|
|
2
|
+
import { msg, str } from '@lit/localize';
|
|
3
|
+
import type { SortParam } from '@internetarchive/search-service';
|
|
4
|
+
import type { TileModel } from '../models';
|
|
5
|
+
import { formatDate } from '../utils/format-date';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A class encapsulating shared logic for converting model values into display values
|
|
9
|
+
* across different types of tiles.
|
|
10
|
+
*/
|
|
11
|
+
export class TileDisplayValueProvider {
|
|
12
|
+
private model?: TileModel;
|
|
13
|
+
|
|
14
|
+
private baseNavigationUrl?: string;
|
|
15
|
+
|
|
16
|
+
private collectionPagePath?: string;
|
|
17
|
+
|
|
18
|
+
private sortParam?: SortParam;
|
|
19
|
+
|
|
20
|
+
private creatorFilter?: string;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
options: {
|
|
24
|
+
model?: TileModel;
|
|
25
|
+
baseNavigationUrl?: string;
|
|
26
|
+
collectionPagePath?: string;
|
|
27
|
+
sortParam?: SortParam;
|
|
28
|
+
creatorFilter?: string;
|
|
29
|
+
} = {},
|
|
30
|
+
) {
|
|
31
|
+
this.model = options.model;
|
|
32
|
+
this.baseNavigationUrl = options.baseNavigationUrl;
|
|
33
|
+
this.collectionPagePath = options.collectionPagePath ?? '/details/';
|
|
34
|
+
this.sortParam = options.sortParam;
|
|
35
|
+
this.creatorFilter = options.creatorFilter;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Examines the creator(s) for the given tile model, returning
|
|
40
|
+
* the first creator whose name matches the provided filter
|
|
41
|
+
* (or simply the first creator overall if no filter is provided).
|
|
42
|
+
*/
|
|
43
|
+
get firstCreatorMatchingFilter(): string | undefined {
|
|
44
|
+
let matchingCreator;
|
|
45
|
+
|
|
46
|
+
// If we're filtering by creator initial and have multiple creators, we want
|
|
47
|
+
// to surface the first creator who matches the filter.
|
|
48
|
+
if (this.creatorFilter && this.model?.creators.length) {
|
|
49
|
+
const firstLetter = this.creatorFilter; // This is just to satisfy tsc
|
|
50
|
+
matchingCreator = this.model.creators.find(creator =>
|
|
51
|
+
// Decompose combining characters first, so that e.g., filtering on E matches É too.
|
|
52
|
+
// Then remove anything that isn't strictly alphabetic, since our filters currently
|
|
53
|
+
// only handle A-Z. The first such letter (if one exists) is what needs to match.
|
|
54
|
+
creator
|
|
55
|
+
.normalize('NFD')
|
|
56
|
+
.replace(/[^A-Z]+/gi, '')
|
|
57
|
+
.toUpperCase()
|
|
58
|
+
.startsWith(firstLetter),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return matchingCreator ?? this.model?.creator;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The label indicating what year an account item was created.
|
|
67
|
+
* E.g., "Archivist since 2015"
|
|
68
|
+
*/
|
|
69
|
+
get accountLabel(): string {
|
|
70
|
+
return this.model?.dateAdded
|
|
71
|
+
? msg(str`Archivist since ${this.model.dateAdded.getFullYear()}`)
|
|
72
|
+
: '';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The readable label for the current sort if it is a type of date sort,
|
|
77
|
+
* or the empty string otherwise.
|
|
78
|
+
*/
|
|
79
|
+
get dateLabel(): string {
|
|
80
|
+
switch (this.sortParam?.field) {
|
|
81
|
+
case 'publicdate':
|
|
82
|
+
return msg('Archived');
|
|
83
|
+
case 'reviewdate':
|
|
84
|
+
return msg('Reviewed');
|
|
85
|
+
case 'addeddate':
|
|
86
|
+
return msg('Added');
|
|
87
|
+
case 'date':
|
|
88
|
+
return msg('Published');
|
|
89
|
+
default:
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Produces a URL pointing at the item page for the given identifier,
|
|
96
|
+
* using the current base URL and the correct path based on whether the
|
|
97
|
+
* item is specified to be a collection (default false).
|
|
98
|
+
*/
|
|
99
|
+
itemPageUrl(
|
|
100
|
+
identifier?: string,
|
|
101
|
+
isCollection = false,
|
|
102
|
+
): string | typeof nothing {
|
|
103
|
+
if (!identifier || this.baseNavigationUrl == null) return nothing;
|
|
104
|
+
const basePath = isCollection ? this.collectionPagePath : '/details/';
|
|
105
|
+
return `${this.baseNavigationUrl}${basePath}${identifier}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Produces a template for a link to a single web capture of the given URL and date
|
|
110
|
+
*/
|
|
111
|
+
webArchivesCaptureLink(url: string, date: Date): TemplateResult {
|
|
112
|
+
// Convert the date into the format used to identify wayback captures (e.g., '20150102124550')
|
|
113
|
+
const captureDateStr = date
|
|
114
|
+
.toISOString()
|
|
115
|
+
.replace(/[TZ:-]/g, '')
|
|
116
|
+
.replace(/\..*/, '');
|
|
117
|
+
const captureHref = `https://web.archive.org/web/${captureDateStr}/${encodeURIComponent(
|
|
118
|
+
url,
|
|
119
|
+
)}`;
|
|
120
|
+
const captureText = formatDate(date, 'long');
|
|
121
|
+
|
|
122
|
+
return html` <a href=${captureHref}> ${captureText} </a> `;
|
|
123
|
+
}
|
|
124
|
+
}
|