@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.
45 lines (44 loc) • 2.13 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { RenderWidgetService } from '../../services/render-widget-service';
import { Tracer } from '@progress/sitefinity-nextjs-sdk/diagnostics/empty';
import { RenderViewClient } from './render-view-client';
/**
* If there is custom view it will be rendered. If there is not the children of this component will be rendered
*
* @param {string | undefined} viewName - Used to identify the custom view.
* @param {string} widgetKey - Used in the widget registry as a property name.
* @param {ReactNode} children - The children of the component. Used as a fallback if there is no custom view.
* @param {any} viewProps - Props that are used for the view component.
* @param {any} traceSpan Required param for the trace functionality.
*
* @returns {ReactNode} - The view for the widget.
*/
export function RenderView({ viewName, widgetKey, children, viewProps, traceSpan }) {
let views = RenderWidgetService.widgetRegistry.widgets[widgetKey]?.views || {};
// Fallback for deprecated 'templates' props. Remove this code once the prop is removed.
if (RenderWidgetService.widgetRegistry.widgets[widgetKey]?.templates) {
views = { ...views, ...RenderWidgetService.widgetRegistry.widgets[widgetKey]?.templates };
}
let widgetView = children;
let renderClient = false;
let widgetViewFunction = null;
if (views && viewName && views[viewName]) {
const view = views[viewName];
if (typeof view === 'object' && view.ViewFunction) {
widgetViewFunction = view.ViewFunction;
}
else {
const viewFunction = views[viewName];
widgetViewFunction = viewFunction;
}
if (widgetViewFunction.$$typeof) {
renderClient = true;
}
else {
widgetView = widgetViewFunction(viewProps);
}
}
return (_jsxs(_Fragment, { children: [!renderClient ?
widgetView :
_jsx(RenderViewClient, { viewName, viewProps, widgetKey }), traceSpan && Tracer.endSpan(traceSpan)] }));
}