-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
executable file
·39 lines (36 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const components = require('../index');
module.exports = function (input, out) {
const slotData = input.slotData;
const slotName = input.slotName;
const template = slotData.template;
const widgetsMap = slotData.widgetsMap;
const widgetId = getWidgetId(template, slotName);
if (!widgetId || !widgetsMap[widgetId]) {
console.error(`No widget found for slotName=${slotName}`);
return;
}
const widgetObject = widgetsMap[widgetId];
if (widgetObject.componentId === 'load-slot' || widgetObject.componentId === 'load-component') {
throw new Error('slot widget can not be loaded dynamically');
}
const widgetAttributes = Object.assign(widgetObject.attributes || {}, slotData);
if (!components[widgetObject.componentId]) {
// console.error(widgetObject.componentId, "component doesn't exist");
return;
} else {
out.write(`<div class='${slotName}'>`);
out.write(`<div class='${widgetObject.componentId}'>`);
components[widgetObject.componentId]
.render(widgetAttributes, out)
.catch((err) => {
console.error(`Error occurred while rendering widgetName=${widgetObject.componentId}`, err);
});
out.write('</div>');
out.write('</div>');
}
};
function getWidgetId(template, slotName) {
if (template && template.widgetConfig && template.widgetConfig[slotName]) {
return template.widgetConfig[slotName];
}
}