@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.
Files changed (30) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/collection-browser.d.ts +9 -2
  5. package/dist/src/collection-browser.js +778 -761
  6. package/dist/src/collection-browser.js.map +1 -1
  7. package/dist/src/data-source/collection-browser-data-source.js +1 -0
  8. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  9. package/dist/src/data-source/collection-browser-query-state.d.ts +5 -2
  10. package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
  11. package/dist/src/models.d.ts +20 -2
  12. package/dist/src/models.js +36 -0
  13. package/dist/src/models.js.map +1 -1
  14. package/dist/src/sort-filter-bar/sort-filter-bar.d.ts +2 -2
  15. package/dist/src/sort-filter-bar/sort-filter-bar.js +280 -280
  16. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  17. package/dist/test/collection-browser.test.js +189 -189
  18. package/dist/test/collection-browser.test.js.map +1 -1
  19. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +22 -22
  20. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  21. package/index.ts +5 -0
  22. package/package.json +1 -1
  23. package/src/collection-browser.ts +3091 -3070
  24. package/src/data-source/collection-browser-data-source.ts +1445 -1444
  25. package/src/data-source/collection-browser-query-state.ts +70 -60
  26. package/src/models.ts +46 -4
  27. package/src/sort-filter-bar/sort-filter-bar.ts +732 -733
  28. package/test/collection-browser.test.ts +2402 -2402
  29. package/test/sort-filter-bar/sort-filter-bar.test.ts +443 -443
  30. 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 { FacetLoadStrategy, SelectedFacets, SortField } from '../models';
10
- import type { CollectionBrowserDataSourceInterface } from './collection-browser-data-source-interface';
11
-
12
- /**
13
- * Properties of collection browser that affect the overall search query
14
- */
15
- export interface CollectionBrowserQueryState {
16
- baseQuery?: string;
17
- identifiers?: string[];
18
- withinCollection?: string;
19
- withinProfile?: string;
20
- profileElement?: PageElementName;
21
- searchType: SearchType;
22
- selectedFacets?: SelectedFacets;
23
- internalFilters?: SelectedFacets;
24
- minSelectedDate?: string;
25
- maxSelectedDate?: string;
26
- selectedTitleFilter: string | null;
27
- selectedCreatorFilter: string | null;
28
- selectedSort?: SortField;
29
- sortDirection: SortDirection | null;
30
- }
31
-
32
- /**
33
- * Interface representing search-related state and operations required by the
34
- * data source on its host component.
35
- */
36
- export interface CollectionBrowserSearchInterface
37
- extends CollectionBrowserQueryState {
38
- searchService?: SearchServiceInterface;
39
- isTVCollection: boolean;
40
- readonly sortParam: SortParam | null;
41
- readonly defaultSortField: SortField | null;
42
- readonly defaultSortDirection: SortDirection | null;
43
- readonly facetLoadStrategy: FacetLoadStrategy;
44
- readonly initialPageNumber: number;
45
- readonly maxPagesToManage: number;
46
- readonly currentVisiblePageNumbers: number[];
47
- readonly clearResultsOnEmptyQuery?: boolean;
48
- readonly dataSource?: CollectionBrowserDataSourceInterface;
49
-
50
- getSessionId(): Promise<string>;
51
- setSearchResultsLoading(loading: boolean): void;
52
- setFacetsLoading(loading: boolean): void;
53
- setTotalResultCount(count: number): void;
54
- setTileCount(count: number): void;
55
- applyDefaultCollectionSort(collectionInfo?: CollectionExtraInfo): void;
56
- emitEmptyResults(): void;
57
- emitSearchError(): void;
58
- emitQueryStateChanged(): void;
59
- refreshVisibleResults(): void;
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,