@internetarchive/collection-browser 4.1.0 → 4.1.1-alpha-webdev8185.1

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 -18
  5. package/dist/src/collection-browser.js +779 -838
  6. package/dist/src/collection-browser.js.map +1 -1
  7. package/dist/src/data-source/collection-browser-data-source.js +2 -3
  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 -3
  10. package/dist/src/data-source/collection-browser-query-state.js.map +1 -1
  11. package/dist/src/models.d.ts +27 -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 +204 -206
  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 +3001 -3070
  24. package/src/data-source/collection-browser-data-source.ts +1443 -1444
  25. package/src/data-source/collection-browser-query-state.ts +69 -60
  26. package/src/models.ts +53 -4
  27. package/src/sort-filter-bar/sort-filter-bar.ts +732 -733
  28. package/test/collection-browser.test.ts +2400 -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,69 @@
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
+ emitCollectionExtraInfoLoaded(
63
+ collectionExtraInfo?: CollectionExtraInfo,
64
+ ): void;
65
+ emitEmptyResults(): void;
66
+ emitSearchError(): void;
67
+ emitQueryStateChanged(): void;
68
+ refreshVisibleResults(): void;
69
+ }
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,16 @@ export enum SortField {
322
323
  'creator' = 'creator',
323
324
  }
324
325
 
326
+ /**
327
+ * A sort field other than the abstract "default" placeholder.
328
+ * This is useful because the "default" sort field is just an indicator to
329
+ * revert to an explicitly defined fallback value. So when defining default
330
+ * sort logic, this type should be preferred to avoid accidentally permitting
331
+ * that fallback to itself equal the "default" placeholder (which would be
332
+ * rather circular/ill-defined).
333
+ */
334
+ export type ExplicitSortField = Exclude<SortField, SortField.default>;
335
+
325
336
  /**
326
337
  * Views-related sort fields
327
338
  */
@@ -553,6 +564,47 @@ export function sortOptionFromAPIString(sortName?: string | null): SortOption {
553
564
  );
554
565
  }
555
566
 
567
+ /**
568
+ * Resolves the default sort option for a collection based on its metadata.
569
+ *
570
+ * - Favorite collections (`fav-*`) default to Date Favorited descending.
571
+ * - Other collections default to Weekly Views descending.
572
+ * - If the collection metadata specifies a `sort-by` field, that overrides the above.
573
+ *
574
+ * Supports both `-field` (dash prefix = desc) and `field:dir` metadata formats.
575
+ *
576
+ * Note: This does NOT handle the "relevance when a query is present" rule,
577
+ * which is managed separately by collection-browser itself.
578
+ */
579
+ export function resolveCollectionDefaultSort(
580
+ collectionInfo?: CollectionExtraInfo,
581
+ ): { field: ExplicitSortField; direction: SortDirection } {
582
+ const isFav = collectionInfo?.public_metadata?.identifier?.startsWith('fav-');
583
+ const baseDefaultSort: string = isFav ? '-favoritedate' : '-week';
584
+ const metadataSort: string | undefined =
585
+ collectionInfo?.public_metadata?.['sort-by'];
586
+ const defaultSortToApply = metadataSort ?? baseDefaultSort;
587
+
588
+ // Account for both -field and field:dir formats
589
+ let [field, dir] = defaultSortToApply.split(':');
590
+ if (field.startsWith('-')) {
591
+ field = field.slice(1);
592
+ dir = 'desc';
593
+ } else if (!['asc', 'desc'].includes(dir)) {
594
+ dir = 'asc';
595
+ }
596
+
597
+ const sortOption = sortOptionFromAPIString(field);
598
+ const sortField = sortOption.field;
599
+ if (sortField && sortField !== SortField.default) {
600
+ return {
601
+ field: sortField as ExplicitSortField,
602
+ direction: dir as SortDirection,
603
+ };
604
+ }
605
+ return { field: SortField.weeklyview, direction: 'desc' };
606
+ }
607
+
556
608
  export const defaultSortAvailability: Record<SortField, boolean> = {
557
609
  [SortField.relevance]: true,
558
610
  [SortField.weeklyview]: true,
@@ -580,10 +632,7 @@ export const tvSortAvailability: Record<SortField, boolean> = {
580
632
  [SortField.dateadded]: false,
581
633
  };
582
634
 
583
- export const defaultProfileElementSorts: Record<
584
- string,
585
- Exclude<SortField, SortField.default>
586
- > = {
635
+ export const defaultProfileElementSorts: Record<string, ExplicitSortField> = {
587
636
  uploads: SortField.datearchived,
588
637
  reviews: SortField.datereviewed,
589
638
  collections: SortField.datearchived,