Skip to content

Commit c9b9f0b

Browse files
committed
Fixes
1 parent 0734bef commit c9b9f0b

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"workspaces": {
3535
"packages": ["packages/*"],
3636
"catalog": {
37-
"@gitbook/api": "^0.138.0",
37+
"@gitbook/api": "^0.139.0",
3838
"bidc": "^0.0.2"
3939
}
4040
},

packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Image } from '@/components/utils';
33
import { type ResolvedContentRef, resolveContentRef } from '@/lib/references';
44
import { tcls } from '@/lib/tailwind';
55
import {
6+
type CardsImageObjectFit,
67
type ContentRef,
78
type DocumentTableViewCards,
89
SiteInsightsLinkPosition,
@@ -39,6 +40,14 @@ export async function RecordCard(
3940
const darkCoverIsSquareOrPortrait = isSquareOrPortrait(darkCover);
4041
const lightCoverIsSquareOrPortrait = isSquareOrPortrait(lightCover);
4142

43+
const darkObjectFit = dark.objectFit
44+
? `dark:${getObjectFitClass(dark.objectFit as CardsImageObjectFit)}`
45+
: '';
46+
const lightObjectFit = light.objectFit
47+
? getObjectFitClass(light.objectFit as CardsImageObjectFit)
48+
: '';
49+
const objectFits = `${lightObjectFit} ${darkObjectFit}`;
50+
4251
const body = (
4352
<div
4453
className={tcls(
@@ -99,11 +108,6 @@ export async function RecordCard(
99108
'w-full',
100109
'h-full',
101110
'bg-tint-subtle',
102-
getObjectFitClass(light.objectFit),
103-
// Apply dark mode object-fit if different from light
104-
dark.objectFit && dark.objectFit !== light.objectFit
105-
? `dark:${getObjectFitClass(dark.objectFit)}`
106-
: '',
107111
lightCoverIsSquareOrPortrait || darkCoverIsSquareOrPortrait
108112
? [
109113
lightCoverIsSquareOrPortrait
@@ -113,7 +117,8 @@ export async function RecordCard(
113117
? 'dark:min-[432px]:aspect-video dark:min-[432px]:h-auto'
114118
: '',
115119
].filter(Boolean)
116-
: ['h-auto', 'aspect-video']
120+
: ['h-auto', 'aspect-video'],
121+
objectFits
117122
)}
118123
priority={isOffscreen ? 'lazy' : 'high'}
119124
preload
@@ -203,13 +208,15 @@ function isSquareOrPortrait(contentRef: ResolvedContentRef | null) {
203208
/**
204209
* Get the CSS class for object-fit based on the objectFit value.
205210
*/
206-
function getObjectFitClass(objectFit?: string): string {
211+
function getObjectFitClass(objectFit?: CardsImageObjectFit): string {
207212
switch (objectFit) {
208213
case 'contain':
209214
return 'object-contain';
210215
case 'fill':
211216
return 'object-fill';
212-
default:
217+
case 'cover':
213218
return 'object-cover';
219+
default:
220+
throw new Error(`Unsupported object fit: ${objectFit}`);
214221
}
215222
}

packages/gitbook/src/components/DocumentView/Table/utils.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,10 @@ import type {
33
ContentRefFile,
44
ContentRefURL,
55
DocumentTableDefinition,
6+
DocumentTableImageRecord,
67
DocumentTableRecord,
78
DocumentTableViewCards,
89
} from '@gitbook/api';
9-
10-
/**
11-
* Cover value can be either a direct ContentRef or an object with objectFit and ref
12-
*/
13-
export type CoverValue =
14-
| ContentRefFile
15-
| ContentRefURL
16-
| {
17-
objectFit: string;
18-
ref: ContentRefFile | ContentRefURL;
19-
};
2010
import assertNever from 'assert-never';
2111

2212
/**
@@ -46,11 +36,11 @@ export function getRecordCardCovers(
4636
};
4737
} {
4838
const lightValue = view.coverDefinition
49-
? (getRecordValue(record, view.coverDefinition) as CoverValue | string[])
39+
? (getRecordValue(record, view.coverDefinition) as DocumentTableImageRecord | string[])
5040
: null;
5141

5242
const darkValue = view.coverDefinitionDark
53-
? (getRecordValue(record, view.coverDefinitionDark) as CoverValue)
43+
? (getRecordValue(record, view.coverDefinitionDark) as DocumentTableImageRecord)
5444
: null;
5545

5646
return {
@@ -62,7 +52,7 @@ export function getRecordCardCovers(
6252
/**
6353
* Process a cover value and return the content ref and object fit.
6454
*/
65-
function processCoverValue(value: CoverValue | string[] | null | undefined): {
55+
function processCoverValue(value: DocumentTableImageRecord | string[] | null | undefined): {
6656
contentRef: ContentRefFile | ContentRefURL | null;
6757
objectFit?: string;
6858
} {

0 commit comments

Comments
 (0)