qumra-engine 2.0.117 → 2.0.119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -21,14 +21,19 @@ exports.default = new (class WidgetExtension {
|
|
|
21
21
|
widgetPreview = env.getGlobal("widget");
|
|
22
22
|
}
|
|
23
23
|
let widgets = [];
|
|
24
|
+
let template = {};
|
|
24
25
|
if (!widgetPreview) {
|
|
25
|
-
|
|
26
|
+
const templates = env.getGlobal("templates");
|
|
27
|
+
template = templates.find((t) => t.key === "main");
|
|
28
|
+
widgets = template?.widgets || [];
|
|
26
29
|
}
|
|
27
30
|
else {
|
|
28
|
-
widgets = [
|
|
31
|
+
widgets = [
|
|
32
|
+
{
|
|
29
33
|
...widgetPreview,
|
|
30
34
|
widget: widgetPreview.widgetKey,
|
|
31
|
-
}
|
|
35
|
+
},
|
|
36
|
+
];
|
|
32
37
|
}
|
|
33
38
|
const renderedWidgets = [];
|
|
34
39
|
for (const widget of widgets) {
|
|
@@ -57,7 +62,7 @@ exports.default = new (class WidgetExtension {
|
|
|
57
62
|
}
|
|
58
63
|
if (isIframe) {
|
|
59
64
|
renderedWidgets.push(`
|
|
60
|
-
<section content-type="widget" widget-id="${widget._id}" id="qumra-widget-id-${widget._id}" template-key="main">
|
|
65
|
+
<section content-type="widget" widget-id="${widget._id}" id="qumra-widget-id-${widget._id}" template-key="main" template-id="${template._id}">
|
|
61
66
|
${html}
|
|
62
67
|
</section>
|
|
63
68
|
`);
|
|
@@ -388,6 +388,25 @@ exports.default = new (class SeoExtension {
|
|
|
388
388
|
</script>
|
|
389
389
|
|
|
390
390
|
|
|
391
|
+
<script>
|
|
392
|
+
// الاستماع لأي رسائل جاية من الـ parent
|
|
393
|
+
window.addEventListener("message", (event) => {
|
|
394
|
+
// يفضل تتحقق من الـ origin لو عايز أمان أكتر
|
|
395
|
+
// if (event.origin !== "https://dashboard.qumra.cloud") return;
|
|
396
|
+
|
|
397
|
+
const data = event.data;
|
|
398
|
+
|
|
399
|
+
if (data?.type === "reRender") {
|
|
400
|
+
console.log("📩 تم استقبال رسالة إعادة الرندر:", data);
|
|
401
|
+
// هنا تقدر تنفذ أي كود لإعادة الرندر أو تحديث الصفحة
|
|
402
|
+
// مثلا:
|
|
403
|
+
// location.reload();
|
|
404
|
+
} else {
|
|
405
|
+
console.log("📩 رسالة وصلت:", data);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
</script>
|
|
409
|
+
|
|
391
410
|
<script>
|
|
392
411
|
window.addEventListener("message", (event) => {
|
|
393
412
|
// لو عايز تتحقق من الـ origin:
|
|
@@ -7,9 +7,34 @@ const renderMiddleware = (req, res, next) => {
|
|
|
7
7
|
const render = res.locals.render;
|
|
8
8
|
const { context, globals, engine } = render;
|
|
9
9
|
const jsonPreview = req.query?.jsonPreview ?? null;
|
|
10
|
+
const widgetId = req.query?.widgetId ?? null;
|
|
10
11
|
(0, globals_1.setGlobal)("injectionCode", engine?.injectionCode);
|
|
11
12
|
const env = res.locals.env;
|
|
12
13
|
const pageLayout = env.getGlobal("pageData").layout ?? "layout";
|
|
14
|
+
console.log("🚀 ~ renderMiddleware ~ widgetId:", widgetId);
|
|
15
|
+
console.log("🚀 ~ renderMiddleware ~ jsonPreview:", jsonPreview);
|
|
16
|
+
if (widgetId && jsonPreview === "true") {
|
|
17
|
+
const overrideLayout = `{% content %}`;
|
|
18
|
+
env.renderString(overrideLayout, (0, resolveTranslations_1.resolveTranslations)({
|
|
19
|
+
context,
|
|
20
|
+
globals,
|
|
21
|
+
settings: env.getGlobal("settings"),
|
|
22
|
+
}, env.getGlobal("t")), (err, html) => {
|
|
23
|
+
console.log("🚀 ~ renderMiddleware ~ html:", html);
|
|
24
|
+
if (err) {
|
|
25
|
+
return next(new Error(`❌ Nunjucks render error: ${err.message}`));
|
|
26
|
+
}
|
|
27
|
+
if (!html) {
|
|
28
|
+
return next(new Error("❌ Nunjucks rendered null HTML"));
|
|
29
|
+
}
|
|
30
|
+
if (jsonPreview === "true") {
|
|
31
|
+
res.status(200).json({ html });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
res.send(html);
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
13
38
|
env.render(`layouts/${pageLayout}.njk`, (0, resolveTranslations_1.resolveTranslations)({
|
|
14
39
|
context,
|
|
15
40
|
globals,
|