@internetarchive/collection-browser 3.3.1 → 3.3.3
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 +683 -683
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/collection-facets/more-facets-content.js +118 -118
- package/dist/src/collection-facets/more-facets-content.js.map +1 -1
- package/dist/src/collection-facets.js +265 -266
- 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/tiles/base-tile-component.js.map +1 -1
- package/dist/src/tiles/grid/account-tile.js +36 -36
- package/dist/src/tiles/grid/account-tile.js.map +1 -1
- package/dist/src/tiles/grid/collection-tile.js +77 -77
- package/dist/src/tiles/grid/collection-tile.js.map +1 -1
- package/dist/src/tiles/grid/item-tile.js +137 -137
- package/dist/src/tiles/grid/item-tile.js.map +1 -1
- package/dist/src/tiles/hover/hover-pane-controller.d.ts +9 -1
- package/dist/src/tiles/hover/hover-pane-controller.js +105 -37
- package/dist/src/tiles/hover/hover-pane-controller.js.map +1 -1
- package/dist/src/tiles/hover/tile-hover-pane.d.ts +1 -0
- package/dist/src/tiles/hover/tile-hover-pane.js +115 -112
- package/dist/src/tiles/hover/tile-hover-pane.js.map +1 -1
- package/dist/src/tiles/list/tile-list-compact.js +99 -99
- package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
- package/dist/src/tiles/list/tile-list.js +297 -297
- package/dist/src/tiles/list/tile-list.js.map +1 -1
- package/dist/src/tiles/tile-dispatcher.d.ts +4 -1
- package/dist/src/tiles/tile-dispatcher.js +231 -204
- package/dist/src/tiles/tile-dispatcher.js.map +1 -1
- package/dist/src/utils/format-date.js.map +1 -1
- package/dist/test/collection-browser.test.js +189 -189
- package/dist/test/collection-browser.test.js.map +1 -1
- package/dist/test/tiles/grid/item-tile.test.js +77 -77
- package/dist/test/tiles/grid/item-tile.test.js.map +1 -1
- package/dist/test/tiles/hover/hover-pane-controller.test.js +68 -21
- package/dist/test/tiles/hover/hover-pane-controller.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list-compact.test.js +70 -70
- package/dist/test/tiles/list/tile-list-compact.test.js.map +1 -1
- package/dist/test/tiles/list/tile-list.test.js +126 -126
- package/dist/test/tiles/list/tile-list.test.js.map +1 -1
- package/dist/test/tiles/tile-dispatcher.test.js +130 -52
- package/dist/test/tiles/tile-dispatcher.test.js.map +1 -1
- package/dist/test/utils/format-date.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 +118 -117
- package/renovate.json +6 -6
- package/src/collection-browser.ts +2829 -2829
- package/src/collection-facets/more-facets-content.ts +639 -639
- package/src/collection-facets.ts +994 -995
- package/src/data-source/collection-browser-data-source.ts +1401 -1401
- package/src/data-source/collection-browser-query-state.ts +65 -65
- package/src/data-source/models.ts +43 -43
- package/src/tiles/base-tile-component.ts +65 -65
- package/src/tiles/grid/account-tile.ts +113 -113
- package/src/tiles/grid/collection-tile.ts +163 -163
- package/src/tiles/grid/item-tile.ts +340 -340
- package/src/tiles/hover/hover-pane-controller.ts +613 -517
- package/src/tiles/hover/tile-hover-pane.ts +184 -180
- package/src/tiles/list/tile-list-compact.ts +239 -239
- package/src/tiles/list/tile-list.ts +700 -700
- package/src/tiles/tile-dispatcher.ts +517 -490
- package/src/utils/format-date.ts +62 -62
- package/test/collection-browser.test.ts +2403 -2403
- package/test/tiles/grid/item-tile.test.ts +520 -520
- package/test/tiles/hover/hover-pane-controller.test.ts +418 -353
- package/test/tiles/list/tile-list-compact.test.ts +282 -282
- package/test/tiles/list/tile-list.test.ts +552 -552
- package/test/tiles/tile-dispatcher.test.ts +283 -187
- package/test/utils/format-date.test.ts +89 -89
- package/tsconfig.json +20 -20
- package/web-dev-server.config.mjs +30 -30
- package/web-test-runner.config.mjs +41 -41
package/src/utils/format-date.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Display date
|
|
3
|
-
* Override browser timezone to always display same date as in data
|
|
4
|
-
*/
|
|
5
|
-
export type DateFormat =
|
|
6
|
-
| 'year-only' // 2020
|
|
7
|
-
| 'short' // Dec 2020
|
|
8
|
-
| 'long'; // Dec 20, 2020
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Extra options accepted by the `formatDate` function
|
|
12
|
-
*/
|
|
13
|
-
export type FormatDateOptions = {
|
|
14
|
-
/**
|
|
15
|
-
* Which locale to format the date string for (default `'en-US'`)
|
|
16
|
-
*/
|
|
17
|
-
locale?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Whether to display the date in the browser's local time zone.
|
|
20
|
-
* Default is `false`, displaying the dates in UTC.
|
|
21
|
-
*/
|
|
22
|
-
useLocalTime?: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export function formatDate(
|
|
26
|
-
date: Date | undefined,
|
|
27
|
-
format: DateFormat = 'short',
|
|
28
|
-
{ locale = 'en-US', useLocalTime = false }: FormatDateOptions = {},
|
|
29
|
-
): string {
|
|
30
|
-
// Return blank if undefined
|
|
31
|
-
if (!date) return '';
|
|
32
|
-
|
|
33
|
-
// The dates provided by the backend are assumed to already be with respect to UTC,
|
|
34
|
-
// and by default we specify that they should be rendered as such. If the
|
|
35
|
-
// `useLocalTime` option was set, we omit the UTC time zone from our format options
|
|
36
|
-
// so that the browser's local time zone is used instead.
|
|
37
|
-
const options: Intl.DateTimeFormatOptions = useLocalTime
|
|
38
|
-
? {}
|
|
39
|
-
: { timeZone: 'UTC' };
|
|
40
|
-
|
|
41
|
-
switch (format) {
|
|
42
|
-
case 'year-only':
|
|
43
|
-
// If we're only using the year, ensure we output the correct UTC year and not
|
|
44
|
-
// the local year. If the local timezone is used, we can get strange off-by-one
|
|
45
|
-
// errors due to quirks of timezone handling for older years.
|
|
46
|
-
return `${date.getUTCFullYear()}`;
|
|
47
|
-
case 'short':
|
|
48
|
-
options.month = 'short';
|
|
49
|
-
options.year = 'numeric';
|
|
50
|
-
break;
|
|
51
|
-
case 'long':
|
|
52
|
-
options.year = 'numeric';
|
|
53
|
-
options.month = 'short';
|
|
54
|
-
options.day = '2-digit';
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const dateFormatter = new Intl.DateTimeFormat(locale, options);
|
|
61
|
-
return dateFormatter.format(date);
|
|
62
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* Display date
|
|
3
|
+
* Override browser timezone to always display same date as in data
|
|
4
|
+
*/
|
|
5
|
+
export type DateFormat =
|
|
6
|
+
| 'year-only' // 2020
|
|
7
|
+
| 'short' // Dec 2020
|
|
8
|
+
| 'long'; // Dec 20, 2020
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Extra options accepted by the `formatDate` function
|
|
12
|
+
*/
|
|
13
|
+
export type FormatDateOptions = {
|
|
14
|
+
/**
|
|
15
|
+
* Which locale to format the date string for (default `'en-US'`)
|
|
16
|
+
*/
|
|
17
|
+
locale?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to display the date in the browser's local time zone.
|
|
20
|
+
* Default is `false`, displaying the dates in UTC.
|
|
21
|
+
*/
|
|
22
|
+
useLocalTime?: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function formatDate(
|
|
26
|
+
date: Date | undefined,
|
|
27
|
+
format: DateFormat = 'short',
|
|
28
|
+
{ locale = 'en-US', useLocalTime = false }: FormatDateOptions = {},
|
|
29
|
+
): string {
|
|
30
|
+
// Return blank if undefined
|
|
31
|
+
if (!date) return '';
|
|
32
|
+
|
|
33
|
+
// The dates provided by the backend are assumed to already be with respect to UTC,
|
|
34
|
+
// and by default we specify that they should be rendered as such. If the
|
|
35
|
+
// `useLocalTime` option was set, we omit the UTC time zone from our format options
|
|
36
|
+
// so that the browser's local time zone is used instead.
|
|
37
|
+
const options: Intl.DateTimeFormatOptions = useLocalTime
|
|
38
|
+
? {}
|
|
39
|
+
: { timeZone: 'UTC' };
|
|
40
|
+
|
|
41
|
+
switch (format) {
|
|
42
|
+
case 'year-only':
|
|
43
|
+
// If we're only using the year, ensure we output the correct UTC year and not
|
|
44
|
+
// the local year. If the local timezone is used, we can get strange off-by-one
|
|
45
|
+
// errors due to quirks of timezone handling for older years.
|
|
46
|
+
return `${date.getUTCFullYear()}`;
|
|
47
|
+
case 'short':
|
|
48
|
+
options.month = 'short';
|
|
49
|
+
options.year = 'numeric';
|
|
50
|
+
break;
|
|
51
|
+
case 'long':
|
|
52
|
+
options.year = 'numeric';
|
|
53
|
+
options.month = 'short';
|
|
54
|
+
options.day = '2-digit';
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const dateFormatter = new Intl.DateTimeFormat(locale, options);
|
|
61
|
+
return dateFormatter.format(date);
|
|
62
|
+
}
|