Skip to content

Commit 8108557

Browse files
committed
review fix
1 parent 1f49066 commit 8108557

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ import type { BlockProps } from '../Block';
1919
import { Blocks } from '../Blocks';
2020
import { FileIcon } from '../FileIcon';
2121
import type { TableRecordKV } from './Table';
22-
import { type VerticalAlignment, getColumnAlignment, isContentRef, isStringArray } from './utils';
22+
import {
23+
type VerticalAlignment,
24+
getColumnAlignment,
25+
isContentRef,
26+
isDocumentTableImageRecord,
27+
isStringArray,
28+
} from './utils';
2329

2430
const alignmentMap: Record<'text-left' | 'text-center' | 'text-right', string> = {
2531
'text-left': '**:text-left text-left',
@@ -355,12 +361,15 @@ export async function RecordColumnValue<Tag extends React.ElementType = 'div'>(
355361
);
356362
}
357363
case 'image': {
358-
if (!isContentRef(value)) {
364+
if (!isDocumentTableImageRecord(value)) {
359365
return null;
360366
}
361367

362368
const image = context.contentContext
363-
? await resolveContentRef(value, context.contentContext)
369+
? await resolveContentRef(
370+
'ref' in value ? value.ref : value,
371+
context.contentContext
372+
)
364373
: null;
365374

366375
if (!image) {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,17 @@ export function isContentRef(ref?: DocumentTableRecord['values'][string]): ref i
141141
export function isStringArray(value?: DocumentTableRecord['values'][string]): value is string[] {
142142
return Array.isArray(value) && value.every((v) => typeof v === 'string');
143143
}
144+
145+
/**
146+
* Check if a value is a DocumentTableImageRecord.
147+
* @param value The value to check.
148+
* @returns True if the value is a DocumentTableImageRecord, false otherwise.
149+
*/
150+
export function isDocumentTableImageRecord(
151+
value?: DocumentTableRecord['values'][string]
152+
): value is DocumentTableImageRecord {
153+
if (isContentRef(value) && (value.kind === 'file' || value.kind === 'url')) {
154+
return true;
155+
}
156+
return Boolean(value && typeof value === 'object' && 'ref' in value && isContentRef(value.ref));
157+
}

0 commit comments

Comments
 (0)