@internetarchive/collection-browser 4.1.0 → 4.1.1-alpha-webdev8185.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/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/src/collection-browser.d.ts +9 -2
- package/dist/src/collection-browser.js +778 -761
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/data-source/collection-browser-data-source.js +1 -0
- package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
- package/dist/src/data-source/collection-browser-query-state.d.ts +5 -2
- package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
- package/dist/src/models.d.ts +20 -2
- package/dist/src/models.js +36 -0
- package/dist/src/models.js.map +1 -1
- package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +2 -2
- package/dist/src/sort-filter-bar/sort-filter-bar.js +280 -280
- package/dist/src/sort-filter-bar/sort-filter-bar.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/sort-filter-bar/sort-filter-bar.test.js +22 -22
- package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
- package/index.ts +5 -0
- package/package.json +1 -1
- package/src/collection-browser.ts +3091 -3070
- package/src/data-source/collection-browser-data-source.ts +1445 -1444
- package/src/data-source/collection-browser-query-state.ts +70 -60
- package/src/models.ts +46 -4
- package/src/sort-filter-bar/sort-filter-bar.ts +732 -733
- package/test/collection-browser.test.ts +2402 -2402
- package/test/sort-filter-bar/sort-filter-bar.test.ts +443 -443
- package/.claude/settings.local.json +0 -8
|
@@ -1,60 +1,70 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CollectionExtraInfo,
|
|
3
|
-
PageElementName,
|
|
4
|
-
SearchServiceInterface,
|
|
5
|
-
SearchType,
|
|
6
|
-
SortDirection,
|
|
7
|
-
SortParam,
|
|
8
|
-
} from '@internetarchive/search-service';
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
readonly
|
|
48
|
-
readonly
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
import type {
|
|
2
|
+
CollectionExtraInfo,
|
|
3
|
+
PageElementName,
|
|
4
|
+
SearchServiceInterface,
|
|
5
|
+
SearchType,
|
|
6
|
+
SortDirection,
|
|
7
|
+
SortParam,
|
|
8
|
+
} from '@internetarchive/search-service';
|
|
9
|
+
import type {
|
|
10
|
+
ExplicitSortField,
|
|
11
|
+
FacetLoadStrategy,
|
|
12
|
+
SelectedFacets,
|
|
13
|
+
SortField,
|
|
14
|
+
} from '../models';
|
|
15
|
+
import type { CollectionBrowserDataSourceInterface } from './collection-browser-data-source-interface';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Properties of collection browser that affect the overall search query
|
|
19
|
+
*/
|
|
20
|
+
export interface CollectionBrowserQueryState {
|
|
21
|
+
baseQuery?: string;
|
|
22
|
+
identifiers?: string[];
|
|
23
|
+
withinCollection?: string;
|
|
24
|
+
withinProfile?: string;
|
|
25
|
+
profileElement?: PageElementName;
|
|
26
|
+
searchType: SearchType;
|
|
27
|
+
selectedFacets?: SelectedFacets;
|
|
28
|
+
internalFilters?: SelectedFacets;
|
|
29
|
+
minSelectedDate?: string;
|
|
30
|
+
maxSelectedDate?: string;
|
|
31
|
+
selectedTitleFilter: string | null;
|
|
32
|
+
selectedCreatorFilter: string | null;
|
|
33
|
+
selectedSort?: SortField;
|
|
34
|
+
sortDirection: SortDirection | null;
|
|
35
|
+
defaultSortField?: ExplicitSortField;
|
|
36
|
+
defaultSortDirection?: SortDirection | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Interface representing search-related state and operations required by the
|
|
41
|
+
* data source on its host component.
|
|
42
|
+
*/
|
|
43
|
+
export interface CollectionBrowserSearchInterface
|
|
44
|
+
extends CollectionBrowserQueryState {
|
|
45
|
+
searchService?: SearchServiceInterface;
|
|
46
|
+
isTVCollection: boolean;
|
|
47
|
+
readonly sortParam: SortParam | null;
|
|
48
|
+
readonly defaultSortField: ExplicitSortField;
|
|
49
|
+
readonly defaultSortDirection: SortDirection | null;
|
|
50
|
+
readonly facetLoadStrategy: FacetLoadStrategy;
|
|
51
|
+
readonly initialPageNumber: number;
|
|
52
|
+
readonly maxPagesToManage: number;
|
|
53
|
+
readonly currentVisiblePageNumbers: number[];
|
|
54
|
+
readonly clearResultsOnEmptyQuery?: boolean;
|
|
55
|
+
readonly dataSource?: CollectionBrowserDataSourceInterface;
|
|
56
|
+
|
|
57
|
+
getSessionId(): Promise<string>;
|
|
58
|
+
setSearchResultsLoading(loading: boolean): void;
|
|
59
|
+
setFacetsLoading(loading: boolean): void;
|
|
60
|
+
setTotalResultCount(count: number): void;
|
|
61
|
+
setTileCount(count: number): void;
|
|
62
|
+
applyDefaultCollectionSort(collectionInfo?: CollectionExtraInfo): void;
|
|
63
|
+
emitCollectionExtraInfoLoaded(
|
|
64
|
+
collectionExtraInfo?: CollectionExtraInfo,
|
|
65
|
+
): void;
|
|
66
|
+
emitEmptyResults(): void;
|
|
67
|
+
emitSearchError(): void;
|
|
68
|
+
emitQueryStateChanged(): void;
|
|
69
|
+
refreshVisibleResults(): void;
|
|
70
|
+
}
|
package/src/models.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { msg } from '@lit/localize';
|
|
|
3
3
|
import type { MediaType } from '@internetarchive/field-parsers';
|
|
4
4
|
import {
|
|
5
5
|
AggregationSortType,
|
|
6
|
+
CollectionExtraInfo,
|
|
6
7
|
HitType,
|
|
7
8
|
SearchReview,
|
|
8
9
|
SearchResult,
|
|
@@ -322,6 +323,9 @@ export enum SortField {
|
|
|
322
323
|
'creator' = 'creator',
|
|
323
324
|
}
|
|
324
325
|
|
|
326
|
+
/** A sort field excluding the abstract "default" placeholder. */
|
|
327
|
+
export type ExplicitSortField = Exclude<SortField, SortField.default>;
|
|
328
|
+
|
|
325
329
|
/**
|
|
326
330
|
* Views-related sort fields
|
|
327
331
|
*/
|
|
@@ -553,6 +557,47 @@ export function sortOptionFromAPIString(sortName?: string | null): SortOption {
|
|
|
553
557
|
);
|
|
554
558
|
}
|
|
555
559
|
|
|
560
|
+
/**
|
|
561
|
+
* Resolves the default sort option for a collection based on its metadata.
|
|
562
|
+
*
|
|
563
|
+
* - Favorite collections (`fav-*`) default to Date Favorited descending.
|
|
564
|
+
* - Other collections default to Weekly Views descending.
|
|
565
|
+
* - If the collection metadata specifies a `sort-by` field, that overrides the above.
|
|
566
|
+
*
|
|
567
|
+
* Supports both `-field` (dash prefix = desc) and `field:dir` metadata formats.
|
|
568
|
+
*
|
|
569
|
+
* Note: This does NOT handle the "relevance when a query is present" rule,
|
|
570
|
+
* which is managed separately by collection-browser itself.
|
|
571
|
+
*/
|
|
572
|
+
export function resolveCollectionDefaultSort(
|
|
573
|
+
collectionInfo?: CollectionExtraInfo,
|
|
574
|
+
): { field: ExplicitSortField; direction: SortDirection } {
|
|
575
|
+
const isFav = collectionInfo?.public_metadata?.identifier?.startsWith('fav-');
|
|
576
|
+
const baseDefaultSort: string = isFav ? '-favoritedate' : '-week';
|
|
577
|
+
const metadataSort: string | undefined =
|
|
578
|
+
collectionInfo?.public_metadata?.['sort-by'];
|
|
579
|
+
const defaultSortToApply = metadataSort ?? baseDefaultSort;
|
|
580
|
+
|
|
581
|
+
// Account for both -field and field:dir formats
|
|
582
|
+
let [field, dir] = defaultSortToApply.split(':');
|
|
583
|
+
if (field.startsWith('-')) {
|
|
584
|
+
field = field.slice(1);
|
|
585
|
+
dir = 'desc';
|
|
586
|
+
} else if (!['asc', 'desc'].includes(dir)) {
|
|
587
|
+
dir = 'asc';
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const sortOption = sortOptionFromAPIString(field);
|
|
591
|
+
const sortField = sortOption.field;
|
|
592
|
+
if (sortField && sortField !== SortField.default) {
|
|
593
|
+
return {
|
|
594
|
+
field: sortField as ExplicitSortField,
|
|
595
|
+
direction: dir as SortDirection,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
return { field: SortField.weeklyview, direction: 'desc' };
|
|
599
|
+
}
|
|
600
|
+
|
|
556
601
|
export const defaultSortAvailability: Record<SortField, boolean> = {
|
|
557
602
|
[SortField.relevance]: true,
|
|
558
603
|
[SortField.weeklyview]: true,
|
|
@@ -580,10 +625,7 @@ export const tvSortAvailability: Record<SortField, boolean> = {
|
|
|
580
625
|
[SortField.dateadded]: false,
|
|
581
626
|
};
|
|
582
627
|
|
|
583
|
-
export const defaultProfileElementSorts: Record<
|
|
584
|
-
string,
|
|
585
|
-
Exclude<SortField, SortField.default>
|
|
586
|
-
> = {
|
|
628
|
+
export const defaultProfileElementSorts: Record<string, ExplicitSortField> = {
|
|
587
629
|
uploads: SortField.datearchived,
|
|
588
630
|
reviews: SortField.datereviewed,
|
|
589
631
|
collections: SortField.datearchived,
|