@progress/sitefinity-nextjs-sdk
Version:
Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.
117 lines (116 loc) • 5.24 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment } from 'react';
import { ListWithImageView } from './list-with-image/list-with-image.view';
import { ListWithSummaryView } from './list-with-summary/list-with-summary.view';
import { CardsListView } from './cards-list/cards-list.view';
import { RenderView } from '../../common/render-view';
export function ContentListMaster(props) {
let data = {};
const dataItems = props.items;
if (props.viewName === 'CardsList' || props.viewName === 'ListWithImage') {
const viewProps = {
attributes: props.attributes,
detailPageUrl: props.detailPageUrl,
widgetContext: props.widgetContext,
items: dataItems.Items.map((x) => {
let url;
const imageProp = x[props.fieldMap['Image']];
let image = null;
if (imageProp && imageProp.length > 0) {
image = imageProp[0];
if (image.Thumbnails && image.Thumbnails.length > 0) {
url = image.Thumbnails[0].Url;
}
else {
url = image.Url;
}
}
return {
Title: {
Value: x[props.fieldMap['Title']],
Css: (props.fieldCssClassMap['Title'] || ''),
Link: ''
},
Image: {
Title: image?.Title,
Url: url,
AlternativeText: image?.AlternativeText,
Css: props.fieldCssClassMap['Image']
},
Text: {
Value: x[props.fieldMap['Text']],
Css: `${props.fieldCssClassMap['Text'] || ''}`
},
Original: x
};
}),
totalCount: props.items.TotalCount,
pageNumber: props.pageNumber
};
data = { viewName: props.viewName, model: viewProps };
}
else if (props.viewName === 'ListWithSummary') {
const viewProps = {
attributes: props.attributes,
detailPageUrl: props.detailPageUrl,
widgetContext: props.widgetContext,
items: dataItems.Items.map((x) => {
const itemModel = {
Title: {
Value: x[props.fieldMap['Title']],
Css: (props.fieldCssClassMap['Title'] || ''),
Link: ''
},
PublicationDate: {
Value: x[props.fieldMap['Publication date']],
Css: props.fieldCssClassMap['Publication date']
},
Text: {
Value: x[props.fieldMap['Text']],
Css: `${props.fieldCssClassMap['Text'] || ''}`
},
Original: x
};
if (!itemModel.PublicationDate.Css) {
itemModel.PublicationDate.Css = '';
}
return itemModel;
}),
totalCount: props.items.TotalCount,
pageNumber: props.pageNumber
};
data = { viewName: props.viewName, model: viewProps };
}
else {
const fieldMap = props.fieldMap || {};
const fieldCssMap = props.fieldCssClassMap || {};
data = {
viewName: props.viewName,
model: {
attributes: props.attributes,
detailPageUrl: props.detailPageUrl,
widgetContext: props.widgetContext,
items: dataItems.Items.map(dataItem => {
const item = { Original: dataItem };
Object.keys(fieldMap).forEach(field => {
const key = field.split(' ').map(x => x.charAt(0).toUpperCase() + x.slice(1)).join('');
item[key] = {
Value: dataItem[fieldMap[field]],
Css: fieldCssMap[field]
};
});
return item;
}),
totalCount: props.items.TotalCount,
pageNumber: props.pageNumber
}
};
}
if (props.widgetContext.model.Properties.SelectedItems?.Content && props.widgetContext.model.Properties.SelectedItems?.Content.length > 0) {
data.model.type = props.widgetContext.model.Properties.SelectedItems?.Content[0].Type;
}
return (_jsx(RenderView, { viewName: props.viewName, widgetKey: props.widgetContext.model.Name, viewProps: data?.model, children: _jsxs(Fragment, { children: [(data?.model && data?.viewName === 'ListWithImage') &&
_jsx(ListWithImageView, { ...data?.model }), (data?.model && data?.viewName === 'ListWithSummary') &&
_jsx(ListWithSummaryView, { ...data?.model }), (data?.model && data?.viewName === 'CardsList') &&
_jsx(CardsListView, { ...data?.model })] }) }));
}