@@ -45,60 +45,53 @@ export function getRecordCardCovers(
45
45
objectFit ?: string ;
46
46
} ;
47
47
} {
48
+ const lightValue = view . coverDefinition
49
+ ? ( getRecordValue ( record , view . coverDefinition ) as CoverValue | string [ ] )
50
+ : null ;
51
+
52
+ const darkValue = view . coverDefinitionDark
53
+ ? ( getRecordValue ( record , view . coverDefinitionDark ) as CoverValue )
54
+ : null ;
55
+
48
56
return {
49
- light : ( ( ) => {
50
- if ( ! view . coverDefinition ) {
51
- return { contentRef : null } ;
52
- }
53
-
54
- const value = getRecordValue ( record , view . coverDefinition ) as CoverValue | string [ ] ;
55
-
56
- if ( Array . isArray ( value ) ) {
57
- if ( value . length === 0 ) {
58
- return { contentRef : null } ;
59
- }
60
-
61
- if ( typeof value [ 0 ] === 'string' ) {
62
- return { contentRef : { kind : 'file' , file : value [ 0 ] } } ;
63
- }
64
- }
65
-
66
- // Check if it's the new schema with objectFit
67
- if ( value && typeof value === 'object' && 'ref' in value && 'objectFit' in value ) {
68
- return {
69
- contentRef : value . ref ,
70
- objectFit : value . objectFit ,
71
- } ;
72
- }
73
-
74
- // It's a direct ContentRef
75
- return { contentRef : value as ContentRefFile | ContentRefURL } ;
76
- } ) ( ) ,
77
- dark : ( ( ) => {
78
- if ( ! view . coverDefinitionDark ) {
79
- return { contentRef : null } ;
80
- }
81
-
82
- const value = getRecordValue ( record , view . coverDefinitionDark ) as CoverValue ;
83
-
84
- if ( ! value ) {
85
- return { contentRef : null } ;
86
- }
87
-
88
- // Check if it's the new schema with objectFit
89
- if ( typeof value === 'object' && 'ref' in value && 'objectFit' in value ) {
90
- return {
91
- contentRef : value . ref ,
92
- objectFit : value . objectFit ,
93
- } ;
94
- }
95
-
96
- // It's a direct ContentRef
97
- return { contentRef : value as ContentRefFile | ContentRefURL } ;
98
- } ) ( ) ,
57
+ light : processCoverValue ( lightValue ) ,
58
+ dark : processCoverValue ( darkValue ) ,
99
59
} ;
100
60
}
101
61
62
+ /**
63
+ * Process a cover value and return the content ref and object fit.
64
+ */
65
+ function processCoverValue ( value : CoverValue | string [ ] | null | undefined ) : {
66
+ contentRef : ContentRefFile | ContentRefURL | null ;
67
+ objectFit ?: string ;
68
+ } {
69
+ if ( ! value ) {
70
+ return { contentRef : null } ;
71
+ }
72
+
73
+ if ( Array . isArray ( value ) ) {
74
+ if ( value . length === 0 ) {
75
+ return { contentRef : null } ;
76
+ }
77
+
78
+ if ( typeof value [ 0 ] === 'string' ) {
79
+ return { contentRef : { kind : 'file' , file : value [ 0 ] } } ;
80
+ }
81
+ }
82
+
83
+ // Check if it's the new schema with objectFit
84
+ if ( value && typeof value === 'object' && 'ref' in value && 'objectFit' in value ) {
85
+ return {
86
+ contentRef : value . ref ,
87
+ objectFit : value . objectFit ,
88
+ } ;
89
+ }
90
+
91
+ // It's a direct ContentRef
92
+ return { contentRef : value as ContentRefFile | ContentRefURL } ;
93
+ }
94
+
102
95
/**
103
96
* Get the text alignment for a column.
104
97
*/
0 commit comments