import React, { Suspense } from 'react';
import { Box, Text, TextButton } from '@wix/design-system';
import { Confirm, Minus } from '@wix/wix-ui-icons-common';
import type { PatternsFieldType } from '@wix/bex-core';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { observer } from 'mobx-react-lite';
import type { CellAddressViewProps } from '@wix/patterns-fields';
import type { WixCodeGalleryItem } from '@wix/patterns-fields/auto-field-types';
import { getDateWithoutTimezone } from '../../utils/datesUtil';
// Cell renderers live in @wix/patterns-fields, which statically pulls the
// rich-text editor (Ricos/draft-js) and media SDKs. Importing them eagerly put
// that weight into every bundle that renders a source column (DataExtension,
// CMS, the tables). Loading them lazily moves it into an async chunk fetched
// only when a cell of one of these types first renders. The light types in the
// switch below stay inline (WDS only) and ship nothing extra.
function lazyCell
(
pick: (m: typeof import('@wix/patterns-fields')) => React.ComponentType
,
) {
const C = React.lazy(async () => ({
default: pick(await import('@wix/patterns-fields')),
}));
return (props: P) => (
);
}
const CellAddressView = lazyCell((m) => m.CellAddressView);
const CellAudioView = lazyCell((m) => m.CellAudioView);
const CellColorView = lazyCell((m) => m.CellColorView);
const CellDocumentView = lazyCell((m) => m.CellDocumentView);
const CellMediaGalleryView = lazyCell((m) => m.CellMediaGalleryView);
const CellMultiDocumentView = lazyCell((m) => m.CellMultiDocumentView);
const CellRichContentView = lazyCell((m) => m.CellRichContentView);
const CellRichTextView = lazyCell((m) => m.CellRichTextView);
const ImageView = lazyCell((m) => m.ImageView);
const JsonView = lazyCell((m) => m.JsonView);
export interface FieldCellProps {
value?: unknown;
type: PatternsFieldType;
/** Stable id for cells that render WDS Tags (document, multi-document). */
fieldId?: string;
}
function _FieldCell(props: FieldCellProps) {
const { dateFormatters } = useWixPatternsContainer();
switch (props.type) {
case 'LONG_TEXT':
return (
{props.value as React.ReactNode}
);
case 'DATE':
return (
{props.value
? dateFormatters.medium.format(
getDateWithoutTimezone(props.value as string),
)
: null}
);
case 'DATETIME':
return (
{props.value
? dateFormatters.mediumTime.format(new Date(props.value as string))
: null}
);
case 'BOOLEAN':
return (
{props.value ? : }
);
case 'URL':
return (
{props.value as React.ReactNode}
);
case 'IMAGE':
return (
);
case 'VIDEO':
return (
);
case 'AUDIO':
return (
);
case 'MEDIA_GALLERY':
return (
);
case 'DOCUMENT':
return (
);
case 'MULTI_DOCUMENT':
return (
);
case 'ARRAY':
return (
{(props.value as unknown[] | undefined)?.join?.(', ')}
);
case 'ADDRESS':
return (
);
case 'RICH_TEXT':
return ;
case 'RICH_CONTENT':
return ;
case 'COLOR':
return ;
case 'OBJECT':
return ;
default:
return (
{props.value as React.ReactNode}
);
}
}
export const FieldCell = observer(_FieldCell);